lemon/concept/graph_component.h
author hegyi
Thu, 12 Jan 2006 15:24:24 +0000
changeset 1893 4a35c7847c77
parent 1669 66ae78d29f1e
child 1909 2d806130e700
permissions -rw-r--r--
Documenatation of MapWin.
     1 /* -*- C++ -*-
     2  * lemon/concept/graph_component.h - Part of LEMON, a generic C++ optimization library
     3  *
     4  * Copyright (C) 2006 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     5  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     6  *
     7  * Permission to use, modify and distribute this software is granted
     8  * provided that this copyright notice appears in all copies. For
     9  * precise terms see the accompanying LICENSE file.
    10  *
    11  * This software is provided "AS IS" with no warranty of any kind,
    12  * express or implied, and with no claim as to its suitability for any
    13  * purpose.
    14  *
    15  */
    16 
    17 ///\ingroup graph_concepts
    18 ///\file
    19 ///\brief The graph components.
    20 
    21 
    22 #ifndef LEMON_CONCEPT_GRAPH_COMPONENT_H
    23 #define LEMON_CONCEPT_GRAPH_COMPONENT_H
    24 
    25 #include <lemon/invalid.h>
    26 #include <lemon/concept/maps.h>
    27 
    28 #include <lemon/bits/alteration_notifier.h>
    29 
    30 namespace lemon {
    31   namespace concept {
    32 
    33     /****************   Graph iterator concepts   ****************/
    34 
    35     /// Skeleton class for graph Node and Edge types
    36 
    37     /// This class describes the interface of Node and Edge (and UndirEdge
    38     /// in undirected graphs) subtypes of graph types.
    39     ///
    40     /// \note This class is a template class so that we can use it to
    41     /// create graph skeleton classes. The reason for this is than Node
    42     /// and Edge types should \em not derive from the same base class.
    43     /// For Node you should instantiate it with character 'n' and for Edge
    44     /// with 'e'.
    45 
    46 #ifndef DOXYGEN
    47     template <char _selector = '0'>
    48 #endif
    49     class GraphItem {
    50     public:
    51       /// Default constructor.
    52       
    53       /// \warning The default constructor is not required to set
    54       /// the item to some well-defined value. So you should consider it
    55       /// as uninitialized.
    56       GraphItem() {}
    57       /// Copy constructor.
    58       
    59       /// Copy constructor.
    60       ///
    61       GraphItem(GraphItem const&) {}
    62       /// Invalid constructor \& conversion.
    63 
    64       /// This constructor initializes the item to be invalid.
    65       /// \sa Invalid for more details.
    66       GraphItem(Invalid) {}
    67       /// Assign operator for nodes.
    68 
    69       /// The nodes are assignable. 
    70       ///
    71       GraphItem& operator=(GraphItem const&) { return *this; }
    72       /// Equality operator.
    73       
    74       /// Two iterators are equal if and only if they represents the
    75       /// same node in the graph or both are invalid.
    76       bool operator==(GraphItem) const { return false; }
    77       /// Inequality operator.
    78 	
    79       /// \sa operator==(const Node& n)
    80       ///
    81       bool operator!=(GraphItem) const { return false; }
    82 
    83       /// Artificial ordering operator.
    84 
    85       /// To allow the use of graph descriptors as key type in std::map or
    86       /// similar associative container we require this.
    87       ///
    88       /// \note This operator only have to define some strict ordering of
    89       /// the items; this order has nothing to do with the iteration
    90       /// ordering of the items.
    91       ///
    92       /// \bug This is a technical requirement. Do we really need this?
    93       bool operator<(GraphItem) const { return false; }
    94 
    95       template<typename _GraphItem>
    96       struct Constraints {
    97 	void constraints() {
    98 	  _GraphItem i1;
    99 	  _GraphItem i2 = i1;
   100 	  _GraphItem i3 = INVALID;
   101 	  
   102 	  i1 = i2 = i3;
   103 
   104 	  bool b;
   105 	  //	  b = (ia == ib) && (ia != ib) && (ia < ib);
   106 	  b = (ia == ib) && (ia != ib);
   107 	  b = (ia == INVALID) && (ib != INVALID);
   108 	  //	  b = (ia < ib);
   109 	}
   110 
   111 	const _GraphItem &ia;
   112 	const _GraphItem &ib;
   113       };
   114     };
   115 
   116     /// A type describing the concept of graph node
   117 
   118     /// This is an instantiation of \ref GraphItem which can be used as a
   119     /// Node subtype in graph skeleton definitions
   120     typedef GraphItem<'n'> GraphNode;
   121 
   122     /// A type describing the concept of graph edge
   123 
   124     /// This is an instantiation of \ref GraphItem which can be used as a
   125     /// Edge subtype in graph skeleton definitions
   126     typedef GraphItem<'e'> GraphEdge;
   127 
   128 
   129     /**************** Basic features of graphs ****************/
   130 
   131     /// An empty base graph class.
   132   
   133     /// This class provides the minimal set of features needed for a graph
   134     /// structure. All graph concepts have to be conform to this base
   135     /// graph.
   136     ///
   137     /// \bug This is not true. The minimal graph concept is the
   138     /// BaseIterableGraphComponent.
   139 
   140     class BaseGraphComponent {
   141     public:
   142 
   143       typedef BaseGraphComponent Graph;
   144       
   145       /// Node class of the graph.
   146 
   147       /// This class represents the Nodes of the graph. 
   148       ///
   149       typedef GraphItem<'n'> Node;
   150 
   151       /// Edge class of the graph.
   152 
   153       /// This class represents the Edges of the graph. 
   154       ///
   155       typedef GraphItem<'e'> Edge;
   156 
   157       ///Gives back the target node of an edge.
   158 
   159       ///Gives back the target node of an edge.
   160       ///
   161       Node target(const Edge&) const { return INVALID;}
   162 
   163       ///Gives back the source node of an edge.
   164 
   165       ///Gives back the source node of an edge.
   166       ///
   167       Node source(const Edge&) const { return INVALID;}
   168 
   169 
   170       template <typename _Graph>
   171       struct Constraints {
   172 	typedef typename _Graph::Node Node;
   173 	typedef typename _Graph::Edge Edge;
   174       
   175 	void constraints() {
   176 	  checkConcept<GraphItem<'n'>, Node>();
   177 	  checkConcept<GraphItem<'e'>, Edge>();
   178 	  {
   179 	    Node n;
   180 	    Edge e(INVALID);
   181 	    n = graph.source(e);
   182 	    n = graph.target(e);
   183 	  }      
   184 	}
   185       
   186 	const _Graph& graph;
   187       };
   188     };
   189 
   190     /// An empty iterable base graph class.
   191   
   192     /// This class provides beside the core graph features
   193     /// core iterable interface for the graph structure.
   194     /// Most of the base graphs should be conform to this concept.
   195 
   196     class BaseIterableGraphComponent : virtual public BaseGraphComponent {
   197     public:
   198 
   199       typedef BaseGraphComponent::Node Node;
   200       typedef BaseGraphComponent::Edge Edge;
   201 
   202       /// Gives back the first Node in the iterating order.
   203       
   204       /// Gives back the first Node in the iterating order.
   205       ///     
   206       void first(Node&) const {}
   207 
   208       /// Gives back the next Node in the iterating order.
   209       
   210       /// Gives back the next Node in the iterating order.
   211       ///     
   212       void next(Node&) const {}
   213 
   214       /// Gives back the first Edge in the iterating order.
   215       
   216       /// Gives back the first Edge in the iterating order.
   217       ///     
   218       void first(Edge&) const {}
   219       /// Gives back the next Edge in the iterating order.
   220       
   221       /// Gives back the next Edge in the iterating order.
   222       ///     
   223       void next(Edge&) const {}
   224 
   225 
   226       /// Gives back the first of the Edges point to the given Node.
   227       
   228       /// Gives back the first of the Edges point to the given Node.
   229       ///     
   230       void firstIn(Edge&, const Node&) const {}
   231 
   232       /// Gives back the next of the Edges points to the given Node.
   233 
   234 
   235       /// Gives back the next of the Edges points to the given Node.
   236       ///
   237       void nextIn(Edge&) const {}
   238 
   239       /// Gives back the first of the Edges start from the given Node.
   240       
   241       /// Gives back the first of the Edges start from the given Node.
   242       ///     
   243       void firstOut(Edge&, const Node&) const {}
   244 
   245       /// Gives back the next of the Edges start from the given Node.
   246       
   247       /// Gives back the next of the Edges start from the given Node.
   248       ///     
   249       void nextOut(Edge&) const {}
   250 
   251 
   252       template <typename _Graph>
   253       struct Constraints {
   254       
   255 	void constraints() {
   256 	  checkConcept< BaseGraphComponent, _Graph >();
   257 	  typename _Graph::Node node;      
   258 	  typename _Graph::Edge edge;
   259 	  {
   260 	    graph.first(node);
   261 	    graph.next(node);
   262 	  }
   263 	  {
   264 	    graph.first(edge);
   265 	    graph.next(edge);
   266 	  }
   267 	  {
   268 	    graph.firstIn(edge, node);
   269 	    graph.nextIn(edge);
   270 	  }
   271 	  {
   272 	    graph.firstOut(edge, node);
   273 	    graph.nextOut(edge);
   274 	  }
   275 	}
   276 
   277 	const _Graph& graph;
   278       };
   279     };
   280 
   281     /// An empty idable base graph class.
   282   
   283     /// This class provides beside the core graph features
   284     /// core id functions for the graph structure.
   285     /// The most of the base graphs should be conform to this concept.
   286     /// The id's are unique and immutable.
   287     class IDableGraphComponent : virtual public BaseGraphComponent {
   288     public:
   289 
   290       typedef BaseGraphComponent::Node Node;
   291       typedef BaseGraphComponent::Edge Edge;
   292 
   293       /// Gives back an unique integer id for the Node. 
   294 
   295       /// Gives back an unique integer id for the Node. 
   296       ///
   297       int id(const Node&) const { return -1;}
   298 
   299       /// \brief Gives back the node by the unique id.
   300       ///
   301       /// Gives back the node by the unique id.
   302       /// If the graph does not contain node with the given id
   303       /// then the result of the function is undetermined. 
   304       Node fromId(int , Node) const { return INVALID;}
   305 
   306       /// \brief Gives back an unique integer id for the Edge. 
   307       ///
   308       /// Gives back an unique integer id for the Edge. 
   309       ///
   310       int id(const Edge&) const { return -1;}
   311 
   312       /// \brief Gives back the edge by the unique id.
   313       ///
   314       /// Gives back the edge by the unique id.
   315       /// If the graph does not contain edge with the given id
   316       /// then the result of the function is undetermined. 
   317       Edge fromId(int, Edge) const { return INVALID;}
   318 
   319       template <typename _Graph>
   320       struct Constraints {
   321 
   322 	void constraints() {
   323 	  checkConcept< BaseGraphComponent, _Graph >();
   324 	  typename _Graph::Node node;
   325 	  int nid = graph.id(node);
   326 	  nid = graph.id(node);
   327 	  node = graph.fromId(nid, Node());
   328 	  typename _Graph::Edge edge;
   329 	  int eid = graph.id(edge);
   330 	  eid = graph.id(edge);
   331 	  edge = graph.fromId(eid, Edge());
   332 	}
   333 
   334 	const _Graph& graph;
   335       };
   336     };
   337 
   338 
   339     /// An empty max-idable base graph class.
   340   
   341     /// This class provides beside the core graph features
   342     /// core max id functions for the graph structure.
   343     /// The most of the base graphs should be conform to this concept.
   344     /// The id's are unique and immutable.
   345     class MaxIDableGraphComponent : virtual public BaseGraphComponent {
   346     public:
   347 
   348       /// Gives back an integer greater or equal to the maximum Node id. 
   349 
   350       /// Gives back an integer greater or equal to the maximum Node id. 
   351       ///
   352       int maxId(Node = INVALID) const { return -1;}
   353 
   354       /// Gives back an integer greater or equal to the maximum Edge id. 
   355 
   356       /// Gives back an integer greater or equal to the maximum Edge id. 
   357       ///
   358       int maxId(Edge = INVALID) const { return -1;}
   359 
   360       template <typename _Graph>
   361       struct Constraints {
   362 
   363 	void constraints() {
   364 	  checkConcept<BaseGraphComponent, _Graph>();
   365 	  int nid = graph.maxId(typename _Graph::Node());
   366 	  ignore_unused_variable_warning(nid);
   367 	  int eid = graph.maxId(typename _Graph::Edge());
   368 	  ignore_unused_variable_warning(eid);
   369 	}
   370       
   371 	const _Graph& graph;
   372       };
   373     };
   374 
   375     /// An empty extendable base graph class.
   376   
   377     /// This class provides beside the core graph features
   378     /// core graph extend interface for the graph structure.
   379     /// The most of the base graphs should be conform to this concept.
   380     class BaseExtendableGraphComponent : virtual public BaseGraphComponent {
   381     public:
   382 
   383       typedef BaseGraphComponent::Node Node;
   384       typedef BaseGraphComponent::Edge Edge;
   385 
   386       /// Adds a new Node to the graph.
   387 
   388       /// Adds a new Node to the graph.
   389       ///
   390       Node addNode() {
   391 	return INVALID;
   392       }
   393     
   394       /// Adds a new Edge connects the two Nodes to the graph.
   395 
   396       /// Adds a new Edge connects the two Nodes to the graph.
   397       ///
   398       Edge addEdge(const Node&, const Node&) {
   399 	return INVALID;
   400       }
   401 
   402       template <typename _Graph>
   403       struct Constraints {
   404 	void constraints() {
   405 	  checkConcept<BaseGraphComponent, _Graph >();
   406 	  typename _Graph::Node node_a, node_b;
   407 	  node_a = graph.addNode();
   408 	  node_b = graph.addNode();
   409 	  typename _Graph::Edge edge;
   410 	  edge = graph.addEdge(node_a, node_b);
   411 	}
   412 
   413 	_Graph& graph;
   414       };
   415     };
   416 
   417     /// An empty erasable base graph class.
   418   
   419     /// This class provides beside the core graph features
   420     /// core erase functions for the graph structure.
   421     /// The most of the base graphs should be conform to this concept.
   422     class BaseErasableGraphComponent : virtual public BaseGraphComponent {
   423     public:
   424 
   425       typedef BaseGraphComponent::Node Node;
   426       typedef BaseGraphComponent::Edge Edge;
   427 
   428       /// Erase a Node from the graph.
   429       
   430       /// Erase a Node from the graph. This function should not
   431       /// erase edges connecting to the Node.
   432       void erase(const Node&) {}    
   433 
   434       /// Erase an Edge from the graph.
   435 
   436       /// Erase an Edge from the graph.
   437       ///
   438       void erase(const Edge&) {}
   439 
   440       template <typename _Graph>
   441       struct Constraints {
   442 	void constraints() {
   443 	  checkConcept<BaseGraphComponent, _Graph>();
   444 	  typename _Graph::Node node;
   445 	  graph.erase(node);
   446 	  typename _Graph::Edge edge;
   447 	  graph.erase(edge);
   448 	}
   449 
   450 	_Graph& graph;
   451       };
   452     };
   453 
   454     /// An empty clearable base graph class.
   455   
   456     /// This class provides beside the core graph features
   457     /// core clear functions for the graph structure.
   458     /// The most of the base graphs should be conform to this concept.
   459     class ClearableGraphComponent : virtual public BaseGraphComponent {
   460     public:
   461 
   462       /// Erase all the Nodes and Edges from the graph.
   463 
   464       /// Erase all the Nodes and Edges from the graph.
   465       ///
   466       void clear() {}    
   467 
   468       template <typename _Graph>
   469       struct Constraints {
   470 	void constraints() {
   471 	  checkConcept<BaseGraphComponent, _Graph>();
   472 	  graph.clear();
   473 	}
   474 
   475 	_Graph graph;
   476       };
   477     };
   478 
   479 
   480     /// Skeleton class for graph NodeIt and EdgeIt
   481 
   482     /// Skeleton class for graph NodeIt and EdgeIt.
   483     ///
   484     template <typename _Graph, typename _Item>
   485     class GraphIterator : public _Item {
   486     public:
   487       /// \todo Don't we need the Item type as typedef?
   488 
   489       /// Default constructor.
   490       
   491       /// @warning The default constructor sets the iterator
   492       /// to an undefined value.
   493       GraphIterator() {}
   494       /// Copy constructor.
   495       
   496       /// Copy constructor.
   497       ///
   498       GraphIterator(GraphIterator const&) {}
   499       /// Sets the iterator to the first item.
   500       
   501       /// Sets the iterator to the first item of \c the graph.
   502       ///
   503       explicit GraphIterator(const _Graph&) {}
   504       /// Invalid constructor \& conversion.
   505 
   506       /// This constructor initializes the item to be invalid.
   507       /// \sa Invalid for more details.
   508       GraphIterator(Invalid) {}
   509       /// Assign operator for items.
   510 
   511       /// The items are assignable. 
   512       ///
   513       GraphIterator& operator=(GraphIterator const&) { return *this; }      
   514       /// Next item.
   515 
   516       /// Assign the iterator to the next item.
   517       ///
   518       GraphIterator& operator++() { return *this; }
   519       //	Node operator*() const { return INVALID; }
   520       /// Equality operator
   521 
   522       /// Two iterators are equal if and only if they point to the
   523       /// same object or both are invalid.
   524       bool operator==(const GraphIterator&) const { return true;}
   525       /// Inequality operator
   526 	
   527       /// \sa operator==(Node n)
   528       ///
   529       bool operator!=(const GraphIterator&) const { return true;}
   530       
   531       template<typename _GraphIterator>
   532       struct Constraints {
   533 	void constraints() {
   534 	  //	  checkConcept< Item, _GraphIterator >();
   535 	  _GraphIterator it1(g);
   536 	
   537 	  /// \todo Do we need NodeIt(Node) kind of constructor?
   538 	  //	_GraphIterator it2(bj);
   539 	  _GraphIterator it2;
   540 
   541 	  it2 = ++it1;
   542 	  ++it2 = it1;
   543 	  ++(++it1);
   544 	  /// \bug This should be: is_base_and_derived<BaseItem, _GraphIterator>
   545 	  _Item bi = it1;
   546 	  bi = it2;
   547 	}
   548 	_Graph& g;
   549       };
   550     };
   551 
   552     /// Skeleton class for graph InEdgeIt and OutEdgeIt
   553 
   554     /// \note Because InEdgeIt and OutEdgeIt may not inherit from the same
   555     /// base class, the _selector is a additional template parameter. For 
   556     /// InEdgeIt you should instantiate it with character 'i' and for 
   557     /// OutEdgeIt with 'o'.
   558     /// \todo Is this a good name for this concept?
   559     template <typename Graph,
   560 	      typename Edge = typename Graph::Edge,
   561 	      char _selector = '0'>
   562     class GraphIncIterator : public Edge {
   563     public:
   564       /// Default constructor.
   565       
   566       /// @warning The default constructor sets the iterator
   567       /// to an undefined value.
   568       GraphIncIterator() {}
   569       /// Copy constructor.
   570       
   571       /// Copy constructor.
   572       ///
   573       GraphIncIterator(GraphIncIterator const& gi) :Edge(gi) {}
   574       /// Sets the iterator to the first edge incoming into or outgoing 
   575       /// from the node.
   576       
   577       /// Sets the iterator to the first edge incoming into or outgoing 
   578       /// from the node.
   579       ///
   580       explicit GraphIncIterator(const Graph&, const typename Graph::Node&) {}
   581       /// Invalid constructor \& conversion.
   582 
   583       /// This constructor initializes the item to be invalid.
   584       /// \sa Invalid for more details.
   585       GraphIncIterator(Invalid) {}
   586       /// Assign operator for nodes.
   587 
   588       /// The nodes are assignable. 
   589       ///
   590       GraphIncIterator& operator=(GraphIncIterator const&) { return *this; }      
   591       /// Next edge.
   592 
   593       /// Assign the iterator to the next node.
   594       ///
   595       GraphIncIterator& operator++() { return *this; }
   596 
   597       //	Node operator*() const { return INVALID; }
   598 
   599       /// Equality operator
   600 
   601       /// Two iterators are equal if and only if they point to the
   602       /// same object or both are invalid.
   603       bool operator==(const GraphIncIterator&) const { return true;}
   604 
   605       /// Inequality operator
   606 	
   607       /// \sa operator==(Node n)
   608       ///
   609       bool operator!=(const GraphIncIterator&) const { return true;}
   610 
   611       template <typename _GraphIncIterator>
   612       struct Constraints {
   613 	typedef typename Graph::Node Node;
   614 	void constraints() {
   615 	  checkConcept<GraphItem<'e'>, _GraphIncIterator>();
   616 	  _GraphIncIterator it1(graph, node);
   617 	  /// \todo Do we need OutEdgeIt(Edge) kind of constructor?
   618 	  //	_GraphIncIterator it2(edge);
   619 	  _GraphIncIterator it2;
   620 
   621 	  it2 = ++it1;
   622 	  ++it2 = it1;
   623 	  ++(++it1);
   624 	  Edge e = it1;
   625 	  e = it2;
   626 
   627 	  const_constraits();
   628 	}
   629 
   630 	void const_constraits() {
   631 	  Node n = graph.baseNode(it);
   632 	  n = graph.runningNode(it);
   633 	}
   634 
   635 	Edge edge;
   636 	Node node;
   637 	Graph graph;
   638 	_GraphIncIterator it;
   639       };
   640     };
   641 
   642 
   643     /// An empty iterable base graph class.
   644   
   645     /// This class provides beside the core graph features
   646     /// iterator based iterable interface for the graph structure.
   647     /// This concept is part of the StaticGraphConcept.
   648     class IterableGraphComponent : virtual public BaseGraphComponent {
   649 
   650     public:
   651     
   652       typedef IterableGraphComponent Graph;
   653 
   654       typedef BaseGraphComponent::Node Node;
   655       typedef BaseGraphComponent::Edge Edge;
   656 
   657       /// This iterator goes through each node.
   658 
   659       /// This iterator goes through each node.
   660       ///
   661       typedef GraphIterator<Graph, Node> NodeIt;
   662       /// This iterator goes through each node.
   663 
   664       /// This iterator goes through each node.
   665       ///
   666       typedef GraphIterator<Graph, Edge> EdgeIt;
   667       /// This iterator goes trough the incoming edges of a node.
   668 
   669       /// This iterator goes trough the \e inccoming edges of a certain node
   670       /// of a graph.
   671       typedef GraphIncIterator<Graph, Edge, 'i'> InEdgeIt;
   672       /// This iterator goes trough the outgoing edges of a node.
   673 
   674       /// This iterator goes trough the \e outgoing edges of a certain node
   675       /// of a graph.
   676       typedef GraphIncIterator<Graph, Edge, 'o'> OutEdgeIt;
   677 
   678       /// \brief The base node of the iterator.
   679       ///
   680       /// Gives back the base node of the iterator.
   681       /// It is always the target of the pointed edge.
   682       Node baseNode(const InEdgeIt&) const { return INVALID; }
   683 
   684       /// \brief The running node of the iterator.
   685       ///
   686       /// Gives back the running node of the iterator.
   687       /// It is always the source of the pointed edge.
   688       Node runningNode(const InEdgeIt&) const { return INVALID; }
   689 
   690       /// \brief The base node of the iterator.
   691       ///
   692       /// Gives back the base node of the iterator.
   693       /// It is always the source of the pointed edge.
   694       Node baseNode(const OutEdgeIt&) const { return INVALID; }
   695 
   696       /// \brief The running node of the iterator.
   697       ///
   698       /// Gives back the running node of the iterator.
   699       /// It is always the target of the pointed edge.
   700       Node runningNode(const OutEdgeIt&) const { return INVALID; }
   701 
   702       /// \brief The opposite node on the given edge.
   703       ///
   704       /// Gives back the opposite on the given edge.
   705       /// \todo It should not be here.
   706       Node oppositeNode(const Node&, const Edge&) const { return INVALID; }
   707 
   708     
   709       template <typename _Graph> 
   710       struct Constraints {
   711 	void constraints() {
   712 	  checkConcept< BaseGraphComponent, _Graph>();
   713 	  
   714 	  checkConcept<GraphIterator<_Graph, typename _Graph::Edge>,
   715 	    typename _Graph::EdgeIt >();
   716 	  checkConcept<GraphIterator<_Graph, typename _Graph::Node>,
   717 	    typename _Graph::NodeIt >();
   718 	  checkConcept<GraphIncIterator<_Graph>, typename _Graph::InEdgeIt>();
   719 	  checkConcept<GraphIncIterator<_Graph>, typename _Graph::OutEdgeIt>();
   720 
   721 	  typename _Graph::Node n(INVALID);
   722 	  typename _Graph::Edge e(INVALID);
   723 	  n = graph.oppositeNode(n, e);
   724 	}
   725 	
   726 	const _Graph& graph;
   727 	
   728       };
   729     };
   730 
   731     /// An empty alteration notifier base graph class.
   732   
   733     /// This class provides beside the core graph features
   734     /// alteration notifier interface for the graph structure.
   735     /// This is an observer-notifier pattern. More Obsevers can
   736     /// be registered into the notifier and whenever an alteration
   737     /// occured in the graph all the observers will notified about it.
   738     class AlterableGraphComponent : virtual public BaseGraphComponent {
   739     public:
   740 
   741       /// The edge observer registry.
   742       typedef AlterationNotifier<Edge> EdgeNotifier;
   743       /// The node observer registry.
   744       typedef AlterationNotifier<Node> NodeNotifier;
   745       
   746       /// \brief Gives back the edge alteration notifier.
   747       ///
   748       /// Gives back the edge alteration notifier.
   749       EdgeNotifier getNotifier(Edge) const {
   750 	return EdgeNotifier();
   751       }
   752       
   753       /// \brief Gives back the node alteration notifier.
   754       ///
   755       /// Gives back the node alteration notifier.
   756       NodeNotifier getNotifier(Node) const {
   757 	return NodeNotifier();
   758       }
   759       
   760     };
   761 
   762 
   763     /// Class describing the concept of graph maps
   764 
   765     /// This class describes the common interface of the graph maps
   766     /// (NodeMap, EdgeMap), that is \ref maps-page "maps" which can be used to
   767     /// associate data to graph descriptors (nodes or edges).
   768     template <typename Graph, typename Item, typename _Value>
   769     class GraphMap : public ReadWriteMap<Item, _Value> {
   770     protected:      
   771       GraphMap() {}
   772     public:
   773       /// \brief Construct a new map.
   774       ///
   775       /// Construct a new map for the graph.
   776       explicit GraphMap(const Graph&) {}
   777       /// \brief Construct a new map with default value.
   778       ///
   779       /// Construct a new map for the graph and initalise the values.
   780       GraphMap(const Graph&, const _Value&) {}
   781       /// \brief Copy constructor.
   782       ///
   783       /// Copy Constructor.
   784       GraphMap(const GraphMap& gm) :ReadWriteMap<Item, _Value>(gm) {}
   785       
   786       /// \brief Assign operator.
   787       ///
   788       /// Assign operator.
   789       GraphMap& operator=(const GraphMap&) { return *this;}
   790 
   791       template<typename _Map>
   792       struct Constraints {
   793 	void constraints() {
   794 	  checkConcept<ReadWriteMap<Item, _Value>, _Map >();
   795 	  // Construction with a graph parameter
   796 	  _Map a(g);
   797 	  // Constructor with a graph and a default value parameter
   798 	  _Map a2(g,t);
   799 	  // Copy constructor. Do we need it?
   800 	  _Map b=c;
   801 
   802 	  ignore_unused_variable_warning(a2);
   803 	}
   804 
   805 	const _Map &c;
   806 	const Graph &g;
   807 	const typename GraphMap::Value &t;
   808       };
   809 
   810     };
   811 
   812     /// An empty mappable base graph class.
   813   
   814     /// This class provides beside the core graph features
   815     /// map interface for the graph structure.
   816     /// This concept is part of the StaticGraphConcept.
   817     class MappableGraphComponent : virtual public BaseGraphComponent {
   818     public:
   819 
   820       typedef MappableGraphComponent Graph;
   821 
   822       typedef BaseGraphComponent::Node Node;
   823       typedef BaseGraphComponent::Edge Edge;
   824 
   825       /// ReadWrite map of the nodes.
   826     
   827       /// ReadWrite map of the nodes.
   828       ///
   829       template <typename _Value>
   830       class NodeMap : public GraphMap<Graph, Node, _Value> {
   831       private:
   832 	NodeMap();
   833       public:
   834 	/// \brief Construct a new map.
   835 	///
   836 	/// Construct a new map for the graph.
   837 	/// \todo call the right parent class constructor
   838 	explicit NodeMap(const Graph&) {}
   839 	/// \brief Construct a new map with default value.
   840 	///
   841 	/// Construct a new map for the graph and initalise the values.
   842 	NodeMap(const Graph&, const _Value&) {}
   843 	/// \brief Copy constructor.
   844 	///
   845 	/// Copy Constructor.
   846 	NodeMap(const NodeMap& nm) : GraphMap<Graph, Node, _Value>(nm) {}
   847 
   848 	/// \brief Assign operator.
   849 	///
   850 	/// Assign operator.
   851 	NodeMap& operator=(const NodeMap&) { return *this;}
   852 
   853       };
   854 
   855       /// ReadWrite map of the edges.
   856     
   857       /// ReadWrite map of the edges.
   858       ///
   859       template <typename _Value>
   860       class EdgeMap : public GraphMap<Graph, Edge, _Value> {
   861       private:
   862 	EdgeMap();
   863       public:
   864 	/// \brief Construct a new map.
   865 	///
   866 	/// Construct a new map for the graph.
   867 	/// \todo call the right parent class constructor
   868 	explicit EdgeMap(const Graph&) {}
   869 	/// \brief Construct a new map with default value.
   870 	///
   871 	/// Construct a new map for the graph and initalise the values.
   872 	EdgeMap(const Graph&, const _Value&) {}
   873 	/// \brief Copy constructor.
   874 	///
   875 	/// Copy Constructor.
   876 	EdgeMap(const EdgeMap& em) :GraphMap<Graph, Edge, _Value>(em) {}
   877 
   878 	/// \brief Assign operator.
   879 	///
   880 	/// Assign operator.
   881 	EdgeMap& operator=(const EdgeMap&) { return *this;}
   882 
   883       };
   884 
   885       template <typename _Graph>
   886       struct Constraints {
   887 
   888 	struct Type {
   889 	  int value;
   890 	  Type() : value(0) {}
   891 	  Type(int _v) : value(_v) {}
   892 	};
   893 
   894 	void constraints() {
   895 	  checkConcept<BaseGraphComponent, _Graph>();
   896 	  { // int map test
   897 	    typedef typename _Graph::template NodeMap<int> IntNodeMap;
   898 	    checkConcept<GraphMap<_Graph, typename _Graph::Node, int>, 
   899 	      IntNodeMap >();
   900 	  } { // bool map test
   901 	    typedef typename _Graph::template NodeMap<bool> BoolNodeMap;
   902 	    checkConcept<GraphMap<_Graph, typename _Graph::Node, bool>,
   903 	      BoolNodeMap >();
   904 	  } { // Type map test
   905 	    typedef typename _Graph::template NodeMap<Type> TypeNodeMap;
   906 	    checkConcept<GraphMap<_Graph, typename _Graph::Node, Type>,
   907 	      TypeNodeMap >();
   908 	  } 
   909 
   910 	  { // int map test
   911 	    typedef typename _Graph::template EdgeMap<int> IntEdgeMap;
   912 	    checkConcept<GraphMap<_Graph, typename _Graph::Edge, int>,
   913 	      IntEdgeMap >();
   914 	  } { // bool map test
   915 	    typedef typename _Graph::template EdgeMap<bool> BoolEdgeMap;
   916 	    checkConcept<GraphMap<_Graph, typename _Graph::Edge, bool>,
   917 	      BoolEdgeMap >();
   918 	  } { // Type map test
   919 	    typedef typename _Graph::template EdgeMap<Type> TypeEdgeMap;
   920 	    checkConcept<GraphMap<_Graph, typename _Graph::Edge, Type>, 
   921 	      TypeEdgeMap >();
   922 	  } 
   923 	}
   924 
   925 	_Graph& graph;
   926       };
   927     };
   928 
   929     /// \brief An empty extendable extended graph class.
   930     ///
   931     /// This class provides beside the core graph features
   932     /// item addition interface for the graph structure.
   933     /// The difference between this class and the 
   934     /// \c BaseExtendableGraphComponent is that it should
   935     /// notify the item alteration observers.
   936     class ExtendableGraphComponent : virtual public BaseGraphComponent {
   937     public:
   938 
   939       typedef ExtendableGraphComponent Graph;
   940 
   941       typedef BaseGraphComponent::Node Node;
   942       typedef BaseGraphComponent::Edge Edge;
   943 
   944       /// \brief Add a node to the graph.
   945       ///
   946       /// Add a node to the graph and notify the observers.
   947       Node addNode() {
   948 	return INVALID;
   949       }
   950     
   951       /// \brief Add an edge to the graph.
   952       ///
   953       /// Add an edge to the graph and notify the observers.
   954       Edge addEdge(const Node&, const Node&) {
   955 	return INVALID;
   956       }
   957 
   958       template <typename _Graph>
   959       struct Constraints {
   960 	void constraints() {
   961 	  checkConcept<BaseGraphComponent, _Graph >();
   962 	  typename _Graph::Node node_a, node_b;
   963 	  node_a = graph.addNode();
   964 	  node_b = graph.addNode();
   965 	  typename _Graph::Edge edge;
   966 	  edge = graph.addEdge(node_a, node_b);      
   967 	}
   968 	_Graph& graph;
   969       };
   970     };
   971 
   972     /// \brief An empty erasable extended graph class.
   973     ///
   974     /// This class provides beside the core graph features
   975     /// item erase interface for the graph structure.
   976     /// The difference between this class and the 
   977     /// \c BaseErasableGraphComponent is that it should
   978     /// notify the item alteration observers.
   979     class ErasableGraphComponent : virtual public BaseGraphComponent {
   980     public:
   981 
   982       typedef ErasableGraphComponent Graph;
   983 
   984       typedef BaseGraphComponent::Node Node;
   985       typedef BaseGraphComponent::Edge Edge;
   986 
   987       /// \brief Erase the Node and notify the node alteration observers.
   988       ///
   989       ///  Erase the Node and notify the node alteration observers.
   990       void erase(const Node&) {}    
   991 
   992       /// \brief Erase the Edge and notify the edge alteration observers.
   993       ///
   994       ///  Erase the Edge and notify the edge alteration observers.
   995       void erase(const Edge&) {}
   996 
   997       template <typename _Graph>
   998       struct Constraints {
   999 	void constraints() {
  1000 	  checkConcept<BaseGraphComponent, _Graph >();
  1001 	  typename _Graph::Node node;
  1002 	  graph.erase(node);
  1003 	  typename _Graph::Edge edge;
  1004 	  graph.erase(edge);      
  1005 	}
  1006 
  1007 	_Graph& graph;
  1008       };
  1009     };
  1010 
  1011   }
  1012 
  1013 }
  1014 
  1015 #endif