lemon/bits/graph_extender.h
changeset 57 c1acf0018c0a
child 77 2de55e4f57a7
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/lemon/bits/graph_extender.h	Sun Jan 20 20:43:48 2008 +0100
     1.3 @@ -0,0 +1,747 @@
     1.4 +/* -*- C++ -*-
     1.5 + *
     1.6 + * This file is a part of LEMON, a generic C++ optimization library
     1.7 + *
     1.8 + * Copyright (C) 2003-2007
     1.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    1.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
    1.11 + *
    1.12 + * Permission to use, modify and distribute this software is granted
    1.13 + * provided that this copyright notice appears in all copies. For
    1.14 + * precise terms see the accompanying LICENSE file.
    1.15 + *
    1.16 + * This software is provided "AS IS" with no warranty of any kind,
    1.17 + * express or implied, and with no claim as to its suitability for any
    1.18 + * purpose.
    1.19 + *
    1.20 + */
    1.21 +
    1.22 +#ifndef LEMON_BITS_GRAPH_EXTENDER_H
    1.23 +#define LEMON_BITS_GRAPH_EXTENDER_H
    1.24 +
    1.25 +#include <lemon/bits/invalid.h>
    1.26 +
    1.27 +#include <lemon/bits/map_extender.h>
    1.28 +#include <lemon/bits/default_map.h>
    1.29 +
    1.30 +#include <lemon/concept_check.h>
    1.31 +#include <lemon/concepts/maps.h>
    1.32 +
    1.33 +///\ingroup graphbits
    1.34 +///\file
    1.35 +///\brief Extenders for the digraph types
    1.36 +namespace lemon {
    1.37 +
    1.38 +  /// \ingroup graphbits
    1.39 +  ///
    1.40 +  /// \brief Extender for the Digraphs
    1.41 +  template <typename Base>
    1.42 +  class DigraphExtender : public Base {
    1.43 +  public:
    1.44 +
    1.45 +    typedef Base Parent;
    1.46 +    typedef DigraphExtender Digraph;
    1.47 +
    1.48 +    // Base extensions
    1.49 +
    1.50 +    typedef typename Parent::Node Node;
    1.51 +    typedef typename Parent::Arc Arc;
    1.52 +
    1.53 +    int maxId(Node) const {
    1.54 +      return Parent::maxNodeId();
    1.55 +    }
    1.56 +
    1.57 +    int maxId(Arc) const {
    1.58 +      return Parent::maxArcId();
    1.59 +    }
    1.60 +
    1.61 +    Node fromId(int id, Node) const {
    1.62 +      return Parent::nodeFromId(id);
    1.63 +    }
    1.64 +
    1.65 +    Arc fromId(int id, Arc) const {
    1.66 +      return Parent::arcFromId(id);
    1.67 +    }
    1.68 +
    1.69 +    Node oppositeNode(const Node &n, const Arc &e) const {
    1.70 +      if (n == Parent::source(e))
    1.71 +	return Parent::target(e);
    1.72 +      else if(n==Parent::target(e))
    1.73 +	return Parent::source(e);
    1.74 +      else
    1.75 +	return INVALID;
    1.76 +    }
    1.77 +
    1.78 +    // Alterable extension
    1.79 +
    1.80 +    typedef AlterationNotifier<DigraphExtender, Node> NodeNotifier;
    1.81 +    typedef AlterationNotifier<DigraphExtender, Arc> ArcNotifier;
    1.82 +
    1.83 +
    1.84 +  protected:
    1.85 +
    1.86 +    mutable NodeNotifier node_notifier;
    1.87 +    mutable ArcNotifier arc_notifier;
    1.88 +
    1.89 +  public:
    1.90 +
    1.91 +    NodeNotifier& notifier(Node) const {
    1.92 +      return node_notifier;
    1.93 +    }
    1.94 +    
    1.95 +    ArcNotifier& notifier(Arc) const {
    1.96 +      return arc_notifier;
    1.97 +    }
    1.98 +
    1.99 +    class NodeIt : public Node { 
   1.100 +      const Digraph* digraph;
   1.101 +    public:
   1.102 +
   1.103 +      NodeIt() {}
   1.104 +
   1.105 +      NodeIt(Invalid i) : Node(i) { }
   1.106 +
   1.107 +      explicit NodeIt(const Digraph& _digraph) : digraph(&_digraph) {
   1.108 +	_digraph.first(static_cast<Node&>(*this));
   1.109 +      }
   1.110 +
   1.111 +      NodeIt(const Digraph& _digraph, const Node& node) 
   1.112 +	: Node(node), digraph(&_digraph) {}
   1.113 +
   1.114 +      NodeIt& operator++() { 
   1.115 +	digraph->next(*this);
   1.116 +	return *this; 
   1.117 +      }
   1.118 +
   1.119 +    };
   1.120 +
   1.121 +
   1.122 +    class ArcIt : public Arc { 
   1.123 +      const Digraph* digraph;
   1.124 +    public:
   1.125 +
   1.126 +      ArcIt() { }
   1.127 +
   1.128 +      ArcIt(Invalid i) : Arc(i) { }
   1.129 +
   1.130 +      explicit ArcIt(const Digraph& _digraph) : digraph(&_digraph) {
   1.131 +	_digraph.first(static_cast<Arc&>(*this));
   1.132 +      }
   1.133 +
   1.134 +      ArcIt(const Digraph& _digraph, const Arc& e) : 
   1.135 +	Arc(e), digraph(&_digraph) { }
   1.136 +
   1.137 +      ArcIt& operator++() { 
   1.138 +	digraph->next(*this);
   1.139 +	return *this; 
   1.140 +      }
   1.141 +
   1.142 +    };
   1.143 +
   1.144 +
   1.145 +    class OutArcIt : public Arc { 
   1.146 +      const Digraph* digraph;
   1.147 +    public:
   1.148 +
   1.149 +      OutArcIt() { }
   1.150 +
   1.151 +      OutArcIt(Invalid i) : Arc(i) { }
   1.152 +
   1.153 +      OutArcIt(const Digraph& _digraph, const Node& node) 
   1.154 +	: digraph(&_digraph) {
   1.155 +	_digraph.firstOut(*this, node);
   1.156 +      }
   1.157 +
   1.158 +      OutArcIt(const Digraph& _digraph, const Arc& arc) 
   1.159 +	: Arc(arc), digraph(&_digraph) {}
   1.160 +
   1.161 +      OutArcIt& operator++() { 
   1.162 +	digraph->nextOut(*this);
   1.163 +	return *this; 
   1.164 +      }
   1.165 +
   1.166 +    };
   1.167 +
   1.168 +
   1.169 +    class InArcIt : public Arc { 
   1.170 +      const Digraph* digraph;
   1.171 +    public:
   1.172 +
   1.173 +      InArcIt() { }
   1.174 +
   1.175 +      InArcIt(Invalid i) : Arc(i) { }
   1.176 +
   1.177 +      InArcIt(const Digraph& _digraph, const Node& node) 
   1.178 +	: digraph(&_digraph) {
   1.179 +	_digraph.firstIn(*this, node);
   1.180 +      }
   1.181 +
   1.182 +      InArcIt(const Digraph& _digraph, const Arc& arc) : 
   1.183 +	Arc(arc), digraph(&_digraph) {}
   1.184 +
   1.185 +      InArcIt& operator++() { 
   1.186 +	digraph->nextIn(*this);
   1.187 +	return *this; 
   1.188 +      }
   1.189 +
   1.190 +    };
   1.191 +
   1.192 +    /// \brief Base node of the iterator
   1.193 +    ///
   1.194 +    /// Returns the base node (i.e. the source in this case) of the iterator
   1.195 +    Node baseNode(const OutArcIt &e) const {
   1.196 +      return Parent::source(e);
   1.197 +    }
   1.198 +    /// \brief Running node of the iterator
   1.199 +    ///
   1.200 +    /// Returns the running node (i.e. the target in this case) of the
   1.201 +    /// iterator
   1.202 +    Node runningNode(const OutArcIt &e) const {
   1.203 +      return Parent::target(e);
   1.204 +    }
   1.205 +
   1.206 +    /// \brief Base node of the iterator
   1.207 +    ///
   1.208 +    /// Returns the base node (i.e. the target in this case) of the iterator
   1.209 +    Node baseNode(const InArcIt &e) const {
   1.210 +      return Parent::target(e);
   1.211 +    }
   1.212 +    /// \brief Running node of the iterator
   1.213 +    ///
   1.214 +    /// Returns the running node (i.e. the source in this case) of the
   1.215 +    /// iterator
   1.216 +    Node runningNode(const InArcIt &e) const {
   1.217 +      return Parent::source(e);
   1.218 +    }
   1.219 +
   1.220 +    
   1.221 +    template <typename _Value>
   1.222 +    class NodeMap 
   1.223 +      : public MapExtender<DefaultMap<Digraph, Node, _Value> > {
   1.224 +    public:
   1.225 +      typedef DigraphExtender Digraph;
   1.226 +      typedef MapExtender<DefaultMap<Digraph, Node, _Value> > Parent;
   1.227 +
   1.228 +      explicit NodeMap(const Digraph& digraph) 
   1.229 +	: Parent(digraph) {}
   1.230 +      NodeMap(const Digraph& digraph, const _Value& value) 
   1.231 +	: Parent(digraph, value) {}
   1.232 +
   1.233 +      NodeMap& operator=(const NodeMap& cmap) {
   1.234 +	return operator=<NodeMap>(cmap);
   1.235 +      }
   1.236 +
   1.237 +      template <typename CMap>
   1.238 +      NodeMap& operator=(const CMap& cmap) {
   1.239 +        Parent::operator=(cmap);
   1.240 +	return *this;
   1.241 +      }
   1.242 +
   1.243 +    };
   1.244 +
   1.245 +    template <typename _Value>
   1.246 +    class ArcMap 
   1.247 +      : public MapExtender<DefaultMap<Digraph, Arc, _Value> > {
   1.248 +    public:
   1.249 +      typedef DigraphExtender Digraph;
   1.250 +      typedef MapExtender<DefaultMap<Digraph, Arc, _Value> > Parent;
   1.251 +
   1.252 +      explicit ArcMap(const Digraph& digraph) 
   1.253 +	: Parent(digraph) {}
   1.254 +      ArcMap(const Digraph& digraph, const _Value& value) 
   1.255 +	: Parent(digraph, value) {}
   1.256 +
   1.257 +      ArcMap& operator=(const ArcMap& cmap) {
   1.258 +	return operator=<ArcMap>(cmap);
   1.259 +      }
   1.260 +
   1.261 +      template <typename CMap>
   1.262 +      ArcMap& operator=(const CMap& cmap) {
   1.263 +        Parent::operator=(cmap);
   1.264 +	return *this;
   1.265 +      }
   1.266 +    };
   1.267 +
   1.268 +
   1.269 +    Node addNode() {
   1.270 +      Node node = Parent::addNode();
   1.271 +      notifier(Node()).add(node);
   1.272 +      return node;
   1.273 +    }
   1.274 +    
   1.275 +    Arc addArc(const Node& from, const Node& to) {
   1.276 +      Arc arc = Parent::addArc(from, to);
   1.277 +      notifier(Arc()).add(arc);
   1.278 +      return arc;
   1.279 +    }
   1.280 +
   1.281 +    void clear() {
   1.282 +      notifier(Arc()).clear();
   1.283 +      notifier(Node()).clear();
   1.284 +      Parent::clear();
   1.285 +    }
   1.286 +
   1.287 +    template <typename Digraph, typename NodeRefMap, typename ArcRefMap>
   1.288 +    void build(const Digraph& digraph, NodeRefMap& nodeRef, ArcRefMap& arcRef) {
   1.289 +      Parent::build(digraph, nodeRef, arcRef);
   1.290 +      notifier(Node()).build();
   1.291 +      notifier(Arc()).build();
   1.292 +    }
   1.293 +
   1.294 +    void erase(const Node& node) {
   1.295 +      Arc arc;
   1.296 +      Parent::firstOut(arc, node);
   1.297 +      while (arc != INVALID ) {
   1.298 +	erase(arc);
   1.299 +	Parent::firstOut(arc, node);
   1.300 +      } 
   1.301 +
   1.302 +      Parent::firstIn(arc, node);
   1.303 +      while (arc != INVALID ) {
   1.304 +	erase(arc);
   1.305 +	Parent::firstIn(arc, node);
   1.306 +      }
   1.307 +
   1.308 +      notifier(Node()).erase(node);
   1.309 +      Parent::erase(node);
   1.310 +    }
   1.311 +    
   1.312 +    void erase(const Arc& arc) {
   1.313 +      notifier(Arc()).erase(arc);
   1.314 +      Parent::erase(arc);
   1.315 +    }
   1.316 +
   1.317 +    DigraphExtender() {
   1.318 +      node_notifier.setContainer(*this);
   1.319 +      arc_notifier.setContainer(*this);
   1.320 +    } 
   1.321 +    
   1.322 +
   1.323 +    ~DigraphExtender() {
   1.324 +      arc_notifier.clear();
   1.325 +      node_notifier.clear();
   1.326 +    }
   1.327 +  };
   1.328 +
   1.329 +  /// \ingroup graphbits
   1.330 +  ///
   1.331 +  /// \brief Extender for the Graphs
   1.332 +  template <typename Base> 
   1.333 +  class GraphExtender : public Base {
   1.334 +  public:
   1.335 +    
   1.336 +    typedef Base Parent;
   1.337 +    typedef GraphExtender Digraph;
   1.338 +
   1.339 +    typedef typename Parent::Node Node;
   1.340 +    typedef typename Parent::Arc Arc;
   1.341 +    typedef typename Parent::Edge Edge;
   1.342 +
   1.343 +    // Graph extension    
   1.344 +
   1.345 +    int maxId(Node) const {
   1.346 +      return Parent::maxNodeId();
   1.347 +    }
   1.348 +
   1.349 +    int maxId(Arc) const {
   1.350 +      return Parent::maxArcId();
   1.351 +    }
   1.352 +
   1.353 +    int maxId(Edge) const {
   1.354 +      return Parent::maxEdgeId();
   1.355 +    }
   1.356 +
   1.357 +    Node fromId(int id, Node) const {
   1.358 +      return Parent::nodeFromId(id);
   1.359 +    }
   1.360 +
   1.361 +    Arc fromId(int id, Arc) const {
   1.362 +      return Parent::arcFromId(id);
   1.363 +    }
   1.364 +
   1.365 +    Edge fromId(int id, Edge) const {
   1.366 +      return Parent::edgeFromId(id);
   1.367 +    }
   1.368 +
   1.369 +    Node oppositeNode(const Node &n, const Edge &e) const {
   1.370 +      if( n == Parent::source(e))
   1.371 +	return Parent::target(e);
   1.372 +      else if( n == Parent::target(e))
   1.373 +	return Parent::source(e);
   1.374 +      else
   1.375 +	return INVALID;
   1.376 +    }
   1.377 +
   1.378 +    Arc oppositeArc(const Arc &e) const {
   1.379 +      return Parent::direct(e, !Parent::direction(e));
   1.380 +    }
   1.381 +
   1.382 +    using Parent::direct;
   1.383 +    Arc direct(const Edge &ue, const Node &s) const {
   1.384 +      return Parent::direct(ue, Parent::source(ue) == s);
   1.385 +    }
   1.386 +
   1.387 +    // Alterable extension
   1.388 +
   1.389 +    typedef AlterationNotifier<GraphExtender, Node> NodeNotifier;
   1.390 +    typedef AlterationNotifier<GraphExtender, Arc> ArcNotifier;
   1.391 +    typedef AlterationNotifier<GraphExtender, Edge> EdgeNotifier;
   1.392 +
   1.393 +
   1.394 +  protected:
   1.395 +
   1.396 +    mutable NodeNotifier node_notifier;
   1.397 +    mutable ArcNotifier arc_notifier;
   1.398 +    mutable EdgeNotifier edge_notifier;
   1.399 +
   1.400 +  public:
   1.401 +
   1.402 +    NodeNotifier& notifier(Node) const {
   1.403 +      return node_notifier;
   1.404 +    }
   1.405 +    
   1.406 +    ArcNotifier& notifier(Arc) const {
   1.407 +      return arc_notifier;
   1.408 +    }
   1.409 +
   1.410 +    EdgeNotifier& notifier(Edge) const {
   1.411 +      return edge_notifier;
   1.412 +    }
   1.413 +
   1.414 +
   1.415 +
   1.416 +    class NodeIt : public Node { 
   1.417 +      const Digraph* digraph;
   1.418 +    public:
   1.419 +
   1.420 +      NodeIt() {}
   1.421 +
   1.422 +      NodeIt(Invalid i) : Node(i) { }
   1.423 +
   1.424 +      explicit NodeIt(const Digraph& _digraph) : digraph(&_digraph) {
   1.425 +	_digraph.first(static_cast<Node&>(*this));
   1.426 +      }
   1.427 +
   1.428 +      NodeIt(const Digraph& _digraph, const Node& node) 
   1.429 +	: Node(node), digraph(&_digraph) {}
   1.430 +
   1.431 +      NodeIt& operator++() { 
   1.432 +	digraph->next(*this);
   1.433 +	return *this; 
   1.434 +      }
   1.435 +
   1.436 +    };
   1.437 +
   1.438 +
   1.439 +    class ArcIt : public Arc { 
   1.440 +      const Digraph* digraph;
   1.441 +    public:
   1.442 +
   1.443 +      ArcIt() { }
   1.444 +
   1.445 +      ArcIt(Invalid i) : Arc(i) { }
   1.446 +
   1.447 +      explicit ArcIt(const Digraph& _digraph) : digraph(&_digraph) {
   1.448 +	_digraph.first(static_cast<Arc&>(*this));
   1.449 +      }
   1.450 +
   1.451 +      ArcIt(const Digraph& _digraph, const Arc& e) : 
   1.452 +	Arc(e), digraph(&_digraph) { }
   1.453 +
   1.454 +      ArcIt& operator++() { 
   1.455 +	digraph->next(*this);
   1.456 +	return *this; 
   1.457 +      }
   1.458 +
   1.459 +    };
   1.460 +
   1.461 +
   1.462 +    class OutArcIt : public Arc { 
   1.463 +      const Digraph* digraph;
   1.464 +    public:
   1.465 +
   1.466 +      OutArcIt() { }
   1.467 +
   1.468 +      OutArcIt(Invalid i) : Arc(i) { }
   1.469 +
   1.470 +      OutArcIt(const Digraph& _digraph, const Node& node) 
   1.471 +	: digraph(&_digraph) {
   1.472 +	_digraph.firstOut(*this, node);
   1.473 +      }
   1.474 +
   1.475 +      OutArcIt(const Digraph& _digraph, const Arc& arc) 
   1.476 +	: Arc(arc), digraph(&_digraph) {}
   1.477 +
   1.478 +      OutArcIt& operator++() { 
   1.479 +	digraph->nextOut(*this);
   1.480 +	return *this; 
   1.481 +      }
   1.482 +
   1.483 +    };
   1.484 +
   1.485 +
   1.486 +    class InArcIt : public Arc { 
   1.487 +      const Digraph* digraph;
   1.488 +    public:
   1.489 +
   1.490 +      InArcIt() { }
   1.491 +
   1.492 +      InArcIt(Invalid i) : Arc(i) { }
   1.493 +
   1.494 +      InArcIt(const Digraph& _digraph, const Node& node) 
   1.495 +	: digraph(&_digraph) {
   1.496 +	_digraph.firstIn(*this, node);
   1.497 +      }
   1.498 +
   1.499 +      InArcIt(const Digraph& _digraph, const Arc& arc) : 
   1.500 +	Arc(arc), digraph(&_digraph) {}
   1.501 +
   1.502 +      InArcIt& operator++() { 
   1.503 +	digraph->nextIn(*this);
   1.504 +	return *this; 
   1.505 +      }
   1.506 +
   1.507 +    };
   1.508 +
   1.509 +
   1.510 +    class EdgeIt : public Parent::Edge { 
   1.511 +      const Digraph* digraph;
   1.512 +    public:
   1.513 +
   1.514 +      EdgeIt() { }
   1.515 +
   1.516 +      EdgeIt(Invalid i) : Edge(i) { }
   1.517 +
   1.518 +      explicit EdgeIt(const Digraph& _digraph) : digraph(&_digraph) {
   1.519 +	_digraph.first(static_cast<Edge&>(*this));
   1.520 +      }
   1.521 +
   1.522 +      EdgeIt(const Digraph& _digraph, const Edge& e) : 
   1.523 +	Edge(e), digraph(&_digraph) { }
   1.524 +
   1.525 +      EdgeIt& operator++() { 
   1.526 +	digraph->next(*this);
   1.527 +	return *this; 
   1.528 +      }
   1.529 +
   1.530 +    };
   1.531 +
   1.532 +    class IncArcIt : public Parent::Edge {
   1.533 +      friend class GraphExtender;
   1.534 +      const Digraph* digraph;
   1.535 +      bool direction;
   1.536 +    public:
   1.537 +
   1.538 +      IncArcIt() { }
   1.539 +
   1.540 +      IncArcIt(Invalid i) : Edge(i), direction(false) { }
   1.541 +
   1.542 +      IncArcIt(const Digraph& _digraph, const Node &n) : digraph(&_digraph) {
   1.543 +	_digraph.firstInc(*this, direction, n);
   1.544 +      }
   1.545 +
   1.546 +      IncArcIt(const Digraph& _digraph, const Edge &ue, const Node &n)
   1.547 +	: digraph(&_digraph), Edge(ue) {
   1.548 +	direction = (_digraph.source(ue) == n);
   1.549 +      }
   1.550 +
   1.551 +      IncArcIt& operator++() {
   1.552 +	digraph->nextInc(*this, direction);
   1.553 +	return *this; 
   1.554 +      }
   1.555 +    };
   1.556 +
   1.557 +    /// \brief Base node of the iterator
   1.558 +    ///
   1.559 +    /// Returns the base node (ie. the source in this case) of the iterator
   1.560 +    Node baseNode(const OutArcIt &e) const {
   1.561 +      return Parent::source(static_cast<const Arc&>(e));
   1.562 +    }
   1.563 +    /// \brief Running node of the iterator
   1.564 +    ///
   1.565 +    /// Returns the running node (ie. the target in this case) of the
   1.566 +    /// iterator
   1.567 +    Node runningNode(const OutArcIt &e) const {
   1.568 +      return Parent::target(static_cast<const Arc&>(e));
   1.569 +    }
   1.570 +
   1.571 +    /// \brief Base node of the iterator
   1.572 +    ///
   1.573 +    /// Returns the base node (ie. the target in this case) of the iterator
   1.574 +    Node baseNode(const InArcIt &e) const {
   1.575 +      return Parent::target(static_cast<const Arc&>(e));
   1.576 +    }
   1.577 +    /// \brief Running node of the iterator
   1.578 +    ///
   1.579 +    /// Returns the running node (ie. the source in this case) of the
   1.580 +    /// iterator
   1.581 +    Node runningNode(const InArcIt &e) const {
   1.582 +      return Parent::source(static_cast<const Arc&>(e));
   1.583 +    }
   1.584 +
   1.585 +    /// Base node of the iterator
   1.586 +    ///
   1.587 +    /// Returns the base node of the iterator
   1.588 +    Node baseNode(const IncArcIt &e) const {
   1.589 +      return e.direction ? source(e) : target(e);
   1.590 +    }
   1.591 +    /// Running node of the iterator
   1.592 +    ///
   1.593 +    /// Returns the running node of the iterator
   1.594 +    Node runningNode(const IncArcIt &e) const {
   1.595 +      return e.direction ? target(e) : source(e);
   1.596 +    }
   1.597 +
   1.598 +    // Mappable extension
   1.599 +
   1.600 +    template <typename _Value>
   1.601 +    class NodeMap 
   1.602 +      : public MapExtender<DefaultMap<Digraph, Node, _Value> > {
   1.603 +    public:
   1.604 +      typedef GraphExtender Digraph;
   1.605 +      typedef MapExtender<DefaultMap<Digraph, Node, _Value> > Parent;
   1.606 +
   1.607 +      NodeMap(const Digraph& digraph) 
   1.608 +	: Parent(digraph) {}
   1.609 +      NodeMap(const Digraph& digraph, const _Value& value) 
   1.610 +	: Parent(digraph, value) {}
   1.611 +
   1.612 +      NodeMap& operator=(const NodeMap& cmap) {
   1.613 +	return operator=<NodeMap>(cmap);
   1.614 +      }
   1.615 +
   1.616 +      template <typename CMap>
   1.617 +      NodeMap& operator=(const CMap& cmap) {
   1.618 +        Parent::operator=(cmap);
   1.619 +	return *this;
   1.620 +      }
   1.621 +
   1.622 +    };
   1.623 +
   1.624 +    template <typename _Value>
   1.625 +    class ArcMap 
   1.626 +      : public MapExtender<DefaultMap<Digraph, Arc, _Value> > {
   1.627 +    public:
   1.628 +      typedef GraphExtender Digraph;
   1.629 +      typedef MapExtender<DefaultMap<Digraph, Arc, _Value> > Parent;
   1.630 +
   1.631 +      ArcMap(const Digraph& digraph) 
   1.632 +	: Parent(digraph) {}
   1.633 +      ArcMap(const Digraph& digraph, const _Value& value) 
   1.634 +	: Parent(digraph, value) {}
   1.635 +
   1.636 +      ArcMap& operator=(const ArcMap& cmap) {
   1.637 +	return operator=<ArcMap>(cmap);
   1.638 +      }
   1.639 +
   1.640 +      template <typename CMap>
   1.641 +      ArcMap& operator=(const CMap& cmap) {
   1.642 +        Parent::operator=(cmap);
   1.643 +	return *this;
   1.644 +      }
   1.645 +    };
   1.646 +
   1.647 +
   1.648 +    template <typename _Value>
   1.649 +    class EdgeMap 
   1.650 +      : public MapExtender<DefaultMap<Digraph, Edge, _Value> > {
   1.651 +    public:
   1.652 +      typedef GraphExtender Digraph;
   1.653 +      typedef MapExtender<DefaultMap<Digraph, Edge, _Value> > Parent;
   1.654 +
   1.655 +      EdgeMap(const Digraph& digraph) 
   1.656 +	: Parent(digraph) {}
   1.657 +
   1.658 +      EdgeMap(const Digraph& digraph, const _Value& value) 
   1.659 +	: Parent(digraph, value) {}
   1.660 +
   1.661 +      EdgeMap& operator=(const EdgeMap& cmap) {
   1.662 +	return operator=<EdgeMap>(cmap);
   1.663 +      }
   1.664 +
   1.665 +      template <typename CMap>
   1.666 +      EdgeMap& operator=(const CMap& cmap) {
   1.667 +        Parent::operator=(cmap);
   1.668 +	return *this;
   1.669 +      }
   1.670 +
   1.671 +    };
   1.672 +
   1.673 +    // Alteration extension
   1.674 +
   1.675 +    Node addNode() {
   1.676 +      Node node = Parent::addNode();
   1.677 +      notifier(Node()).add(node);
   1.678 +      return node;
   1.679 +    }
   1.680 +
   1.681 +    Edge addEdge(const Node& from, const Node& to) {
   1.682 +      Edge edge = Parent::addEdge(from, to);
   1.683 +      notifier(Edge()).add(edge);
   1.684 +      std::vector<Arc> ev;
   1.685 +      ev.push_back(Parent::direct(edge, true));
   1.686 +      ev.push_back(Parent::direct(edge, false));      
   1.687 +      notifier(Arc()).add(ev);
   1.688 +      return edge;
   1.689 +    }
   1.690 +    
   1.691 +    void clear() {
   1.692 +      notifier(Arc()).clear();
   1.693 +      notifier(Edge()).clear();
   1.694 +      notifier(Node()).clear();
   1.695 +      Parent::clear();
   1.696 +    }
   1.697 +
   1.698 +    template <typename Digraph, typename NodeRefMap, typename EdgeRefMap>
   1.699 +    void build(const Digraph& digraph, NodeRefMap& nodeRef, 
   1.700 +               EdgeRefMap& edgeRef) {
   1.701 +      Parent::build(digraph, nodeRef, edgeRef);
   1.702 +      notifier(Node()).build();
   1.703 +      notifier(Edge()).build();
   1.704 +      notifier(Arc()).build();
   1.705 +    }
   1.706 +
   1.707 +    void erase(const Node& node) {
   1.708 +      Arc arc;
   1.709 +      Parent::firstOut(arc, node);
   1.710 +      while (arc != INVALID ) {
   1.711 +	erase(arc);
   1.712 +	Parent::firstOut(arc, node);
   1.713 +      } 
   1.714 +
   1.715 +      Parent::firstIn(arc, node);
   1.716 +      while (arc != INVALID ) {
   1.717 +	erase(arc);
   1.718 +	Parent::firstIn(arc, node);
   1.719 +      }
   1.720 +
   1.721 +      notifier(Node()).erase(node);
   1.722 +      Parent::erase(node);
   1.723 +    }
   1.724 +
   1.725 +    void erase(const Edge& edge) {
   1.726 +      std::vector<Arc> ev;
   1.727 +      ev.push_back(Parent::direct(edge, true));
   1.728 +      ev.push_back(Parent::direct(edge, false));      
   1.729 +      notifier(Arc()).erase(ev);
   1.730 +      notifier(Edge()).erase(edge);
   1.731 +      Parent::erase(edge);
   1.732 +    }
   1.733 +
   1.734 +    GraphExtender() {
   1.735 +      node_notifier.setContainer(*this); 
   1.736 +      arc_notifier.setContainer(*this);
   1.737 +      edge_notifier.setContainer(*this);
   1.738 +    } 
   1.739 +
   1.740 +    ~GraphExtender() {
   1.741 +      edge_notifier.clear();
   1.742 +      arc_notifier.clear();
   1.743 +      node_notifier.clear(); 
   1.744 +    } 
   1.745 +
   1.746 +  };
   1.747 +
   1.748 +}
   1.749 +
   1.750 +#endif