#ifndef dataGraph_H #define dataGraph_H #include #include #include #include "graphtype.h" class DataGraph { public: typedef std::vector Edges; enum DescriptorType {local,global}; DataGraph(DataGraphT& dataGraph); DataGraph(DataGraphT& dataGraph, const DataVertices& dataVertices); // Graph Data accessor methods struct VertexData { typedef boost::graph_property_iter_range ::iterator iterator; typedef boost::graph_property_iter_range ::const_iterator const_iterator; typedef Vertex_Datum value_type; VertexData(DataGraphT& dataGraph); iterator begin(void) {return boost::get_property_iter_range(dataGraph_,vertex_Datum).first;} const_iterator begin(void) const {return boost::get_property_iter_range(const_cast(dataGraph_),vertex_Datum).first;} iterator end(void) {return boost::get_property_iter_range(dataGraph_,vertex_Datum).second;} const_iterator end(void) const {return boost::get_property_iter_range(const_cast(dataGraph_),vertex_Datum).second;} Vertex_Datum& operator[] (const DataVertex& index); private: DataGraphT& dataGraph_; }; struct EdgeData { typedef boost::graph_property_iter_range ::iterator iterator; typedef boost::graph_property_iter_range ::const_iterator const_iterator; typedef Edge_Datum value_type; EdgeData(DataGraphT& subgraph); iterator begin(void) {return boost::get_property_iter_range(dataGraph_,edge_Datum).first;} const_iterator begin(void) const {return boost::get_property_iter_range(const_cast(dataGraph_),edge_Datum).first;} iterator end(void) {return boost::get_property_iter_range(dataGraph_,edge_Datum).second;} const_iterator end(void) const {return boost::get_property_iter_range( const_cast(dataGraph_),edge_Datum).second;} Edge_Datum& operator[] (const DataEdge& index); private: DataGraphT& dataGraph_; }; VertexData getVertexData(DescriptorType type = local) {return (type == local) ? VertexData(dataGraph_) : VertexData(dataGraph_.root());} EdgeData getEdgeData(DescriptorType type = local) {return (type == local) ? EdgeData(dataGraph_) : EdgeData(dataGraph_.root());} // access to held subgraph DataGraphT& getGraph(void) {return dataGraph_;} // Max/Min Rank Set manipulator methods. typedef std::set SameRank; const SameRank& getMinRanks(void) const {return minRanks_;} SameRank& getMinRanks(void) {return minRanks_;} const SameRank& getMaxRanks(void) const {return maxRanks_;} SameRank& getMaxRanks(void) {return maxRanks_;} // graph mutator methods DataEdge add_edge(LayoutEdge* pLayoutEdge,DataVertex source,DataVertex target); DataEdge add_edge(PseudoEdge* pPseudoEdge,DataVertex source,DataVertex target); DataEdge add_edge(const Edge_Datum& edgeDatum,DataVertex source,DataVertex target); DataVertex add_vertex(LayoutVertex *pLayoutVertex); DataVertex add_vertex(PseudoVertex *pPseudoVertex); void remove_edge(DataEdge edge); void remove_vertex(DataVertex vertex); void handleExternalEdges(DataGraph::Edges& in_external_edges,DataGraph::Edges& out_external_edges); void handleParallelEdges(void); void markBackEdges(void); private: std::string label(DataVertex v); DataGraphT& dataGraph_; SameRank minRanks_; SameRank maxRanks_; }; /* * This should be a template that has overloaded operator() methods. */ struct FindViaInterface : std::unary_function { FindViaInterface(DataGraph& dataGraph, const void *pPointer) : dataGraph_(dataGraph),pPointer_(pPointer) {} bool operator() (const DataVertex& x) const { if (dataGraph_.getVertexData(DataGraph::global)[x].isPseudo()) { return dataGraph_.getVertexData(DataGraph::global)[x].getPseudoInterface() == pPointer_; } else return dataGraph_.getVertexData(DataGraph::global)[x].getLayoutInterface() == pPointer_; } private: DataGraph& dataGraph_; const void *pPointer_; }; template< typename T1> struct IsPseudo : std::unary_function { bool operator()(typename T1::value_type& x) const { return x.isPseudo(); } }; template< typename T1> struct IsDeleted : std::unary_function { bool operator()(typename T1::value_type& x) const { return x.isDeleted(); } }; struct IsReversed : std::unary_function { bool operator()(DataGraph::EdgeData::value_type& x) const { return x.isReversed(); } }; template< typename T1, typename T2> struct IsType : public std::unary_function { IsType(typename T2::type type) : type_(type) {} bool operator() (typename T1::value_type x) const; private: typename T2::type type_; }; template<> inline bool IsType::operator()(DataGraph::VertexData::value_type x) const { if (x.isPseudo()) return type_ == x.getPseudoInterface()->getType(); else return false; } template<> inline bool IsType::operator()(DataGraph::VertexData::value_type x) const { if (!x.isPseudo()) return type_ == x.getLayoutInterface()->getType(); else return false; } template<> inline bool IsType::operator()(DataGraph::EdgeData::value_type x) const { if (x.isPseudo()) return type_ == x.getPseudoInterface()->getType(); else return false; } template<> inline bool IsType::operator()(DataGraph::EdgeData::value_type x) const { if (!x.isPseudo()) return type_ == x.getLayoutInterface()->getType(); else return false; } #endif