#include <LINK/basic/ElementOps.h>
#include <LINK/graph/Attribute.h>
#include <LINK/graph/BinGraph.h>
#include <LINK/graph/DBinGraph.h>
#include <LINK/graph/DHyperGraph.h>
#include <LINK/graph/Edge.h>
#include <LINK/graph/Graph.h>
#include <LINK/graph/HyperGraph.h>
#include <LINK/graph/UBinGraph.h>
#include <LINK/graph/UHyperGraph.h>
#include <LINK/graph/UBinGraph.h>
#include <LINK/graph/Buckets.h>
#include <LINK/graph/Vertex.h>
#include <LINK/graph/Attribute.h>
#include <LINK/basic/Container.h>
#include <LINK/basic/DJSet.h>
#include <LINK/graph/GraphObject.h>
#include <LINK/basic/DList.h>
#include <LINK/basic/randomPermutation.h>

typedef AttributeBase* _AttributeBasep;
typedef BinGraph* _BinGraphp;
typedef DBinGraph* _DBinGraphp;
typedef DHyperGraph* _DHyperGraphp;
typedef Edge* _Edgep;
typedef Graph* _Graphp;
typedef HyperGraph* _HyperGraphp;
typedef MBinGraph* _MBinGraphp;
typedef MDBinGraph* _MDBinGraphp;
typedef MDHyperGraph* _MDHyperGraphp;
typedef MHyperGraph* _MHyperGraphp;
typedef MUBinGraph* _MUBinGraphp;
typedef MUHyperGraph* _MUHyperGraphp;
typedef UBinGraph* _UBinGraphp;
typedef UHyperGraph* _UHyperGraphp;
typedef VertexInfo* _VertexInfop;
typedef Vertex* _Vertexp;
typedef Attribute<ContainerNode*>* _Attribute_ContainerNodep_p;
typedef Attribute<DJSet*>* _Attribute_DJSetp_p;
typedef Attribute<Edge*>* _Attribute_Edgep_p;
typedef Attribute<GraphObject*>* _Attribute_GraphObjectp_p;
typedef Attribute<Graph*>* _Attribute_Graphp_p;
typedef Attribute<Vertex*>* _Attribute_Vertexp_p;
typedef Attribute<char>* _Attribute_char_p;
typedef Attribute<char*>* _Attribute_charp_p;
typedef Attribute<double>* _Attribute_double_p;
typedef Attribute<float>* _Attribute_float_p;
typedef Attribute<int>* _Attribute_int_p;
typedef Set<Vertex*>* _Set_Vertexp_p;
typedef Attribute<DList<Vertex*>* >* _Attribute_DList_Vertexp_p_p;
typedef Attribute<List<Vertex*>* > * _Attribute_List_Vertexp_p_p;
typedef char* String;
typedef Vertex* VertexPtr;
typedef Edge* EdgePtr;

template void randomPermutation(Sequence<Vertex*>*, int);
template void randomPermutation(Set<Vertex*>*, int);
template void randomPermutation(Vertex**, int);

int ElementOps<_AttributeBasep>::compareItems(const _AttributeBasep& e1, const _AttributeBasep& e2) 
{
	if (e1 && e2)  {
		if (*e1 == *e2)
			return 0;
		else
			return (*e1<*e2)? -1 : 1;
	} else {
		if (e1 == e2)
			return 0;
		else
			return (e1<e2)? -1 : 1;
	}
}

ostream& ElementOps<_AttributeBasep>::displayItem(ostream& os, const _AttributeBasep& e)
{
	if (e)
		os << *e;
	else
		os << e;
	return os;
}
int ElementOps<_BinGraphp>::compareItems(const _BinGraphp& e1, const _BinGraphp& e2) 
{
	if (e1 && e2)  {
		if (*e1 == *e2)
			return 0;
		else
			return (*e1<*e2)? -1 : 1;
	} else {
		if (e1 == e2)
			return 0;
		else
			return (e1<e2)? -1 : 1;
	}
}

ostream& ElementOps<_BinGraphp>::displayItem(ostream& os, const _BinGraphp& e)
{
	if (e)
		os << *e;
	else
		os << e;
	return os;
}
int ElementOps<_DBinGraphp>::compareItems(const _DBinGraphp& e1, const _DBinGraphp& e2) 
{
	if (e1 && e2)  {
		if (*e1 == *e2)
			return 0;
		else
			return (*e1<*e2)? -1 : 1;
	} else {
		if (e1 == e2)
			return 0;
		else
			return (e1<e2)? -1 : 1;
	}
}

ostream& ElementOps<_DBinGraphp>::displayItem(ostream& os, const _DBinGraphp& e)
{
	if (e)
		os << *e;
	else
		os << e;
	return os;
}
int ElementOps<_DHyperGraphp>::compareItems(const _DHyperGraphp& e1, const _DHyperGraphp& e2) 
{
	if (e1 && e2)  {
		if (*e1 == *e2)
			return 0;
		else
			return (*e1<*e2)? -1 : 1;
	} else {
		if (e1 == e2)
			return 0;
		else
			return (e1<e2)? -1 : 1;
	}
}

ostream& ElementOps<_DHyperGraphp>::displayItem(ostream& os, const _DHyperGraphp& e)
{
	if (e)
		os << *e;
	else
		os << e;
	return os;
}
int ElementOps<_Edgep>::compareItems(const _Edgep& e1, const _Edgep& e2) 
{
	if (e1 && e2)  {
		if (*e1 == *e2)
			return 0;
		else
			return (*e1<*e2)? -1 : 1;
	} else {
		if (e1 == e2)
			return 0;
		else
			return (e1<e2)? -1 : 1;
	}
}

ostream& ElementOps<_Edgep>::displayItem(ostream& os, const _Edgep& e)
{
	if (e)
		os << *e;
	else
		os << e;
	return os;
}
int ElementOps<_Graphp>::compareItems(const _Graphp& e1, const _Graphp& e2) 
{
	if (e1 && e2)  {
		if (*e1 == *e2)
			return 0;
		else
			return (*e1<*e2)? -1 : 1;
	} else {
		if (e1 == e2)
			return 0;
		else
			return (e1<e2)? -1 : 1;
	}
}

ostream& ElementOps<_Graphp>::displayItem(ostream& os, const _Graphp& e)
{
	if (e)
		os << *e;
	else
		os << e;
	return os;
}
int ElementOps<_HyperGraphp>::compareItems(const _HyperGraphp& e1, const _HyperGraphp& e2) 
{
	if (e1 && e2)  {
		if (*e1 == *e2)
			return 0;
		else
			return (*e1<*e2)? -1 : 1;
	} else {
		if (e1 == e2)
			return 0;
		else
			return (e1<e2)? -1 : 1;
	}
}

ostream& ElementOps<_HyperGraphp>::displayItem(ostream& os, const _HyperGraphp& e)
{
	if (e)
		os << *e;
	else
		os << e;
	return os;
}
int ElementOps<_MBinGraphp>::compareItems(const _MBinGraphp& e1, const _MBinGraphp& e2) 
{
	if (e1 && e2)  {
		if (*e1 == *e2)
			return 0;
		else
			return (*e1<*e2)? -1 : 1;
	} else {
		if (e1 == e2)
			return 0;
		else
			return (e1<e2)? -1 : 1;
	}
}

ostream& ElementOps<_MBinGraphp>::displayItem(ostream& os, const _MBinGraphp& e)
{
	if (e)
		os << *e;
	else
		os << e;
	return os;
}
int ElementOps<_MDBinGraphp>::compareItems(const _MDBinGraphp& e1, const _MDBinGraphp& e2) 
{
	if (e1 && e2)  {
		if (*e1 == *e2)
			return 0;
		else
			return (*e1<*e2)? -1 : 1;
	} else {
		if (e1 == e2)
			return 0;
		else
			return (e1<e2)? -1 : 1;
	}
}

ostream& ElementOps<_MDBinGraphp>::displayItem(ostream& os, const _MDBinGraphp& e)
{
	if (e)
		os << *e;
	else
		os << e;
	return os;
}
int ElementOps<_MDHyperGraphp>::compareItems(const _MDHyperGraphp& e1, const _MDHyperGraphp& e2) 
{
	if (e1 && e2)  {
		if (*e1 == *e2)
			return 0;
		else
			return (*e1<*e2)? -1 : 1;
	} else {
		if (e1 == e2)
			return 0;
		else
			return (e1<e2)? -1 : 1;
	}
}

ostream& ElementOps<_MDHyperGraphp>::displayItem(ostream& os, const _MDHyperGraphp& e)
{
	if (e)
		os << *e;
	else
		os << e;
	return os;
}
int ElementOps<_MHyperGraphp>::compareItems(const _MHyperGraphp& e1, const _MHyperGraphp& e2) 
{
	if (e1 && e2)  {
		if (*e1 == *e2)
			return 0;
		else
			return (*e1<*e2)? -1 : 1;
	} else {
		if (e1 == e2)
			return 0;
		else
			return (e1<e2)? -1 : 1;
	}
}

ostream& ElementOps<_MHyperGraphp>::displayItem(ostream& os, const _MHyperGraphp& e)
{
	if (e)
		os << *e;
	else
		os << e;
	return os;
}
int ElementOps<_MUBinGraphp>::compareItems(const _MUBinGraphp& e1, const _MUBinGraphp& e2) 
{
	if (e1 && e2)  {
		if (*e1 == *e2)
			return 0;
		else
			return (*e1<*e2)? -1 : 1;
	} else {
		if (e1 == e2)
			return 0;
		else
			return (e1<e2)? -1 : 1;
	}
}

ostream& ElementOps<_MUBinGraphp>::displayItem(ostream& os, const _MUBinGraphp& e)
{
	if (e)
		os << *e;
	else
		os << e;
	return os;
}
int ElementOps<_MUHyperGraphp>::compareItems(const _MUHyperGraphp& e1, const _MUHyperGraphp& e2) 
{
	if (e1 && e2)  {
		if (*e1 == *e2)
			return 0;
		else
			return (*e1<*e2)? -1 : 1;
	} else {
		if (e1 == e2)
			return 0;
		else
			return (e1<e2)? -1 : 1;
	}
}

ostream& ElementOps<_MUHyperGraphp>::displayItem(ostream& os, const _MUHyperGraphp& e)
{
	if (e)
		os << *e;
	else
		os << e;
	return os;
}
int ElementOps<_UBinGraphp>::compareItems(const _UBinGraphp& e1, const _UBinGraphp& e2) 
{
	if (e1 && e2)  {
		if (*e1 == *e2)
			return 0;
		else
			return (*e1<*e2)? -1 : 1;
	} else {
		if (e1 == e2)
			return 0;
		else
			return (e1<e2)? -1 : 1;
	}
}

ostream& ElementOps<_UBinGraphp>::displayItem(ostream& os, const _UBinGraphp& e)
{
	if (e)
		os << *e;
	else
		os << e;
	return os;
}
int ElementOps<_UHyperGraphp>::compareItems(const _UHyperGraphp& e1, const _UHyperGraphp& e2) 
{
	if (e1 && e2)  {
		if (*e1 == *e2)
			return 0;
		else
			return (*e1<*e2)? -1 : 1;
	} else {
		if (e1 == e2)
			return 0;
		else
			return (e1<e2)? -1 : 1;
	}
}

ostream& ElementOps<_UHyperGraphp>::displayItem(ostream& os, const _UHyperGraphp& e)
{
	if (e)
		os << *e;
	else
		os << e;
	return os;
}
int ElementOps<_VertexInfop>::compareItems(const _VertexInfop& e1, const _VertexInfop& e2) 
{
	if (e1 && e2)  {
		if (*e1 == *e2)
			return 0;
		else
			return (*e1<*e2)? -1 : 1;
	} else {
		if (e1 == e2)
			return 0;
		else
			return (e1<e2)? -1 : 1;
	}
}

ostream& ElementOps<_VertexInfop>::displayItem(ostream& os, const _VertexInfop& e)
{
	if (e)
		os << *e;
	else
		os << e;
	return os;
}
int ElementOps<_Vertexp>::compareItems(const _Vertexp& e1, const _Vertexp& e2) 
{
	if (e1 && e2)  {
		if (*e1 == *e2)
			return 0;
		else
			return (*e1<*e2)? -1 : 1;
	} else {
		if (e1 == e2)
			return 0;
		else
			return (e1<e2)? -1 : 1;
	}
}

ostream& ElementOps<_Vertexp>::displayItem(ostream& os, const _Vertexp& e)
{
	if (e)
		os << *e;
	else
		os << e;
	return os;
}
int ElementOps<_Attribute_ContainerNodep_p>::compareItems(const _Attribute_ContainerNodep_p& e1, const _Attribute_ContainerNodep_p& e2) 
{
	if (e1 && e2)  {
		if (*e1 == *e2)
			return 0;
		else
			return (*e1<*e2)? -1 : 1;
	} else {
		if (e1 == e2)
			return 0;
		else
			return (e1<e2)? -1 : 1;
	}
}

ostream& ElementOps<_Attribute_ContainerNodep_p>::displayItem(ostream& os, const _Attribute_ContainerNodep_p& e)
{
	if (e)
		os << *e;
	else
		os << e;
	return os;
}
int ElementOps<_Attribute_DJSetp_p>::compareItems(const _Attribute_DJSetp_p& e1, const _Attribute_DJSetp_p& e2) 
{
	if (e1 && e2)  {
		if (*e1 == *e2)
			return 0;
		else
			return (*e1<*e2)? -1 : 1;
	} else {
		if (e1 == e2)
			return 0;
		else
			return (e1<e2)? -1 : 1;
	}
}

ostream& ElementOps<_Attribute_DJSetp_p>::displayItem(ostream& os, const _Attribute_DJSetp_p& e)
{
	if (e)
		os << *e;
	else
		os << e;
	return os;
}
int ElementOps<_Attribute_Edgep_p>::compareItems(const _Attribute_Edgep_p& e1, const _Attribute_Edgep_p& e2) 
{
	if (e1 && e2)  {
		if (*e1 == *e2)
			return 0;
		else
			return (*e1<*e2)? -1 : 1;
	} else {
		if (e1 == e2)
			return 0;
		else
			return (e1<e2)? -1 : 1;
	}
}

ostream& ElementOps<_Attribute_Edgep_p>::displayItem(ostream& os, const _Attribute_Edgep_p& e)
{
	if (e)
		os << *e;
	else
		os << e;
	return os;
}
int ElementOps<_Attribute_GraphObjectp_p>::compareItems(const _Attribute_GraphObjectp_p& e1, const _Attribute_GraphObjectp_p& e2) 
{
	if (e1 && e2)  {
		if (*e1 == *e2)
			return 0;
		else
			return (*e1<*e2)? -1 : 1;
	} else {
		if (e1 == e2)
			return 0;
		else
			return (e1<e2)? -1 : 1;
	}
}

ostream& ElementOps<_Attribute_GraphObjectp_p>::displayItem(ostream& os, const _Attribute_GraphObjectp_p& e)
{
	if (e)
		os << *e;
	else
		os << e;
	return os;
}
int ElementOps<_Attribute_Graphp_p>::compareItems(const _Attribute_Graphp_p& e1, const _Attribute_Graphp_p& e2) 
{
	if (e1 && e2)  {
		if (*e1 == *e2)
			return 0;
		else
			return (*e1<*e2)? -1 : 1;
	} else {
		if (e1 == e2)
			return 0;
		else
			return (e1<e2)? -1 : 1;
	}
}

ostream& ElementOps<_Attribute_Graphp_p>::displayItem(ostream& os, const _Attribute_Graphp_p& e)
{
	if (e)
		os << *e;
	else
		os << e;
	return os;
}
int ElementOps<_Attribute_Vertexp_p>::compareItems(const _Attribute_Vertexp_p& e1, const _Attribute_Vertexp_p& e2) 
{
	if (e1 && e2)  {
		if (*e1 == *e2)
			return 0;
		else
			return (*e1<*e2)? -1 : 1;
	} else {
		if (e1 == e2)
			return 0;
		else
			return (e1<e2)? -1 : 1;
	}
}

ostream& ElementOps<_Attribute_Vertexp_p>::displayItem(ostream& os, const _Attribute_Vertexp_p& e)
{
	if (e)
		os << *e;
	else
		os << e;
	return os;
}
int ElementOps<_Attribute_char_p>::compareItems(const _Attribute_char_p& e1, const _Attribute_char_p& e2) 
{
	if (e1 && e2)  {
		if (*e1 == *e2)
			return 0;
		else
			return (*e1<*e2)? -1 : 1;
	} else {
		if (e1 == e2)
			return 0;
		else
			return (e1<e2)? -1 : 1;
	}
}

ostream& ElementOps<_Attribute_char_p>::displayItem(ostream& os, const _Attribute_char_p& e)
{
	if (e)
		os << *e;
	else
		os << e;
	return os;
}
int ElementOps<_Attribute_charp_p>::compareItems(const _Attribute_charp_p& e1, const _Attribute_charp_p& e2) 
{
	if (e1 && e2)  {
		if (*e1 == *e2)
			return 0;
		else
			return (*e1<*e2)? -1 : 1;
	} else {
		if (e1 == e2)
			return 0;
		else
			return (e1<e2)? -1 : 1;
	}
}

ostream& ElementOps<_Attribute_charp_p>::displayItem(ostream& os, const _Attribute_charp_p& e)
{
	if (e)
		os << *e;
	else
		os << e;
	return os;
}
int ElementOps<_Attribute_double_p>::compareItems(const _Attribute_double_p& e1, const _Attribute_double_p& e2) 
{
	if (e1 && e2)  {
		if (*e1 == *e2)
			return 0;
		else
			return (*e1<*e2)? -1 : 1;
	} else {
		if (e1 == e2)
			return 0;
		else
			return (e1<e2)? -1 : 1;
	}
}

ostream& ElementOps<_Attribute_double_p>::displayItem(ostream& os, const _Attribute_double_p& e)
{
	if (e)
		os << *e;
	else
		os << e;
	return os;
}
int ElementOps<_Attribute_float_p>::compareItems(const _Attribute_float_p& e1, const _Attribute_float_p& e2) 
{
	if (e1 && e2)  {
		if (*e1 == *e2)
			return 0;
		else
			return (*e1<*e2)? -1 : 1;
	} else {
		if (e1 == e2)
			return 0;
		else
			return (e1<e2)? -1 : 1;
	}
}

ostream& ElementOps<_Attribute_float_p>::displayItem(ostream& os, const _Attribute_float_p& e)
{
	if (e)
		os << *e;
	else
		os << e;
	return os;
}
int ElementOps<_Attribute_int_p>::compareItems(const _Attribute_int_p& e1, const _Attribute_int_p& e2) 
{
	if (e1 && e2)  {
		if (*e1 == *e2)
			return 0;
		else
			return (*e1<*e2)? -1 : 1;
	} else {
		if (e1 == e2)
			return 0;
		else
			return (e1<e2)? -1 : 1;
	}
}

ostream& ElementOps<_Attribute_int_p>::displayItem(ostream& os, const _Attribute_int_p& e)
{
	if (e)
		os << *e;
	else
		os << e;
	return os;
}
int ElementOps<_Set_Vertexp_p>::compareItems(const _Set_Vertexp_p& e1, const _Set_Vertexp_p& e2) 
{
	if (e1 && e2)  {
		if (*e1 == *e2)
			return 0;
		else
			return (*e1<*e2)? -1 : 1;
	} else {
		if (e1 == e2)
			return 0;
		else
			return (e1<e2)? -1 : 1;
	}
}

ostream& ElementOps<_Set_Vertexp_p>::displayItem(ostream& os, const _Set_Vertexp_p& e)
{
	if (e)
		os << *e;
	else
		os << e;
	return os;
}
int ElementOps<_Attribute_DList_Vertexp_p_p>::compareItems(const _Attribute_DList_Vertexp_p_p& e1, const _Attribute_DList_Vertexp_p_p& e2) 
{
	if (e1 && e2)  {
		if (*e1 == *e2)
			return 0;
		else
			return (*e1<*e2)? -1 : 1;
	} else {
		if (e1 == e2)
			return 0;
		else
			return (e1<e2)? -1 : 1;
	}
}

ostream& ElementOps<_Attribute_DList_Vertexp_p_p>::displayItem(ostream& os, const _Attribute_DList_Vertexp_p_p& e)
{
	if (e)
		os << *e;
	else
		os << e;
	return os;
}
int ElementOps<_Attribute_List_Vertexp_p_p>::compareItems(const _Attribute_List_Vertexp_p_p& e1, const _Attribute_List_Vertexp_p_p& e2) 
{
	if (e1 && e2)  {
		if (*e1 == *e2)
			return 0;
		else
			return (*e1<*e2)? -1 : 1;
	} else {
		if (e1 == e2)
			return 0;
		else
			return (e1<e2)? -1 : 1;
	}
}

ostream& ElementOps<_Attribute_List_Vertexp_p_p>::displayItem(ostream& os, const _Attribute_List_Vertexp_p_p& e)
{
	if (e)
		os << *e;
	else
		os << e;
	return os;
}
ostream& AttributeElementOps<float>::displayItem(ostream& os,
                                                  const float& e) const
{
        os.setf(ios::showpoint);
        os << e << "f";
        return os;
}
ostream& AttributeElementOps<double>::displayItem(ostream& os,
                                                  const double& e) const
{
        os.setf(ios::showpoint);
        os << e;
        return os;
}
ostream& AttributeElementOps<String>::displayItem(ostream& os,
                                                  const String& e) const
{
        os << "\"" << e << "\"";
        return os;
}
typedef Vertex *VertexPtr;
ostream& AttributeElementOps<VertexPtr>::displayItem(ostream& os,
                                                const VertexPtr& v) const
{
	if (v) {
		os << *v;
	} else
		os << 0;
        return os;
}
typedef Edge *EdgePtr;
ostream& AttributeElementOps<EdgePtr>::displayItem(ostream& os,
                                                const EdgePtr& e) const
{
	if (e) {
        	os << *e;
	} else
		os << 0;
        return os;
}
