lemon/bits/graph_adaptor_extender.h
author deba
Tue, 04 Apr 2006 17:43:23 +0000
changeset 2037 32e4bebee616
parent 1996 5dc13b93f8b4
child 2041 28df5272df99
permissions -rw-r--r--
Doxygen log corrections

doc of ResGraphAdaptor has a bug in graph_adaptor.h
deba@1979
     1
/* -*- C++ -*-
deba@1979
     2
 *
deba@1979
     3
 * This file is a part of LEMON, a generic C++ optimization library
deba@1979
     4
 *
deba@1979
     5
 * Copyright (C) 2003-2006
deba@1979
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
deba@1979
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
deba@1979
     8
 *
deba@1979
     9
 * Permission to use, modify and distribute this software is granted
deba@1979
    10
 * provided that this copyright notice appears in all copies. For
deba@1979
    11
 * precise terms see the accompanying LICENSE file.
deba@1979
    12
 *
deba@1979
    13
 * This software is provided "AS IS" with no warranty of any kind,
deba@1979
    14
 * express or implied, and with no claim as to its suitability for any
deba@1979
    15
 * purpose.
deba@1979
    16
 *
deba@1979
    17
 */
deba@1979
    18
deba@1996
    19
#ifndef LEMON_BITS_GRAPH_ADAPTOR_EXTENDER_H
deba@1996
    20
#define LEMON_BITS_GRAPH_ADAPTOR_EXTENDER_H
deba@1979
    21
deba@1996
    22
#include <lemon/bits/invalid.h>
deba@1996
    23
#include <lemon/error.h>
deba@1979
    24
deba@1996
    25
#include <lemon/bits/default_map.h>
deba@1996
    26
deba@1996
    27
deba@1996
    28
///\ingroup graphbits
deba@1996
    29
///\file
deba@1996
    30
///\brief Extenders for the graph adaptor types
deba@1979
    31
namespace lemon {
deba@1979
    32
deba@1996
    33
  /// \ingroup graphbits
deba@1996
    34
  ///
deba@1996
    35
  /// \brief Extender for the GraphAdaptors
deba@2031
    36
  template <typename _Graph>
deba@2031
    37
  class GraphAdaptorExtender : public _Graph {
deba@1979
    38
  public:
deba@1979
    39
deba@2031
    40
    typedef _Graph Parent;
deba@2031
    41
    typedef _Graph Graph;
deba@2031
    42
    typedef GraphAdaptorExtender Adaptor;
deba@1979
    43
deba@1979
    44
    // Base extensions
deba@1979
    45
deba@1979
    46
    typedef typename Parent::Node Node;
deba@1979
    47
    typedef typename Parent::Edge Edge;
deba@1979
    48
deba@1979
    49
    int maxId(Node) const {
deba@1979
    50
      return Parent::maxNodeId();
deba@1979
    51
    }
deba@1979
    52
deba@1979
    53
    int maxId(Edge) const {
deba@1979
    54
      return Parent::maxEdgeId();
deba@1979
    55
    }
deba@1979
    56
deba@1979
    57
    Node fromId(int id, Node) const {
deba@1979
    58
      return Parent::nodeFromId(id);
deba@1979
    59
    }
deba@1979
    60
deba@1979
    61
    Edge fromId(int id, Edge) const {
deba@1979
    62
      return Parent::edgeFromId(id);
deba@1979
    63
    }
deba@1979
    64
deba@1979
    65
    Node oppositeNode(const Node &n, const Edge &e) const {
deba@1979
    66
      if (n == Parent::source(e))
deba@1979
    67
	return Parent::target(e);
deba@1979
    68
      else if(n==Parent::target(e))
deba@1979
    69
	return Parent::source(e);
deba@1979
    70
      else
deba@1979
    71
	return INVALID;
deba@1979
    72
    }
deba@1979
    73
deba@1979
    74
    class NodeIt : public Node { 
deba@2031
    75
      const Adaptor* graph;
deba@1979
    76
    public:
deba@1979
    77
deba@1979
    78
      NodeIt() {}
deba@1979
    79
deba@1979
    80
      NodeIt(Invalid i) : Node(i) { }
deba@1979
    81
deba@2031
    82
      explicit NodeIt(const Adaptor& _graph) : graph(&_graph) {
deba@2031
    83
	_graph.first(static_cast<Node&>(*this));
deba@1979
    84
      }
deba@1979
    85
deba@2031
    86
      NodeIt(const Adaptor& _graph, const Node& node) 
deba@1979
    87
	: Node(node), graph(&_graph) {}
deba@1979
    88
deba@1979
    89
      NodeIt& operator++() { 
deba@1979
    90
	graph->next(*this);
deba@1979
    91
	return *this; 
deba@1979
    92
      }
deba@1979
    93
deba@1979
    94
    };
deba@1979
    95
deba@1979
    96
deba@1979
    97
    class EdgeIt : public Edge { 
deba@2031
    98
      const Adaptor* graph;
deba@1979
    99
    public:
deba@1979
   100
deba@1979
   101
      EdgeIt() { }
deba@1979
   102
deba@1979
   103
      EdgeIt(Invalid i) : Edge(i) { }
deba@1979
   104
deba@2031
   105
      explicit EdgeIt(const Adaptor& _graph) : graph(&_graph) {
deba@2031
   106
	_graph.first(static_cast<Edge&>(*this));
deba@1979
   107
      }
deba@1979
   108
deba@2031
   109
      EdgeIt(const Adaptor& _graph, const Edge& e) : 
deba@1979
   110
	Edge(e), graph(&_graph) { }
deba@1979
   111
deba@1979
   112
      EdgeIt& operator++() { 
deba@1979
   113
	graph->next(*this);
deba@1979
   114
	return *this; 
deba@1979
   115
      }
deba@1979
   116
deba@1979
   117
    };
deba@1979
   118
deba@1979
   119
deba@1979
   120
    class OutEdgeIt : public Edge { 
deba@2031
   121
      const Adaptor* graph;
deba@1979
   122
    public:
deba@1979
   123
deba@1979
   124
      OutEdgeIt() { }
deba@1979
   125
deba@1979
   126
      OutEdgeIt(Invalid i) : Edge(i) { }
deba@1979
   127
deba@2031
   128
      OutEdgeIt(const Adaptor& _graph, const Node& node) 
deba@1979
   129
	: graph(&_graph) {
deba@1979
   130
	_graph.firstOut(*this, node);
deba@1979
   131
      }
deba@1979
   132
deba@2031
   133
      OutEdgeIt(const Adaptor& _graph, const Edge& edge) 
deba@1979
   134
	: Edge(edge), graph(&_graph) {}
deba@1979
   135
deba@1979
   136
      OutEdgeIt& operator++() { 
deba@1979
   137
	graph->nextOut(*this);
deba@1979
   138
	return *this; 
deba@1979
   139
      }
deba@1979
   140
deba@1979
   141
    };
deba@1979
   142
deba@1979
   143
deba@1979
   144
    class InEdgeIt : public Edge { 
deba@2031
   145
      const Adaptor* graph;
deba@1979
   146
    public:
deba@1979
   147
deba@1979
   148
      InEdgeIt() { }
deba@1979
   149
deba@1979
   150
      InEdgeIt(Invalid i) : Edge(i) { }
deba@1979
   151
deba@2031
   152
      InEdgeIt(const Adaptor& _graph, const Node& node) 
deba@1979
   153
	: graph(&_graph) {
deba@1979
   154
	_graph.firstIn(*this, node);
deba@1979
   155
      }
deba@1979
   156
deba@2031
   157
      InEdgeIt(const Adaptor& _graph, const Edge& edge) : 
deba@1979
   158
	Edge(edge), graph(&_graph) {}
deba@1979
   159
deba@1979
   160
      InEdgeIt& operator++() { 
deba@1979
   161
	graph->nextIn(*this);
deba@1979
   162
	return *this; 
deba@1979
   163
      }
deba@1979
   164
deba@1979
   165
    };
deba@1979
   166
deba@1979
   167
    /// \brief Base node of the iterator
deba@1979
   168
    ///
deba@1979
   169
    /// Returns the base node (ie. the source in this case) of the iterator
deba@1979
   170
    Node baseNode(const OutEdgeIt &e) const {
deba@1979
   171
      return Parent::source(e);
deba@1979
   172
    }
deba@1979
   173
    /// \brief Running node of the iterator
deba@1979
   174
    ///
deba@1979
   175
    /// Returns the running node (ie. the target in this case) of the
deba@1979
   176
    /// iterator
deba@1979
   177
    Node runningNode(const OutEdgeIt &e) const {
deba@1979
   178
      return Parent::target(e);
deba@1979
   179
    }
deba@1979
   180
deba@1979
   181
    /// \brief Base node of the iterator
deba@1979
   182
    ///
deba@1979
   183
    /// Returns the base node (ie. the target in this case) of the iterator
deba@1979
   184
    Node baseNode(const InEdgeIt &e) const {
deba@1979
   185
      return Parent::target(e);
deba@1979
   186
    }
deba@1979
   187
    /// \brief Running node of the iterator
deba@1979
   188
    ///
deba@1979
   189
    /// Returns the running node (ie. the source in this case) of the
deba@1979
   190
    /// iterator
deba@1979
   191
    Node runningNode(const InEdgeIt &e) const {
deba@1979
   192
      return Parent::source(e);
deba@1979
   193
    }
deba@1979
   194
deba@1979
   195
  };
deba@1979
   196
deba@1979
   197
deba@1996
   198
  /// \ingroup graphbits
deba@1996
   199
  ///
deba@1996
   200
  /// \brief Extender for the UGraphAdaptors
deba@2031
   201
  template <typename _UGraph> 
deba@2031
   202
  class UGraphAdaptorExtender : public _UGraph {
deba@1979
   203
  public:
deba@1979
   204
    
deba@2031
   205
    typedef _UGraph Parent;
deba@2031
   206
    typedef _UGraph UGraph;
deba@2031
   207
    typedef UGraphAdaptorExtender Adaptor;
deba@1979
   208
deba@1979
   209
    typedef typename Parent::Node Node;
deba@1979
   210
    typedef typename Parent::Edge Edge;
deba@1979
   211
    typedef typename Parent::UEdge UEdge;
deba@1979
   212
deba@1979
   213
    // UGraph extension    
deba@1979
   214
deba@1979
   215
    int maxId(Node) const {
deba@1979
   216
      return Parent::maxNodeId();
deba@1979
   217
    }
deba@1979
   218
deba@1979
   219
    int maxId(Edge) const {
deba@1979
   220
      return Parent::maxEdgeId();
deba@1979
   221
    }
deba@1979
   222
deba@1979
   223
    int maxId(UEdge) const {
deba@1979
   224
      return Parent::maxUEdgeId();
deba@1979
   225
    }
deba@1979
   226
deba@1979
   227
    Node fromId(int id, Node) const {
deba@1979
   228
      return Parent::nodeFromId(id);
deba@1979
   229
    }
deba@1979
   230
deba@1979
   231
    Edge fromId(int id, Edge) const {
deba@1979
   232
      return Parent::edgeFromId(id);
deba@1979
   233
    }
deba@1979
   234
deba@1979
   235
    UEdge fromId(int id, UEdge) const {
deba@1979
   236
      return Parent::uEdgeFromId(id);
deba@1979
   237
    }
deba@1979
   238
deba@1979
   239
    Node oppositeNode(const Node &n, const UEdge &e) const {
deba@1979
   240
      if( n == Parent::source(e))
deba@1979
   241
	return Parent::target(e);
deba@1979
   242
      else if( n == Parent::target(e))
deba@1979
   243
	return Parent::source(e);
deba@1979
   244
      else
deba@1979
   245
	return INVALID;
deba@1979
   246
    }
deba@1979
   247
deba@1979
   248
    Edge oppositeEdge(const Edge &e) const {
deba@1979
   249
      return Parent::direct(e, !Parent::direction(e));
deba@1979
   250
    }
deba@1979
   251
deba@1979
   252
    using Parent::direct;
deba@1979
   253
    Edge direct(const UEdge &ue, const Node &s) const {
deba@1979
   254
      return Parent::direct(ue, Parent::source(ue) == s);
deba@1979
   255
    }
deba@1979
   256
deba@1979
   257
deba@1979
   258
    class NodeIt : public Node { 
deba@2031
   259
      const Adaptor* graph;
deba@1979
   260
    public:
deba@1979
   261
deba@1979
   262
      NodeIt() {}
deba@1979
   263
deba@1979
   264
      NodeIt(Invalid i) : Node(i) { }
deba@1979
   265
deba@2031
   266
      explicit NodeIt(const Adaptor& _graph) : graph(&_graph) {
deba@2031
   267
	_graph.first(static_cast<Node&>(*this));
deba@1979
   268
      }
deba@1979
   269
deba@2031
   270
      NodeIt(const Adaptor& _graph, const Node& node) 
deba@1979
   271
	: Node(node), graph(&_graph) {}
deba@1979
   272
deba@1979
   273
      NodeIt& operator++() { 
deba@1979
   274
	graph->next(*this);
deba@1979
   275
	return *this; 
deba@1979
   276
      }
deba@1979
   277
deba@1979
   278
    };
deba@1979
   279
deba@1979
   280
deba@1979
   281
    class EdgeIt : public Edge { 
deba@2031
   282
      const Adaptor* graph;
deba@1979
   283
    public:
deba@1979
   284
deba@1979
   285
      EdgeIt() { }
deba@1979
   286
deba@1979
   287
      EdgeIt(Invalid i) : Edge(i) { }
deba@1979
   288
deba@2031
   289
      explicit EdgeIt(const Adaptor& _graph) : graph(&_graph) {
deba@2031
   290
	_graph.first(static_cast<Edge&>(*this));
deba@1979
   291
      }
deba@1979
   292
deba@2031
   293
      EdgeIt(const Adaptor& _graph, const Edge& e) : 
deba@1979
   294
	Edge(e), graph(&_graph) { }
deba@1979
   295
deba@1979
   296
      EdgeIt& operator++() { 
deba@1979
   297
	graph->next(*this);
deba@1979
   298
	return *this; 
deba@1979
   299
      }
deba@1979
   300
deba@1979
   301
    };
deba@1979
   302
deba@1979
   303
deba@1979
   304
    class OutEdgeIt : public Edge { 
deba@2031
   305
      const Adaptor* graph;
deba@1979
   306
    public:
deba@1979
   307
deba@1979
   308
      OutEdgeIt() { }
deba@1979
   309
deba@1979
   310
      OutEdgeIt(Invalid i) : Edge(i) { }
deba@1979
   311
deba@2031
   312
      OutEdgeIt(const Adaptor& _graph, const Node& node) 
deba@1979
   313
	: graph(&_graph) {
deba@1979
   314
	_graph.firstOut(*this, node);
deba@1979
   315
      }
deba@1979
   316
deba@2031
   317
      OutEdgeIt(const Adaptor& _graph, const Edge& edge) 
deba@1979
   318
	: Edge(edge), graph(&_graph) {}
deba@1979
   319
deba@1979
   320
      OutEdgeIt& operator++() { 
deba@1979
   321
	graph->nextOut(*this);
deba@1979
   322
	return *this; 
deba@1979
   323
      }
deba@1979
   324
deba@1979
   325
    };
deba@1979
   326
deba@1979
   327
deba@1979
   328
    class InEdgeIt : public Edge { 
deba@2031
   329
      const Adaptor* graph;
deba@1979
   330
    public:
deba@1979
   331
deba@1979
   332
      InEdgeIt() { }
deba@1979
   333
deba@1979
   334
      InEdgeIt(Invalid i) : Edge(i) { }
deba@1979
   335
deba@2031
   336
      InEdgeIt(const Adaptor& _graph, const Node& node) 
deba@1979
   337
	: graph(&_graph) {
deba@1979
   338
	_graph.firstIn(*this, node);
deba@1979
   339
      }
deba@1979
   340
deba@2031
   341
      InEdgeIt(const Adaptor& _graph, const Edge& edge) : 
deba@1979
   342
	Edge(edge), graph(&_graph) {}
deba@1979
   343
deba@1979
   344
      InEdgeIt& operator++() { 
deba@1979
   345
	graph->nextIn(*this);
deba@1979
   346
	return *this; 
deba@1979
   347
      }
deba@1979
   348
deba@1979
   349
    };
deba@1979
   350
deba@1979
   351
    class UEdgeIt : public Parent::UEdge { 
deba@2031
   352
      const Adaptor* graph;
deba@1979
   353
    public:
deba@1979
   354
deba@1979
   355
      UEdgeIt() { }
deba@1979
   356
deba@1979
   357
      UEdgeIt(Invalid i) : UEdge(i) { }
deba@1979
   358
deba@2031
   359
      explicit UEdgeIt(const Adaptor& _graph) : graph(&_graph) {
deba@2031
   360
	_graph.first(static_cast<UEdge&>(*this));
deba@1979
   361
      }
deba@1979
   362
deba@2031
   363
      UEdgeIt(const Adaptor& _graph, const UEdge& e) : 
deba@1979
   364
	UEdge(e), graph(&_graph) { }
deba@1979
   365
deba@1979
   366
      UEdgeIt& operator++() { 
deba@1979
   367
	graph->next(*this);
deba@1979
   368
	return *this; 
deba@1979
   369
      }
deba@1979
   370
deba@1979
   371
    };
deba@1979
   372
deba@1979
   373
    class IncEdgeIt : public Parent::UEdge { 
deba@1979
   374
      friend class UGraphAdaptorExtender;
deba@2031
   375
      const Adaptor* graph;
deba@1979
   376
      bool direction;
deba@1979
   377
    public:
deba@1979
   378
deba@1979
   379
      IncEdgeIt() { }
deba@1979
   380
deba@1979
   381
      IncEdgeIt(Invalid i) : UEdge(i), direction(false) { }
deba@1979
   382
deba@2031
   383
      IncEdgeIt(const Adaptor& _graph, const Node &n) : graph(&_graph) {
deba@1979
   384
	_graph.firstInc(static_cast<UEdge&>(*this), direction, n);
deba@1979
   385
      }
deba@1979
   386
deba@2031
   387
      IncEdgeIt(const Adaptor& _graph, const UEdge &ue, const Node &n)
deba@1979
   388
	: graph(&_graph), UEdge(ue) {
deba@1979
   389
	direction = (_graph.source(ue) == n);
deba@1979
   390
      }
deba@1979
   391
deba@1979
   392
      IncEdgeIt& operator++() {
deba@1979
   393
	graph->nextInc(*this, direction);
deba@1979
   394
	return *this; 
deba@1979
   395
      }
deba@1979
   396
    };
deba@1979
   397
deba@1979
   398
    /// \brief Base node of the iterator
deba@1979
   399
    ///
deba@1979
   400
    /// Returns the base node (ie. the source in this case) of the iterator
deba@1979
   401
    Node baseNode(const OutEdgeIt &e) const {
deba@1979
   402
      return Parent::source((Edge)e);
deba@1979
   403
    }
deba@1979
   404
    /// \brief Running node of the iterator
deba@1979
   405
    ///
deba@1979
   406
    /// Returns the running node (ie. the target in this case) of the
deba@1979
   407
    /// iterator
deba@1979
   408
    Node runningNode(const OutEdgeIt &e) const {
deba@1979
   409
      return Parent::target((Edge)e);
deba@1979
   410
    }
deba@1979
   411
deba@1979
   412
    /// \brief Base node of the iterator
deba@1979
   413
    ///
deba@1979
   414
    /// Returns the base node (ie. the target in this case) of the iterator
deba@1979
   415
    Node baseNode(const InEdgeIt &e) const {
deba@1979
   416
      return Parent::target((Edge)e);
deba@1979
   417
    }
deba@1979
   418
    /// \brief Running node of the iterator
deba@1979
   419
    ///
deba@1979
   420
    /// Returns the running node (ie. the source in this case) of the
deba@1979
   421
    /// iterator
deba@1979
   422
    Node runningNode(const InEdgeIt &e) const {
deba@1979
   423
      return Parent::source((Edge)e);
deba@1979
   424
    }
deba@1979
   425
deba@1979
   426
    /// Base node of the iterator
deba@1979
   427
    ///
deba@1979
   428
    /// Returns the base node of the iterator
deba@1979
   429
    Node baseNode(const IncEdgeIt &e) const {
deba@1979
   430
      return e.direction ? source(e) : target(e);
deba@1979
   431
    }
deba@1979
   432
    /// Running node of the iterator
deba@1979
   433
    ///
deba@1979
   434
    /// Returns the running node of the iterator
deba@1979
   435
    Node runningNode(const IncEdgeIt &e) const {
deba@1979
   436
      return e.direction ? target(e) : source(e);
deba@1979
   437
    }
deba@1979
   438
deba@1979
   439
  };
deba@1979
   440
deba@2031
   441
  /// \ingroup graphbits
deba@2031
   442
  ///
deba@2031
   443
  /// \brief Extender for the BpUGraphAdaptors
deba@2031
   444
  template <typename Base>
deba@2031
   445
  class BpUGraphAdaptorExtender : public Base {
deba@2031
   446
  public:
deba@2031
   447
    typedef Base Parent;
deba@2031
   448
    typedef BpUGraphAdaptorExtender Graph;
deba@2031
   449
deba@2031
   450
    typedef typename Parent::Node Node;
deba@2031
   451
    typedef typename Parent::BNode BNode;
deba@2031
   452
    typedef typename Parent::ANode ANode;
deba@2031
   453
    typedef typename Parent::Edge Edge;
deba@2031
   454
    typedef typename Parent::UEdge UEdge;
deba@2031
   455
deba@2031
   456
    Node oppositeNode(const UEdge& edge, const Node& node) const {
deba@2031
   457
      return source(edge) == node ? 
deba@2031
   458
	target(edge) : source(edge);
deba@2031
   459
    }
deba@2031
   460
deba@2031
   461
deba@2031
   462
    int maxId(Node) const {
deba@2031
   463
      return Parent::maxNodeId();
deba@2031
   464
    }
deba@2031
   465
    int maxId(BNode) const {
deba@2031
   466
      return Parent::maxBNodeId();
deba@2031
   467
    }
deba@2031
   468
    int maxId(ANode) const {
deba@2031
   469
      return Parent::maxANodeId();
deba@2031
   470
    }
deba@2031
   471
    int maxId(Edge) const {
deba@2031
   472
      return Parent::maxEdgeId();
deba@2031
   473
    }
deba@2031
   474
    int maxId(UEdge) const {
deba@2031
   475
      return Parent::maxUEdgeId();
deba@2031
   476
    }
deba@2031
   477
deba@2031
   478
deba@2031
   479
    Node fromId(int id, Node) const {
deba@2031
   480
      return Parent::nodeFromId(id);
deba@2031
   481
    }
deba@2031
   482
    ANode fromId(int id, ANode) const {
deba@2031
   483
      return Parent::fromANodeId(id);
deba@2031
   484
    }
deba@2031
   485
    BNode fromId(int id, BNode) const {
deba@2031
   486
      return Parent::fromBNodeId(id);
deba@2031
   487
    }
deba@2031
   488
    Edge fromId(int id, Edge) const {
deba@2031
   489
      return Parent::edgeFromId(id);
deba@2031
   490
    }
deba@2031
   491
    UEdge fromId(int id, UEdge) const {
deba@2031
   492
      return Parent::uEdgeFromId(id);
deba@2031
   493
    }  
deba@2031
   494
  
deba@2031
   495
    class NodeIt : public Node { 
deba@2031
   496
      const Graph* graph;
deba@2031
   497
    public:
deba@2031
   498
    
deba@2031
   499
      NodeIt() { }
deba@2031
   500
    
deba@2031
   501
      NodeIt(Invalid i) : Node(INVALID) { }
deba@2031
   502
    
deba@2031
   503
      explicit NodeIt(const Graph& _graph) : graph(&_graph) {
deba@2031
   504
	graph->first(static_cast<Node&>(*this));
deba@2031
   505
      }
deba@2031
   506
deba@2031
   507
      NodeIt(const Graph& _graph, const Node& node) 
deba@2031
   508
	: Node(node), graph(&_graph) { }
deba@2031
   509
    
deba@2031
   510
      NodeIt& operator++() { 
deba@2031
   511
	graph->next(*this);
deba@2031
   512
	return *this; 
deba@2031
   513
      }
deba@2031
   514
deba@2031
   515
    };
deba@2031
   516
deba@2031
   517
    class ANodeIt : public Node { 
deba@2031
   518
      friend class BpUGraphAdaptorExtender;
deba@2031
   519
      const Graph* graph;
deba@2031
   520
    public:
deba@2031
   521
    
deba@2031
   522
      ANodeIt() { }
deba@2031
   523
    
deba@2031
   524
      ANodeIt(Invalid i) : Node(INVALID) { }
deba@2031
   525
    
deba@2031
   526
      explicit ANodeIt(const Graph& _graph) : graph(&_graph) {
deba@2031
   527
	graph->firstANode(static_cast<Node&>(*this));
deba@2031
   528
      }
deba@2031
   529
deba@2031
   530
      ANodeIt(const Graph& _graph, const Node& node) 
deba@2031
   531
	: Node(node), graph(&_graph) {}
deba@2031
   532
    
deba@2031
   533
      ANodeIt& operator++() { 
deba@2031
   534
	graph->nextANode(*this);
deba@2031
   535
	return *this; 
deba@2031
   536
      }
deba@2031
   537
    };
deba@2031
   538
deba@2031
   539
    class BNodeIt : public Node { 
deba@2031
   540
      friend class BpUGraphAdaptorExtender;
deba@2031
   541
      const Graph* graph;
deba@2031
   542
    public:
deba@2031
   543
    
deba@2031
   544
      BNodeIt() { }
deba@2031
   545
    
deba@2031
   546
      BNodeIt(Invalid i) : Node(INVALID) { }
deba@2031
   547
    
deba@2031
   548
      explicit BNodeIt(const Graph& _graph) : graph(&_graph) {
deba@2031
   549
	graph->firstBNode(static_cast<Node&>(*this));
deba@2031
   550
      }
deba@2031
   551
deba@2031
   552
      BNodeIt(const Graph& _graph, const Node& node) 
deba@2031
   553
	: Node(node), graph(&_graph) {}
deba@2031
   554
    
deba@2031
   555
      BNodeIt& operator++() { 
deba@2031
   556
	graph->nextBNode(*this);
deba@2031
   557
	return *this; 
deba@2031
   558
      }
deba@2031
   559
    };
deba@2031
   560
deba@2031
   561
    class EdgeIt : public Edge { 
deba@2031
   562
      friend class BpUGraphAdaptorExtender;
deba@2031
   563
      const Graph* graph;
deba@2031
   564
    public:
deba@2031
   565
    
deba@2031
   566
      EdgeIt() { }
deba@2031
   567
    
deba@2031
   568
      EdgeIt(Invalid i) : Edge(INVALID) { }
deba@2031
   569
    
deba@2031
   570
      explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
deba@2031
   571
	graph->first(static_cast<Edge&>(*this));
deba@2031
   572
      }
deba@2031
   573
deba@2031
   574
      EdgeIt(const Graph& _graph, const Edge& edge) 
deba@2031
   575
	: Edge(edge), graph(&_graph) { }
deba@2031
   576
    
deba@2031
   577
      EdgeIt& operator++() { 
deba@2031
   578
	graph->next(*this);
deba@2031
   579
	return *this; 
deba@2031
   580
      }
deba@2031
   581
deba@2031
   582
    };
deba@2031
   583
deba@2031
   584
    class UEdgeIt : public UEdge { 
deba@2031
   585
      friend class BpUGraphAdaptorExtender;
deba@2031
   586
      const Graph* graph;
deba@2031
   587
    public:
deba@2031
   588
    
deba@2031
   589
      UEdgeIt() { }
deba@2031
   590
    
deba@2031
   591
      UEdgeIt(Invalid i) : UEdge(INVALID) { }
deba@2031
   592
    
deba@2031
   593
      explicit UEdgeIt(const Graph& _graph) : graph(&_graph) {
deba@2031
   594
	graph->first(static_cast<UEdge&>(*this));
deba@2031
   595
      }
deba@2031
   596
deba@2031
   597
      UEdgeIt(const Graph& _graph, const UEdge& edge) 
deba@2031
   598
	: UEdge(edge), graph(&_graph) { }
deba@2031
   599
    
deba@2031
   600
      UEdgeIt& operator++() { 
deba@2031
   601
	graph->next(*this);
deba@2031
   602
	return *this; 
deba@2031
   603
      }
deba@2031
   604
    };
deba@2031
   605
deba@2031
   606
    class OutEdgeIt : public Edge { 
deba@2031
   607
      friend class BpUGraphAdaptorExtender;
deba@2031
   608
      const Graph* graph;
deba@2031
   609
    public:
deba@2031
   610
    
deba@2031
   611
      OutEdgeIt() { }
deba@2031
   612
    
deba@2031
   613
      OutEdgeIt(Invalid i) : Edge(i) { }
deba@2031
   614
    
deba@2031
   615
      OutEdgeIt(const Graph& _graph, const Node& node) 
deba@2031
   616
	: graph(&_graph) {
deba@2031
   617
	graph->firstOut(*this, node);
deba@2031
   618
      }
deba@2031
   619
    
deba@2031
   620
      OutEdgeIt(const Graph& _graph, const Edge& edge) 
deba@2031
   621
	: Edge(edge), graph(&_graph) {}
deba@2031
   622
    
deba@2031
   623
      OutEdgeIt& operator++() { 
deba@2031
   624
	graph->nextOut(*this);
deba@2031
   625
	return *this; 
deba@2031
   626
      }
deba@2031
   627
deba@2031
   628
    };
deba@2031
   629
deba@2031
   630
deba@2031
   631
    class InEdgeIt : public Edge { 
deba@2031
   632
      friend class BpUGraphAdaptorExtender;
deba@2031
   633
      const Graph* graph;
deba@2031
   634
    public:
deba@2031
   635
    
deba@2031
   636
      InEdgeIt() { }
deba@2031
   637
    
deba@2031
   638
      InEdgeIt(Invalid i) : Edge(i) { }
deba@2031
   639
    
deba@2031
   640
      InEdgeIt(const Graph& _graph, const Node& node) 
deba@2031
   641
	: graph(&_graph) {
deba@2031
   642
	graph->firstIn(*this, node);
deba@2031
   643
      }
deba@2031
   644
    
deba@2031
   645
      InEdgeIt(const Graph& _graph, const Edge& edge) : 
deba@2031
   646
	Edge(edge), graph(&_graph) {}
deba@2031
   647
    
deba@2031
   648
      InEdgeIt& operator++() { 
deba@2031
   649
	graph->nextIn(*this);
deba@2031
   650
	return *this; 
deba@2031
   651
      }
deba@2031
   652
deba@2031
   653
    };
deba@2031
   654
  
deba@2031
   655
    /// \brief Base node of the iterator
deba@2031
   656
    ///
deba@2031
   657
    /// Returns the base node (ie. the source in this case) of the iterator
deba@2031
   658
    Node baseNode(const OutEdgeIt &e) const {
deba@2031
   659
      return Parent::source((Edge&)e);
deba@2031
   660
    }
deba@2031
   661
    /// \brief Running node of the iterator
deba@2031
   662
    ///
deba@2031
   663
    /// Returns the running node (ie. the target in this case) of the
deba@2031
   664
    /// iterator
deba@2031
   665
    Node runningNode(const OutEdgeIt &e) const {
deba@2031
   666
      return Parent::target((Edge&)e);
deba@2031
   667
    }
deba@2031
   668
  
deba@2031
   669
    /// \brief Base node of the iterator
deba@2031
   670
    ///
deba@2031
   671
    /// Returns the base node (ie. the target in this case) of the iterator
deba@2031
   672
    Node baseNode(const InEdgeIt &e) const {
deba@2031
   673
      return Parent::target((Edge&)e);
deba@2031
   674
    }
deba@2031
   675
    /// \brief Running node of the iterator
deba@2031
   676
    ///
deba@2031
   677
    /// Returns the running node (ie. the source in this case) of the
deba@2031
   678
    /// iterator
deba@2031
   679
    Node runningNode(const InEdgeIt &e) const {
deba@2031
   680
      return Parent::source((Edge&)e);
deba@2031
   681
    }
deba@2031
   682
  
deba@2031
   683
    class IncEdgeIt : public Parent::UEdge { 
deba@2031
   684
      friend class BpUGraphAdaptorExtender;
deba@2031
   685
      const Graph* graph;
deba@2031
   686
      bool direction;
deba@2031
   687
    public:
deba@2031
   688
    
deba@2031
   689
      IncEdgeIt() { }
deba@2031
   690
    
deba@2031
   691
      IncEdgeIt(Invalid i) : UEdge(i), direction(true) { }
deba@2031
   692
    
deba@2031
   693
      IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
deba@2031
   694
	graph->firstInc(*this, direction, n);
deba@2031
   695
      }
deba@2031
   696
deba@2031
   697
      IncEdgeIt(const Graph& _graph, const UEdge &ue, const Node &n)
deba@2031
   698
	: graph(&_graph), UEdge(ue) {
deba@2031
   699
	direction = (graph->source(ue) == n);
deba@2031
   700
      }
deba@2031
   701
deba@2031
   702
      IncEdgeIt& operator++() {
deba@2031
   703
	graph->nextInc(*this, direction);
deba@2031
   704
	return *this; 
deba@2031
   705
      }
deba@2031
   706
    };
deba@2031
   707
  
deba@2031
   708
deba@2031
   709
    /// Base node of the iterator
deba@2031
   710
    ///
deba@2031
   711
    /// Returns the base node of the iterator
deba@2031
   712
    Node baseNode(const IncEdgeIt &e) const {
deba@2031
   713
      return e.direction ? source(e) : target(e);
deba@2031
   714
    }
deba@2031
   715
deba@2031
   716
    /// Running node of the iterator
deba@2031
   717
    ///
deba@2031
   718
    /// Returns the running node of the iterator
deba@2031
   719
    Node runningNode(const IncEdgeIt &e) const {
deba@2031
   720
      return e.direction ? target(e) : source(e);
deba@2031
   721
    }
deba@2031
   722
deba@2031
   723
  };
deba@2031
   724
deba@1979
   725
deba@1979
   726
}
deba@1979
   727
deba@1979
   728
deba@1979
   729
#endif