lemon/bits/edge_set_extender.h
author deba
Tue, 30 Oct 2007 10:51:07 +0000
changeset 2504 46a82ce84cc6
parent 2391 14a343be7a5a
child 2553 bfced05fa852
permissions -rw-r--r--
Bug fix
deba@1979
     1
/* -*- C++ -*-
deba@1979
     2
 *
deba@1979
     3
 * This file is a part of LEMON, a generic C++ optimization library
deba@1979
     4
 *
alpar@2391
     5
 * Copyright (C) 2003-2007
deba@1979
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
deba@1979
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
deba@1979
     8
 *
deba@1979
     9
 * Permission to use, modify and distribute this software is granted
deba@1979
    10
 * provided that this copyright notice appears in all copies. For
deba@1979
    11
 * precise terms see the accompanying LICENSE file.
deba@1979
    12
 *
deba@1979
    13
 * This software is provided "AS IS" with no warranty of any kind,
deba@1979
    14
 * express or implied, and with no claim as to its suitability for any
deba@1979
    15
 * purpose.
deba@1979
    16
 *
deba@1979
    17
 */
deba@1979
    18
deba@1996
    19
#ifndef LEMON_BITS_EDGE_SET_EXTENDER_H
deba@1996
    20
#define LEMON_BITS_EDGE_SET_EXTENDER_H
deba@1979
    21
deba@1996
    22
#include <lemon/bits/invalid.h>
deba@1996
    23
#include <lemon/error.h>
deba@1996
    24
deba@1996
    25
#include <lemon/bits/default_map.h>
deba@1996
    26
deba@1996
    27
///\ingroup graphbits
deba@1996
    28
///\file
deba@1996
    29
///\brief Extenders for the edge set types
deba@1979
    30
namespace lemon {
deba@1979
    31
deba@1996
    32
  /// \ingroup graphbits
deba@1996
    33
  ///
deba@1996
    34
  /// \brief Extender for the EdgeSets
deba@1979
    35
  template <typename Base>
deba@1979
    36
  class EdgeSetExtender : public Base {
deba@1979
    37
  public:
deba@1979
    38
deba@1979
    39
    typedef Base Parent;
deba@1979
    40
    typedef EdgeSetExtender Graph;
deba@1979
    41
deba@1979
    42
    // Base extensions
deba@1979
    43
deba@1979
    44
    typedef typename Parent::Node Node;
deba@1979
    45
    typedef typename Parent::Edge Edge;
deba@1979
    46
deba@1979
    47
    int maxId(Node) const {
deba@1979
    48
      return Parent::maxNodeId();
deba@1979
    49
    }
deba@1979
    50
deba@1979
    51
    int maxId(Edge) const {
deba@1979
    52
      return Parent::maxEdgeId();
deba@1979
    53
    }
deba@1979
    54
deba@1979
    55
    Node fromId(int id, Node) const {
deba@1979
    56
      return Parent::nodeFromId(id);
deba@1979
    57
    }
deba@1979
    58
deba@1979
    59
    Edge fromId(int id, Edge) const {
deba@1979
    60
      return Parent::edgeFromId(id);
deba@1979
    61
    }
deba@1979
    62
deba@1979
    63
    Node oppositeNode(const Node &n, const Edge &e) const {
deba@1979
    64
      if (n == Parent::source(e))
deba@1979
    65
	return Parent::target(e);
deba@1979
    66
      else if(n==Parent::target(e))
deba@1979
    67
	return Parent::source(e);
deba@1979
    68
      else
deba@1979
    69
	return INVALID;
deba@1979
    70
    }
deba@1979
    71
deba@1979
    72
deba@1979
    73
    // Alteration notifier extensions
deba@1979
    74
deba@1979
    75
    /// The edge observer registry.
deba@1999
    76
    typedef AlterationNotifier<EdgeSetExtender, Edge> EdgeNotifier;
deba@1979
    77
deba@1979
    78
  protected:
deba@1979
    79
deba@1979
    80
    mutable EdgeNotifier edge_notifier;
deba@1979
    81
deba@1979
    82
  public:
deba@1979
    83
deba@2384
    84
    using Parent::notifier;
deba@1991
    85
deba@1979
    86
    /// \brief Gives back the edge alteration notifier.
deba@1979
    87
    ///
deba@1979
    88
    /// Gives back the edge alteration notifier.
deba@2384
    89
    EdgeNotifier& notifier(Edge) const {
deba@1979
    90
      return edge_notifier;
deba@1979
    91
    }
deba@1979
    92
deba@1979
    93
    // Iterable extensions
deba@1979
    94
deba@1979
    95
    class NodeIt : public Node { 
deba@1979
    96
      const Graph* graph;
deba@1979
    97
    public:
deba@1979
    98
deba@1979
    99
      NodeIt() {}
deba@1979
   100
deba@1979
   101
      NodeIt(Invalid i) : Node(i) { }
deba@1979
   102
deba@1979
   103
      explicit NodeIt(const Graph& _graph) : graph(&_graph) {
deba@2031
   104
	_graph.first(static_cast<Node&>(*this));
deba@1979
   105
      }
deba@1979
   106
deba@1979
   107
      NodeIt(const Graph& _graph, const Node& node) 
deba@1979
   108
	: Node(node), graph(&_graph) {}
deba@1979
   109
deba@1979
   110
      NodeIt& operator++() { 
deba@1979
   111
	graph->next(*this);
deba@1979
   112
	return *this; 
deba@1979
   113
      }
deba@1979
   114
deba@1979
   115
    };
deba@1979
   116
deba@1979
   117
deba@1979
   118
    class EdgeIt : public Edge { 
deba@1979
   119
      const Graph* graph;
deba@1979
   120
    public:
deba@1979
   121
deba@1979
   122
      EdgeIt() { }
deba@1979
   123
deba@1979
   124
      EdgeIt(Invalid i) : Edge(i) { }
deba@1979
   125
deba@1979
   126
      explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
deba@2031
   127
	_graph.first(static_cast<Edge&>(*this));
deba@1979
   128
      }
deba@1979
   129
deba@1979
   130
      EdgeIt(const Graph& _graph, const Edge& e) : 
deba@1979
   131
	Edge(e), graph(&_graph) { }
deba@1979
   132
deba@1979
   133
      EdgeIt& operator++() { 
deba@1979
   134
	graph->next(*this);
deba@1979
   135
	return *this; 
deba@1979
   136
      }
deba@1979
   137
deba@1979
   138
    };
deba@1979
   139
deba@1979
   140
deba@1979
   141
    class OutEdgeIt : public Edge { 
deba@1979
   142
      const Graph* graph;
deba@1979
   143
    public:
deba@1979
   144
deba@1979
   145
      OutEdgeIt() { }
deba@1979
   146
deba@1979
   147
      OutEdgeIt(Invalid i) : Edge(i) { }
deba@1979
   148
deba@1979
   149
      OutEdgeIt(const Graph& _graph, const Node& node) 
deba@1979
   150
	: graph(&_graph) {
deba@1979
   151
	_graph.firstOut(*this, node);
deba@1979
   152
      }
deba@1979
   153
deba@1979
   154
      OutEdgeIt(const Graph& _graph, const Edge& edge) 
deba@1979
   155
	: Edge(edge), graph(&_graph) {}
deba@1979
   156
deba@1979
   157
      OutEdgeIt& operator++() { 
deba@1979
   158
	graph->nextOut(*this);
deba@1979
   159
	return *this; 
deba@1979
   160
      }
deba@1979
   161
deba@1979
   162
    };
deba@1979
   163
deba@1979
   164
deba@1979
   165
    class InEdgeIt : public Edge { 
deba@1979
   166
      const Graph* graph;
deba@1979
   167
    public:
deba@1979
   168
deba@1979
   169
      InEdgeIt() { }
deba@1979
   170
deba@1979
   171
      InEdgeIt(Invalid i) : Edge(i) { }
deba@1979
   172
deba@1979
   173
      InEdgeIt(const Graph& _graph, const Node& node) 
deba@1979
   174
	: graph(&_graph) {
deba@1979
   175
	_graph.firstIn(*this, node);
deba@1979
   176
      }
deba@1979
   177
deba@1979
   178
      InEdgeIt(const Graph& _graph, const Edge& edge) : 
deba@1979
   179
	Edge(edge), graph(&_graph) {}
deba@1979
   180
deba@1979
   181
      InEdgeIt& operator++() { 
deba@1979
   182
	graph->nextIn(*this);
deba@1979
   183
	return *this; 
deba@1979
   184
      }
deba@1979
   185
deba@1979
   186
    };
deba@1979
   187
deba@1979
   188
    /// \brief Base node of the iterator
deba@1979
   189
    ///
deba@1979
   190
    /// Returns the base node (ie. the source in this case) of the iterator
deba@1979
   191
    Node baseNode(const OutEdgeIt &e) const {
deba@2386
   192
      return Parent::source(static_cast<const Edge&>(e));
deba@1979
   193
    }
deba@1979
   194
    /// \brief Running node of the iterator
deba@1979
   195
    ///
deba@1979
   196
    /// Returns the running node (ie. the target in this case) of the
deba@1979
   197
    /// iterator
deba@1979
   198
    Node runningNode(const OutEdgeIt &e) const {
deba@2386
   199
      return Parent::target(static_cast<const Edge&>(e));
deba@1979
   200
    }
deba@1979
   201
deba@1979
   202
    /// \brief Base node of the iterator
deba@1979
   203
    ///
deba@1979
   204
    /// Returns the base node (ie. the target in this case) of the iterator
deba@1979
   205
    Node baseNode(const InEdgeIt &e) const {
deba@2386
   206
      return Parent::target(static_cast<const Edge&>(e));
deba@1979
   207
    }
deba@1979
   208
    /// \brief Running node of the iterator
deba@1979
   209
    ///
deba@1979
   210
    /// Returns the running node (ie. the source in this case) of the
deba@1979
   211
    /// iterator
deba@1979
   212
    Node runningNode(const InEdgeIt &e) const {
deba@2386
   213
      return Parent::source(static_cast<const Edge&>(e));
deba@1979
   214
    }
deba@1979
   215
deba@1979
   216
    using Parent::first;
deba@1979
   217
deba@1979
   218
    // Mappable extension
deba@1979
   219
    
deba@1979
   220
    template <typename _Value>
deba@1979
   221
    class EdgeMap 
deba@1999
   222
      : public MapExtender<DefaultMap<Graph, Edge, _Value> > {
deba@1979
   223
    public:
deba@1979
   224
      typedef EdgeSetExtender Graph;
deba@1999
   225
      typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
deba@1979
   226
klao@2046
   227
      explicit EdgeMap(const Graph& _g) 
deba@1979
   228
	: Parent(_g) {}
deba@1979
   229
      EdgeMap(const Graph& _g, const _Value& _v) 
deba@1979
   230
	: Parent(_g, _v) {}
deba@1979
   231
deba@1979
   232
      EdgeMap& operator=(const EdgeMap& cmap) {
deba@1979
   233
	return operator=<EdgeMap>(cmap);
deba@1979
   234
      }
deba@1979
   235
deba@1979
   236
      template <typename CMap>
deba@1979
   237
      EdgeMap& operator=(const CMap& cmap) {
deba@2031
   238
        Parent::operator=(cmap);
deba@1979
   239
	return *this;
deba@1979
   240
      }
deba@2031
   241
deba@1979
   242
    };
deba@1979
   243
deba@1979
   244
deba@1979
   245
    // Alteration extension
deba@1979
   246
deba@1979
   247
    Edge addEdge(const Node& from, const Node& to) {
deba@1979
   248
      Edge edge = Parent::addEdge(from, to);
deba@2384
   249
      notifier(Edge()).add(edge);
deba@1979
   250
      return edge;
deba@1979
   251
    }
deba@1979
   252
    
deba@1979
   253
    void clear() {
deba@2384
   254
      notifier(Edge()).clear();
deba@1979
   255
      Parent::clear();
deba@1979
   256
    }
deba@1979
   257
deba@1979
   258
    void erase(const Edge& edge) {
deba@2384
   259
      notifier(Edge()).erase(edge);
deba@1979
   260
      Parent::erase(edge);
deba@1979
   261
    }
deba@1979
   262
deba@1999
   263
    EdgeSetExtender() {
deba@1999
   264
      edge_notifier.setContainer(*this);
deba@1999
   265
    }
deba@1979
   266
deba@1979
   267
    ~EdgeSetExtender() {
deba@1979
   268
      edge_notifier.clear();
deba@1979
   269
    }
deba@1979
   270
deba@1979
   271
  };
deba@1979
   272
deba@1979
   273
deba@1996
   274
  /// \ingroup graphbits
deba@1996
   275
  ///
deba@1996
   276
  /// \brief Extender for the UEdgeSets
deba@1979
   277
  template <typename Base>
deba@1979
   278
  class UEdgeSetExtender : public Base {
deba@1979
   279
deba@1979
   280
  public:
deba@1979
   281
deba@1979
   282
    typedef Base Parent;
deba@1979
   283
    typedef UEdgeSetExtender Graph;
deba@1979
   284
deba@1979
   285
    typedef typename Parent::Node Node;
deba@1979
   286
    typedef typename Parent::Edge Edge;
deba@1979
   287
    typedef typename Parent::UEdge UEdge;
deba@1979
   288
deba@1979
   289
deba@1979
   290
    int maxId(Node) const {
deba@1979
   291
      return Parent::maxNodeId();
deba@1979
   292
    }
deba@1979
   293
deba@1979
   294
    int maxId(Edge) const {
deba@1979
   295
      return Parent::maxEdgeId();
deba@1979
   296
    }
deba@1979
   297
deba@1979
   298
    int maxId(UEdge) const {
deba@1979
   299
      return Parent::maxUEdgeId();
deba@1979
   300
    }
deba@1979
   301
deba@1979
   302
    Node fromId(int id, Node) const {
deba@1979
   303
      return Parent::nodeFromId(id);
deba@1979
   304
    }
deba@1979
   305
deba@1979
   306
    Edge fromId(int id, Edge) const {
deba@1979
   307
      return Parent::edgeFromId(id);
deba@1979
   308
    }
deba@1979
   309
deba@1979
   310
    UEdge fromId(int id, UEdge) const {
deba@1979
   311
      return Parent::uEdgeFromId(id);
deba@1979
   312
    }
deba@1979
   313
deba@1979
   314
    Node oppositeNode(const Node &n, const UEdge &e) const {
deba@1979
   315
      if( n == Parent::source(e))
deba@1979
   316
	return Parent::target(e);
deba@1979
   317
      else if( n == Parent::target(e))
deba@1979
   318
	return Parent::source(e);
deba@1979
   319
      else
deba@1979
   320
	return INVALID;
deba@1979
   321
    }
deba@1979
   322
deba@1979
   323
    Edge oppositeEdge(const Edge &e) const {
deba@1979
   324
      return Parent::direct(e, !Parent::direction(e));
deba@1979
   325
    }
deba@1979
   326
deba@1979
   327
    using Parent::direct;
deba@1979
   328
    Edge direct(const UEdge &ue, const Node &s) const {
deba@1979
   329
      return Parent::direct(ue, Parent::source(ue) == s);
deba@1979
   330
    }
deba@1979
   331
deba@1999
   332
    typedef AlterationNotifier<UEdgeSetExtender, Edge> EdgeNotifier;
deba@1999
   333
    typedef AlterationNotifier<UEdgeSetExtender, UEdge> UEdgeNotifier;
deba@1979
   334
deba@1979
   335
deba@1979
   336
  protected:
deba@1979
   337
deba@1979
   338
    mutable EdgeNotifier edge_notifier;
deba@1979
   339
    mutable UEdgeNotifier uedge_notifier;
deba@1979
   340
deba@1979
   341
  public:
deba@1991
   342
deba@2384
   343
    using Parent::notifier;
deba@1979
   344
    
deba@2384
   345
    EdgeNotifier& notifier(Edge) const {
deba@1979
   346
      return edge_notifier;
deba@1979
   347
    }
deba@1979
   348
deba@2384
   349
    UEdgeNotifier& notifier(UEdge) const {
deba@1979
   350
      return uedge_notifier;
deba@1979
   351
    }
deba@1979
   352
deba@1979
   353
deba@1979
   354
    class NodeIt : public Node { 
deba@1979
   355
      const Graph* graph;
deba@1979
   356
    public:
deba@1979
   357
deba@1979
   358
      NodeIt() {}
deba@1979
   359
deba@1979
   360
      NodeIt(Invalid i) : Node(i) { }
deba@1979
   361
deba@1979
   362
      explicit NodeIt(const Graph& _graph) : graph(&_graph) {
deba@2031
   363
	_graph.first(static_cast<Node&>(*this));
deba@1979
   364
      }
deba@1979
   365
deba@1979
   366
      NodeIt(const Graph& _graph, const Node& node) 
deba@1979
   367
	: Node(node), graph(&_graph) {}
deba@1979
   368
deba@1979
   369
      NodeIt& operator++() { 
deba@1979
   370
	graph->next(*this);
deba@1979
   371
	return *this; 
deba@1979
   372
      }
deba@1979
   373
deba@1979
   374
    };
deba@1979
   375
deba@1979
   376
deba@1979
   377
    class EdgeIt : public Edge { 
deba@1979
   378
      const Graph* graph;
deba@1979
   379
    public:
deba@1979
   380
deba@1979
   381
      EdgeIt() { }
deba@1979
   382
deba@1979
   383
      EdgeIt(Invalid i) : Edge(i) { }
deba@1979
   384
deba@1979
   385
      explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
deba@2031
   386
	_graph.first(static_cast<Edge&>(*this));
deba@1979
   387
      }
deba@1979
   388
deba@1979
   389
      EdgeIt(const Graph& _graph, const Edge& e) : 
deba@1979
   390
	Edge(e), graph(&_graph) { }
deba@1979
   391
deba@1979
   392
      EdgeIt& operator++() { 
deba@1979
   393
	graph->next(*this);
deba@1979
   394
	return *this; 
deba@1979
   395
      }
deba@1979
   396
deba@1979
   397
    };
deba@1979
   398
deba@1979
   399
deba@1979
   400
    class OutEdgeIt : public Edge { 
deba@1979
   401
      const Graph* graph;
deba@1979
   402
    public:
deba@1979
   403
deba@1979
   404
      OutEdgeIt() { }
deba@1979
   405
deba@1979
   406
      OutEdgeIt(Invalid i) : Edge(i) { }
deba@1979
   407
deba@1979
   408
      OutEdgeIt(const Graph& _graph, const Node& node) 
deba@1979
   409
	: graph(&_graph) {
deba@1979
   410
	_graph.firstOut(*this, node);
deba@1979
   411
      }
deba@1979
   412
deba@1979
   413
      OutEdgeIt(const Graph& _graph, const Edge& edge) 
deba@1979
   414
	: Edge(edge), graph(&_graph) {}
deba@1979
   415
deba@1979
   416
      OutEdgeIt& operator++() { 
deba@1979
   417
	graph->nextOut(*this);
deba@1979
   418
	return *this; 
deba@1979
   419
      }
deba@1979
   420
deba@1979
   421
    };
deba@1979
   422
deba@1979
   423
deba@1979
   424
    class InEdgeIt : public Edge { 
deba@1979
   425
      const Graph* graph;
deba@1979
   426
    public:
deba@1979
   427
deba@1979
   428
      InEdgeIt() { }
deba@1979
   429
deba@1979
   430
      InEdgeIt(Invalid i) : Edge(i) { }
deba@1979
   431
deba@1979
   432
      InEdgeIt(const Graph& _graph, const Node& node) 
deba@1979
   433
	: graph(&_graph) {
deba@1979
   434
	_graph.firstIn(*this, node);
deba@1979
   435
      }
deba@1979
   436
deba@1979
   437
      InEdgeIt(const Graph& _graph, const Edge& edge) : 
deba@1979
   438
	Edge(edge), graph(&_graph) {}
deba@1979
   439
deba@1979
   440
      InEdgeIt& operator++() { 
deba@1979
   441
	graph->nextIn(*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 UEdgeIt : public Parent::UEdge { 
deba@1979
   449
      const Graph* graph;
deba@1979
   450
    public:
deba@1979
   451
deba@1979
   452
      UEdgeIt() { }
deba@1979
   453
deba@1979
   454
      UEdgeIt(Invalid i) : UEdge(i) { }
deba@1979
   455
deba@1979
   456
      explicit UEdgeIt(const Graph& _graph) : graph(&_graph) {
deba@2031
   457
	_graph.first(static_cast<UEdge&>(*this));
deba@1979
   458
      }
deba@1979
   459
deba@1979
   460
      UEdgeIt(const Graph& _graph, const UEdge& e) : 
deba@1979
   461
	UEdge(e), graph(&_graph) { }
deba@1979
   462
deba@1979
   463
      UEdgeIt& 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
    class IncEdgeIt : public Parent::UEdge {
deba@1979
   471
      friend class UEdgeSetExtender;
deba@1979
   472
      const Graph* graph;
deba@1979
   473
      bool direction;
deba@1979
   474
    public:
deba@1979
   475
deba@1979
   476
      IncEdgeIt() { }
deba@1979
   477
deba@1979
   478
      IncEdgeIt(Invalid i) : UEdge(i), direction(false) { }
deba@1979
   479
deba@1979
   480
      IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
deba@1979
   481
	_graph.firstInc(*this, direction, n);
deba@1979
   482
      }
deba@1979
   483
deba@1979
   484
      IncEdgeIt(const Graph& _graph, const UEdge &ue, const Node &n)
deba@1979
   485
	: graph(&_graph), UEdge(ue) {
deba@1979
   486
	direction = (_graph.source(ue) == n);
deba@1979
   487
      }
deba@1979
   488
deba@1979
   489
      IncEdgeIt& operator++() {
deba@1979
   490
	graph->nextInc(*this, direction);
deba@1979
   491
	return *this; 
deba@1979
   492
      }
deba@1979
   493
    };
deba@1979
   494
deba@1979
   495
    /// \brief Base node of the iterator
deba@1979
   496
    ///
deba@1979
   497
    /// Returns the base node (ie. the source in this case) of the iterator
deba@1979
   498
    Node baseNode(const OutEdgeIt &e) const {
deba@2386
   499
      return Parent::source(static_cast<const Edge&>(e));
deba@1979
   500
    }
deba@1979
   501
    /// \brief Running node of the iterator
deba@1979
   502
    ///
deba@1979
   503
    /// Returns the running node (ie. the target in this case) of the
deba@1979
   504
    /// iterator
deba@1979
   505
    Node runningNode(const OutEdgeIt &e) const {
deba@2386
   506
      return Parent::target(static_cast<const Edge&>(e));
deba@1979
   507
    }
deba@1979
   508
deba@1979
   509
    /// \brief Base node of the iterator
deba@1979
   510
    ///
deba@1979
   511
    /// Returns the base node (ie. the target in this case) of the iterator
deba@1979
   512
    Node baseNode(const InEdgeIt &e) const {
deba@2386
   513
      return Parent::target(static_cast<const Edge&>(e));
deba@1979
   514
    }
deba@1979
   515
    /// \brief Running node of the iterator
deba@1979
   516
    ///
deba@1979
   517
    /// Returns the running node (ie. the source in this case) of the
deba@1979
   518
    /// iterator
deba@1979
   519
    Node runningNode(const InEdgeIt &e) const {
deba@2386
   520
      return Parent::source(static_cast<const Edge&>(e));
deba@1979
   521
    }
deba@1979
   522
deba@1979
   523
    /// Base node of the iterator
deba@1979
   524
    ///
deba@1979
   525
    /// Returns the base node of the iterator
deba@1979
   526
    Node baseNode(const IncEdgeIt &e) const {
deba@1979
   527
      return e.direction ? source(e) : target(e);
deba@1979
   528
    }
deba@1979
   529
    /// Running node of the iterator
deba@1979
   530
    ///
deba@1979
   531
    /// Returns the running node of the iterator
deba@1979
   532
    Node runningNode(const IncEdgeIt &e) const {
deba@1979
   533
      return e.direction ? target(e) : source(e);
deba@1979
   534
    }
deba@1979
   535
deba@1979
   536
deba@1979
   537
    template <typename _Value>
deba@1979
   538
    class EdgeMap 
deba@1999
   539
      : public MapExtender<DefaultMap<Graph, Edge, _Value> > {
deba@1979
   540
    public:
deba@1979
   541
      typedef UEdgeSetExtender Graph;
deba@1999
   542
      typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
deba@1979
   543
deba@1979
   544
      EdgeMap(const Graph& _g) 
deba@1979
   545
	: Parent(_g) {}
deba@1979
   546
      EdgeMap(const Graph& _g, const _Value& _v) 
deba@1979
   547
	: Parent(_g, _v) {}
deba@1979
   548
deba@1979
   549
      EdgeMap& operator=(const EdgeMap& cmap) {
deba@1979
   550
	return operator=<EdgeMap>(cmap);
deba@1979
   551
      }
deba@1979
   552
deba@1979
   553
      template <typename CMap>
deba@1979
   554
      EdgeMap& operator=(const CMap& cmap) {
deba@2031
   555
        Parent::operator=(cmap);
deba@1979
   556
	return *this;
deba@1979
   557
      }
deba@2031
   558
deba@1979
   559
    };
deba@1979
   560
deba@1979
   561
deba@1979
   562
    template <typename _Value>
deba@1979
   563
    class UEdgeMap 
deba@1999
   564
      : public MapExtender<DefaultMap<Graph, UEdge, _Value> > {
deba@1979
   565
    public:
deba@1979
   566
      typedef UEdgeSetExtender Graph;
deba@1999
   567
      typedef MapExtender<DefaultMap<Graph, UEdge, _Value> > Parent;
deba@1979
   568
deba@1979
   569
      UEdgeMap(const Graph& _g) 
deba@1979
   570
	: Parent(_g) {}
deba@2031
   571
deba@1979
   572
      UEdgeMap(const Graph& _g, const _Value& _v) 
deba@1979
   573
	: Parent(_g, _v) {}
deba@1979
   574
deba@1979
   575
      UEdgeMap& operator=(const UEdgeMap& cmap) {
deba@1979
   576
	return operator=<UEdgeMap>(cmap);
deba@1979
   577
      }
deba@1979
   578
deba@1979
   579
      template <typename CMap>
deba@1979
   580
      UEdgeMap& operator=(const CMap& cmap) {
deba@2031
   581
        Parent::operator=(cmap);
deba@1979
   582
	return *this;
deba@1979
   583
      }
deba@2031
   584
deba@1979
   585
    };
deba@1979
   586
deba@1979
   587
deba@1979
   588
    // Alteration extension
deba@1979
   589
deba@1979
   590
    UEdge addEdge(const Node& from, const Node& to) {
deba@1979
   591
      UEdge uedge = Parent::addEdge(from, to);
deba@2384
   592
      notifier(UEdge()).add(uedge);
deba@2498
   593
      std::vector<Edge> edges;
deba@2498
   594
      edges.push_back(Parent::direct(uedge, true));
deba@2498
   595
      edges.push_back(Parent::direct(uedge, false));
deba@2498
   596
      notifier(Edge()).add(edges);
deba@1979
   597
      return uedge;
deba@1979
   598
    }
deba@1979
   599
    
deba@1979
   600
    void clear() {
deba@2384
   601
      notifier(Edge()).clear();
deba@2384
   602
      notifier(UEdge()).clear();
deba@1979
   603
      Parent::clear();
deba@1979
   604
    }
deba@1979
   605
deba@1979
   606
    void erase(const UEdge& uedge) {
deba@2498
   607
      std::vector<Edge> edges;
deba@2498
   608
      edges.push_back(Parent::direct(uedge, true));
deba@2498
   609
      edges.push_back(Parent::direct(uedge, false));
deba@2498
   610
      notifier(Edge()).erase(edges);
deba@2384
   611
      notifier(UEdge()).erase(uedge);
deba@1979
   612
      Parent::erase(uedge);
deba@1979
   613
    }
deba@1979
   614
deba@1979
   615
deba@1999
   616
    UEdgeSetExtender() {
deba@1999
   617
      edge_notifier.setContainer(*this);
deba@1999
   618
      uedge_notifier.setContainer(*this);
deba@1999
   619
    }
deba@1999
   620
deba@1979
   621
    ~UEdgeSetExtender() {
deba@1999
   622
      uedge_notifier.clear();
deba@1999
   623
      edge_notifier.clear();
deba@1979
   624
    }
deba@1979
   625
    
deba@1979
   626
  };
deba@1996
   627
deba@1979
   628
}
deba@1996
   629
deba@1996
   630
#endif