lemon/bits/graph_extender.h
author alpar
Thu, 12 Oct 2006 10:53:49 +0000
changeset 2236 9f329faa4aee
parent 2222 a24939ee343c
child 2260 4274224f8a7d
permissions -rw-r--r--
EdgeLookUp and AllEdgeLookUp tests added.
deba@1791
     1
/* -*- C++ -*-
deba@1791
     2
 *
alpar@1956
     3
 * This file is a part of LEMON, a generic C++ optimization library
alpar@1956
     4
 *
alpar@1956
     5
 * Copyright (C) 2003-2006
alpar@1956
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@1956
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
deba@1791
     8
 *
deba@1791
     9
 * Permission to use, modify and distribute this software is granted
deba@1791
    10
 * provided that this copyright notice appears in all copies. For
deba@1791
    11
 * precise terms see the accompanying LICENSE file.
deba@1791
    12
 *
deba@1791
    13
 * This software is provided "AS IS" with no warranty of any kind,
deba@1791
    14
 * express or implied, and with no claim as to its suitability for any
deba@1791
    15
 * purpose.
deba@1791
    16
 *
deba@1791
    17
 */
deba@1791
    18
deba@1996
    19
#ifndef LEMON_BITS_GRAPH_EXTENDER_H
deba@1996
    20
#define LEMON_BITS_GRAPH_EXTENDER_H
deba@1791
    21
deba@1993
    22
#include <lemon/bits/invalid.h>
deba@2116
    23
#include <lemon/error.h>
deba@1791
    24
deba@1999
    25
#include <lemon/bits/map_extender.h>
deba@1979
    26
#include <lemon/bits/default_map.h>
deba@1979
    27
deba@2116
    28
#include <lemon/concept_check.h>
deba@2116
    29
#include <lemon/concept/maps.h>
deba@2116
    30
deba@1996
    31
///\ingroup graphbits
deba@1996
    32
///\file
deba@1996
    33
///\brief Extenders for the graph types
deba@1791
    34
namespace lemon {
deba@1791
    35
deba@1996
    36
  /// \ingroup graphbits
deba@1996
    37
  ///
deba@1996
    38
  /// \brief Extender for the Graphs
deba@1979
    39
  template <typename Base>
deba@1979
    40
  class GraphExtender : public Base {
deba@1791
    41
  public:
deba@1791
    42
deba@1979
    43
    typedef Base Parent;
deba@1791
    44
    typedef GraphExtender Graph;
deba@1791
    45
deba@1979
    46
    // Base extensions
deba@1979
    47
deba@1791
    48
    typedef typename Parent::Node Node;
deba@1791
    49
    typedef typename Parent::Edge Edge;
deba@1791
    50
deba@1791
    51
    int maxId(Node) const {
deba@1791
    52
      return Parent::maxNodeId();
deba@1791
    53
    }
deba@1791
    54
deba@1791
    55
    int maxId(Edge) const {
deba@1791
    56
      return Parent::maxEdgeId();
deba@1791
    57
    }
deba@1791
    58
deba@1791
    59
    Node fromId(int id, Node) const {
deba@1791
    60
      return Parent::nodeFromId(id);
deba@1791
    61
    }
deba@1791
    62
deba@1791
    63
    Edge fromId(int id, Edge) const {
deba@1791
    64
      return Parent::edgeFromId(id);
deba@1791
    65
    }
deba@1791
    66
deba@1791
    67
    Node oppositeNode(const Node &n, const Edge &e) const {
deba@1791
    68
      if (n == Parent::source(e))
deba@1791
    69
	return Parent::target(e);
deba@1791
    70
      else if(n==Parent::target(e))
deba@1791
    71
	return Parent::source(e);
deba@1791
    72
      else
deba@1791
    73
	return INVALID;
deba@1791
    74
    }
deba@1791
    75
deba@1979
    76
    // Alterable extension
deba@1791
    77
deba@1999
    78
    typedef AlterationNotifier<GraphExtender, Node> NodeNotifier;
deba@1999
    79
    typedef AlterationNotifier<GraphExtender, Edge> EdgeNotifier;
deba@1979
    80
deba@1979
    81
deba@1979
    82
  protected:
deba@1979
    83
deba@1979
    84
    mutable NodeNotifier node_notifier;
deba@1979
    85
    mutable EdgeNotifier edge_notifier;
deba@1791
    86
deba@1791
    87
  public:
deba@1791
    88
deba@1979
    89
    NodeNotifier& getNotifier(Node) const {
deba@1979
    90
      return node_notifier;
deba@1979
    91
    }
deba@1979
    92
    
deba@1979
    93
    EdgeNotifier& getNotifier(Edge) const {
deba@1979
    94
      return edge_notifier;
deba@1979
    95
    }
deba@1979
    96
deba@1979
    97
    class NodeIt : public Node { 
deba@1979
    98
      const Graph* graph;
deba@1979
    99
    public:
deba@1979
   100
deba@1979
   101
      NodeIt() {}
deba@1979
   102
deba@1979
   103
      NodeIt(Invalid i) : Node(i) { }
deba@1979
   104
deba@1979
   105
      explicit NodeIt(const Graph& _graph) : graph(&_graph) {
deba@2031
   106
	_graph.first(static_cast<Node&>(*this));
deba@1979
   107
      }
deba@1979
   108
deba@1979
   109
      NodeIt(const Graph& _graph, const Node& node) 
deba@1979
   110
	: Node(node), graph(&_graph) {}
deba@1979
   111
deba@1979
   112
      NodeIt& 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 EdgeIt : public Edge { 
deba@1979
   121
      const Graph* graph;
deba@1979
   122
    public:
deba@1979
   123
deba@1979
   124
      EdgeIt() { }
deba@1979
   125
deba@1979
   126
      EdgeIt(Invalid i) : Edge(i) { }
deba@1979
   127
deba@1979
   128
      explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
deba@2031
   129
	_graph.first(static_cast<Edge&>(*this));
deba@1979
   130
      }
deba@1979
   131
deba@1979
   132
      EdgeIt(const Graph& _graph, const Edge& e) : 
deba@1979
   133
	Edge(e), graph(&_graph) { }
deba@1979
   134
deba@1979
   135
      EdgeIt& operator++() { 
deba@1979
   136
	graph->next(*this);
deba@1979
   137
	return *this; 
deba@1979
   138
      }
deba@1979
   139
deba@1979
   140
    };
deba@1979
   141
deba@1979
   142
deba@1979
   143
    class OutEdgeIt : public Edge { 
deba@1979
   144
      const Graph* graph;
deba@1979
   145
    public:
deba@1979
   146
deba@1979
   147
      OutEdgeIt() { }
deba@1979
   148
deba@1979
   149
      OutEdgeIt(Invalid i) : Edge(i) { }
deba@1979
   150
deba@1979
   151
      OutEdgeIt(const Graph& _graph, const Node& node) 
deba@1979
   152
	: graph(&_graph) {
deba@1979
   153
	_graph.firstOut(*this, node);
deba@1979
   154
      }
deba@1979
   155
deba@1979
   156
      OutEdgeIt(const Graph& _graph, const Edge& edge) 
deba@1979
   157
	: Edge(edge), graph(&_graph) {}
deba@1979
   158
deba@1979
   159
      OutEdgeIt& operator++() { 
deba@1979
   160
	graph->nextOut(*this);
deba@1979
   161
	return *this; 
deba@1979
   162
      }
deba@1979
   163
deba@1979
   164
    };
deba@1979
   165
deba@1979
   166
deba@1979
   167
    class InEdgeIt : public Edge { 
deba@1979
   168
      const Graph* graph;
deba@1979
   169
    public:
deba@1979
   170
deba@1979
   171
      InEdgeIt() { }
deba@1979
   172
deba@1979
   173
      InEdgeIt(Invalid i) : Edge(i) { }
deba@1979
   174
deba@1979
   175
      InEdgeIt(const Graph& _graph, const Node& node) 
deba@1979
   176
	: graph(&_graph) {
deba@1979
   177
	_graph.firstIn(*this, node);
deba@1979
   178
      }
deba@1979
   179
deba@1979
   180
      InEdgeIt(const Graph& _graph, const Edge& edge) : 
deba@1979
   181
	Edge(edge), graph(&_graph) {}
deba@1979
   182
deba@1979
   183
      InEdgeIt& operator++() { 
deba@1979
   184
	graph->nextIn(*this);
deba@1979
   185
	return *this; 
deba@1979
   186
      }
deba@1979
   187
deba@1979
   188
    };
deba@1979
   189
deba@1979
   190
    /// \brief Base node of the iterator
deba@1979
   191
    ///
athos@2102
   192
    /// Returns the base node (i.e. the source in this case) of the iterator
deba@1979
   193
    Node baseNode(const OutEdgeIt &e) const {
deba@1979
   194
      return Parent::source(e);
deba@1979
   195
    }
deba@1979
   196
    /// \brief Running node of the iterator
deba@1979
   197
    ///
athos@2102
   198
    /// Returns the running node (i.e. the target in this case) of the
deba@1979
   199
    /// iterator
deba@1979
   200
    Node runningNode(const OutEdgeIt &e) const {
deba@1979
   201
      return Parent::target(e);
deba@1979
   202
    }
deba@1979
   203
deba@1979
   204
    /// \brief Base node of the iterator
deba@1979
   205
    ///
athos@2102
   206
    /// Returns the base node (i.e. the target in this case) of the iterator
deba@1979
   207
    Node baseNode(const InEdgeIt &e) const {
deba@1979
   208
      return Parent::target(e);
deba@1979
   209
    }
deba@1979
   210
    /// \brief Running node of the iterator
deba@1979
   211
    ///
athos@2102
   212
    /// Returns the running node (i.e. the source in this case) of the
deba@1979
   213
    /// iterator
deba@1979
   214
    Node runningNode(const InEdgeIt &e) const {
deba@1979
   215
      return Parent::source(e);
deba@1979
   216
    }
deba@1979
   217
deba@1979
   218
    
deba@1979
   219
    template <typename _Value>
deba@1979
   220
    class NodeMap 
deba@1999
   221
      : public MapExtender<DefaultMap<Graph, Node, _Value> > {
deba@1979
   222
    public:
deba@1979
   223
      typedef GraphExtender Graph;
deba@1999
   224
      typedef MapExtender<DefaultMap<Graph, Node, _Value> > Parent;
deba@1979
   225
klao@2046
   226
      explicit NodeMap(const Graph& graph) 
deba@1999
   227
	: Parent(graph) {}
deba@1999
   228
      NodeMap(const Graph& graph, const _Value& value) 
deba@1999
   229
	: Parent(graph, value) {}
deba@1979
   230
deba@1979
   231
      NodeMap& operator=(const NodeMap& cmap) {
deba@1979
   232
	return operator=<NodeMap>(cmap);
deba@1979
   233
      }
deba@1979
   234
deba@1979
   235
      template <typename CMap>
deba@1979
   236
      NodeMap& operator=(const CMap& cmap) {
deba@2031
   237
        Parent::operator=(cmap);
deba@1979
   238
	return *this;
deba@1979
   239
      }
deba@1979
   240
deba@1979
   241
    };
deba@1979
   242
deba@1979
   243
    template <typename _Value>
deba@1979
   244
    class EdgeMap 
deba@1999
   245
      : public MapExtender<DefaultMap<Graph, Edge, _Value> > {
deba@1979
   246
    public:
deba@1979
   247
      typedef GraphExtender Graph;
deba@1999
   248
      typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
deba@1979
   249
klao@2046
   250
      explicit EdgeMap(const Graph& graph) 
deba@1999
   251
	: Parent(graph) {}
deba@1999
   252
      EdgeMap(const Graph& graph, const _Value& value) 
deba@1999
   253
	: Parent(graph, value) {}
deba@1979
   254
deba@1979
   255
      EdgeMap& operator=(const EdgeMap& cmap) {
deba@1979
   256
	return operator=<EdgeMap>(cmap);
deba@1979
   257
      }
deba@1979
   258
deba@1979
   259
      template <typename CMap>
deba@1979
   260
      EdgeMap& operator=(const CMap& cmap) {
deba@2031
   261
        Parent::operator=(cmap);
deba@1979
   262
	return *this;
deba@1979
   263
      }
deba@1979
   264
    };
deba@1979
   265
deba@1979
   266
deba@1979
   267
    Node addNode() {
deba@1979
   268
      Node node = Parent::addNode();
deba@1979
   269
      getNotifier(Node()).add(node);
deba@1979
   270
      return node;
deba@1979
   271
    }
deba@1979
   272
    
deba@1979
   273
    Edge addEdge(const Node& from, const Node& to) {
deba@1979
   274
      Edge edge = Parent::addEdge(from, to);
deba@1979
   275
      getNotifier(Edge()).add(edge);
deba@1979
   276
      return edge;
deba@1979
   277
    }
deba@1979
   278
deba@1979
   279
    void clear() {
deba@1979
   280
      getNotifier(Edge()).clear();
deba@1979
   281
      getNotifier(Node()).clear();
deba@1979
   282
      Parent::clear();
deba@1979
   283
    }
deba@1979
   284
deba@1979
   285
deba@1979
   286
    void erase(const Node& node) {
deba@1979
   287
      Edge edge;
deba@1979
   288
      Parent::firstOut(edge, node);
deba@1979
   289
      while (edge != INVALID ) {
deba@1979
   290
	erase(edge);
deba@1979
   291
	Parent::firstOut(edge, node);
deba@1979
   292
      } 
deba@1979
   293
deba@1979
   294
      Parent::firstIn(edge, node);
deba@1979
   295
      while (edge != INVALID ) {
deba@1979
   296
	erase(edge);
deba@1979
   297
	Parent::firstIn(edge, node);
deba@1979
   298
      }
deba@1979
   299
deba@1979
   300
      getNotifier(Node()).erase(node);
deba@1979
   301
      Parent::erase(node);
deba@1979
   302
    }
deba@1979
   303
    
deba@1979
   304
    void erase(const Edge& edge) {
deba@1979
   305
      getNotifier(Edge()).erase(edge);
deba@1979
   306
      Parent::erase(edge);
deba@1979
   307
    }
deba@1979
   308
deba@1999
   309
    GraphExtender() {
deba@1999
   310
      node_notifier.setContainer(*this);
deba@1999
   311
      edge_notifier.setContainer(*this);
deba@1999
   312
    } 
deba@1999
   313
    
deba@1979
   314
deba@1979
   315
    ~GraphExtender() {
deba@1999
   316
      edge_notifier.clear();
deba@1999
   317
      node_notifier.clear();
deba@1979
   318
    }
deba@1979
   319
  };
deba@1979
   320
deba@2116
   321
  /// \ingroup graphbits
deba@2116
   322
  ///
deba@2116
   323
  /// \brief Extender for the UGraphs
deba@2116
   324
  template <typename Base> 
deba@2116
   325
  class UGraphExtender : public Base {
deba@2116
   326
  public:
deba@2116
   327
    
deba@2116
   328
    typedef Base Parent;
deba@2116
   329
    typedef UGraphExtender Graph;
deba@2116
   330
deba@2116
   331
    typedef typename Parent::Node Node;
deba@2116
   332
    typedef typename Parent::Edge Edge;
deba@2116
   333
    typedef typename Parent::UEdge UEdge;
deba@2116
   334
deba@2116
   335
    // UGraph extension    
deba@2116
   336
deba@2116
   337
    int maxId(Node) const {
deba@2116
   338
      return Parent::maxNodeId();
deba@2116
   339
    }
deba@2116
   340
deba@2116
   341
    int maxId(Edge) const {
deba@2116
   342
      return Parent::maxEdgeId();
deba@2116
   343
    }
deba@2116
   344
deba@2116
   345
    int maxId(UEdge) const {
deba@2116
   346
      return Parent::maxUEdgeId();
deba@2116
   347
    }
deba@2116
   348
deba@2116
   349
    Node fromId(int id, Node) const {
deba@2116
   350
      return Parent::nodeFromId(id);
deba@2116
   351
    }
deba@2116
   352
deba@2116
   353
    Edge fromId(int id, Edge) const {
deba@2116
   354
      return Parent::edgeFromId(id);
deba@2116
   355
    }
deba@2116
   356
deba@2116
   357
    UEdge fromId(int id, UEdge) const {
deba@2116
   358
      return Parent::uEdgeFromId(id);
deba@2116
   359
    }
deba@2116
   360
deba@2116
   361
    Node oppositeNode(const Node &n, const UEdge &e) const {
deba@2116
   362
      if( n == Parent::source(e))
deba@2116
   363
	return Parent::target(e);
deba@2116
   364
      else if( n == Parent::target(e))
deba@2116
   365
	return Parent::source(e);
deba@2116
   366
      else
deba@2116
   367
	return INVALID;
deba@2116
   368
    }
deba@2116
   369
deba@2116
   370
    Edge oppositeEdge(const Edge &e) const {
deba@2116
   371
      return Parent::direct(e, !Parent::direction(e));
deba@2116
   372
    }
deba@2116
   373
deba@2116
   374
    using Parent::direct;
deba@2116
   375
    Edge direct(const UEdge &ue, const Node &s) const {
deba@2116
   376
      return Parent::direct(ue, Parent::source(ue) == s);
deba@2116
   377
    }
deba@2116
   378
deba@2116
   379
    // Alterable extension
deba@2116
   380
deba@2116
   381
    typedef AlterationNotifier<UGraphExtender, Node> NodeNotifier;
deba@2116
   382
    typedef AlterationNotifier<UGraphExtender, Edge> EdgeNotifier;
deba@2116
   383
    typedef AlterationNotifier<UGraphExtender, UEdge> UEdgeNotifier;
deba@2116
   384
deba@2116
   385
deba@2116
   386
  protected:
deba@2116
   387
deba@2116
   388
    mutable NodeNotifier node_notifier;
deba@2116
   389
    mutable EdgeNotifier edge_notifier;
deba@2116
   390
    mutable UEdgeNotifier uedge_notifier;
deba@2116
   391
deba@2116
   392
  public:
deba@2116
   393
deba@2116
   394
    NodeNotifier& getNotifier(Node) const {
deba@2116
   395
      return node_notifier;
deba@2116
   396
    }
deba@2116
   397
    
deba@2116
   398
    EdgeNotifier& getNotifier(Edge) const {
deba@2116
   399
      return edge_notifier;
deba@2116
   400
    }
deba@2116
   401
deba@2116
   402
    UEdgeNotifier& getNotifier(UEdge) const {
deba@2116
   403
      return uedge_notifier;
deba@2116
   404
    }
deba@2116
   405
deba@2116
   406
deba@2116
   407
deba@2116
   408
    class NodeIt : public Node { 
deba@2116
   409
      const Graph* graph;
deba@2116
   410
    public:
deba@2116
   411
deba@2116
   412
      NodeIt() {}
deba@2116
   413
deba@2116
   414
      NodeIt(Invalid i) : Node(i) { }
deba@2116
   415
deba@2116
   416
      explicit NodeIt(const Graph& _graph) : graph(&_graph) {
deba@2116
   417
	_graph.first(static_cast<Node&>(*this));
deba@2116
   418
      }
deba@2116
   419
deba@2116
   420
      NodeIt(const Graph& _graph, const Node& node) 
deba@2116
   421
	: Node(node), graph(&_graph) {}
deba@2116
   422
deba@2116
   423
      NodeIt& operator++() { 
deba@2116
   424
	graph->next(*this);
deba@2116
   425
	return *this; 
deba@2116
   426
      }
deba@2116
   427
deba@2116
   428
    };
deba@2116
   429
deba@2116
   430
deba@2116
   431
    class EdgeIt : public Edge { 
deba@2116
   432
      const Graph* graph;
deba@2116
   433
    public:
deba@2116
   434
deba@2116
   435
      EdgeIt() { }
deba@2116
   436
deba@2116
   437
      EdgeIt(Invalid i) : Edge(i) { }
deba@2116
   438
deba@2116
   439
      explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
deba@2116
   440
	_graph.first(static_cast<Edge&>(*this));
deba@2116
   441
      }
deba@2116
   442
deba@2116
   443
      EdgeIt(const Graph& _graph, const Edge& e) : 
deba@2116
   444
	Edge(e), graph(&_graph) { }
deba@2116
   445
deba@2116
   446
      EdgeIt& operator++() { 
deba@2116
   447
	graph->next(*this);
deba@2116
   448
	return *this; 
deba@2116
   449
      }
deba@2116
   450
deba@2116
   451
    };
deba@2116
   452
deba@2116
   453
deba@2116
   454
    class OutEdgeIt : public Edge { 
deba@2116
   455
      const Graph* graph;
deba@2116
   456
    public:
deba@2116
   457
deba@2116
   458
      OutEdgeIt() { }
deba@2116
   459
deba@2116
   460
      OutEdgeIt(Invalid i) : Edge(i) { }
deba@2116
   461
deba@2116
   462
      OutEdgeIt(const Graph& _graph, const Node& node) 
deba@2116
   463
	: graph(&_graph) {
deba@2116
   464
	_graph.firstOut(*this, node);
deba@2116
   465
      }
deba@2116
   466
deba@2116
   467
      OutEdgeIt(const Graph& _graph, const Edge& edge) 
deba@2116
   468
	: Edge(edge), graph(&_graph) {}
deba@2116
   469
deba@2116
   470
      OutEdgeIt& operator++() { 
deba@2116
   471
	graph->nextOut(*this);
deba@2116
   472
	return *this; 
deba@2116
   473
      }
deba@2116
   474
deba@2116
   475
    };
deba@2116
   476
deba@2116
   477
deba@2116
   478
    class InEdgeIt : public Edge { 
deba@2116
   479
      const Graph* graph;
deba@2116
   480
    public:
deba@2116
   481
deba@2116
   482
      InEdgeIt() { }
deba@2116
   483
deba@2116
   484
      InEdgeIt(Invalid i) : Edge(i) { }
deba@2116
   485
deba@2116
   486
      InEdgeIt(const Graph& _graph, const Node& node) 
deba@2116
   487
	: graph(&_graph) {
deba@2116
   488
	_graph.firstIn(*this, node);
deba@2116
   489
      }
deba@2116
   490
deba@2116
   491
      InEdgeIt(const Graph& _graph, const Edge& edge) : 
deba@2116
   492
	Edge(edge), graph(&_graph) {}
deba@2116
   493
deba@2116
   494
      InEdgeIt& operator++() { 
deba@2116
   495
	graph->nextIn(*this);
deba@2116
   496
	return *this; 
deba@2116
   497
      }
deba@2116
   498
deba@2116
   499
    };
deba@2116
   500
deba@2116
   501
deba@2116
   502
    class UEdgeIt : public Parent::UEdge { 
deba@2116
   503
      const Graph* graph;
deba@2116
   504
    public:
deba@2116
   505
deba@2116
   506
      UEdgeIt() { }
deba@2116
   507
deba@2116
   508
      UEdgeIt(Invalid i) : UEdge(i) { }
deba@2116
   509
deba@2116
   510
      explicit UEdgeIt(const Graph& _graph) : graph(&_graph) {
deba@2116
   511
	_graph.first(static_cast<UEdge&>(*this));
deba@2116
   512
      }
deba@2116
   513
deba@2116
   514
      UEdgeIt(const Graph& _graph, const UEdge& e) : 
deba@2116
   515
	UEdge(e), graph(&_graph) { }
deba@2116
   516
deba@2116
   517
      UEdgeIt& operator++() { 
deba@2116
   518
	graph->next(*this);
deba@2116
   519
	return *this; 
deba@2116
   520
      }
deba@2116
   521
deba@2116
   522
    };
deba@2116
   523
deba@2116
   524
    class IncEdgeIt : public Parent::UEdge {
deba@2116
   525
      friend class UGraphExtender;
deba@2116
   526
      const Graph* graph;
deba@2116
   527
      bool direction;
deba@2116
   528
    public:
deba@2116
   529
deba@2116
   530
      IncEdgeIt() { }
deba@2116
   531
deba@2116
   532
      IncEdgeIt(Invalid i) : UEdge(i), direction(false) { }
deba@2116
   533
deba@2116
   534
      IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
deba@2116
   535
	_graph.firstInc(*this, direction, n);
deba@2116
   536
      }
deba@2116
   537
deba@2116
   538
      IncEdgeIt(const Graph& _graph, const UEdge &ue, const Node &n)
deba@2116
   539
	: graph(&_graph), UEdge(ue) {
deba@2116
   540
	direction = (_graph.source(ue) == n);
deba@2116
   541
      }
deba@2116
   542
deba@2116
   543
      IncEdgeIt& operator++() {
deba@2116
   544
	graph->nextInc(*this, direction);
deba@2116
   545
	return *this; 
deba@2116
   546
      }
deba@2116
   547
    };
deba@2116
   548
deba@2116
   549
    /// \brief Base node of the iterator
deba@2116
   550
    ///
deba@2116
   551
    /// Returns the base node (ie. the source in this case) of the iterator
deba@2116
   552
    Node baseNode(const OutEdgeIt &e) const {
deba@2116
   553
      return Parent::source((Edge)e);
deba@2116
   554
    }
deba@2116
   555
    /// \brief Running node of the iterator
deba@2116
   556
    ///
deba@2116
   557
    /// Returns the running node (ie. the target in this case) of the
deba@2116
   558
    /// iterator
deba@2116
   559
    Node runningNode(const OutEdgeIt &e) const {
deba@2116
   560
      return Parent::target((Edge)e);
deba@2116
   561
    }
deba@2116
   562
deba@2116
   563
    /// \brief Base node of the iterator
deba@2116
   564
    ///
deba@2116
   565
    /// Returns the base node (ie. the target in this case) of the iterator
deba@2116
   566
    Node baseNode(const InEdgeIt &e) const {
deba@2116
   567
      return Parent::target((Edge)e);
deba@2116
   568
    }
deba@2116
   569
    /// \brief Running node of the iterator
deba@2116
   570
    ///
deba@2116
   571
    /// Returns the running node (ie. the source in this case) of the
deba@2116
   572
    /// iterator
deba@2116
   573
    Node runningNode(const InEdgeIt &e) const {
deba@2116
   574
      return Parent::source((Edge)e);
deba@2116
   575
    }
deba@2116
   576
deba@2116
   577
    /// Base node of the iterator
deba@2116
   578
    ///
deba@2116
   579
    /// Returns the base node of the iterator
deba@2116
   580
    Node baseNode(const IncEdgeIt &e) const {
deba@2116
   581
      return e.direction ? source(e) : target(e);
deba@2116
   582
    }
deba@2116
   583
    /// Running node of the iterator
deba@2116
   584
    ///
deba@2116
   585
    /// Returns the running node of the iterator
deba@2116
   586
    Node runningNode(const IncEdgeIt &e) const {
deba@2116
   587
      return e.direction ? target(e) : source(e);
deba@2116
   588
    }
deba@2116
   589
deba@2116
   590
    // Mappable extension
deba@2116
   591
deba@2116
   592
    template <typename _Value>
deba@2116
   593
    class NodeMap 
deba@2116
   594
      : public MapExtender<DefaultMap<Graph, Node, _Value> > {
deba@2116
   595
    public:
deba@2116
   596
      typedef UGraphExtender Graph;
deba@2116
   597
      typedef MapExtender<DefaultMap<Graph, Node, _Value> > Parent;
deba@2116
   598
deba@2116
   599
      NodeMap(const Graph& graph) 
deba@2116
   600
	: Parent(graph) {}
deba@2116
   601
      NodeMap(const Graph& graph, const _Value& value) 
deba@2116
   602
	: Parent(graph, value) {}
deba@2116
   603
deba@2116
   604
      NodeMap& operator=(const NodeMap& cmap) {
deba@2116
   605
	return operator=<NodeMap>(cmap);
deba@2116
   606
      }
deba@2116
   607
deba@2116
   608
      template <typename CMap>
deba@2116
   609
      NodeMap& operator=(const CMap& cmap) {
deba@2116
   610
        Parent::operator=(cmap);
deba@2116
   611
	return *this;
deba@2116
   612
      }
deba@2116
   613
deba@2116
   614
    };
deba@2116
   615
deba@2116
   616
    template <typename _Value>
deba@2116
   617
    class EdgeMap 
deba@2116
   618
      : public MapExtender<DefaultMap<Graph, Edge, _Value> > {
deba@2116
   619
    public:
deba@2116
   620
      typedef UGraphExtender Graph;
deba@2116
   621
      typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
deba@2116
   622
deba@2116
   623
      EdgeMap(const Graph& graph) 
deba@2116
   624
	: Parent(graph) {}
deba@2116
   625
      EdgeMap(const Graph& graph, const _Value& value) 
deba@2116
   626
	: Parent(graph, value) {}
deba@2116
   627
deba@2116
   628
      EdgeMap& operator=(const EdgeMap& cmap) {
deba@2116
   629
	return operator=<EdgeMap>(cmap);
deba@2116
   630
      }
deba@2116
   631
deba@2116
   632
      template <typename CMap>
deba@2116
   633
      EdgeMap& operator=(const CMap& cmap) {
deba@2116
   634
        Parent::operator=(cmap);
deba@2116
   635
	return *this;
deba@2116
   636
      }
deba@2116
   637
    };
deba@2116
   638
deba@2116
   639
deba@2116
   640
    template <typename _Value>
deba@2116
   641
    class UEdgeMap 
deba@2116
   642
      : public MapExtender<DefaultMap<Graph, UEdge, _Value> > {
deba@2116
   643
    public:
deba@2116
   644
      typedef UGraphExtender Graph;
deba@2116
   645
      typedef MapExtender<DefaultMap<Graph, UEdge, _Value> > Parent;
deba@2116
   646
deba@2116
   647
      UEdgeMap(const Graph& graph) 
deba@2116
   648
	: Parent(graph) {}
deba@2116
   649
deba@2116
   650
      UEdgeMap(const Graph& graph, const _Value& value) 
deba@2116
   651
	: Parent(graph, value) {}
deba@2116
   652
deba@2116
   653
      UEdgeMap& operator=(const UEdgeMap& cmap) {
deba@2116
   654
	return operator=<UEdgeMap>(cmap);
deba@2116
   655
      }
deba@2116
   656
deba@2116
   657
      template <typename CMap>
deba@2116
   658
      UEdgeMap& operator=(const CMap& cmap) {
deba@2116
   659
        Parent::operator=(cmap);
deba@2116
   660
	return *this;
deba@2116
   661
      }
deba@2116
   662
deba@2116
   663
    };
deba@2116
   664
deba@2116
   665
    // Alteration extension
deba@2116
   666
deba@2116
   667
    Node addNode() {
deba@2116
   668
      Node node = Parent::addNode();
deba@2116
   669
      getNotifier(Node()).add(node);
deba@2116
   670
      return node;
deba@2116
   671
    }
deba@2116
   672
deba@2116
   673
    UEdge addEdge(const Node& from, const Node& to) {
deba@2116
   674
      UEdge uedge = Parent::addEdge(from, to);
deba@2116
   675
      getNotifier(UEdge()).add(uedge);
deba@2116
   676
      getNotifier(Edge()).add(Parent::direct(uedge, true));
deba@2116
   677
      getNotifier(Edge()).add(Parent::direct(uedge, false));
deba@2116
   678
      return uedge;
deba@2116
   679
    }
deba@2116
   680
    
deba@2116
   681
    void clear() {
deba@2116
   682
      getNotifier(Edge()).clear();
deba@2116
   683
      getNotifier(UEdge()).clear();
deba@2116
   684
      getNotifier(Node()).clear();
deba@2116
   685
      Parent::clear();
deba@2116
   686
    }
deba@2116
   687
deba@2116
   688
    void erase(const Node& node) {
deba@2116
   689
      Edge edge;
deba@2116
   690
      Parent::firstOut(edge, node);
deba@2116
   691
      while (edge != INVALID ) {
deba@2116
   692
	erase(edge);
deba@2116
   693
	Parent::firstOut(edge, node);
deba@2116
   694
      } 
deba@2116
   695
deba@2116
   696
      Parent::firstIn(edge, node);
deba@2116
   697
      while (edge != INVALID ) {
deba@2116
   698
	erase(edge);
deba@2116
   699
	Parent::firstIn(edge, node);
deba@2116
   700
      }
deba@2116
   701
deba@2116
   702
      getNotifier(Node()).erase(node);
deba@2116
   703
      Parent::erase(node);
deba@2116
   704
    }
deba@2116
   705
deba@2116
   706
    void erase(const UEdge& uedge) {
deba@2116
   707
      getNotifier(Edge()).erase(Parent::direct(uedge, true));
deba@2116
   708
      getNotifier(Edge()).erase(Parent::direct(uedge, false));
deba@2116
   709
      getNotifier(UEdge()).erase(uedge);
deba@2116
   710
      Parent::erase(uedge);
deba@2116
   711
    }
deba@2116
   712
deba@2116
   713
    UGraphExtender() {
deba@2116
   714
      node_notifier.setContainer(*this); 
deba@2116
   715
      edge_notifier.setContainer(*this);
deba@2116
   716
      uedge_notifier.setContainer(*this);
deba@2116
   717
    } 
deba@2116
   718
deba@2116
   719
    ~UGraphExtender() {
deba@2116
   720
      uedge_notifier.clear();
deba@2116
   721
      edge_notifier.clear();
deba@2116
   722
      node_notifier.clear(); 
deba@2116
   723
    } 
deba@2116
   724
deba@2116
   725
  };
deba@2116
   726
deba@2116
   727
  /// \ingroup graphbits
deba@2116
   728
  ///
deba@2116
   729
  /// \brief Extender for the BpUGraphs
deba@2116
   730
  template <typename Base>
deba@2116
   731
  class BpUGraphExtender : public Base {
deba@2116
   732
  public:
deba@2231
   733
deba@2116
   734
    typedef Base Parent;
deba@2116
   735
    typedef BpUGraphExtender Graph;
deba@2116
   736
deba@2116
   737
    typedef typename Parent::Node Node;
deba@2231
   738
    typedef typename Parent::ANode ANode;
deba@2231
   739
    typedef typename Parent::BNode BNode;
deba@2231
   740
    typedef typename Parent::Edge Edge;
deba@2116
   741
    typedef typename Parent::UEdge UEdge;
deba@2116
   742
deba@2116
   743
deba@2231
   744
    Node oppositeNode(const Node& node, const UEdge& edge) const {
deba@2231
   745
      return Parent::aNode(edge) == node ? 
deba@2231
   746
	Parent::bNode(edge) : Parent::aNode(edge);
deba@2116
   747
    }
deba@2116
   748
deba@2231
   749
    using Parent::direct;
deba@2116
   750
    Edge direct(const UEdge& edge, const Node& node) const {
deba@2231
   751
      return Parent::direct(edge, node == Parent::source(edge));
deba@2116
   752
    }
deba@2116
   753
deba@2116
   754
    Edge oppositeEdge(const Edge& edge) const {
deba@2231
   755
      return direct(edge, !Parent::direction(edge));
deba@2116
   756
    }
deba@2231
   757
    
deba@2116
   758
    int maxId(Node) const {
deba@2116
   759
      return Parent::maxNodeId();
deba@2116
   760
    }
deba@2116
   761
    int maxId(BNode) const {
deba@2116
   762
      return Parent::maxBNodeId();
deba@2116
   763
    }
deba@2116
   764
    int maxId(ANode) const {
deba@2116
   765
      return Parent::maxANodeId();
deba@2116
   766
    }
deba@2116
   767
    int maxId(Edge) const {
deba@2231
   768
      return Parent::maxEdgeId();
deba@2116
   769
    }
deba@2116
   770
    int maxId(UEdge) const {
deba@2116
   771
      return Parent::maxUEdgeId();
deba@2116
   772
    }
deba@2116
   773
deba@2116
   774
deba@2116
   775
    Node fromId(int id, Node) const {
deba@2116
   776
      return Parent::nodeFromId(id);
deba@2116
   777
    }
deba@2116
   778
    ANode fromId(int id, ANode) const {
deba@2231
   779
      return Parent::nodeFromANodeId(id);
deba@2116
   780
    }
deba@2116
   781
    BNode fromId(int id, BNode) const {
deba@2231
   782
      return Parent::nodeFromBNodeId(id);
deba@2116
   783
    }
deba@2116
   784
    Edge fromId(int id, Edge) const {
deba@2116
   785
      return Parent::edgeFromId(id);
deba@2116
   786
    }
deba@2116
   787
    UEdge fromId(int id, UEdge) const {
deba@2116
   788
      return Parent::uEdgeFromId(id);
deba@2116
   789
    }  
deba@2116
   790
  
deba@2116
   791
    typedef AlterationNotifier<BpUGraphExtender, ANode> ANodeNotifier;
deba@2116
   792
    typedef AlterationNotifier<BpUGraphExtender, BNode> BNodeNotifier;
deba@2116
   793
    typedef AlterationNotifier<BpUGraphExtender, Node> NodeNotifier;
deba@2116
   794
    typedef AlterationNotifier<BpUGraphExtender, Edge> EdgeNotifier;
deba@2116
   795
    typedef AlterationNotifier<BpUGraphExtender, UEdge> UEdgeNotifier;
deba@2116
   796
deba@2116
   797
  protected:
deba@2116
   798
deba@2116
   799
    mutable ANodeNotifier anode_notifier;
deba@2116
   800
    mutable BNodeNotifier bnode_notifier;
deba@2116
   801
    mutable NodeNotifier node_notifier;
deba@2116
   802
    mutable EdgeNotifier edge_notifier;
deba@2116
   803
    mutable UEdgeNotifier uedge_notifier;
deba@2116
   804
deba@2116
   805
  public:
deba@2116
   806
deba@2116
   807
    NodeNotifier& getNotifier(Node) const {
deba@2116
   808
      return node_notifier;
deba@2116
   809
    }
deba@2116
   810
deba@2116
   811
    ANodeNotifier& getNotifier(ANode) const {
deba@2116
   812
      return anode_notifier;
deba@2116
   813
    }
deba@2116
   814
deba@2116
   815
    BNodeNotifier& getNotifier(BNode) const {
deba@2116
   816
      return bnode_notifier;
deba@2116
   817
    }
deba@2116
   818
deba@2116
   819
    EdgeNotifier& getNotifier(Edge) const {
deba@2116
   820
      return edge_notifier;
deba@2116
   821
    }
deba@2116
   822
deba@2116
   823
    UEdgeNotifier& getNotifier(UEdge) const {
deba@2116
   824
      return uedge_notifier;
deba@2116
   825
    }
deba@2116
   826
deba@2116
   827
    class NodeIt : public Node { 
deba@2116
   828
      const Graph* graph;
deba@2116
   829
    public:
deba@2116
   830
    
deba@2116
   831
      NodeIt() { }
deba@2116
   832
    
deba@2116
   833
      NodeIt(Invalid i) : Node(INVALID) { }
deba@2116
   834
    
deba@2116
   835
      explicit NodeIt(const Graph& _graph) : graph(&_graph) {
deba@2116
   836
	graph->first(static_cast<Node&>(*this));
deba@2116
   837
      }
deba@2116
   838
deba@2116
   839
      NodeIt(const Graph& _graph, const Node& node) 
deba@2116
   840
	: Node(node), graph(&_graph) { }
deba@2116
   841
    
deba@2116
   842
      NodeIt& operator++() { 
deba@2116
   843
	graph->next(*this);
deba@2116
   844
	return *this; 
deba@2116
   845
      }
deba@2116
   846
deba@2116
   847
    };
deba@2116
   848
deba@2116
   849
    class ANodeIt : public Node { 
deba@2116
   850
      friend class BpUGraphExtender;
deba@2116
   851
      const Graph* graph;
deba@2116
   852
    public:
deba@2116
   853
    
deba@2116
   854
      ANodeIt() { }
deba@2116
   855
    
deba@2116
   856
      ANodeIt(Invalid i) : Node(INVALID) { }
deba@2116
   857
    
deba@2116
   858
      explicit ANodeIt(const Graph& _graph) : graph(&_graph) {
deba@2116
   859
	graph->firstANode(static_cast<Node&>(*this));
deba@2116
   860
      }
deba@2116
   861
deba@2116
   862
      ANodeIt(const Graph& _graph, const Node& node) 
deba@2116
   863
	: Node(node), graph(&_graph) {}
deba@2116
   864
    
deba@2116
   865
      ANodeIt& operator++() { 
deba@2116
   866
	graph->nextANode(*this);
deba@2116
   867
	return *this; 
deba@2116
   868
      }
deba@2116
   869
    };
deba@2116
   870
deba@2116
   871
    class BNodeIt : public Node { 
deba@2116
   872
      friend class BpUGraphExtender;
deba@2116
   873
      const Graph* graph;
deba@2116
   874
    public:
deba@2116
   875
    
deba@2116
   876
      BNodeIt() { }
deba@2116
   877
    
deba@2116
   878
      BNodeIt(Invalid i) : Node(INVALID) { }
deba@2116
   879
    
deba@2116
   880
      explicit BNodeIt(const Graph& _graph) : graph(&_graph) {
deba@2116
   881
	graph->firstBNode(static_cast<Node&>(*this));
deba@2116
   882
      }
deba@2116
   883
deba@2116
   884
      BNodeIt(const Graph& _graph, const Node& node) 
deba@2116
   885
	: Node(node), graph(&_graph) {}
deba@2116
   886
    
deba@2116
   887
      BNodeIt& operator++() { 
deba@2116
   888
	graph->nextBNode(*this);
deba@2116
   889
	return *this; 
deba@2116
   890
      }
deba@2116
   891
    };
deba@2116
   892
deba@2116
   893
    class EdgeIt : public Edge { 
deba@2116
   894
      friend class BpUGraphExtender;
deba@2116
   895
      const Graph* graph;
deba@2116
   896
    public:
deba@2116
   897
    
deba@2116
   898
      EdgeIt() { }
deba@2116
   899
    
deba@2116
   900
      EdgeIt(Invalid i) : Edge(INVALID) { }
deba@2116
   901
    
deba@2116
   902
      explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
deba@2116
   903
	graph->first(static_cast<Edge&>(*this));
deba@2116
   904
      }
deba@2116
   905
deba@2116
   906
      EdgeIt(const Graph& _graph, const Edge& edge) 
deba@2116
   907
	: Edge(edge), graph(&_graph) { }
deba@2116
   908
    
deba@2116
   909
      EdgeIt& operator++() { 
deba@2116
   910
	graph->next(*this);
deba@2116
   911
	return *this; 
deba@2116
   912
      }
deba@2116
   913
deba@2116
   914
    };
deba@2116
   915
deba@2116
   916
    class UEdgeIt : public UEdge { 
deba@2116
   917
      friend class BpUGraphExtender;
deba@2116
   918
      const Graph* graph;
deba@2116
   919
    public:
deba@2116
   920
    
deba@2116
   921
      UEdgeIt() { }
deba@2116
   922
    
deba@2116
   923
      UEdgeIt(Invalid i) : UEdge(INVALID) { }
deba@2116
   924
    
deba@2116
   925
      explicit UEdgeIt(const Graph& _graph) : graph(&_graph) {
deba@2116
   926
	graph->first(static_cast<UEdge&>(*this));
deba@2116
   927
      }
deba@2116
   928
deba@2116
   929
      UEdgeIt(const Graph& _graph, const UEdge& edge) 
deba@2116
   930
	: UEdge(edge), graph(&_graph) { }
deba@2116
   931
    
deba@2116
   932
      UEdgeIt& operator++() { 
deba@2116
   933
	graph->next(*this);
deba@2116
   934
	return *this; 
deba@2116
   935
      }
deba@2116
   936
    };
deba@2116
   937
deba@2116
   938
    class OutEdgeIt : public Edge { 
deba@2116
   939
      friend class BpUGraphExtender;
deba@2116
   940
      const Graph* graph;
deba@2116
   941
    public:
deba@2116
   942
    
deba@2116
   943
      OutEdgeIt() { }
deba@2116
   944
    
deba@2116
   945
      OutEdgeIt(Invalid i) : Edge(i) { }
deba@2116
   946
    
deba@2116
   947
      OutEdgeIt(const Graph& _graph, const Node& node) 
deba@2116
   948
	: graph(&_graph) {
deba@2116
   949
	graph->firstOut(*this, node);
deba@2116
   950
      }
deba@2116
   951
    
deba@2116
   952
      OutEdgeIt(const Graph& _graph, const Edge& edge) 
deba@2116
   953
	: Edge(edge), graph(&_graph) {}
deba@2116
   954
    
deba@2116
   955
      OutEdgeIt& operator++() { 
deba@2116
   956
	graph->nextOut(*this);
deba@2116
   957
	return *this; 
deba@2116
   958
      }
deba@2116
   959
deba@2116
   960
    };
deba@2116
   961
deba@2116
   962
deba@2116
   963
    class InEdgeIt : public Edge { 
deba@2116
   964
      friend class BpUGraphExtender;
deba@2116
   965
      const Graph* graph;
deba@2116
   966
    public:
deba@2116
   967
    
deba@2116
   968
      InEdgeIt() { }
deba@2116
   969
    
deba@2116
   970
      InEdgeIt(Invalid i) : Edge(i) { }
deba@2116
   971
    
deba@2116
   972
      InEdgeIt(const Graph& _graph, const Node& node) 
deba@2116
   973
	: graph(&_graph) {
deba@2116
   974
	graph->firstIn(*this, node);
deba@2116
   975
      }
deba@2116
   976
    
deba@2116
   977
      InEdgeIt(const Graph& _graph, const Edge& edge) : 
deba@2116
   978
	Edge(edge), graph(&_graph) {}
deba@2116
   979
    
deba@2116
   980
      InEdgeIt& operator++() { 
deba@2116
   981
	graph->nextIn(*this);
deba@2116
   982
	return *this; 
deba@2116
   983
      }
deba@2116
   984
deba@2116
   985
    };
deba@2116
   986
  
deba@2116
   987
    /// \brief Base node of the iterator
deba@2116
   988
    ///
deba@2116
   989
    /// Returns the base node (ie. the source in this case) of the iterator
deba@2116
   990
    Node baseNode(const OutEdgeIt &e) const {
deba@2116
   991
      return Parent::source((Edge&)e);
deba@2116
   992
    }
deba@2116
   993
    /// \brief Running node of the iterator
deba@2116
   994
    ///
deba@2116
   995
    /// Returns the running node (ie. the target in this case) of the
deba@2116
   996
    /// iterator
deba@2116
   997
    Node runningNode(const OutEdgeIt &e) const {
deba@2116
   998
      return Parent::target((Edge&)e);
deba@2116
   999
    }
deba@2116
  1000
  
deba@2116
  1001
    /// \brief Base node of the iterator
deba@2116
  1002
    ///
deba@2116
  1003
    /// Returns the base node (ie. the target in this case) of the iterator
deba@2116
  1004
    Node baseNode(const InEdgeIt &e) const {
deba@2116
  1005
      return Parent::target((Edge&)e);
deba@2116
  1006
    }
deba@2116
  1007
    /// \brief Running node of the iterator
deba@2116
  1008
    ///
deba@2116
  1009
    /// Returns the running node (ie. the source in this case) of the
deba@2116
  1010
    /// iterator
deba@2116
  1011
    Node runningNode(const InEdgeIt &e) const {
deba@2116
  1012
      return Parent::source((Edge&)e);
deba@2116
  1013
    }
deba@2116
  1014
  
deba@2116
  1015
    class IncEdgeIt : public Parent::UEdge { 
deba@2116
  1016
      friend class BpUGraphExtender;
deba@2116
  1017
      const Graph* graph;
deba@2116
  1018
      bool direction;
deba@2116
  1019
    public:
deba@2116
  1020
    
deba@2116
  1021
      IncEdgeIt() { }
deba@2116
  1022
    
deba@2116
  1023
      IncEdgeIt(Invalid i) : UEdge(i), direction(true) { }
deba@2116
  1024
    
deba@2116
  1025
      IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
deba@2116
  1026
	graph->firstInc(*this, direction, n);
deba@2116
  1027
      }
deba@2116
  1028
deba@2116
  1029
      IncEdgeIt(const Graph& _graph, const UEdge &ue, const Node &n)
deba@2116
  1030
	: graph(&_graph), UEdge(ue) {
deba@2116
  1031
	direction = (graph->source(ue) == n);
deba@2116
  1032
      }
deba@2116
  1033
deba@2116
  1034
      IncEdgeIt& operator++() {
deba@2116
  1035
	graph->nextInc(*this, direction);
deba@2116
  1036
	return *this; 
deba@2116
  1037
      }
deba@2116
  1038
    };
deba@2116
  1039
  
deba@2116
  1040
deba@2116
  1041
    /// Base node of the iterator
deba@2116
  1042
    ///
deba@2116
  1043
    /// Returns the base node of the iterator
deba@2116
  1044
    Node baseNode(const IncEdgeIt &e) const {
deba@2116
  1045
      return e.direction ? source(e) : target(e);
deba@2116
  1046
    }
deba@2116
  1047
deba@2116
  1048
    /// Running node of the iterator
deba@2116
  1049
    ///
deba@2116
  1050
    /// Returns the running node of the iterator
deba@2116
  1051
    Node runningNode(const IncEdgeIt &e) const {
deba@2116
  1052
      return e.direction ? target(e) : source(e);
deba@2116
  1053
    }
deba@2116
  1054
deba@2116
  1055
    template <typename _Value>
deba@2116
  1056
    class ANodeMap 
deba@2116
  1057
      : public MapExtender<DefaultMap<Graph, ANode, _Value> > {
deba@2116
  1058
    public:
deba@2116
  1059
      typedef BpUGraphExtender Graph;
deba@2116
  1060
      typedef MapExtender<DefaultMap<Graph, ANode, _Value> > Parent;
deba@2116
  1061
    
deba@2116
  1062
      ANodeMap(const Graph& graph) 
deba@2116
  1063
	: Parent(graph) {}
deba@2116
  1064
      ANodeMap(const Graph& graph, const _Value& value) 
deba@2116
  1065
	: Parent(graph, value) {}
deba@2116
  1066
    
deba@2116
  1067
      ANodeMap& operator=(const ANodeMap& cmap) {
deba@2116
  1068
	return operator=<ANodeMap>(cmap);
deba@2116
  1069
      }
deba@2116
  1070
    
deba@2116
  1071
      template <typename CMap>
deba@2116
  1072
      ANodeMap& operator=(const CMap& cmap) {
deba@2116
  1073
        Parent::operator=(cmap);
deba@2116
  1074
	return *this;
deba@2116
  1075
      }
deba@2116
  1076
    
deba@2116
  1077
    };
deba@2116
  1078
deba@2116
  1079
    template <typename _Value>
deba@2116
  1080
    class BNodeMap 
deba@2116
  1081
      : public MapExtender<DefaultMap<Graph, BNode, _Value> > {
deba@2116
  1082
    public:
deba@2116
  1083
      typedef BpUGraphExtender Graph;
deba@2116
  1084
      typedef MapExtender<DefaultMap<Graph, BNode, _Value> > Parent;
deba@2116
  1085
    
deba@2116
  1086
      BNodeMap(const Graph& graph) 
deba@2116
  1087
	: Parent(graph) {}
deba@2116
  1088
      BNodeMap(const Graph& graph, const _Value& value) 
deba@2116
  1089
	: Parent(graph, value) {}
deba@2116
  1090
    
deba@2116
  1091
      BNodeMap& operator=(const BNodeMap& cmap) {
deba@2116
  1092
	return operator=<BNodeMap>(cmap);
deba@2116
  1093
      }
deba@2116
  1094
    
deba@2116
  1095
      template <typename CMap>
deba@2116
  1096
      BNodeMap& operator=(const CMap& cmap) {
deba@2116
  1097
        Parent::operator=(cmap);
deba@2116
  1098
	return *this;
deba@2116
  1099
      }
deba@2116
  1100
    
deba@2116
  1101
    };
deba@2116
  1102
deba@2116
  1103
  public:
deba@2116
  1104
deba@2116
  1105
    template <typename _Value>
deba@2116
  1106
    class NodeMap {
deba@2116
  1107
    public:
deba@2116
  1108
      typedef BpUGraphExtender Graph;
deba@2116
  1109
deba@2116
  1110
      typedef Node Key;
deba@2116
  1111
      typedef _Value Value;
deba@2116
  1112
deba@2116
  1113
      /// The reference type of the map;
deba@2116
  1114
      typedef typename ANodeMap<_Value>::Reference Reference;
deba@2116
  1115
      /// The const reference type of the map;
deba@2116
  1116
      typedef typename ANodeMap<_Value>::ConstReference ConstReference;
deba@2116
  1117
deba@2116
  1118
      typedef True ReferenceMapTag;
deba@2116
  1119
deba@2116
  1120
      NodeMap(const Graph& _graph) 
deba@2116
  1121
	: graph(_graph), aNodeMap(_graph), bNodeMap(_graph) {}
deba@2116
  1122
      NodeMap(const Graph& _graph, const _Value& _value) 
deba@2116
  1123
	: graph(_graph), aNodeMap(_graph, _value), bNodeMap(_graph, _value) {}
deba@2116
  1124
deba@2116
  1125
      NodeMap& operator=(const NodeMap& cmap) {
deba@2116
  1126
	return operator=<NodeMap>(cmap);
deba@2116
  1127
      }
deba@2116
  1128
    
deba@2116
  1129
      template <typename CMap>
deba@2116
  1130
      NodeMap& operator=(const CMap& cmap) {
deba@2116
  1131
	checkConcept<concept::ReadMap<Node, _Value>, CMap>();
deba@2231
  1132
        aNodeMap = cmap;
deba@2231
  1133
        bNodeMap = cmap;
deba@2231
  1134
        return *this;
deba@2116
  1135
      }
deba@2116
  1136
deba@2116
  1137
      ConstReference operator[](const Key& node) const {
deba@2116
  1138
	if (Parent::aNode(node)) {
deba@2116
  1139
	  return aNodeMap[node];
deba@2116
  1140
	} else {
deba@2116
  1141
	  return bNodeMap[node];
deba@2116
  1142
	}
deba@2116
  1143
      } 
deba@2116
  1144
deba@2116
  1145
      Reference operator[](const Key& node) {
deba@2116
  1146
	if (Parent::aNode(node)) {
deba@2116
  1147
	  return aNodeMap[node];
deba@2116
  1148
	} else {
deba@2116
  1149
	  return bNodeMap[node];
deba@2116
  1150
	}
deba@2116
  1151
      }
deba@2116
  1152
deba@2116
  1153
      void set(const Key& node, const Value& value) {
deba@2116
  1154
	if (Parent::aNode(node)) {
deba@2116
  1155
	  aNodeMap.set(node, value);
deba@2116
  1156
	} else {
deba@2116
  1157
	  bNodeMap.set(node, value);
deba@2116
  1158
	}
deba@2116
  1159
      }
deba@2116
  1160
deba@2116
  1161
      class MapIt : public NodeIt {
deba@2116
  1162
      public:
deba@2116
  1163
deba@2116
  1164
        typedef NodeIt Parent;
deba@2116
  1165
        
deba@2116
  1166
        explicit MapIt(NodeMap& _map) 
deba@2116
  1167
          : Parent(_map.graph), map(_map) {}
deba@2116
  1168
        
deba@2116
  1169
        typename MapTraits<NodeMap>::ConstReturnValue operator*() const {
deba@2116
  1170
          return map[*this];
deba@2116
  1171
        }
deba@2116
  1172
        
deba@2116
  1173
        typename MapTraits<NodeMap>::ReturnValue operator*() {
deba@2116
  1174
          return map[*this];
deba@2116
  1175
        }
deba@2116
  1176
        
deba@2116
  1177
        void set(const Value& value) {
deba@2116
  1178
          map.set(*this, value);
deba@2116
  1179
        }
deba@2116
  1180
deba@2116
  1181
      private:
deba@2116
  1182
        NodeMap& map;
deba@2116
  1183
      };
deba@2116
  1184
deba@2116
  1185
      class ConstMapIt : public NodeIt {
deba@2116
  1186
      public:
deba@2116
  1187
deba@2116
  1188
        typedef NodeIt Parent;
deba@2116
  1189
        
deba@2116
  1190
        explicit ConstMapIt(const NodeMap& _map) 
deba@2116
  1191
          : Parent(_map.graph), map(_map) {}
deba@2116
  1192
        
deba@2116
  1193
        typename MapTraits<NodeMap>::ConstReturnValue operator*() const {
deba@2116
  1194
          return map[*this];
deba@2116
  1195
        }
deba@2116
  1196
        
deba@2116
  1197
      private:
deba@2116
  1198
        const NodeMap& map;
deba@2116
  1199
      };
deba@2116
  1200
deba@2116
  1201
      class ItemIt : public NodeIt {
deba@2116
  1202
      public:
deba@2116
  1203
deba@2116
  1204
        typedef NodeIt Parent;
deba@2116
  1205
deba@2116
  1206
        explicit ItemIt(const NodeMap& _map)
deba@2116
  1207
          : Parent(_map.graph) {}
deba@2116
  1208
        
deba@2116
  1209
      };
deba@2116
  1210
      
deba@2116
  1211
    private:
deba@2116
  1212
      const Graph& graph;
deba@2116
  1213
      ANodeMap<_Value> aNodeMap;
deba@2116
  1214
      BNodeMap<_Value> bNodeMap;
deba@2116
  1215
    };
deba@2116
  1216
    
deba@2116
  1217
deba@2116
  1218
    template <typename _Value>
deba@2116
  1219
    class EdgeMap 
deba@2116
  1220
      : public MapExtender<DefaultMap<Graph, Edge, _Value> > {
deba@2116
  1221
    public:
deba@2116
  1222
      typedef BpUGraphExtender Graph;
deba@2116
  1223
      typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
deba@2116
  1224
    
deba@2116
  1225
      EdgeMap(const Graph& graph) 
deba@2116
  1226
	: Parent(graph) {}
deba@2116
  1227
      EdgeMap(const Graph& graph, const _Value& value) 
deba@2116
  1228
	: Parent(graph, value) {}
deba@2116
  1229
    
deba@2116
  1230
      EdgeMap& operator=(const EdgeMap& cmap) {
deba@2116
  1231
	return operator=<EdgeMap>(cmap);
deba@2116
  1232
      }
deba@2116
  1233
    
deba@2116
  1234
      template <typename CMap>
deba@2116
  1235
      EdgeMap& operator=(const CMap& cmap) {
deba@2116
  1236
        Parent::operator=(cmap);
deba@2116
  1237
	return *this;
deba@2116
  1238
      }
deba@2116
  1239
    };
deba@2116
  1240
deba@2116
  1241
    template <typename _Value>
deba@2116
  1242
    class UEdgeMap 
deba@2116
  1243
      : public MapExtender<DefaultMap<Graph, UEdge, _Value> > {
deba@2116
  1244
    public:
deba@2116
  1245
      typedef BpUGraphExtender Graph;
deba@2116
  1246
      typedef MapExtender<DefaultMap<Graph, UEdge, _Value> > Parent;
deba@2116
  1247
    
deba@2116
  1248
      UEdgeMap(const Graph& graph) 
deba@2116
  1249
	: Parent(graph) {}
deba@2116
  1250
      UEdgeMap(const Graph& graph, const _Value& value) 
deba@2116
  1251
	: Parent(graph, value) {}
deba@2116
  1252
    
deba@2116
  1253
      UEdgeMap& operator=(const UEdgeMap& cmap) {
deba@2116
  1254
	return operator=<UEdgeMap>(cmap);
deba@2116
  1255
      }
deba@2116
  1256
    
deba@2116
  1257
      template <typename CMap>
deba@2116
  1258
      UEdgeMap& operator=(const CMap& cmap) {
deba@2116
  1259
        Parent::operator=(cmap);
deba@2116
  1260
	return *this;
deba@2116
  1261
      }
deba@2116
  1262
    };
deba@2116
  1263
deba@2116
  1264
  
deba@2116
  1265
    Node addANode() {
deba@2116
  1266
      Node node = Parent::addANode();
deba@2116
  1267
      getNotifier(ANode()).add(node);
deba@2116
  1268
      getNotifier(Node()).add(node);
deba@2116
  1269
      return node;
deba@2116
  1270
    }
deba@2116
  1271
deba@2116
  1272
    Node addBNode() {
deba@2116
  1273
      Node node = Parent::addBNode();
deba@2116
  1274
      getNotifier(BNode()).add(node);
deba@2116
  1275
      getNotifier(Node()).add(node);
deba@2116
  1276
      return node;
deba@2116
  1277
    }
deba@2116
  1278
  
deba@2116
  1279
    UEdge addEdge(const Node& source, const Node& target) {
deba@2116
  1280
      UEdge uedge = Parent::addEdge(source, target);
deba@2116
  1281
      getNotifier(UEdge()).add(uedge);
deba@2116
  1282
    
deba@2116
  1283
      std::vector<Edge> edges;
deba@2231
  1284
      edges.push_back(Parent::direct(uedge, true));
deba@2231
  1285
      edges.push_back(Parent::direct(uedge, false));
deba@2116
  1286
      getNotifier(Edge()).add(edges);
deba@2116
  1287
    
deba@2116
  1288
      return uedge;
deba@2116
  1289
    }
deba@2116
  1290
deba@2116
  1291
    void clear() {
deba@2116
  1292
      getNotifier(Edge()).clear();
deba@2116
  1293
      getNotifier(UEdge()).clear();
deba@2116
  1294
      getNotifier(Node()).clear();
deba@2116
  1295
      getNotifier(BNode()).clear();
deba@2116
  1296
      getNotifier(ANode()).clear();
deba@2116
  1297
      Parent::clear();
deba@2116
  1298
    }
deba@2116
  1299
deba@2116
  1300
    void erase(const Node& node) {
deba@2116
  1301
      UEdge uedge;
deba@2116
  1302
      if (Parent::aNode(node)) {
deba@2116
  1303
        Parent::firstFromANode(uedge, node);
deba@2116
  1304
        while (uedge != INVALID) {
deba@2116
  1305
          erase(uedge);
deba@2116
  1306
          Parent::firstFromANode(uedge, node);
deba@2116
  1307
        }
deba@2203
  1308
        getNotifier(ANode()).erase(node);
deba@2116
  1309
      } else {
deba@2116
  1310
        Parent::firstFromBNode(uedge, node);
deba@2116
  1311
        while (uedge != INVALID) {
deba@2116
  1312
          erase(uedge);
deba@2116
  1313
          Parent::firstFromBNode(uedge, node);
deba@2116
  1314
        }
deba@2203
  1315
        getNotifier(BNode()).erase(node);
deba@2116
  1316
      }
deba@2116
  1317
deba@2116
  1318
      getNotifier(Node()).erase(node);
deba@2116
  1319
      Parent::erase(node);
deba@2116
  1320
    }
deba@2116
  1321
    
deba@2116
  1322
    void erase(const UEdge& uedge) {
deba@2116
  1323
      std::vector<Edge> edges;
deba@2231
  1324
      edges.push_back(Parent::direct(uedge, true));
deba@2231
  1325
      edges.push_back(Parent::direct(uedge, false));
deba@2116
  1326
      getNotifier(Edge()).erase(edges);
deba@2116
  1327
      getNotifier(UEdge()).erase(uedge);
deba@2116
  1328
      Parent::erase(uedge);
deba@2116
  1329
    }
deba@2116
  1330
deba@2116
  1331
deba@2116
  1332
    BpUGraphExtender() {
deba@2116
  1333
      anode_notifier.setContainer(*this); 
deba@2116
  1334
      bnode_notifier.setContainer(*this); 
deba@2116
  1335
      node_notifier.setContainer(*this); 
deba@2116
  1336
      edge_notifier.setContainer(*this); 
deba@2116
  1337
      uedge_notifier.setContainer(*this);
deba@2116
  1338
    } 
deba@2116
  1339
deba@2116
  1340
    ~BpUGraphExtender() {
deba@2116
  1341
      uedge_notifier.clear();
deba@2116
  1342
      edge_notifier.clear(); 
deba@2116
  1343
      node_notifier.clear(); 
deba@2116
  1344
      anode_notifier.clear(); 
deba@2116
  1345
      bnode_notifier.clear(); 
deba@2116
  1346
    }
deba@2116
  1347
deba@2222
  1348
    Edge findEdge(Node u, Node v, Edge prev = INVALID) const {
deba@2222
  1349
      UEdge uedge = Parent::findUEdge(u, v, prev);
deba@2222
  1350
      if (uedge != INVALID) {
deba@2231
  1351
        return Parent::direct(uedge, Parent::aNode(u));
deba@2222
  1352
      } else {
deba@2222
  1353
        return INVALID;
deba@2222
  1354
      }
deba@2222
  1355
    }
deba@2116
  1356
deba@2116
  1357
  };
deba@2116
  1358
deba@1791
  1359
}
deba@1791
  1360
deba@1996
  1361
#endif