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