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