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