diff -r d769d2eb4d50 -r 080d51024ac5 lemon/bits/graph_adaptor_extender.h --- a/lemon/bits/graph_adaptor_extender.h Mon Apr 03 09:24:38 2006 +0000 +++ b/lemon/bits/graph_adaptor_extender.h Mon Apr 03 09:45:23 2006 +0000 @@ -33,12 +33,13 @@ /// \ingroup graphbits /// /// \brief Extender for the GraphAdaptors - template - class GraphAdaptorExtender : public Base { + template + class GraphAdaptorExtender : public _Graph { public: - typedef Base Parent; - typedef GraphAdaptorExtender Graph; + typedef _Graph Parent; + typedef _Graph Graph; + typedef GraphAdaptorExtender Adaptor; // Base extensions @@ -71,18 +72,18 @@ } class NodeIt : public Node { - const Graph* graph; + const Adaptor* graph; public: NodeIt() {} NodeIt(Invalid i) : Node(i) { } - explicit NodeIt(const Graph& _graph) : graph(&_graph) { - _graph.first(*static_cast(this)); + explicit NodeIt(const Adaptor& _graph) : graph(&_graph) { + _graph.first(static_cast(*this)); } - NodeIt(const Graph& _graph, const Node& node) + NodeIt(const Adaptor& _graph, const Node& node) : Node(node), graph(&_graph) {} NodeIt& operator++() { @@ -94,18 +95,18 @@ class EdgeIt : public Edge { - const Graph* graph; + const Adaptor* graph; public: EdgeIt() { } EdgeIt(Invalid i) : Edge(i) { } - explicit EdgeIt(const Graph& _graph) : graph(&_graph) { - _graph.first(*static_cast(this)); + explicit EdgeIt(const Adaptor& _graph) : graph(&_graph) { + _graph.first(static_cast(*this)); } - EdgeIt(const Graph& _graph, const Edge& e) : + EdgeIt(const Adaptor& _graph, const Edge& e) : Edge(e), graph(&_graph) { } EdgeIt& operator++() { @@ -117,19 +118,19 @@ class OutEdgeIt : public Edge { - const Graph* graph; + const Adaptor* graph; public: OutEdgeIt() { } OutEdgeIt(Invalid i) : Edge(i) { } - OutEdgeIt(const Graph& _graph, const Node& node) + OutEdgeIt(const Adaptor& _graph, const Node& node) : graph(&_graph) { _graph.firstOut(*this, node); } - OutEdgeIt(const Graph& _graph, const Edge& edge) + OutEdgeIt(const Adaptor& _graph, const Edge& edge) : Edge(edge), graph(&_graph) {} OutEdgeIt& operator++() { @@ -141,19 +142,19 @@ class InEdgeIt : public Edge { - const Graph* graph; + const Adaptor* graph; public: InEdgeIt() { } InEdgeIt(Invalid i) : Edge(i) { } - InEdgeIt(const Graph& _graph, const Node& node) + InEdgeIt(const Adaptor& _graph, const Node& node) : graph(&_graph) { _graph.firstIn(*this, node); } - InEdgeIt(const Graph& _graph, const Edge& edge) : + InEdgeIt(const Adaptor& _graph, const Edge& edge) : Edge(edge), graph(&_graph) {} InEdgeIt& operator++() { @@ -197,12 +198,13 @@ /// \ingroup graphbits /// /// \brief Extender for the UGraphAdaptors - template - class UGraphAdaptorExtender : public Base { + template + class UGraphAdaptorExtender : public _UGraph { public: - typedef Base Parent; - typedef UGraphAdaptorExtender Graph; + typedef _UGraph Parent; + typedef _UGraph UGraph; + typedef UGraphAdaptorExtender Adaptor; typedef typename Parent::Node Node; typedef typename Parent::Edge Edge; @@ -254,18 +256,18 @@ class NodeIt : public Node { - const Graph* graph; + const Adaptor* graph; public: NodeIt() {} NodeIt(Invalid i) : Node(i) { } - explicit NodeIt(const Graph& _graph) : graph(&_graph) { - _graph.first(*static_cast(this)); + explicit NodeIt(const Adaptor& _graph) : graph(&_graph) { + _graph.first(static_cast(*this)); } - NodeIt(const Graph& _graph, const Node& node) + NodeIt(const Adaptor& _graph, const Node& node) : Node(node), graph(&_graph) {} NodeIt& operator++() { @@ -277,18 +279,18 @@ class EdgeIt : public Edge { - const Graph* graph; + const Adaptor* graph; public: EdgeIt() { } EdgeIt(Invalid i) : Edge(i) { } - explicit EdgeIt(const Graph& _graph) : graph(&_graph) { - _graph.first(*static_cast(this)); + explicit EdgeIt(const Adaptor& _graph) : graph(&_graph) { + _graph.first(static_cast(*this)); } - EdgeIt(const Graph& _graph, const Edge& e) : + EdgeIt(const Adaptor& _graph, const Edge& e) : Edge(e), graph(&_graph) { } EdgeIt& operator++() { @@ -300,19 +302,19 @@ class OutEdgeIt : public Edge { - const Graph* graph; + const Adaptor* graph; public: OutEdgeIt() { } OutEdgeIt(Invalid i) : Edge(i) { } - OutEdgeIt(const Graph& _graph, const Node& node) + OutEdgeIt(const Adaptor& _graph, const Node& node) : graph(&_graph) { _graph.firstOut(*this, node); } - OutEdgeIt(const Graph& _graph, const Edge& edge) + OutEdgeIt(const Adaptor& _graph, const Edge& edge) : Edge(edge), graph(&_graph) {} OutEdgeIt& operator++() { @@ -324,19 +326,19 @@ class InEdgeIt : public Edge { - const Graph* graph; + const Adaptor* graph; public: InEdgeIt() { } InEdgeIt(Invalid i) : Edge(i) { } - InEdgeIt(const Graph& _graph, const Node& node) + InEdgeIt(const Adaptor& _graph, const Node& node) : graph(&_graph) { _graph.firstIn(*this, node); } - InEdgeIt(const Graph& _graph, const Edge& edge) : + InEdgeIt(const Adaptor& _graph, const Edge& edge) : Edge(edge), graph(&_graph) {} InEdgeIt& operator++() { @@ -347,18 +349,18 @@ }; class UEdgeIt : public Parent::UEdge { - const Graph* graph; + const Adaptor* graph; public: UEdgeIt() { } UEdgeIt(Invalid i) : UEdge(i) { } - explicit UEdgeIt(const Graph& _graph) : graph(&_graph) { - _graph.first(*static_cast(this)); + explicit UEdgeIt(const Adaptor& _graph) : graph(&_graph) { + _graph.first(static_cast(*this)); } - UEdgeIt(const Graph& _graph, const UEdge& e) : + UEdgeIt(const Adaptor& _graph, const UEdge& e) : UEdge(e), graph(&_graph) { } UEdgeIt& operator++() { @@ -370,7 +372,7 @@ class IncEdgeIt : public Parent::UEdge { friend class UGraphAdaptorExtender; - const Graph* graph; + const Adaptor* graph; bool direction; public: @@ -378,11 +380,11 @@ IncEdgeIt(Invalid i) : UEdge(i), direction(false) { } - IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) { + IncEdgeIt(const Adaptor& _graph, const Node &n) : graph(&_graph) { _graph.firstInc(static_cast(*this), direction, n); } - IncEdgeIt(const Graph& _graph, const UEdge &ue, const Node &n) + IncEdgeIt(const Adaptor& _graph, const UEdge &ue, const Node &n) : graph(&_graph), UEdge(ue) { direction = (_graph.source(ue) == n); } @@ -436,6 +438,290 @@ }; + /// \ingroup graphbits + /// + /// \brief Extender for the BpUGraphAdaptors + template + class BpUGraphAdaptorExtender : public Base { + public: + typedef Base Parent; + typedef BpUGraphAdaptorExtender Graph; + + typedef typename Parent::Node Node; + typedef typename Parent::BNode BNode; + typedef typename Parent::ANode ANode; + typedef typename Parent::Edge Edge; + typedef typename Parent::UEdge UEdge; + + Node oppositeNode(const UEdge& edge, const Node& node) const { + return source(edge) == node ? + target(edge) : source(edge); + } + + + int maxId(Node) const { + return Parent::maxNodeId(); + } + int maxId(BNode) const { + return Parent::maxBNodeId(); + } + int maxId(ANode) const { + return Parent::maxANodeId(); + } + int maxId(Edge) const { + return Parent::maxEdgeId(); + } + int maxId(UEdge) const { + return Parent::maxUEdgeId(); + } + + + Node fromId(int id, Node) const { + return Parent::nodeFromId(id); + } + ANode fromId(int id, ANode) const { + return Parent::fromANodeId(id); + } + BNode fromId(int id, BNode) const { + return Parent::fromBNodeId(id); + } + Edge fromId(int id, Edge) const { + return Parent::edgeFromId(id); + } + UEdge fromId(int id, UEdge) const { + return Parent::uEdgeFromId(id); + } + + class NodeIt : public Node { + const Graph* graph; + public: + + NodeIt() { } + + NodeIt(Invalid i) : Node(INVALID) { } + + explicit NodeIt(const Graph& _graph) : graph(&_graph) { + graph->first(static_cast(*this)); + } + + NodeIt(const Graph& _graph, const Node& node) + : Node(node), graph(&_graph) { } + + NodeIt& operator++() { + graph->next(*this); + return *this; + } + + }; + + class ANodeIt : public Node { + friend class BpUGraphAdaptorExtender; + const Graph* graph; + public: + + ANodeIt() { } + + ANodeIt(Invalid i) : Node(INVALID) { } + + explicit ANodeIt(const Graph& _graph) : graph(&_graph) { + graph->firstANode(static_cast(*this)); + } + + ANodeIt(const Graph& _graph, const Node& node) + : Node(node), graph(&_graph) {} + + ANodeIt& operator++() { + graph->nextANode(*this); + return *this; + } + }; + + class BNodeIt : public Node { + friend class BpUGraphAdaptorExtender; + const Graph* graph; + public: + + BNodeIt() { } + + BNodeIt(Invalid i) : Node(INVALID) { } + + explicit BNodeIt(const Graph& _graph) : graph(&_graph) { + graph->firstBNode(static_cast(*this)); + } + + BNodeIt(const Graph& _graph, const Node& node) + : Node(node), graph(&_graph) {} + + BNodeIt& operator++() { + graph->nextBNode(*this); + return *this; + } + }; + + class EdgeIt : public Edge { + friend class BpUGraphAdaptorExtender; + const Graph* graph; + public: + + EdgeIt() { } + + EdgeIt(Invalid i) : Edge(INVALID) { } + + explicit EdgeIt(const Graph& _graph) : graph(&_graph) { + graph->first(static_cast(*this)); + } + + EdgeIt(const Graph& _graph, const Edge& edge) + : Edge(edge), graph(&_graph) { } + + EdgeIt& operator++() { + graph->next(*this); + return *this; + } + + }; + + class UEdgeIt : public UEdge { + friend class BpUGraphAdaptorExtender; + const Graph* graph; + public: + + UEdgeIt() { } + + UEdgeIt(Invalid i) : UEdge(INVALID) { } + + explicit UEdgeIt(const Graph& _graph) : graph(&_graph) { + graph->first(static_cast(*this)); + } + + UEdgeIt(const Graph& _graph, const UEdge& edge) + : UEdge(edge), graph(&_graph) { } + + UEdgeIt& operator++() { + graph->next(*this); + return *this; + } + }; + + class OutEdgeIt : public Edge { + friend class BpUGraphAdaptorExtender; + const Graph* graph; + public: + + OutEdgeIt() { } + + OutEdgeIt(Invalid i) : Edge(i) { } + + OutEdgeIt(const Graph& _graph, const Node& node) + : graph(&_graph) { + graph->firstOut(*this, node); + } + + OutEdgeIt(const Graph& _graph, const Edge& edge) + : Edge(edge), graph(&_graph) {} + + OutEdgeIt& operator++() { + graph->nextOut(*this); + return *this; + } + + }; + + + class InEdgeIt : public Edge { + friend class BpUGraphAdaptorExtender; + const Graph* graph; + public: + + InEdgeIt() { } + + InEdgeIt(Invalid i) : Edge(i) { } + + InEdgeIt(const Graph& _graph, const Node& node) + : graph(&_graph) { + graph->firstIn(*this, node); + } + + InEdgeIt(const Graph& _graph, const Edge& edge) : + Edge(edge), graph(&_graph) {} + + InEdgeIt& operator++() { + graph->nextIn(*this); + return *this; + } + + }; + + /// \brief Base node of the iterator + /// + /// Returns the base node (ie. the source in this case) of the iterator + Node baseNode(const OutEdgeIt &e) const { + return Parent::source((Edge&)e); + } + /// \brief Running node of the iterator + /// + /// Returns the running node (ie. the target in this case) of the + /// iterator + Node runningNode(const OutEdgeIt &e) const { + return Parent::target((Edge&)e); + } + + /// \brief Base node of the iterator + /// + /// Returns the base node (ie. the target in this case) of the iterator + Node baseNode(const InEdgeIt &e) const { + return Parent::target((Edge&)e); + } + /// \brief Running node of the iterator + /// + /// Returns the running node (ie. the source in this case) of the + /// iterator + Node runningNode(const InEdgeIt &e) const { + return Parent::source((Edge&)e); + } + + class IncEdgeIt : public Parent::UEdge { + friend class BpUGraphAdaptorExtender; + const Graph* graph; + bool direction; + public: + + IncEdgeIt() { } + + IncEdgeIt(Invalid i) : UEdge(i), direction(true) { } + + IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) { + graph->firstInc(*this, direction, n); + } + + IncEdgeIt(const Graph& _graph, const UEdge &ue, const Node &n) + : graph(&_graph), UEdge(ue) { + direction = (graph->source(ue) == n); + } + + IncEdgeIt& operator++() { + graph->nextInc(*this, direction); + return *this; + } + }; + + + /// Base node of the iterator + /// + /// Returns the base node of the iterator + Node baseNode(const IncEdgeIt &e) const { + return e.direction ? source(e) : target(e); + } + + /// Running node of the iterator + /// + /// Returns the running node of the iterator + Node runningNode(const IncEdgeIt &e) const { + return e.direction ? target(e) : source(e); + } + + }; + }