1.1 --- a/src/work/marci/merge_node_graph_wrapper.h Mon Nov 29 17:55:46 2004 +0000
1.2 +++ b/src/work/marci/merge_node_graph_wrapper.h Wed Dec 01 14:08:37 2004 +0000
1.3 @@ -360,7 +360,7 @@
1.4 Generic implementation for unrelated _Graph1::Edge and _Graph2::Edge.
1.5 */
1.6 template <typename _Graph1, typename _Graph2, typename Enable=void>
1.7 - class MergeEdgeGraphWrapperBase :
1.8 + class MergeEdgeGraphWrapperBaseBase :
1.9 public MergeNodeGraphWrapperBase<_Graph1, _Graph2> {
1.10 public:
1.11 static void printEdge() { std::cout << "edge: generic" << std::endl; }
1.12 @@ -374,15 +374,11 @@
1.13 typedef typename Parent1::Edge Graph1Edge;
1.14 typedef typename Parent2::Edge Graph2Edge;
1.15 protected:
1.16 - MergeEdgeGraphWrapperBase() { }
1.17 + MergeEdgeGraphWrapperBaseBase() { }
1.18 public:
1.19 - template <typename _Value> class EdgeMap;
1.20 -
1.21 - typedef typename Parent::Node Node;
1.22
1.23 class Edge : public Graph1Edge, public Graph2Edge {
1.24 - friend class MergeEdgeGraphWrapperBase<_Graph1, _Graph2>;
1.25 - template <typename _Value> friend class EdgeMap;
1.26 + friend class MergeEdgeGraphWrapperBaseBase<_Graph1, _Graph2>;
1.27 protected:
1.28 bool backward; //true, iff backward
1.29 public:
1.30 @@ -409,134 +405,14 @@
1.31
1.32 using Parent::forward;
1.33 using Parent::backward;
1.34 - bool forward(const Edge& e) const { return !e.backward; }
1.35 - bool backward(const Edge& e) const { return e.backward; }
1.36 + using Parent::setForward;
1.37 + using Parent::setBackward;
1.38 + static bool forward(const Edge& e) { return !e.backward; }
1.39 + static bool backward(const Edge& e) { return e.backward; }
1.40 + static void setForward(Edge& e) { e.backward=false; }
1.41 + static void setBackward(Edge& e) { e.backward=true; }
1.42 + };
1.43
1.44 - using Parent::first;
1.45 - void first(Edge& i) const {
1.46 - Parent1::graph->first(*static_cast<Graph1Edge*>(&i));
1.47 - i.backward=false;
1.48 - if (*static_cast<Graph1Edge*>(&i)==INVALID) {
1.49 - Parent2::graph->first(*static_cast<Graph2Edge*>(&i));
1.50 - i.backward=true;
1.51 - }
1.52 - }
1.53 - void firstIn(Edge& i, const Node& n) const {
1.54 - if (!backward(n)) {
1.55 - Parent1::graph->firstIn(*static_cast<Graph1Edge*>(&i), n);
1.56 - if (*static_cast<Graph1Edge*>(&i)==INVALID)
1.57 - i=INVALID;
1.58 - else
1.59 - i.backward=false;
1.60 - } else {
1.61 - Parent2::graph->firstIn(*static_cast<Graph2Edge*>(&i), n);
1.62 - i.backward=true;
1.63 - }
1.64 - }
1.65 - void firstOut(Edge& i, const Node& n) const {
1.66 - if (!backward(n)) {
1.67 - Parent1::graph->firstOut(*static_cast<Graph1Edge*>(&i), n);
1.68 - if (*static_cast<Graph1Edge*>(&i)==INVALID)
1.69 - i=INVALID;
1.70 - else
1.71 - i.backward=false;
1.72 - } else {
1.73 - Parent2::graph->firstOut(*static_cast<Graph2Edge*>(&i), n);
1.74 - i.backward=true;
1.75 - }
1.76 - }
1.77 -
1.78 - using Parent::next;
1.79 - void next(Edge& i) const {
1.80 - if (!(i.backward)) {
1.81 - Parent1::graph->next(*static_cast<Graph1Edge*>(&i));
1.82 - if (*static_cast<Graph1Edge*>(&i)==INVALID) {
1.83 - Parent2::graph->first(*static_cast<Graph2Edge*>(&i));
1.84 - i.backward=true;
1.85 - }
1.86 - } else {
1.87 - Parent2::graph->next(*static_cast<Graph2Edge*>(&i));
1.88 - }
1.89 - }
1.90 - void nextIn(Edge& i) const {
1.91 - if (!(i.backward)) {
1.92 - Parent1::graph->nextIn(*static_cast<Graph1Edge*>(&i));
1.93 - if (*static_cast<Graph1Edge*>(&i)==INVALID) i=INVALID;
1.94 - } else {
1.95 - Parent2::graph->nextIn(*static_cast<Graph2Edge*>(&i));
1.96 - }
1.97 - }
1.98 - void nextOut(Edge& i) const {
1.99 - if (!(i.backward)) {
1.100 - Parent1::graph->nextOut(*static_cast<Graph1Edge*>(&i));
1.101 - if (*static_cast<Graph1Edge*>(&i)==INVALID) i=INVALID;
1.102 - } else {
1.103 - Parent2::graph->nextOut(*static_cast<Graph2Edge*>(&i));
1.104 - }
1.105 - }
1.106 -
1.107 - Node source(const Edge& i) const {
1.108 - if (!(i.backward)) {
1.109 - return
1.110 - Node(Parent1::graph->source(i), INVALID, false);
1.111 - } else {
1.112 - return
1.113 - Node(INVALID, Parent2::graph->source(i), true);
1.114 - }
1.115 - }
1.116 -
1.117 - Node target(const Edge& i) const {
1.118 - if (!(i.backward)) {
1.119 - return
1.120 - Node(Parent1::graph->target(i), INVALID, false);
1.121 - } else {
1.122 - return
1.123 - Node(INVALID, Parent2::graph->target(i), true);
1.124 - }
1.125 - }
1.126 -
1.127 - using Parent::id;
1.128 - int id(const Edge& n) const {
1.129 - if (!n.backward)
1.130 - return this->Parent1::graph->id(n);
1.131 - else
1.132 - return this->Parent2::graph->id(n);
1.133 - }
1.134 -
1.135 - template <typename _Value>
1.136 - class EdgeMap {
1.137 - protected:
1.138 - typedef typename Parent::Graph1::template EdgeMap<_Value> ParentMap1;
1.139 - typedef typename Parent::Graph2::template EdgeMap<_Value> ParentMap2;
1.140 - ParentMap1 forward_map;
1.141 - ParentMap2 backward_map;
1.142 - public:
1.143 - typedef _Value Value;
1.144 - typedef Edge Key;
1.145 - EdgeMap(const MergeEdgeGraphWrapperBase<_Graph1, _Graph2>& gw) :
1.146 - forward_map(*(gw.Parent1::graph)),
1.147 - backward_map(*(gw.Parent2::graph)) { }
1.148 - EdgeMap(const MergeEdgeGraphWrapperBase<_Graph1, _Graph2>& gw,
1.149 - const _Value& value) :
1.150 - forward_map(*(gw.Parent1::graph), value),
1.151 - backward_map(*(gw.Parent2::graph), value) { }
1.152 - _Value operator[](const Edge& n) const {
1.153 - if (!n.backward)
1.154 - return forward_map[n];
1.155 - else
1.156 - return backward_map[n];
1.157 - }
1.158 - void set(const Edge& n, const _Value& value) {
1.159 - if (!n.backward)
1.160 - forward_map.set(n, value);
1.161 - else
1.162 - backward_map.set(n, value);
1.163 - }
1.164 -// using ParentMap1::operator[];
1.165 -// using ParentMap2::operator[];
1.166 - };
1.167 -
1.168 - };
1.169
1.170
1.171 /*! A graph wrapper base class
1.172 @@ -547,7 +423,7 @@
1.173 are the same.
1.174 */
1.175 template <typename _Graph1, typename _Graph2>
1.176 - class MergeEdgeGraphWrapperBase<
1.177 + class MergeEdgeGraphWrapperBaseBase<
1.178 _Graph1, _Graph2, typename boost::enable_if<
1.179 boost::is_same<typename _Graph1::Edge, typename _Graph2::Edge> >::type> :
1.180 public MergeNodeGraphWrapperBase<_Graph1, _Graph2> {
1.181 @@ -563,15 +439,11 @@
1.182 typedef typename Parent1::Edge Graph1Edge;
1.183 typedef typename Parent2::Edge Graph2Edge;
1.184 protected:
1.185 - MergeEdgeGraphWrapperBase() { }
1.186 + MergeEdgeGraphWrapperBaseBase() { }
1.187 public:
1.188 - template <typename _Value> class EdgeMap;
1.189 -
1.190 - typedef typename Parent::Node Node;
1.191
1.192 class Edge : public Graph1Edge {
1.193 - friend class MergeEdgeGraphWrapperBase<_Graph1, _Graph2>;
1.194 - template <typename _Value> friend class EdgeMap;
1.195 + friend class MergeEdgeGraphWrapperBaseBase<_Graph1, _Graph2>;
1.196 protected:
1.197 bool backward; //true, iff backward
1.198 public:
1.199 @@ -594,133 +466,12 @@
1.200
1.201 using Parent::forward;
1.202 using Parent::backward;
1.203 - bool forward(const Edge& e) const { return !e.backward; }
1.204 - bool backward(const Edge& e) const { return e.backward; }
1.205 -
1.206 - using Parent::first;
1.207 - void first(Edge& i) const {
1.208 - Parent1::graph->first(*static_cast<Graph1Edge*>(&i));
1.209 - i.backward=false;
1.210 - if (*static_cast<Graph1Edge*>(&i)==INVALID) {
1.211 - Parent2::graph->first(*static_cast<Graph1Edge*>(&i));
1.212 - i.backward=true;
1.213 - }
1.214 - }
1.215 - void firstIn(Edge& i, const Node& n) const {
1.216 - if (!backward(n)) {
1.217 - Parent1::graph->firstIn(*static_cast<Graph1Edge*>(&i), n);
1.218 - if (*static_cast<Graph1Edge*>(&i)==INVALID)
1.219 - i=INVALID;
1.220 - else
1.221 - i.backward=false;
1.222 - } else {
1.223 - Parent2::graph->firstIn(*static_cast<Graph1Edge*>(&i), n);
1.224 - i.backward=true;
1.225 - }
1.226 - }
1.227 - void firstOut(Edge& i, const Node& n) const {
1.228 - if (!backward(n)) {
1.229 - Parent1::graph->firstOut(*static_cast<Graph1Edge*>(&i), n);
1.230 - if (*static_cast<Graph1Edge*>(&i)==INVALID)
1.231 - i=INVALID;
1.232 - else
1.233 - i.backward=false;
1.234 - } else {
1.235 - Parent2::graph->firstOut(*static_cast<Graph1Edge*>(&i), n);
1.236 - i.backward=true;
1.237 - }
1.238 - }
1.239 -
1.240 - using Parent::next;
1.241 - void next(Edge& i) const {
1.242 - if (!(i.backward)) {
1.243 - Parent1::graph->next(*static_cast<Graph1Edge*>(&i));
1.244 - if (*static_cast<Graph1Edge*>(&i)==INVALID) {
1.245 - Parent2::graph->first(*static_cast<Graph1Edge*>(&i));
1.246 - i.backward=true;
1.247 - }
1.248 - } else {
1.249 - Parent2::graph->next(*static_cast<Graph1Edge*>(&i));
1.250 - }
1.251 - }
1.252 - void nextIn(Edge& i) const {
1.253 - if (!(i.backward)) {
1.254 - Parent1::graph->nextIn(*static_cast<Graph1Edge*>(&i));
1.255 - if (*static_cast<Graph1Edge*>(&i)==INVALID) i=INVALID;
1.256 - } else {
1.257 - Parent2::graph->nextIn(*static_cast<Graph1Edge*>(&i));
1.258 - }
1.259 - }
1.260 - void nextOut(Edge& i) const {
1.261 - if (!(i.backward)) {
1.262 - Parent1::graph->nextOut(*static_cast<Graph1Edge*>(&i));
1.263 - if (*static_cast<Graph1Edge*>(&i)==INVALID) i=INVALID;
1.264 - } else {
1.265 - Parent2::graph->nextOut(*static_cast<Graph1Edge*>(&i));
1.266 - }
1.267 - }
1.268 -
1.269 - Node source(const Edge& i) const {
1.270 - if (!(i.backward)) {
1.271 - return
1.272 - Node(Parent1::graph->source(i), INVALID, false);
1.273 - } else {
1.274 - return
1.275 - Node(INVALID, Parent2::graph->source(i), true);
1.276 - }
1.277 - }
1.278 -
1.279 - Node target(const Edge& i) const {
1.280 - if (!(i.backward)) {
1.281 - return
1.282 - Node(Parent1::graph->target(i), INVALID, false);
1.283 - } else {
1.284 - return
1.285 - Node(INVALID, Parent2::graph->target(i), true);
1.286 - }
1.287 - }
1.288 -
1.289 - using Parent::id;
1.290 - int id(const Edge& n) const {
1.291 - if (!n.backward)
1.292 - return this->Parent1::graph->id(n);
1.293 - else
1.294 - return this->Parent2::graph->id(n);
1.295 - }
1.296 -
1.297 - template <typename _Value>
1.298 - class EdgeMap {
1.299 - protected:
1.300 - typedef typename Parent::Graph1::template EdgeMap<_Value> ParentMap1;
1.301 - typedef typename Parent::Graph2::template EdgeMap<_Value> ParentMap2;
1.302 - ParentMap1 forward_map;
1.303 - ParentMap2 backward_map;
1.304 - public:
1.305 - typedef _Value Value;
1.306 - typedef Edge Key;
1.307 - EdgeMap(const MergeEdgeGraphWrapperBase<_Graph1, _Graph2>& gw) :
1.308 - forward_map(*(gw.Parent1::graph)),
1.309 - backward_map(*(gw.Parent2::graph)) { }
1.310 - EdgeMap(const MergeEdgeGraphWrapperBase<_Graph1, _Graph2>& gw,
1.311 - const _Value& value) :
1.312 - forward_map(*(gw.Parent1::graph), value),
1.313 - backward_map(*(gw.Parent2::graph), value) { }
1.314 - _Value operator[](const Edge& n) const {
1.315 - if (!n.backward)
1.316 - return forward_map[n];
1.317 - else
1.318 - return backward_map[n];
1.319 - }
1.320 - void set(const Edge& n, const _Value& value) {
1.321 - if (!n.backward)
1.322 - forward_map.set(n, value);
1.323 - else
1.324 - backward_map.set(n, value);
1.325 - }
1.326 -// using ParentMap1::operator[];
1.327 -// using ParentMap2::operator[];
1.328 - };
1.329 -
1.330 + using Parent::setForward;
1.331 + using Parent::setBackward;
1.332 + static bool forward(const Edge& e) { return !e.backward; }
1.333 + static bool backward(const Edge& e) { return e.backward; }
1.334 + static void setForward(Edge& e) { e.backward=false; }
1.335 + static void setBackward(Edge& e) { e.backward=true; }
1.336 };
1.337
1.338
1.339 @@ -733,7 +484,7 @@
1.340 is derived from it.
1.341 */
1.342 template <typename _Graph1, typename _Graph2>
1.343 - class MergeEdgeGraphWrapperBase<
1.344 + class MergeEdgeGraphWrapperBaseBase<
1.345 _Graph1, _Graph2, typename boost::enable_if<
1.346 boost::is_base_and_derived<typename _Graph1::Edge, typename _Graph2::Edge> >::type> :
1.347 public MergeNodeGraphWrapperBase<_Graph1, _Graph2> {
1.348 @@ -749,15 +500,11 @@
1.349 typedef typename Parent1::Edge Graph1Edge;
1.350 typedef typename Parent2::Edge Graph2Edge;
1.351 protected:
1.352 - MergeEdgeGraphWrapperBase() { }
1.353 + MergeEdgeGraphWrapperBaseBase() { }
1.354 public:
1.355 - template <typename _Value> class EdgeMap;
1.356 -
1.357 - typedef typename Parent::Node Node;
1.358
1.359 class Edge : public Graph2Edge {
1.360 - friend class MergeEdgeGraphWrapperBase<_Graph1, _Graph2>;
1.361 - template <typename _Value> friend class EdgeMap;
1.362 + friend class MergeEdgeGraphWrapperBaseBase<_Graph1, _Graph2>;
1.363 protected:
1.364 bool backward; //true, iff backward
1.365 public:
1.366 @@ -786,133 +533,12 @@
1.367
1.368 using Parent::forward;
1.369 using Parent::backward;
1.370 - bool forward(const Edge& e) const { return !e.backward; }
1.371 - bool backward(const Edge& e) const { return e.backward; }
1.372 -
1.373 - using Parent::first;
1.374 - void first(Edge& i) const {
1.375 - Parent1::graph->first(*static_cast<Graph1Edge*>(&i));
1.376 - i.backward=false;
1.377 - if (*static_cast<Graph1Edge*>(&i)==INVALID) {
1.378 - Parent2::graph->first(*static_cast<Graph2Edge*>(&i));
1.379 - i.backward=true;
1.380 - }
1.381 - }
1.382 - void firstIn(Edge& i, const Node& n) const {
1.383 - if (!backward(n)) {
1.384 - Parent1::graph->firstIn(*static_cast<Graph1Edge*>(&i), n);
1.385 - if (*static_cast<Graph1Edge*>(&i)==INVALID)
1.386 - i=INVALID;
1.387 - else
1.388 - i.backward=false;
1.389 - } else {
1.390 - Parent2::graph->firstIn(*static_cast<Graph2Edge*>(&i), n);
1.391 - i.backward=true;
1.392 - }
1.393 - }
1.394 - void firstOut(Edge& i, const Node& n) const {
1.395 - if (!backward(n)) {
1.396 - Parent1::graph->firstOut(*static_cast<Graph1Edge*>(&i), n);
1.397 - if (*static_cast<Graph1Edge*>(&i)==INVALID)
1.398 - i=INVALID;
1.399 - else
1.400 - i.backward=false;
1.401 - } else {
1.402 - Parent2::graph->firstOut(*static_cast<Graph2Edge*>(&i), n);
1.403 - i.backward=true;
1.404 - }
1.405 - }
1.406 -
1.407 - using Parent::next;
1.408 - void next(Edge& i) const {
1.409 - if (!(i.backward)) {
1.410 - Parent1::graph->next(*static_cast<Graph1Edge*>(&i));
1.411 - if (*static_cast<Graph1Edge*>(&i)==INVALID) {
1.412 - Parent2::graph->first(*static_cast<Graph2Edge*>(&i));
1.413 - i.backward=true;
1.414 - }
1.415 - } else {
1.416 - Parent2::graph->next(*static_cast<Graph2Edge*>(&i));
1.417 - }
1.418 - }
1.419 - void nextIn(Edge& i) const {
1.420 - if (!(i.backward)) {
1.421 - Parent1::graph->nextIn(*static_cast<Graph1Edge*>(&i));
1.422 - if (*static_cast<Graph1Edge*>(&i)==INVALID) i=INVALID;
1.423 - } else {
1.424 - Parent2::graph->nextIn(*static_cast<Graph2Edge*>(&i));
1.425 - }
1.426 - }
1.427 - void nextOut(Edge& i) const {
1.428 - if (!(i.backward)) {
1.429 - Parent1::graph->nextOut(*static_cast<Graph1Edge*>(&i));
1.430 - if (*static_cast<Graph1Edge*>(&i)==INVALID) i=INVALID;
1.431 - } else {
1.432 - Parent2::graph->nextOut(*static_cast<Graph2Edge*>(&i));
1.433 - }
1.434 - }
1.435 -
1.436 - Node source(const Edge& i) const {
1.437 - if (!(i.backward)) {
1.438 - return
1.439 - Node(Parent1::graph->source(i), INVALID, false);
1.440 - } else {
1.441 - return
1.442 - Node(INVALID, Parent2::graph->source(i), true);
1.443 - }
1.444 - }
1.445 -
1.446 - Node target(const Edge& i) const {
1.447 - if (!(i.backward)) {
1.448 - return
1.449 - Node(Parent1::graph->target(i), INVALID, false);
1.450 - } else {
1.451 - return
1.452 - Node(INVALID, Parent2::graph->target(i), true);
1.453 - }
1.454 - }
1.455 -
1.456 - using Parent::id;
1.457 - int id(const Edge& n) const {
1.458 - if (!n.backward)
1.459 - return this->Parent1::graph->id(n);
1.460 - else
1.461 - return this->Parent2::graph->id(n);
1.462 - }
1.463 -
1.464 - template <typename _Value>
1.465 - class EdgeMap {
1.466 - protected:
1.467 - typedef typename Parent::Graph1::template EdgeMap<_Value> ParentMap1;
1.468 - typedef typename Parent::Graph2::template EdgeMap<_Value> ParentMap2;
1.469 - ParentMap1 forward_map;
1.470 - ParentMap2 backward_map;
1.471 - public:
1.472 - typedef _Value Value;
1.473 - typedef Edge Key;
1.474 - EdgeMap(const MergeEdgeGraphWrapperBase<_Graph1, _Graph2>& gw) :
1.475 - forward_map(*(gw.Parent1::graph)),
1.476 - backward_map(*(gw.Parent2::graph)) { }
1.477 - EdgeMap(const MergeEdgeGraphWrapperBase<_Graph1, _Graph2>& gw,
1.478 - const _Value& value) :
1.479 - forward_map(*(gw.Parent1::graph), value),
1.480 - backward_map(*(gw.Parent2::graph), value) { }
1.481 - _Value operator[](const Edge& n) const {
1.482 - if (!n.backward)
1.483 - return forward_map[n];
1.484 - else
1.485 - return backward_map[n];
1.486 - }
1.487 - void set(const Edge& n, const _Value& value) {
1.488 - if (!n.backward)
1.489 - forward_map.set(n, value);
1.490 - else
1.491 - backward_map.set(n, value);
1.492 - }
1.493 -// using ParentMap1::operator[];
1.494 -// using ParentMap2::operator[];
1.495 - };
1.496 -
1.497 + using Parent::setForward;
1.498 + using Parent::setBackward;
1.499 + static bool forward(const Edge& e) { return !e.backward; }
1.500 + static bool backward(const Edge& e) { return e.backward; }
1.501 + static void setForward(Edge& e) { e.backward=false; }
1.502 + static void setBackward(Edge& e) { e.backward=true; }
1.503 };
1.504
1.505
1.506 @@ -924,7 +550,7 @@
1.507 when _Graph1::Edge is derived from _Graph2::Edge.
1.508 */
1.509 template <typename _Graph1, typename _Graph2>
1.510 - class MergeEdgeGraphWrapperBase<
1.511 + class MergeEdgeGraphWrapperBaseBase<
1.512 _Graph1, _Graph2, typename boost::enable_if<
1.513 boost::is_base_and_derived<typename _Graph2::Edge, typename _Graph1::Edge> >::type> :
1.514 public MergeNodeGraphWrapperBase<_Graph1, _Graph2> {
1.515 @@ -932,7 +558,7 @@
1.516 static void printEdge() { std::cout << "edge: 1st is derived" << std::endl; }
1.517 typedef _Graph1 Graph1;
1.518 typedef _Graph2 Graph2;
1.519 - typedef MergeNodeGraphWrapperBase<_Graph1, _Graph2> Parent;
1.520 + typedef MergeNodeGraphWrapperBaseBase<_Graph1, _Graph2> Parent;
1.521 typedef typename Parent::Parent1 Parent1;
1.522 typedef typename Parent::Parent2 Parent2;
1.523 // typedef P1<_Graph1> Parent1;
1.524 @@ -940,15 +566,11 @@
1.525 typedef typename Parent1::Edge Graph1Edge;
1.526 typedef typename Parent2::Edge Graph2Edge;
1.527 protected:
1.528 - MergeEdgeGraphWrapperBase() { }
1.529 + MergeEdgeGraphWrapperBaseBase() { }
1.530 public:
1.531 - template <typename _Value> class EdgeMap;
1.532 -
1.533 - typedef typename Parent::Node Node;
1.534
1.535 class Edge : public Graph1Edge {
1.536 - friend class MergeEdgeGraphWrapperBase<_Graph1, _Graph2>;
1.537 - template <typename _Value> friend class EdgeMap;
1.538 + friend class MergeEdgeGraphWrapperBaseBase<_Graph1, _Graph2>;
1.539 protected:
1.540 bool backward; //true, iff backward
1.541 public:
1.542 @@ -977,57 +599,80 @@
1.543
1.544 using Parent::forward;
1.545 using Parent::backward;
1.546 - bool forward(const Edge& e) const { return !e.backward; }
1.547 - bool backward(const Edge& e) const { return e.backward; }
1.548 + using Parent::setForward;
1.549 + using Parent::setBackward;
1.550 + static bool forward(const Edge& e) { return !e.backward; }
1.551 + static bool backward(const Edge& e) { return e.backward; }
1.552 + static void setForward(Edge& e) { e.backward=false; }
1.553 + static void setBackward(Edge& e) { e.backward=true; }
1.554 + };
1.555 +
1.556 +
1.557 + template <typename _Graph1, typename _Graph2>
1.558 + class MergeEdgeGraphWrapperBase :
1.559 + public MergeEdgeGraphWrapperBaseBase<_Graph1, _Graph2> {
1.560 + public:
1.561 + typedef MergeEdgeGraphWrapperBaseBase<_Graph1, _Graph2> Parent;
1.562 + typedef _Graph1 Graph1;
1.563 + typedef _Graph2 Graph2;
1.564 + typedef typename Parent::Parent1 Parent1;
1.565 + typedef typename Parent::Parent2 Parent2;
1.566 + typedef typename Parent1::Node Graph1Node;
1.567 + typedef typename Parent2::Node Graph2Node;
1.568 + typedef typename Parent1::Edge Graph1Edge;
1.569 + typedef typename Parent2::Edge Graph2Edge;
1.570 +
1.571 + typedef typename Parent::Node Node;
1.572 + typedef typename Parent::Edge Edge;
1.573
1.574 using Parent::first;
1.575 void first(Edge& i) const {
1.576 Parent1::graph->first(*static_cast<Graph1Edge*>(&i));
1.577 - i.backward=false;
1.578 + this->setForward(i);
1.579 if (*static_cast<Graph1Edge*>(&i)==INVALID) {
1.580 Parent2::graph->first(*static_cast<Graph2Edge*>(&i));
1.581 - i.backward=true;
1.582 + this->setBackward(i);
1.583 }
1.584 }
1.585 void firstIn(Edge& i, const Node& n) const {
1.586 - if (!backward(n)) {
1.587 + if (forward(n)) {
1.588 Parent1::graph->firstIn(*static_cast<Graph1Edge*>(&i), n);
1.589 if (*static_cast<Graph1Edge*>(&i)==INVALID)
1.590 i=INVALID;
1.591 else
1.592 - i.backward=false;
1.593 + this->setForward(i);
1.594 } else {
1.595 Parent2::graph->firstIn(*static_cast<Graph2Edge*>(&i), n);
1.596 - i.backward=true;
1.597 + this->setBackward(i);
1.598 }
1.599 }
1.600 void firstOut(Edge& i, const Node& n) const {
1.601 - if (!backward(n)) {
1.602 + if (forward(n)) {
1.603 Parent1::graph->firstOut(*static_cast<Graph1Edge*>(&i), n);
1.604 if (*static_cast<Graph1Edge*>(&i)==INVALID)
1.605 i=INVALID;
1.606 - else
1.607 - i.backward=false;
1.608 + else
1.609 + this->setForward(i);
1.610 } else {
1.611 Parent2::graph->firstOut(*static_cast<Graph2Edge*>(&i), n);
1.612 - i.backward=true;
1.613 + this->setBackward(i);
1.614 }
1.615 }
1.616
1.617 using Parent::next;
1.618 void next(Edge& i) const {
1.619 - if (!(i.backward)) {
1.620 + if (forward(i)) {
1.621 Parent1::graph->next(*static_cast<Graph1Edge*>(&i));
1.622 if (*static_cast<Graph1Edge*>(&i)==INVALID) {
1.623 Parent2::graph->first(*static_cast<Graph2Edge*>(&i));
1.624 - i.backward=true;
1.625 + this->setBackward(i);
1.626 }
1.627 } else {
1.628 Parent2::graph->next(*static_cast<Graph2Edge*>(&i));
1.629 }
1.630 }
1.631 void nextIn(Edge& i) const {
1.632 - if (!(i.backward)) {
1.633 + if (forward(i)) {
1.634 Parent1::graph->nextIn(*static_cast<Graph1Edge*>(&i));
1.635 if (*static_cast<Graph1Edge*>(&i)==INVALID) i=INVALID;
1.636 } else {
1.637 @@ -1035,7 +680,7 @@
1.638 }
1.639 }
1.640 void nextOut(Edge& i) const {
1.641 - if (!(i.backward)) {
1.642 + if (Parent::forward(i)) {
1.643 Parent1::graph->nextOut(*static_cast<Graph1Edge*>(&i));
1.644 if (*static_cast<Graph1Edge*>(&i)==INVALID) i=INVALID;
1.645 } else {
1.646 @@ -1044,7 +689,7 @@
1.647 }
1.648
1.649 Node source(const Edge& i) const {
1.650 - if (!(i.backward)) {
1.651 + if (forward(i)) {
1.652 return
1.653 Node(Parent1::graph->source(i), INVALID, false);
1.654 } else {
1.655 @@ -1054,7 +699,7 @@
1.656 }
1.657
1.658 Node target(const Edge& i) const {
1.659 - if (!(i.backward)) {
1.660 + if (forward(i)) {
1.661 return
1.662 Node(Parent1::graph->target(i), INVALID, false);
1.663 } else {
1.664 @@ -1065,7 +710,7 @@
1.665
1.666 using Parent::id;
1.667 int id(const Edge& n) const {
1.668 - if (!n.backward)
1.669 + if (forward(n))
1.670 return this->Parent1::graph->id(n);
1.671 else
1.672 return this->Parent2::graph->id(n);
1.673 @@ -1089,13 +734,13 @@
1.674 forward_map(*(gw.Parent1::graph), value),
1.675 backward_map(*(gw.Parent2::graph), value) { }
1.676 _Value operator[](const Edge& n) const {
1.677 - if (!n.backward)
1.678 + if (Parent::forward(n))
1.679 return forward_map[n];
1.680 else
1.681 return backward_map[n];
1.682 }
1.683 void set(const Edge& n, const _Value& value) {
1.684 - if (!n.backward)
1.685 + if (Parent::forward(n))
1.686 forward_map.set(n, value);
1.687 else
1.688 backward_map.set(n, value);
1.689 @@ -1107,11 +752,24 @@
1.690 };
1.691
1.692
1.693 +
1.694 /*! A graph wrapper class
1.695 - for merging the node-sets and edge-sets of
1.696 - two node-disjoint graphs
1.697 - into one graph.
1.698 - */
1.699 + for merging two node-disjoint graphs
1.700 + into one graph.
1.701 + Different implementations are according to the relation of
1.702 + _Graph1::Edge and _Graph2::Edge.
1.703 + If _Graph1::Edge and _Graph2::Edge are unrelated, then
1.704 + MergeEdgeGraphWrapper<_Graph1, _Graph2>::Edge
1.705 + is derived from both.
1.706 + If _Graph1::Edge and _Graph2::Edge are the same type, then
1.707 + MergeEdgeGraphWrapper<_Graph1, _Graph2>::Edge
1.708 + is derived from _Graph1::Edge.
1.709 + If one of _Graph1::Edge and _Graph2::Edge
1.710 + is derived from the other one, then
1.711 + MergeEdgeGraphWrapper<_Graph1, _Graph2>::Edge
1.712 + is derived from the derived type.
1.713 + It does not satisfy
1.714 + */
1.715 template <typename _Graph1, typename _Graph2>
1.716 class MergeEdgeGraphWrapper : public
1.717 IterableGraphExtender<MergeEdgeGraphWrapperBase<_Graph1, _Graph2> > {