1.1 --- a/lemon/bits/graph_adaptor_extender.h Mon Apr 03 09:24:38 2006 +0000
1.2 +++ b/lemon/bits/graph_adaptor_extender.h Mon Apr 03 09:45:23 2006 +0000
1.3 @@ -33,12 +33,13 @@
1.4 /// \ingroup graphbits
1.5 ///
1.6 /// \brief Extender for the GraphAdaptors
1.7 - template <typename Base>
1.8 - class GraphAdaptorExtender : public Base {
1.9 + template <typename _Graph>
1.10 + class GraphAdaptorExtender : public _Graph {
1.11 public:
1.12
1.13 - typedef Base Parent;
1.14 - typedef GraphAdaptorExtender Graph;
1.15 + typedef _Graph Parent;
1.16 + typedef _Graph Graph;
1.17 + typedef GraphAdaptorExtender Adaptor;
1.18
1.19 // Base extensions
1.20
1.21 @@ -71,18 +72,18 @@
1.22 }
1.23
1.24 class NodeIt : public Node {
1.25 - const Graph* graph;
1.26 + const Adaptor* graph;
1.27 public:
1.28
1.29 NodeIt() {}
1.30
1.31 NodeIt(Invalid i) : Node(i) { }
1.32
1.33 - explicit NodeIt(const Graph& _graph) : graph(&_graph) {
1.34 - _graph.first(*static_cast<Node*>(this));
1.35 + explicit NodeIt(const Adaptor& _graph) : graph(&_graph) {
1.36 + _graph.first(static_cast<Node&>(*this));
1.37 }
1.38
1.39 - NodeIt(const Graph& _graph, const Node& node)
1.40 + NodeIt(const Adaptor& _graph, const Node& node)
1.41 : Node(node), graph(&_graph) {}
1.42
1.43 NodeIt& operator++() {
1.44 @@ -94,18 +95,18 @@
1.45
1.46
1.47 class EdgeIt : public Edge {
1.48 - const Graph* graph;
1.49 + const Adaptor* graph;
1.50 public:
1.51
1.52 EdgeIt() { }
1.53
1.54 EdgeIt(Invalid i) : Edge(i) { }
1.55
1.56 - explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
1.57 - _graph.first(*static_cast<Edge*>(this));
1.58 + explicit EdgeIt(const Adaptor& _graph) : graph(&_graph) {
1.59 + _graph.first(static_cast<Edge&>(*this));
1.60 }
1.61
1.62 - EdgeIt(const Graph& _graph, const Edge& e) :
1.63 + EdgeIt(const Adaptor& _graph, const Edge& e) :
1.64 Edge(e), graph(&_graph) { }
1.65
1.66 EdgeIt& operator++() {
1.67 @@ -117,19 +118,19 @@
1.68
1.69
1.70 class OutEdgeIt : public Edge {
1.71 - const Graph* graph;
1.72 + const Adaptor* graph;
1.73 public:
1.74
1.75 OutEdgeIt() { }
1.76
1.77 OutEdgeIt(Invalid i) : Edge(i) { }
1.78
1.79 - OutEdgeIt(const Graph& _graph, const Node& node)
1.80 + OutEdgeIt(const Adaptor& _graph, const Node& node)
1.81 : graph(&_graph) {
1.82 _graph.firstOut(*this, node);
1.83 }
1.84
1.85 - OutEdgeIt(const Graph& _graph, const Edge& edge)
1.86 + OutEdgeIt(const Adaptor& _graph, const Edge& edge)
1.87 : Edge(edge), graph(&_graph) {}
1.88
1.89 OutEdgeIt& operator++() {
1.90 @@ -141,19 +142,19 @@
1.91
1.92
1.93 class InEdgeIt : public Edge {
1.94 - const Graph* graph;
1.95 + const Adaptor* graph;
1.96 public:
1.97
1.98 InEdgeIt() { }
1.99
1.100 InEdgeIt(Invalid i) : Edge(i) { }
1.101
1.102 - InEdgeIt(const Graph& _graph, const Node& node)
1.103 + InEdgeIt(const Adaptor& _graph, const Node& node)
1.104 : graph(&_graph) {
1.105 _graph.firstIn(*this, node);
1.106 }
1.107
1.108 - InEdgeIt(const Graph& _graph, const Edge& edge) :
1.109 + InEdgeIt(const Adaptor& _graph, const Edge& edge) :
1.110 Edge(edge), graph(&_graph) {}
1.111
1.112 InEdgeIt& operator++() {
1.113 @@ -197,12 +198,13 @@
1.114 /// \ingroup graphbits
1.115 ///
1.116 /// \brief Extender for the UGraphAdaptors
1.117 - template <typename Base>
1.118 - class UGraphAdaptorExtender : public Base {
1.119 + template <typename _UGraph>
1.120 + class UGraphAdaptorExtender : public _UGraph {
1.121 public:
1.122
1.123 - typedef Base Parent;
1.124 - typedef UGraphAdaptorExtender Graph;
1.125 + typedef _UGraph Parent;
1.126 + typedef _UGraph UGraph;
1.127 + typedef UGraphAdaptorExtender Adaptor;
1.128
1.129 typedef typename Parent::Node Node;
1.130 typedef typename Parent::Edge Edge;
1.131 @@ -254,18 +256,18 @@
1.132
1.133
1.134 class NodeIt : public Node {
1.135 - const Graph* graph;
1.136 + const Adaptor* graph;
1.137 public:
1.138
1.139 NodeIt() {}
1.140
1.141 NodeIt(Invalid i) : Node(i) { }
1.142
1.143 - explicit NodeIt(const Graph& _graph) : graph(&_graph) {
1.144 - _graph.first(*static_cast<Node*>(this));
1.145 + explicit NodeIt(const Adaptor& _graph) : graph(&_graph) {
1.146 + _graph.first(static_cast<Node&>(*this));
1.147 }
1.148
1.149 - NodeIt(const Graph& _graph, const Node& node)
1.150 + NodeIt(const Adaptor& _graph, const Node& node)
1.151 : Node(node), graph(&_graph) {}
1.152
1.153 NodeIt& operator++() {
1.154 @@ -277,18 +279,18 @@
1.155
1.156
1.157 class EdgeIt : public Edge {
1.158 - const Graph* graph;
1.159 + const Adaptor* graph;
1.160 public:
1.161
1.162 EdgeIt() { }
1.163
1.164 EdgeIt(Invalid i) : Edge(i) { }
1.165
1.166 - explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
1.167 - _graph.first(*static_cast<Edge*>(this));
1.168 + explicit EdgeIt(const Adaptor& _graph) : graph(&_graph) {
1.169 + _graph.first(static_cast<Edge&>(*this));
1.170 }
1.171
1.172 - EdgeIt(const Graph& _graph, const Edge& e) :
1.173 + EdgeIt(const Adaptor& _graph, const Edge& e) :
1.174 Edge(e), graph(&_graph) { }
1.175
1.176 EdgeIt& operator++() {
1.177 @@ -300,19 +302,19 @@
1.178
1.179
1.180 class OutEdgeIt : public Edge {
1.181 - const Graph* graph;
1.182 + const Adaptor* graph;
1.183 public:
1.184
1.185 OutEdgeIt() { }
1.186
1.187 OutEdgeIt(Invalid i) : Edge(i) { }
1.188
1.189 - OutEdgeIt(const Graph& _graph, const Node& node)
1.190 + OutEdgeIt(const Adaptor& _graph, const Node& node)
1.191 : graph(&_graph) {
1.192 _graph.firstOut(*this, node);
1.193 }
1.194
1.195 - OutEdgeIt(const Graph& _graph, const Edge& edge)
1.196 + OutEdgeIt(const Adaptor& _graph, const Edge& edge)
1.197 : Edge(edge), graph(&_graph) {}
1.198
1.199 OutEdgeIt& operator++() {
1.200 @@ -324,19 +326,19 @@
1.201
1.202
1.203 class InEdgeIt : public Edge {
1.204 - const Graph* graph;
1.205 + const Adaptor* graph;
1.206 public:
1.207
1.208 InEdgeIt() { }
1.209
1.210 InEdgeIt(Invalid i) : Edge(i) { }
1.211
1.212 - InEdgeIt(const Graph& _graph, const Node& node)
1.213 + InEdgeIt(const Adaptor& _graph, const Node& node)
1.214 : graph(&_graph) {
1.215 _graph.firstIn(*this, node);
1.216 }
1.217
1.218 - InEdgeIt(const Graph& _graph, const Edge& edge) :
1.219 + InEdgeIt(const Adaptor& _graph, const Edge& edge) :
1.220 Edge(edge), graph(&_graph) {}
1.221
1.222 InEdgeIt& operator++() {
1.223 @@ -347,18 +349,18 @@
1.224 };
1.225
1.226 class UEdgeIt : public Parent::UEdge {
1.227 - const Graph* graph;
1.228 + const Adaptor* graph;
1.229 public:
1.230
1.231 UEdgeIt() { }
1.232
1.233 UEdgeIt(Invalid i) : UEdge(i) { }
1.234
1.235 - explicit UEdgeIt(const Graph& _graph) : graph(&_graph) {
1.236 - _graph.first(*static_cast<UEdge*>(this));
1.237 + explicit UEdgeIt(const Adaptor& _graph) : graph(&_graph) {
1.238 + _graph.first(static_cast<UEdge&>(*this));
1.239 }
1.240
1.241 - UEdgeIt(const Graph& _graph, const UEdge& e) :
1.242 + UEdgeIt(const Adaptor& _graph, const UEdge& e) :
1.243 UEdge(e), graph(&_graph) { }
1.244
1.245 UEdgeIt& operator++() {
1.246 @@ -370,7 +372,7 @@
1.247
1.248 class IncEdgeIt : public Parent::UEdge {
1.249 friend class UGraphAdaptorExtender;
1.250 - const Graph* graph;
1.251 + const Adaptor* graph;
1.252 bool direction;
1.253 public:
1.254
1.255 @@ -378,11 +380,11 @@
1.256
1.257 IncEdgeIt(Invalid i) : UEdge(i), direction(false) { }
1.258
1.259 - IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
1.260 + IncEdgeIt(const Adaptor& _graph, const Node &n) : graph(&_graph) {
1.261 _graph.firstInc(static_cast<UEdge&>(*this), direction, n);
1.262 }
1.263
1.264 - IncEdgeIt(const Graph& _graph, const UEdge &ue, const Node &n)
1.265 + IncEdgeIt(const Adaptor& _graph, const UEdge &ue, const Node &n)
1.266 : graph(&_graph), UEdge(ue) {
1.267 direction = (_graph.source(ue) == n);
1.268 }
1.269 @@ -436,6 +438,290 @@
1.270
1.271 };
1.272
1.273 + /// \ingroup graphbits
1.274 + ///
1.275 + /// \brief Extender for the BpUGraphAdaptors
1.276 + template <typename Base>
1.277 + class BpUGraphAdaptorExtender : public Base {
1.278 + public:
1.279 + typedef Base Parent;
1.280 + typedef BpUGraphAdaptorExtender Graph;
1.281 +
1.282 + typedef typename Parent::Node Node;
1.283 + typedef typename Parent::BNode BNode;
1.284 + typedef typename Parent::ANode ANode;
1.285 + typedef typename Parent::Edge Edge;
1.286 + typedef typename Parent::UEdge UEdge;
1.287 +
1.288 + Node oppositeNode(const UEdge& edge, const Node& node) const {
1.289 + return source(edge) == node ?
1.290 + target(edge) : source(edge);
1.291 + }
1.292 +
1.293 +
1.294 + int maxId(Node) const {
1.295 + return Parent::maxNodeId();
1.296 + }
1.297 + int maxId(BNode) const {
1.298 + return Parent::maxBNodeId();
1.299 + }
1.300 + int maxId(ANode) const {
1.301 + return Parent::maxANodeId();
1.302 + }
1.303 + int maxId(Edge) const {
1.304 + return Parent::maxEdgeId();
1.305 + }
1.306 + int maxId(UEdge) const {
1.307 + return Parent::maxUEdgeId();
1.308 + }
1.309 +
1.310 +
1.311 + Node fromId(int id, Node) const {
1.312 + return Parent::nodeFromId(id);
1.313 + }
1.314 + ANode fromId(int id, ANode) const {
1.315 + return Parent::fromANodeId(id);
1.316 + }
1.317 + BNode fromId(int id, BNode) const {
1.318 + return Parent::fromBNodeId(id);
1.319 + }
1.320 + Edge fromId(int id, Edge) const {
1.321 + return Parent::edgeFromId(id);
1.322 + }
1.323 + UEdge fromId(int id, UEdge) const {
1.324 + return Parent::uEdgeFromId(id);
1.325 + }
1.326 +
1.327 + class NodeIt : public Node {
1.328 + const Graph* graph;
1.329 + public:
1.330 +
1.331 + NodeIt() { }
1.332 +
1.333 + NodeIt(Invalid i) : Node(INVALID) { }
1.334 +
1.335 + explicit NodeIt(const Graph& _graph) : graph(&_graph) {
1.336 + graph->first(static_cast<Node&>(*this));
1.337 + }
1.338 +
1.339 + NodeIt(const Graph& _graph, const Node& node)
1.340 + : Node(node), graph(&_graph) { }
1.341 +
1.342 + NodeIt& operator++() {
1.343 + graph->next(*this);
1.344 + return *this;
1.345 + }
1.346 +
1.347 + };
1.348 +
1.349 + class ANodeIt : public Node {
1.350 + friend class BpUGraphAdaptorExtender;
1.351 + const Graph* graph;
1.352 + public:
1.353 +
1.354 + ANodeIt() { }
1.355 +
1.356 + ANodeIt(Invalid i) : Node(INVALID) { }
1.357 +
1.358 + explicit ANodeIt(const Graph& _graph) : graph(&_graph) {
1.359 + graph->firstANode(static_cast<Node&>(*this));
1.360 + }
1.361 +
1.362 + ANodeIt(const Graph& _graph, const Node& node)
1.363 + : Node(node), graph(&_graph) {}
1.364 +
1.365 + ANodeIt& operator++() {
1.366 + graph->nextANode(*this);
1.367 + return *this;
1.368 + }
1.369 + };
1.370 +
1.371 + class BNodeIt : public Node {
1.372 + friend class BpUGraphAdaptorExtender;
1.373 + const Graph* graph;
1.374 + public:
1.375 +
1.376 + BNodeIt() { }
1.377 +
1.378 + BNodeIt(Invalid i) : Node(INVALID) { }
1.379 +
1.380 + explicit BNodeIt(const Graph& _graph) : graph(&_graph) {
1.381 + graph->firstBNode(static_cast<Node&>(*this));
1.382 + }
1.383 +
1.384 + BNodeIt(const Graph& _graph, const Node& node)
1.385 + : Node(node), graph(&_graph) {}
1.386 +
1.387 + BNodeIt& operator++() {
1.388 + graph->nextBNode(*this);
1.389 + return *this;
1.390 + }
1.391 + };
1.392 +
1.393 + class EdgeIt : public Edge {
1.394 + friend class BpUGraphAdaptorExtender;
1.395 + const Graph* graph;
1.396 + public:
1.397 +
1.398 + EdgeIt() { }
1.399 +
1.400 + EdgeIt(Invalid i) : Edge(INVALID) { }
1.401 +
1.402 + explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
1.403 + graph->first(static_cast<Edge&>(*this));
1.404 + }
1.405 +
1.406 + EdgeIt(const Graph& _graph, const Edge& edge)
1.407 + : Edge(edge), graph(&_graph) { }
1.408 +
1.409 + EdgeIt& operator++() {
1.410 + graph->next(*this);
1.411 + return *this;
1.412 + }
1.413 +
1.414 + };
1.415 +
1.416 + class UEdgeIt : public UEdge {
1.417 + friend class BpUGraphAdaptorExtender;
1.418 + const Graph* graph;
1.419 + public:
1.420 +
1.421 + UEdgeIt() { }
1.422 +
1.423 + UEdgeIt(Invalid i) : UEdge(INVALID) { }
1.424 +
1.425 + explicit UEdgeIt(const Graph& _graph) : graph(&_graph) {
1.426 + graph->first(static_cast<UEdge&>(*this));
1.427 + }
1.428 +
1.429 + UEdgeIt(const Graph& _graph, const UEdge& edge)
1.430 + : UEdge(edge), graph(&_graph) { }
1.431 +
1.432 + UEdgeIt& operator++() {
1.433 + graph->next(*this);
1.434 + return *this;
1.435 + }
1.436 + };
1.437 +
1.438 + class OutEdgeIt : public Edge {
1.439 + friend class BpUGraphAdaptorExtender;
1.440 + const Graph* graph;
1.441 + public:
1.442 +
1.443 + OutEdgeIt() { }
1.444 +
1.445 + OutEdgeIt(Invalid i) : Edge(i) { }
1.446 +
1.447 + OutEdgeIt(const Graph& _graph, const Node& node)
1.448 + : graph(&_graph) {
1.449 + graph->firstOut(*this, node);
1.450 + }
1.451 +
1.452 + OutEdgeIt(const Graph& _graph, const Edge& edge)
1.453 + : Edge(edge), graph(&_graph) {}
1.454 +
1.455 + OutEdgeIt& operator++() {
1.456 + graph->nextOut(*this);
1.457 + return *this;
1.458 + }
1.459 +
1.460 + };
1.461 +
1.462 +
1.463 + class InEdgeIt : public Edge {
1.464 + friend class BpUGraphAdaptorExtender;
1.465 + const Graph* graph;
1.466 + public:
1.467 +
1.468 + InEdgeIt() { }
1.469 +
1.470 + InEdgeIt(Invalid i) : Edge(i) { }
1.471 +
1.472 + InEdgeIt(const Graph& _graph, const Node& node)
1.473 + : graph(&_graph) {
1.474 + graph->firstIn(*this, node);
1.475 + }
1.476 +
1.477 + InEdgeIt(const Graph& _graph, const Edge& edge) :
1.478 + Edge(edge), graph(&_graph) {}
1.479 +
1.480 + InEdgeIt& operator++() {
1.481 + graph->nextIn(*this);
1.482 + return *this;
1.483 + }
1.484 +
1.485 + };
1.486 +
1.487 + /// \brief Base node of the iterator
1.488 + ///
1.489 + /// Returns the base node (ie. the source in this case) of the iterator
1.490 + Node baseNode(const OutEdgeIt &e) const {
1.491 + return Parent::source((Edge&)e);
1.492 + }
1.493 + /// \brief Running node of the iterator
1.494 + ///
1.495 + /// Returns the running node (ie. the target in this case) of the
1.496 + /// iterator
1.497 + Node runningNode(const OutEdgeIt &e) const {
1.498 + return Parent::target((Edge&)e);
1.499 + }
1.500 +
1.501 + /// \brief Base node of the iterator
1.502 + ///
1.503 + /// Returns the base node (ie. the target in this case) of the iterator
1.504 + Node baseNode(const InEdgeIt &e) const {
1.505 + return Parent::target((Edge&)e);
1.506 + }
1.507 + /// \brief Running node of the iterator
1.508 + ///
1.509 + /// Returns the running node (ie. the source in this case) of the
1.510 + /// iterator
1.511 + Node runningNode(const InEdgeIt &e) const {
1.512 + return Parent::source((Edge&)e);
1.513 + }
1.514 +
1.515 + class IncEdgeIt : public Parent::UEdge {
1.516 + friend class BpUGraphAdaptorExtender;
1.517 + const Graph* graph;
1.518 + bool direction;
1.519 + public:
1.520 +
1.521 + IncEdgeIt() { }
1.522 +
1.523 + IncEdgeIt(Invalid i) : UEdge(i), direction(true) { }
1.524 +
1.525 + IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
1.526 + graph->firstInc(*this, direction, n);
1.527 + }
1.528 +
1.529 + IncEdgeIt(const Graph& _graph, const UEdge &ue, const Node &n)
1.530 + : graph(&_graph), UEdge(ue) {
1.531 + direction = (graph->source(ue) == n);
1.532 + }
1.533 +
1.534 + IncEdgeIt& operator++() {
1.535 + graph->nextInc(*this, direction);
1.536 + return *this;
1.537 + }
1.538 + };
1.539 +
1.540 +
1.541 + /// Base node of the iterator
1.542 + ///
1.543 + /// Returns the base node of the iterator
1.544 + Node baseNode(const IncEdgeIt &e) const {
1.545 + return e.direction ? source(e) : target(e);
1.546 + }
1.547 +
1.548 + /// Running node of the iterator
1.549 + ///
1.550 + /// Returns the running node of the iterator
1.551 + Node runningNode(const IncEdgeIt &e) const {
1.552 + return e.direction ? target(e) : source(e);
1.553 + }
1.554 +
1.555 + };
1.556 +
1.557
1.558 }
1.559