lemon/bits/graph_extender.h
author deba
Thu, 06 Apr 2006 09:33:29 +0000
changeset 2039 dacc4ce9474d
parent 1999 2ff283124dfc
child 2046 66d160810c0a
permissions -rw-r--r--
Commiting The DynamicAsymMatrixMap from Nagy Jano
+ MatrixMapTraits
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@1820
    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@1999
    28
#include <lemon/concept_check.h>
deba@1999
    29
#include <lemon/concept/maps.h>
deba@1999
    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
    ///
deba@1979
   192
    /// Returns the base node (ie. 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
    ///
deba@1979
   198
    /// Returns the running node (ie. 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
    ///
deba@1979
   206
    /// Returns the base node (ie. 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
    ///
deba@1979
   212
    /// Returns the running node (ie. 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
deba@1999
   226
      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
deba@1999
   250
      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@1996
   321
  /// \ingroup graphbits
deba@1996
   322
  ///
deba@1996
   323
  /// \brief Extender for the UGraphs
deba@1979
   324
  template <typename Base> 
deba@1979
   325
  class UGraphExtender : public Base {
deba@1979
   326
  public:
deba@1979
   327
    
deba@1979
   328
    typedef Base Parent;
deba@1979
   329
    typedef UGraphExtender Graph;
deba@1979
   330
deba@1979
   331
    typedef typename Parent::Node Node;
deba@1979
   332
    typedef typename Parent::Edge Edge;
deba@1979
   333
    typedef typename Parent::UEdge UEdge;
deba@1979
   334
deba@1979
   335
    // UGraph extension    
deba@1979
   336
deba@1979
   337
    int maxId(Node) const {
deba@1979
   338
      return Parent::maxNodeId();
deba@1979
   339
    }
deba@1979
   340
deba@1979
   341
    int maxId(Edge) const {
deba@1979
   342
      return Parent::maxEdgeId();
deba@1979
   343
    }
deba@1979
   344
deba@1979
   345
    int maxId(UEdge) const {
deba@1979
   346
      return Parent::maxUEdgeId();
deba@1979
   347
    }
deba@1979
   348
deba@1979
   349
    Node fromId(int id, Node) const {
deba@1979
   350
      return Parent::nodeFromId(id);
deba@1979
   351
    }
deba@1979
   352
deba@1979
   353
    Edge fromId(int id, Edge) const {
deba@1979
   354
      return Parent::edgeFromId(id);
deba@1979
   355
    }
deba@1979
   356
deba@1979
   357
    UEdge fromId(int id, UEdge) const {
deba@1979
   358
      return Parent::uEdgeFromId(id);
deba@1979
   359
    }
deba@1979
   360
deba@1979
   361
    Node oppositeNode(const Node &n, const UEdge &e) const {
deba@1979
   362
      if( n == Parent::source(e))
deba@1979
   363
	return Parent::target(e);
deba@1979
   364
      else if( n == Parent::target(e))
deba@1979
   365
	return Parent::source(e);
deba@1979
   366
      else
deba@1979
   367
	return INVALID;
deba@1979
   368
    }
deba@1979
   369
deba@1979
   370
    Edge oppositeEdge(const Edge &e) const {
deba@1979
   371
      return Parent::direct(e, !Parent::direction(e));
deba@1979
   372
    }
deba@1979
   373
deba@1979
   374
    using Parent::direct;
deba@1979
   375
    Edge direct(const UEdge &ue, const Node &s) const {
deba@1979
   376
      return Parent::direct(ue, Parent::source(ue) == s);
deba@1979
   377
    }
deba@1979
   378
deba@1979
   379
    // Alterable extension
deba@1979
   380
deba@1999
   381
    typedef AlterationNotifier<UGraphExtender, Node> NodeNotifier;
deba@1999
   382
    typedef AlterationNotifier<UGraphExtender, Edge> EdgeNotifier;
deba@1999
   383
    typedef AlterationNotifier<UGraphExtender, UEdge> UEdgeNotifier;
deba@1979
   384
deba@1979
   385
deba@1979
   386
  protected:
deba@1979
   387
deba@1979
   388
    mutable NodeNotifier node_notifier;
deba@1979
   389
    mutable EdgeNotifier edge_notifier;
deba@1979
   390
    mutable UEdgeNotifier uedge_notifier;
deba@1979
   391
deba@1979
   392
  public:
deba@1979
   393
deba@1979
   394
    NodeNotifier& getNotifier(Node) const {
deba@1979
   395
      return node_notifier;
deba@1979
   396
    }
deba@1979
   397
    
deba@1979
   398
    EdgeNotifier& getNotifier(Edge) const {
deba@1979
   399
      return edge_notifier;
deba@1979
   400
    }
deba@1979
   401
deba@1979
   402
    UEdgeNotifier& getNotifier(UEdge) const {
deba@1979
   403
      return uedge_notifier;
deba@1979
   404
    }
deba@1979
   405
deba@1979
   406
deba@1979
   407
deba@1979
   408
    class NodeIt : public Node { 
deba@1979
   409
      const Graph* graph;
deba@1979
   410
    public:
deba@1979
   411
deba@1979
   412
      NodeIt() {}
deba@1979
   413
deba@1979
   414
      NodeIt(Invalid i) : Node(i) { }
deba@1979
   415
deba@1979
   416
      explicit NodeIt(const Graph& _graph) : graph(&_graph) {
deba@2031
   417
	_graph.first(static_cast<Node&>(*this));
deba@1979
   418
      }
deba@1979
   419
deba@1979
   420
      NodeIt(const Graph& _graph, const Node& node) 
deba@1979
   421
	: Node(node), graph(&_graph) {}
deba@1979
   422
deba@1979
   423
      NodeIt& operator++() { 
deba@1979
   424
	graph->next(*this);
deba@1979
   425
	return *this; 
deba@1979
   426
      }
deba@1979
   427
deba@1979
   428
    };
deba@1979
   429
deba@1979
   430
deba@1979
   431
    class EdgeIt : public Edge { 
deba@1979
   432
      const Graph* graph;
deba@1979
   433
    public:
deba@1979
   434
deba@1979
   435
      EdgeIt() { }
deba@1979
   436
deba@1979
   437
      EdgeIt(Invalid i) : Edge(i) { }
deba@1979
   438
deba@1979
   439
      explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
deba@2031
   440
	_graph.first(static_cast<Edge&>(*this));
deba@1979
   441
      }
deba@1979
   442
deba@1979
   443
      EdgeIt(const Graph& _graph, const Edge& e) : 
deba@1979
   444
	Edge(e), graph(&_graph) { }
deba@1979
   445
deba@1979
   446
      EdgeIt& operator++() { 
deba@1979
   447
	graph->next(*this);
deba@1979
   448
	return *this; 
deba@1979
   449
      }
deba@1979
   450
deba@1979
   451
    };
deba@1979
   452
deba@1979
   453
deba@1979
   454
    class OutEdgeIt : public Edge { 
deba@1979
   455
      const Graph* graph;
deba@1979
   456
    public:
deba@1979
   457
deba@1979
   458
      OutEdgeIt() { }
deba@1979
   459
deba@1979
   460
      OutEdgeIt(Invalid i) : Edge(i) { }
deba@1979
   461
deba@1979
   462
      OutEdgeIt(const Graph& _graph, const Node& node) 
deba@1979
   463
	: graph(&_graph) {
deba@1979
   464
	_graph.firstOut(*this, node);
deba@1979
   465
      }
deba@1979
   466
deba@1979
   467
      OutEdgeIt(const Graph& _graph, const Edge& edge) 
deba@1979
   468
	: Edge(edge), graph(&_graph) {}
deba@1979
   469
deba@1979
   470
      OutEdgeIt& operator++() { 
deba@1979
   471
	graph->nextOut(*this);
deba@1979
   472
	return *this; 
deba@1979
   473
      }
deba@1979
   474
deba@1979
   475
    };
deba@1979
   476
deba@1979
   477
deba@1979
   478
    class InEdgeIt : public Edge { 
deba@1979
   479
      const Graph* graph;
deba@1979
   480
    public:
deba@1979
   481
deba@1979
   482
      InEdgeIt() { }
deba@1979
   483
deba@1979
   484
      InEdgeIt(Invalid i) : Edge(i) { }
deba@1979
   485
deba@1979
   486
      InEdgeIt(const Graph& _graph, const Node& node) 
deba@1979
   487
	: graph(&_graph) {
deba@1979
   488
	_graph.firstIn(*this, node);
deba@1979
   489
      }
deba@1979
   490
deba@1979
   491
      InEdgeIt(const Graph& _graph, const Edge& edge) : 
deba@1979
   492
	Edge(edge), graph(&_graph) {}
deba@1979
   493
deba@1979
   494
      InEdgeIt& operator++() { 
deba@1979
   495
	graph->nextIn(*this);
deba@1979
   496
	return *this; 
deba@1979
   497
      }
deba@1979
   498
deba@1979
   499
    };
deba@1979
   500
deba@1979
   501
deba@1979
   502
    class UEdgeIt : public Parent::UEdge { 
deba@1979
   503
      const Graph* graph;
deba@1979
   504
    public:
deba@1979
   505
deba@1979
   506
      UEdgeIt() { }
deba@1979
   507
deba@1979
   508
      UEdgeIt(Invalid i) : UEdge(i) { }
deba@1979
   509
deba@1979
   510
      explicit UEdgeIt(const Graph& _graph) : graph(&_graph) {
deba@2031
   511
	_graph.first(static_cast<UEdge&>(*this));
deba@1979
   512
      }
deba@1979
   513
deba@1979
   514
      UEdgeIt(const Graph& _graph, const UEdge& e) : 
deba@1979
   515
	UEdge(e), graph(&_graph) { }
deba@1979
   516
deba@1979
   517
      UEdgeIt& operator++() { 
deba@1979
   518
	graph->next(*this);
deba@1979
   519
	return *this; 
deba@1979
   520
      }
deba@1979
   521
deba@1979
   522
    };
deba@1979
   523
deba@1979
   524
    class IncEdgeIt : public Parent::UEdge {
deba@1979
   525
      friend class UGraphExtender;
deba@1979
   526
      const Graph* graph;
deba@1979
   527
      bool direction;
deba@1979
   528
    public:
deba@1979
   529
deba@1979
   530
      IncEdgeIt() { }
deba@1979
   531
deba@1979
   532
      IncEdgeIt(Invalid i) : UEdge(i), direction(false) { }
deba@1979
   533
deba@1979
   534
      IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
deba@1979
   535
	_graph.firstInc(*this, direction, n);
deba@1979
   536
      }
deba@1979
   537
deba@1979
   538
      IncEdgeIt(const Graph& _graph, const UEdge &ue, const Node &n)
deba@1979
   539
	: graph(&_graph), UEdge(ue) {
deba@1979
   540
	direction = (_graph.source(ue) == n);
deba@1979
   541
      }
deba@1979
   542
deba@1979
   543
      IncEdgeIt& operator++() {
deba@1979
   544
	graph->nextInc(*this, direction);
deba@1979
   545
	return *this; 
deba@1979
   546
      }
deba@1979
   547
    };
deba@1979
   548
deba@1979
   549
    /// \brief Base node of the iterator
deba@1979
   550
    ///
deba@1979
   551
    /// Returns the base node (ie. the source in this case) of the iterator
deba@1979
   552
    Node baseNode(const OutEdgeIt &e) const {
deba@1979
   553
      return Parent::source((Edge)e);
deba@1979
   554
    }
deba@1979
   555
    /// \brief Running node of the iterator
deba@1979
   556
    ///
deba@1979
   557
    /// Returns the running node (ie. the target in this case) of the
deba@1979
   558
    /// iterator
deba@1979
   559
    Node runningNode(const OutEdgeIt &e) const {
deba@1979
   560
      return Parent::target((Edge)e);
deba@1979
   561
    }
deba@1979
   562
deba@1979
   563
    /// \brief Base node of the iterator
deba@1979
   564
    ///
deba@1979
   565
    /// Returns the base node (ie. the target in this case) of the iterator
deba@1979
   566
    Node baseNode(const InEdgeIt &e) const {
deba@1979
   567
      return Parent::target((Edge)e);
deba@1979
   568
    }
deba@1979
   569
    /// \brief Running node of the iterator
deba@1979
   570
    ///
deba@1979
   571
    /// Returns the running node (ie. the source in this case) of the
deba@1979
   572
    /// iterator
deba@1979
   573
    Node runningNode(const InEdgeIt &e) const {
deba@1979
   574
      return Parent::source((Edge)e);
deba@1979
   575
    }
deba@1979
   576
deba@1979
   577
    /// Base node of the iterator
deba@1979
   578
    ///
deba@1979
   579
    /// Returns the base node of the iterator
deba@1979
   580
    Node baseNode(const IncEdgeIt &e) const {
deba@1979
   581
      return e.direction ? source(e) : target(e);
deba@1979
   582
    }
deba@1979
   583
    /// Running node of the iterator
deba@1979
   584
    ///
deba@1979
   585
    /// Returns the running node of the iterator
deba@1979
   586
    Node runningNode(const IncEdgeIt &e) const {
deba@1979
   587
      return e.direction ? target(e) : source(e);
deba@1979
   588
    }
deba@1979
   589
deba@1979
   590
    // Mappable extension
deba@1979
   591
deba@1979
   592
    template <typename _Value>
deba@1979
   593
    class NodeMap 
deba@1999
   594
      : public MapExtender<DefaultMap<Graph, Node, _Value> > {
deba@1979
   595
    public:
deba@1979
   596
      typedef UGraphExtender Graph;
deba@1999
   597
      typedef MapExtender<DefaultMap<Graph, Node, _Value> > Parent;
deba@1979
   598
deba@1999
   599
      NodeMap(const Graph& graph) 
deba@1999
   600
	: Parent(graph) {}
deba@1999
   601
      NodeMap(const Graph& graph, const _Value& value) 
deba@1999
   602
	: Parent(graph, value) {}
deba@1979
   603
deba@1979
   604
      NodeMap& operator=(const NodeMap& cmap) {
deba@1979
   605
	return operator=<NodeMap>(cmap);
deba@1979
   606
      }
deba@1979
   607
deba@1979
   608
      template <typename CMap>
deba@1979
   609
      NodeMap& operator=(const CMap& cmap) {
deba@2031
   610
        Parent::operator=(cmap);
deba@1979
   611
	return *this;
deba@1979
   612
      }
deba@1979
   613
deba@1979
   614
    };
deba@1979
   615
deba@1979
   616
    template <typename _Value>
deba@1979
   617
    class EdgeMap 
deba@1999
   618
      : public MapExtender<DefaultMap<Graph, Edge, _Value> > {
deba@1979
   619
    public:
deba@1979
   620
      typedef UGraphExtender Graph;
deba@1999
   621
      typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
deba@1979
   622
deba@1999
   623
      EdgeMap(const Graph& graph) 
deba@1999
   624
	: Parent(graph) {}
deba@1999
   625
      EdgeMap(const Graph& graph, const _Value& value) 
deba@1999
   626
	: Parent(graph, value) {}
deba@1979
   627
deba@1979
   628
      EdgeMap& operator=(const EdgeMap& cmap) {
deba@1979
   629
	return operator=<EdgeMap>(cmap);
deba@1979
   630
      }
deba@1979
   631
deba@1979
   632
      template <typename CMap>
deba@1979
   633
      EdgeMap& operator=(const CMap& cmap) {
deba@2031
   634
        Parent::operator=(cmap);
deba@1979
   635
	return *this;
deba@1979
   636
      }
deba@1979
   637
    };
deba@1979
   638
deba@1979
   639
deba@1979
   640
    template <typename _Value>
deba@1979
   641
    class UEdgeMap 
deba@1999
   642
      : public MapExtender<DefaultMap<Graph, UEdge, _Value> > {
deba@1979
   643
    public:
deba@1979
   644
      typedef UGraphExtender Graph;
deba@1999
   645
      typedef MapExtender<DefaultMap<Graph, UEdge, _Value> > Parent;
deba@1979
   646
deba@1999
   647
      UEdgeMap(const Graph& graph) 
deba@1999
   648
	: Parent(graph) {}
deba@2031
   649
deba@1999
   650
      UEdgeMap(const Graph& graph, const _Value& value) 
deba@1999
   651
	: Parent(graph, value) {}
deba@1979
   652
deba@1979
   653
      UEdgeMap& operator=(const UEdgeMap& cmap) {
deba@1979
   654
	return operator=<UEdgeMap>(cmap);
deba@1979
   655
      }
deba@1979
   656
deba@1979
   657
      template <typename CMap>
deba@1979
   658
      UEdgeMap& operator=(const CMap& cmap) {
deba@2031
   659
        Parent::operator=(cmap);
deba@1979
   660
	return *this;
deba@1979
   661
      }
deba@2031
   662
deba@1979
   663
    };
deba@1979
   664
deba@1979
   665
    // Alteration extension
deba@1979
   666
deba@1979
   667
    Node addNode() {
deba@1979
   668
      Node node = Parent::addNode();
deba@1979
   669
      getNotifier(Node()).add(node);
deba@1979
   670
      return node;
deba@1979
   671
    }
deba@1979
   672
deba@1979
   673
    UEdge addEdge(const Node& from, const Node& to) {
deba@1979
   674
      UEdge uedge = Parent::addEdge(from, to);
deba@1979
   675
      getNotifier(UEdge()).add(uedge);
deba@1979
   676
      getNotifier(Edge()).add(Parent::direct(uedge, true));
deba@1979
   677
      getNotifier(Edge()).add(Parent::direct(uedge, false));
deba@1979
   678
      return uedge;
deba@1979
   679
    }
deba@1979
   680
    
deba@1979
   681
    void clear() {
deba@1979
   682
      getNotifier(Edge()).clear();
deba@1979
   683
      getNotifier(UEdge()).clear();
deba@1979
   684
      getNotifier(Node()).clear();
deba@1979
   685
      Parent::clear();
deba@1979
   686
    }
deba@1979
   687
deba@1979
   688
    void erase(const Node& node) {
deba@1979
   689
      Edge edge;
deba@1979
   690
      Parent::firstOut(edge, node);
deba@1979
   691
      while (edge != INVALID ) {
deba@1979
   692
	erase(edge);
deba@1979
   693
	Parent::firstOut(edge, node);
deba@1979
   694
      } 
deba@1979
   695
deba@1979
   696
      Parent::firstIn(edge, node);
deba@1979
   697
      while (edge != INVALID ) {
deba@1979
   698
	erase(edge);
deba@1979
   699
	Parent::firstIn(edge, node);
deba@1979
   700
      }
deba@1979
   701
deba@1979
   702
      getNotifier(Node()).erase(node);
deba@1979
   703
      Parent::erase(node);
deba@1979
   704
    }
deba@1979
   705
deba@1979
   706
    void erase(const UEdge& uedge) {
deba@1979
   707
      getNotifier(Edge()).erase(Parent::direct(uedge, true));
deba@1979
   708
      getNotifier(Edge()).erase(Parent::direct(uedge, false));
deba@1979
   709
      getNotifier(UEdge()).erase(uedge);
deba@1979
   710
      Parent::erase(uedge);
deba@1979
   711
    }
deba@1979
   712
deba@1999
   713
    UGraphExtender() {
deba@1999
   714
      node_notifier.setContainer(*this); 
deba@1999
   715
      edge_notifier.setContainer(*this);
deba@1999
   716
      uedge_notifier.setContainer(*this);
deba@1999
   717
    } 
deba@1999
   718
deba@1979
   719
    ~UGraphExtender() {
deba@1999
   720
      uedge_notifier.clear();
deba@1999
   721
      edge_notifier.clear();
deba@1999
   722
      node_notifier.clear(); 
deba@1999
   723
    } 
deba@1791
   724
deba@1791
   725
  };
deba@1791
   726
deba@1996
   727
  /// \ingroup graphbits
deba@1996
   728
  ///
deba@1996
   729
  /// \brief Extender for the BpUGraphs
deba@1979
   730
  template <typename Base>
deba@1979
   731
  class BpUGraphExtender : public Base {
deba@1979
   732
  public:
deba@1979
   733
    typedef Base Parent;
deba@1979
   734
    typedef BpUGraphExtender Graph;
deba@1979
   735
deba@1979
   736
    typedef typename Parent::Node Node;
deba@1979
   737
    typedef typename Parent::BNode BNode;
deba@1979
   738
    typedef typename Parent::ANode ANode;
deba@1979
   739
    typedef typename Parent::Edge Edge;
deba@1979
   740
    typedef typename Parent::UEdge UEdge;
deba@1979
   741
deba@1979
   742
    Node oppositeNode(const UEdge& edge, const Node& node) const {
deba@1979
   743
      return source(edge) == node ? 
deba@1979
   744
	target(edge) : source(edge);
deba@1820
   745
    }
deba@1820
   746
deba@1979
   747
    using Parent::direct;
deba@1979
   748
    Edge direct(const UEdge& edge, const Node& node) const {
deba@1979
   749
      return Edge(edge, node == Parent::source(edge));
deba@1820
   750
    }
deba@1820
   751
deba@1979
   752
    Edge oppositeEdge(const Edge& edge) const {
deba@1979
   753
      return Parent::direct(edge, !Parent::direction(edge));
deba@1979
   754
    }
deba@1820
   755
deba@1820
   756
deba@1820
   757
    int maxId(Node) const {
deba@1820
   758
      return Parent::maxNodeId();
deba@1820
   759
    }
deba@1910
   760
    int maxId(BNode) const {
deba@1910
   761
      return Parent::maxBNodeId();
deba@1820
   762
    }
deba@1910
   763
    int maxId(ANode) const {
deba@1910
   764
      return Parent::maxANodeId();
deba@1820
   765
    }
deba@1820
   766
    int maxId(Edge) const {
deba@1979
   767
      return Parent::maxEdgeId();
deba@1820
   768
    }
klao@1909
   769
    int maxId(UEdge) const {
deba@1979
   770
      return Parent::maxUEdgeId();
deba@1820
   771
    }
deba@1820
   772
deba@1820
   773
deba@1820
   774
    Node fromId(int id, Node) const {
deba@1820
   775
      return Parent::nodeFromId(id);
deba@1820
   776
    }
deba@1910
   777
    ANode fromId(int id, ANode) const {
deba@1910
   778
      return Parent::fromANodeId(id);
deba@1820
   779
    }
deba@1910
   780
    BNode fromId(int id, BNode) const {
deba@1910
   781
      return Parent::fromBNodeId(id);
deba@1820
   782
    }
deba@1820
   783
    Edge fromId(int id, Edge) const {
deba@1979
   784
      return Parent::edgeFromId(id);
deba@1820
   785
    }
klao@1909
   786
    UEdge fromId(int id, UEdge) const {
deba@1979
   787
      return Parent::uEdgeFromId(id);
deba@1979
   788
    }  
deba@1979
   789
  
deba@1999
   790
    typedef AlterationNotifier<BpUGraphExtender, ANode> ANodeNotifier;
deba@1999
   791
    typedef AlterationNotifier<BpUGraphExtender, BNode> BNodeNotifier;
deba@1999
   792
    typedef AlterationNotifier<BpUGraphExtender, Node> NodeNotifier;
deba@1999
   793
    typedef AlterationNotifier<BpUGraphExtender, Edge> EdgeNotifier;
deba@1999
   794
    typedef AlterationNotifier<BpUGraphExtender, UEdge> UEdgeNotifier;
deba@1979
   795
deba@1979
   796
  protected:
deba@1979
   797
deba@1999
   798
    mutable ANodeNotifier anode_notifier;
deba@1999
   799
    mutable BNodeNotifier bnode_notifier;
deba@1999
   800
    mutable NodeNotifier node_notifier;
deba@1999
   801
    mutable EdgeNotifier edge_notifier;
deba@1999
   802
    mutable UEdgeNotifier uedge_notifier;
deba@1979
   803
deba@1979
   804
  public:
deba@1979
   805
deba@1979
   806
    NodeNotifier& getNotifier(Node) const {
deba@1999
   807
      return node_notifier;
deba@1999
   808
    }
deba@1999
   809
deba@1999
   810
    ANodeNotifier& getNotifier(ANode) const {
deba@1999
   811
      return anode_notifier;
deba@1820
   812
    }
deba@1820
   813
deba@1979
   814
    BNodeNotifier& getNotifier(BNode) const {
deba@1999
   815
      return bnode_notifier;
deba@1979
   816
    }
deba@1979
   817
deba@1979
   818
    EdgeNotifier& getNotifier(Edge) const {
deba@1999
   819
      return edge_notifier;
deba@1979
   820
    }
deba@1979
   821
deba@1979
   822
    UEdgeNotifier& getNotifier(UEdge) const {
deba@1999
   823
      return uedge_notifier;
deba@1979
   824
    }
deba@1979
   825
deba@1979
   826
    class NodeIt : public Node { 
deba@1979
   827
      const Graph* graph;
deba@1979
   828
    public:
deba@1979
   829
    
deba@1979
   830
      NodeIt() { }
deba@1979
   831
    
deba@1979
   832
      NodeIt(Invalid i) : Node(INVALID) { }
deba@1979
   833
    
deba@1979
   834
      explicit NodeIt(const Graph& _graph) : graph(&_graph) {
deba@1979
   835
	graph->first(static_cast<Node&>(*this));
deba@1979
   836
      }
deba@1979
   837
deba@1979
   838
      NodeIt(const Graph& _graph, const Node& node) 
deba@1979
   839
	: Node(node), graph(&_graph) { }
deba@1979
   840
    
deba@1979
   841
      NodeIt& operator++() { 
deba@1979
   842
	graph->next(*this);
deba@1979
   843
	return *this; 
deba@1979
   844
      }
deba@1979
   845
deba@1979
   846
    };
deba@1979
   847
deba@1979
   848
    class ANodeIt : public Node { 
deba@1979
   849
      friend class BpUGraphExtender;
deba@1979
   850
      const Graph* graph;
deba@1979
   851
    public:
deba@1979
   852
    
deba@1979
   853
      ANodeIt() { }
deba@1979
   854
    
deba@1979
   855
      ANodeIt(Invalid i) : Node(INVALID) { }
deba@1979
   856
    
deba@1979
   857
      explicit ANodeIt(const Graph& _graph) : graph(&_graph) {
deba@1979
   858
	graph->firstANode(static_cast<Node&>(*this));
deba@1979
   859
      }
deba@1979
   860
deba@1979
   861
      ANodeIt(const Graph& _graph, const Node& node) 
deba@1979
   862
	: Node(node), graph(&_graph) {}
deba@1979
   863
    
deba@1979
   864
      ANodeIt& operator++() { 
deba@1979
   865
	graph->nextANode(*this);
deba@1979
   866
	return *this; 
deba@1979
   867
      }
deba@1979
   868
    };
deba@1979
   869
deba@1979
   870
    class BNodeIt : public Node { 
deba@1979
   871
      friend class BpUGraphExtender;
deba@1979
   872
      const Graph* graph;
deba@1979
   873
    public:
deba@1979
   874
    
deba@1979
   875
      BNodeIt() { }
deba@1979
   876
    
deba@1979
   877
      BNodeIt(Invalid i) : Node(INVALID) { }
deba@1979
   878
    
deba@1979
   879
      explicit BNodeIt(const Graph& _graph) : graph(&_graph) {
deba@1979
   880
	graph->firstBNode(static_cast<Node&>(*this));
deba@1979
   881
      }
deba@1979
   882
deba@1979
   883
      BNodeIt(const Graph& _graph, const Node& node) 
deba@1979
   884
	: Node(node), graph(&_graph) {}
deba@1979
   885
    
deba@1979
   886
      BNodeIt& operator++() { 
deba@1979
   887
	graph->nextBNode(*this);
deba@1979
   888
	return *this; 
deba@1979
   889
      }
deba@1979
   890
    };
deba@1979
   891
deba@1979
   892
    class EdgeIt : public Edge { 
deba@1979
   893
      friend class BpUGraphExtender;
deba@1979
   894
      const Graph* graph;
deba@1979
   895
    public:
deba@1979
   896
    
deba@1979
   897
      EdgeIt() { }
deba@1979
   898
    
deba@1979
   899
      EdgeIt(Invalid i) : Edge(INVALID) { }
deba@1979
   900
    
deba@1979
   901
      explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
deba@1979
   902
	graph->first(static_cast<Edge&>(*this));
deba@1979
   903
      }
deba@1979
   904
deba@1979
   905
      EdgeIt(const Graph& _graph, const Edge& edge) 
deba@1979
   906
	: Edge(edge), graph(&_graph) { }
deba@1979
   907
    
deba@1979
   908
      EdgeIt& operator++() { 
deba@1979
   909
	graph->next(*this);
deba@1979
   910
	return *this; 
deba@1979
   911
      }
deba@1979
   912
deba@1979
   913
    };
deba@1979
   914
deba@1979
   915
    class UEdgeIt : public UEdge { 
deba@1979
   916
      friend class BpUGraphExtender;
deba@1979
   917
      const Graph* graph;
deba@1979
   918
    public:
deba@1979
   919
    
deba@1979
   920
      UEdgeIt() { }
deba@1979
   921
    
deba@1979
   922
      UEdgeIt(Invalid i) : UEdge(INVALID) { }
deba@1979
   923
    
deba@1979
   924
      explicit UEdgeIt(const Graph& _graph) : graph(&_graph) {
deba@1979
   925
	graph->first(static_cast<UEdge&>(*this));
deba@1979
   926
      }
deba@1979
   927
deba@1979
   928
      UEdgeIt(const Graph& _graph, const UEdge& edge) 
deba@1979
   929
	: UEdge(edge), graph(&_graph) { }
deba@1979
   930
    
deba@1979
   931
      UEdgeIt& operator++() { 
deba@1979
   932
	graph->next(*this);
deba@1979
   933
	return *this; 
deba@1979
   934
      }
deba@1979
   935
    };
deba@1979
   936
deba@1979
   937
    class OutEdgeIt : public Edge { 
deba@1979
   938
      friend class BpUGraphExtender;
deba@1979
   939
      const Graph* graph;
deba@1979
   940
    public:
deba@1979
   941
    
deba@1979
   942
      OutEdgeIt() { }
deba@1979
   943
    
deba@1979
   944
      OutEdgeIt(Invalid i) : Edge(i) { }
deba@1979
   945
    
deba@1979
   946
      OutEdgeIt(const Graph& _graph, const Node& node) 
deba@1979
   947
	: graph(&_graph) {
deba@1979
   948
	graph->firstOut(*this, node);
deba@1979
   949
      }
deba@1979
   950
    
deba@1979
   951
      OutEdgeIt(const Graph& _graph, const Edge& edge) 
deba@1979
   952
	: Edge(edge), graph(&_graph) {}
deba@1979
   953
    
deba@1979
   954
      OutEdgeIt& operator++() { 
deba@1979
   955
	graph->nextOut(*this);
deba@1979
   956
	return *this; 
deba@1979
   957
      }
deba@1979
   958
deba@1979
   959
    };
deba@1979
   960
deba@1979
   961
deba@1979
   962
    class InEdgeIt : public Edge { 
deba@1979
   963
      friend class BpUGraphExtender;
deba@1979
   964
      const Graph* graph;
deba@1979
   965
    public:
deba@1979
   966
    
deba@1979
   967
      InEdgeIt() { }
deba@1979
   968
    
deba@1979
   969
      InEdgeIt(Invalid i) : Edge(i) { }
deba@1979
   970
    
deba@1979
   971
      InEdgeIt(const Graph& _graph, const Node& node) 
deba@1979
   972
	: graph(&_graph) {
deba@1979
   973
	graph->firstIn(*this, node);
deba@1979
   974
      }
deba@1979
   975
    
deba@1979
   976
      InEdgeIt(const Graph& _graph, const Edge& edge) : 
deba@1979
   977
	Edge(edge), graph(&_graph) {}
deba@1979
   978
    
deba@1979
   979
      InEdgeIt& operator++() { 
deba@1979
   980
	graph->nextIn(*this);
deba@1979
   981
	return *this; 
deba@1979
   982
      }
deba@1979
   983
deba@1979
   984
    };
deba@1979
   985
  
deba@1979
   986
    /// \brief Base node of the iterator
deba@1979
   987
    ///
deba@1979
   988
    /// Returns the base node (ie. the source in this case) of the iterator
deba@1979
   989
    Node baseNode(const OutEdgeIt &e) const {
deba@1979
   990
      return Parent::source((Edge&)e);
deba@1979
   991
    }
deba@1979
   992
    /// \brief Running node of the iterator
deba@1979
   993
    ///
deba@1979
   994
    /// Returns the running node (ie. the target in this case) of the
deba@1979
   995
    /// iterator
deba@1979
   996
    Node runningNode(const OutEdgeIt &e) const {
deba@1979
   997
      return Parent::target((Edge&)e);
deba@1979
   998
    }
deba@1979
   999
  
deba@1979
  1000
    /// \brief Base node of the iterator
deba@1979
  1001
    ///
deba@1979
  1002
    /// Returns the base node (ie. the target in this case) of the iterator
deba@1979
  1003
    Node baseNode(const InEdgeIt &e) const {
deba@1979
  1004
      return Parent::target((Edge&)e);
deba@1979
  1005
    }
deba@1979
  1006
    /// \brief Running node of the iterator
deba@1979
  1007
    ///
deba@1979
  1008
    /// Returns the running node (ie. the source in this case) of the
deba@1979
  1009
    /// iterator
deba@1979
  1010
    Node runningNode(const InEdgeIt &e) const {
deba@1979
  1011
      return Parent::source((Edge&)e);
deba@1979
  1012
    }
deba@1979
  1013
  
deba@1979
  1014
    class IncEdgeIt : public Parent::UEdge { 
deba@1979
  1015
      friend class BpUGraphExtender;
deba@1979
  1016
      const Graph* graph;
deba@1979
  1017
      bool direction;
deba@1979
  1018
    public:
deba@1979
  1019
    
deba@1979
  1020
      IncEdgeIt() { }
deba@1979
  1021
    
deba@1979
  1022
      IncEdgeIt(Invalid i) : UEdge(i), direction(true) { }
deba@1979
  1023
    
deba@1979
  1024
      IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
deba@1979
  1025
	graph->firstInc(*this, direction, n);
deba@1979
  1026
      }
deba@1979
  1027
deba@1979
  1028
      IncEdgeIt(const Graph& _graph, const UEdge &ue, const Node &n)
deba@1979
  1029
	: graph(&_graph), UEdge(ue) {
deba@1979
  1030
	direction = (graph->source(ue) == n);
deba@1979
  1031
      }
deba@1979
  1032
deba@1979
  1033
      IncEdgeIt& operator++() {
deba@1979
  1034
	graph->nextInc(*this, direction);
deba@1979
  1035
	return *this; 
deba@1979
  1036
      }
deba@1979
  1037
    };
deba@1979
  1038
  
deba@1979
  1039
deba@1979
  1040
    /// Base node of the iterator
deba@1979
  1041
    ///
deba@1979
  1042
    /// Returns the base node of the iterator
deba@1979
  1043
    Node baseNode(const IncEdgeIt &e) const {
deba@1979
  1044
      return e.direction ? source(e) : target(e);
deba@1979
  1045
    }
deba@1979
  1046
deba@1979
  1047
    /// Running node of the iterator
deba@1979
  1048
    ///
deba@1979
  1049
    /// Returns the running node of the iterator
deba@1979
  1050
    Node runningNode(const IncEdgeIt &e) const {
deba@1979
  1051
      return e.direction ? target(e) : source(e);
deba@1979
  1052
    }
deba@1979
  1053
deba@1979
  1054
    template <typename _Value>
deba@1979
  1055
    class ANodeMap 
deba@1999
  1056
      : public MapExtender<DefaultMap<Graph, ANode, _Value> > {
deba@1979
  1057
    public:
deba@1979
  1058
      typedef BpUGraphExtender Graph;
deba@1999
  1059
      typedef MapExtender<DefaultMap<Graph, ANode, _Value> > Parent;
deba@1979
  1060
    
deba@1999
  1061
      ANodeMap(const Graph& graph) 
deba@1999
  1062
	: Parent(graph) {}
deba@1999
  1063
      ANodeMap(const Graph& graph, const _Value& value) 
deba@1999
  1064
	: Parent(graph, value) {}
deba@1979
  1065
    
deba@1979
  1066
      ANodeMap& operator=(const ANodeMap& cmap) {
deba@1979
  1067
	return operator=<ANodeMap>(cmap);
deba@1979
  1068
      }
deba@1979
  1069
    
deba@1979
  1070
      template <typename CMap>
deba@1979
  1071
      ANodeMap& operator=(const CMap& cmap) {
deba@2031
  1072
        Parent::operator=(cmap);
deba@1979
  1073
	return *this;
deba@1979
  1074
      }
deba@1979
  1075
    
deba@1979
  1076
    };
deba@1979
  1077
deba@1979
  1078
    template <typename _Value>
deba@1979
  1079
    class BNodeMap 
deba@1999
  1080
      : public MapExtender<DefaultMap<Graph, BNode, _Value> > {
deba@1979
  1081
    public:
deba@1979
  1082
      typedef BpUGraphExtender Graph;
deba@1999
  1083
      typedef MapExtender<DefaultMap<Graph, BNode, _Value> > Parent;
deba@1979
  1084
    
deba@1999
  1085
      BNodeMap(const Graph& graph) 
deba@1999
  1086
	: Parent(graph) {}
deba@1999
  1087
      BNodeMap(const Graph& graph, const _Value& value) 
deba@1999
  1088
	: Parent(graph, value) {}
deba@1979
  1089
    
deba@1979
  1090
      BNodeMap& operator=(const BNodeMap& cmap) {
deba@1979
  1091
	return operator=<BNodeMap>(cmap);
deba@1979
  1092
      }
deba@1979
  1093
    
deba@1979
  1094
      template <typename CMap>
deba@1979
  1095
      BNodeMap& operator=(const CMap& cmap) {
deba@2031
  1096
        Parent::operator=(cmap);
deba@1979
  1097
	return *this;
deba@1979
  1098
      }
deba@1979
  1099
    
deba@1979
  1100
    };
deba@1979
  1101
deba@2031
  1102
  public:
deba@1979
  1103
deba@1979
  1104
    template <typename _Value>
deba@2031
  1105
    class NodeMap {
deba@1979
  1106
    public:
deba@1979
  1107
      typedef BpUGraphExtender Graph;
deba@1979
  1108
deba@1979
  1109
      typedef Node Key;
deba@1979
  1110
      typedef _Value Value;
deba@1979
  1111
deba@1979
  1112
      /// The reference type of the map;
deba@1999
  1113
      typedef typename ANodeMap<_Value>::Reference Reference;
deba@1979
  1114
      /// The const reference type of the map;
deba@1999
  1115
      typedef typename ANodeMap<_Value>::ConstReference ConstReference;
deba@1979
  1116
deba@1979
  1117
      typedef True ReferenceMapTag;
deba@1979
  1118
deba@2031
  1119
      NodeMap(const Graph& _graph) 
deba@2031
  1120
	: graph(_graph), aNodeMap(_graph), bNodeMap(_graph) {}
deba@2031
  1121
      NodeMap(const Graph& _graph, const _Value& _value) 
deba@2031
  1122
	: graph(_graph), aNodeMap(_graph, _value), bNodeMap(_graph, _value) {}
deba@2031
  1123
deba@2031
  1124
      NodeMap& operator=(const NodeMap& cmap) {
deba@2031
  1125
	return operator=<NodeMap>(cmap);
deba@2031
  1126
      }
deba@2031
  1127
    
deba@2031
  1128
      template <typename CMap>
deba@2031
  1129
      NodeMap& operator=(const CMap& cmap) {
deba@2031
  1130
	checkConcept<concept::ReadMap<Node, _Value>, CMap>();
deba@2031
  1131
	const typename Parent::Notifier* notifier = Parent::getNotifier();
deba@2031
  1132
	Edge it;
deba@2031
  1133
	for (graph.first(it); it != INVALID; graph.next(it)) {
deba@2031
  1134
	  Parent::set(it, cmap[it]);
deba@2031
  1135
	}
deba@2031
  1136
	return *this;
deba@2031
  1137
      }
deba@1979
  1138
deba@1979
  1139
      ConstReference operator[](const Key& node) const {
deba@1979
  1140
	if (Parent::aNode(node)) {
deba@1979
  1141
	  return aNodeMap[node];
deba@1979
  1142
	} else {
deba@1979
  1143
	  return bNodeMap[node];
deba@1979
  1144
	}
deba@1979
  1145
      } 
deba@1979
  1146
deba@1979
  1147
      Reference operator[](const Key& node) {
deba@1979
  1148
	if (Parent::aNode(node)) {
deba@1979
  1149
	  return aNodeMap[node];
deba@1979
  1150
	} else {
deba@1979
  1151
	  return bNodeMap[node];
deba@1979
  1152
	}
deba@1979
  1153
      }
deba@1979
  1154
deba@1979
  1155
      void set(const Key& node, const Value& value) {
deba@1979
  1156
	if (Parent::aNode(node)) {
deba@1979
  1157
	  aNodeMap.set(node, value);
deba@1979
  1158
	} else {
deba@1979
  1159
	  bNodeMap.set(node, value);
deba@1979
  1160
	}
deba@1979
  1161
      }
deba@1979
  1162
deba@2031
  1163
      class MapIt : public NodeIt {
deba@2031
  1164
      public:
deba@1979
  1165
deba@2031
  1166
        typedef NodeIt Parent;
deba@2031
  1167
        
deba@2031
  1168
        explicit MapIt(NodeMap& _map) 
deba@2031
  1169
          : Parent(_map.graph), map(_map) {}
deba@2031
  1170
        
deba@2031
  1171
        typename MapTraits<NodeMap>::ConstReturnValue operator*() const {
deba@2031
  1172
          return map[*this];
deba@2031
  1173
        }
deba@2031
  1174
        
deba@2031
  1175
        typename MapTraits<NodeMap>::ReturnValue operator*() {
deba@2031
  1176
          return map[*this];
deba@2031
  1177
        }
deba@2031
  1178
        
deba@2031
  1179
        void set(const Value& value) {
deba@2031
  1180
          map.set(*this, value);
deba@2031
  1181
        }
deba@2031
  1182
deba@2031
  1183
      private:
deba@2031
  1184
        NodeMap& map;
deba@2031
  1185
      };
deba@2031
  1186
deba@2031
  1187
      class ConstMapIt : public NodeIt {
deba@2031
  1188
      public:
deba@2031
  1189
deba@2031
  1190
        typedef NodeIt Parent;
deba@2031
  1191
        
deba@2031
  1192
        explicit ConstMapIt(const NodeMap& _map) 
deba@2031
  1193
          : Parent(_map.graph), map(_map) {}
deba@2031
  1194
        
deba@2031
  1195
        typename MapTraits<NodeMap>::ConstReturnValue operator*() const {
deba@2031
  1196
          return map[*this];
deba@2031
  1197
        }
deba@2031
  1198
        
deba@2031
  1199
      private:
deba@2031
  1200
        const NodeMap& map;
deba@2031
  1201
      };
deba@2031
  1202
deba@2031
  1203
      class ItemIt : public NodeIt {
deba@2031
  1204
      public:
deba@2031
  1205
deba@2031
  1206
        typedef NodeIt Parent;
deba@2031
  1207
deba@2031
  1208
        explicit ItemIt(const NodeMap& _map)
deba@2031
  1209
          : Parent(_map.graph) {}
deba@2031
  1210
        
deba@2031
  1211
      };
deba@2031
  1212
      
deba@1979
  1213
    private:
deba@2031
  1214
      const Graph& graph;
deba@1991
  1215
      ANodeMap<_Value> aNodeMap;
deba@1979
  1216
      BNodeMap<_Value> bNodeMap;
deba@1979
  1217
    };
deba@1979
  1218
    
deba@1979
  1219
deba@1979
  1220
    template <typename _Value>
deba@1979
  1221
    class EdgeMap 
deba@1999
  1222
      : public MapExtender<DefaultMap<Graph, Edge, _Value> > {
deba@1979
  1223
    public:
deba@1979
  1224
      typedef BpUGraphExtender Graph;
deba@1999
  1225
      typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
deba@1979
  1226
    
deba@1999
  1227
      EdgeMap(const Graph& graph) 
deba@1999
  1228
	: Parent(graph) {}
deba@1999
  1229
      EdgeMap(const Graph& graph, const _Value& value) 
deba@1999
  1230
	: Parent(graph, value) {}
deba@1979
  1231
    
deba@1979
  1232
      EdgeMap& operator=(const EdgeMap& cmap) {
deba@1979
  1233
	return operator=<EdgeMap>(cmap);
deba@1979
  1234
      }
deba@1979
  1235
    
deba@1979
  1236
      template <typename CMap>
deba@1979
  1237
      EdgeMap& operator=(const CMap& cmap) {
deba@2031
  1238
        Parent::operator=(cmap);
deba@1979
  1239
	return *this;
deba@1979
  1240
      }
deba@1979
  1241
    };
deba@1979
  1242
deba@1979
  1243
    template <typename _Value>
deba@1979
  1244
    class UEdgeMap 
deba@1999
  1245
      : public MapExtender<DefaultMap<Graph, UEdge, _Value> > {
deba@1979
  1246
    public:
deba@1979
  1247
      typedef BpUGraphExtender Graph;
deba@1999
  1248
      typedef MapExtender<DefaultMap<Graph, UEdge, _Value> > Parent;
deba@1979
  1249
    
deba@1999
  1250
      UEdgeMap(const Graph& graph) 
deba@1999
  1251
	: Parent(graph) {}
deba@1999
  1252
      UEdgeMap(const Graph& graph, const _Value& value) 
deba@1999
  1253
	: Parent(graph, value) {}
deba@1979
  1254
    
deba@1979
  1255
      UEdgeMap& operator=(const UEdgeMap& cmap) {
deba@1979
  1256
	return operator=<UEdgeMap>(cmap);
deba@1979
  1257
      }
deba@1979
  1258
    
deba@1979
  1259
      template <typename CMap>
deba@1979
  1260
      UEdgeMap& operator=(const CMap& cmap) {
deba@2031
  1261
        Parent::operator=(cmap);
deba@1979
  1262
	return *this;
deba@1979
  1263
      }
deba@1979
  1264
    };
deba@1979
  1265
deba@1979
  1266
  
deba@1979
  1267
    Node addANode() {
deba@1979
  1268
      Node node = Parent::addANode();
deba@1979
  1269
      getNotifier(ANode()).add(node);
deba@1979
  1270
      getNotifier(Node()).add(node);
deba@1979
  1271
      return node;
deba@1979
  1272
    }
deba@1979
  1273
deba@1979
  1274
    Node addBNode() {
deba@1979
  1275
      Node node = Parent::addBNode();
deba@1979
  1276
      getNotifier(BNode()).add(node);
deba@1979
  1277
      getNotifier(Node()).add(node);
deba@1979
  1278
      return node;
deba@1979
  1279
    }
deba@1979
  1280
  
deba@1979
  1281
    UEdge addEdge(const Node& source, const Node& target) {
deba@1979
  1282
      UEdge uedge = Parent::addEdge(source, target);
deba@1979
  1283
      getNotifier(UEdge()).add(uedge);
deba@1979
  1284
    
deba@1979
  1285
      std::vector<Edge> edges;
deba@1979
  1286
      edges.push_back(direct(uedge, true));
deba@1979
  1287
      edges.push_back(direct(uedge, false));
deba@1979
  1288
      getNotifier(Edge()).add(edges);
deba@1979
  1289
    
deba@1979
  1290
      return uedge;
deba@1979
  1291
    }
deba@1979
  1292
deba@1979
  1293
    void clear() {
deba@1979
  1294
      getNotifier(Edge()).clear();
deba@1979
  1295
      getNotifier(UEdge()).clear();
deba@1979
  1296
      getNotifier(Node()).clear();
deba@1979
  1297
      getNotifier(BNode()).clear();
deba@1979
  1298
      getNotifier(ANode()).clear();
deba@1979
  1299
      Parent::clear();
deba@1979
  1300
    }
deba@1979
  1301
deba@1979
  1302
    void erase(const Node& node) {
deba@1979
  1303
      UEdge uedge;
deba@1979
  1304
      bool dir;
deba@1979
  1305
      Parent::firstInc(uedge, dir, node);
deba@1979
  1306
      while (uedge != INVALID ) {
deba@1979
  1307
	erase(uedge);
deba@1979
  1308
	Parent::firstInc(uedge, dir, node);
deba@1979
  1309
      } 
deba@1979
  1310
deba@1979
  1311
      getNotifier(Node()).erase(node);
deba@1979
  1312
      Parent::erase(node);
deba@1979
  1313
    }
deba@1979
  1314
    
deba@1979
  1315
    void erase(const UEdge& uedge) {
deba@1979
  1316
      std::vector<Edge> edges;
deba@1979
  1317
      edges.push_back(direct(uedge, true));
deba@1979
  1318
      edges.push_back(direct(uedge, false));
deba@1979
  1319
      getNotifier(Edge()).erase(edges);
deba@1979
  1320
      getNotifier(UEdge()).erase(uedge);
deba@1979
  1321
      Parent::erase(uedge);
deba@1979
  1322
    }
deba@1979
  1323
deba@1979
  1324
deba@1999
  1325
    BpUGraphExtender() {
deba@1999
  1326
      anode_notifier.setContainer(*this); 
deba@1999
  1327
      bnode_notifier.setContainer(*this); 
deba@1999
  1328
      node_notifier.setContainer(*this); 
deba@1999
  1329
      edge_notifier.setContainer(*this); 
deba@1999
  1330
      uedge_notifier.setContainer(*this);
deba@1999
  1331
    } 
deba@1999
  1332
deba@1979
  1333
    ~BpUGraphExtender() {
deba@1999
  1334
      uedge_notifier.clear();
deba@1999
  1335
      edge_notifier.clear(); 
deba@1999
  1336
      node_notifier.clear(); 
deba@1999
  1337
      anode_notifier.clear(); 
deba@1999
  1338
      bnode_notifier.clear(); 
deba@1979
  1339
    }
deba@1979
  1340
deba@1979
  1341
deba@1820
  1342
  };
deba@1820
  1343
deba@1791
  1344
}
deba@1791
  1345
deba@1996
  1346
#endif