src/lemon/concept/graph_component.h
changeset 993 21d1b4fa1b24
parent 987 87f7c54892df
child 1021 fd1d073b6557
equal deleted inserted replaced
6:3b504d6a8912 7:4ff57dbf10c1
    35 
    35 
    36     /// \note Because Node and Edge are forbidden to inherit from the same
    36     /// \note Because Node and Edge are forbidden to inherit from the same
    37     /// base class, this is a template. For Node you should instantiate it
    37     /// base class, this is a template. For Node you should instantiate it
    38     /// with character 'n' and for Edge with 'e'.
    38     /// with character 'n' and for Edge with 'e'.
    39 
    39 
    40     template<char Ch>
    40     template<char _selector>
    41     class GraphItem {
    41     class GraphItem {
    42     public:
    42     public:
       
    43       /// Default constructor.
       
    44       
       
    45       /// @warning The default constructor sets the item
       
    46       /// to an undefined value.
    43       GraphItem() {}
    47       GraphItem() {}
       
    48       /// Copy constructor.
       
    49       
       
    50       /// Copy constructor.
       
    51       ///
       
    52       GraphItem(GraphItem const&) {}
       
    53       /// Invalid constructor \& conversion.
       
    54 
       
    55       /// This constructor initializes the item to be invalid.
       
    56       /// \sa Invalid for more details.
    44       GraphItem(Invalid) {}
    57       GraphItem(Invalid) {}
    45 
    58       /// Assign operator for nodes.
    46       // We explicitely list these:
    59 
    47       GraphItem(GraphItem const&) {}
    60       /// The nodes are assignable. 
       
    61       ///
    48       GraphItem& operator=(GraphItem const&) { return *this; }
    62       GraphItem& operator=(GraphItem const&) { return *this; }
    49 
    63       /// Equality operator.
       
    64       
       
    65       /// Two iterators are equal if and only if they represents the
       
    66       /// same node in the graph or both are invalid.
    50       bool operator==(GraphItem) const { return false; }
    67       bool operator==(GraphItem) const { return false; }
       
    68       /// Inequality operator.
       
    69 	
       
    70       /// \sa operator==(const Node& n)
       
    71       ///
    51       bool operator!=(GraphItem) const { return false; }
    72       bool operator!=(GraphItem) const { return false; }
    52 
    73 
    53       // Technical requirement. Do we really need this?
    74       // Technical requirement. Do we really need this?
    54       bool operator<(GraphItem) const { return false; }
    75       //      bool operator<(GraphItem) const { return false; }
    55     };
    76 
    56 
    77 
    57 
    78       template<typename _GraphItem>
    58     template<typename GI>
    79       struct Constraints {
    59     struct GraphItemConcept {
    80 	void constraints() {
    60       void constraints() {
    81 	  _GraphItem i1;
    61 	GI i1;
    82 	  _GraphItem i2 = i1;
    62 	GI i2 = i1;
    83 	  _GraphItem i3 = INVALID;
    63 	GI i3 = INVALID;
    84 	  
    64 	
    85 	  i1 = i2 = i3;
    65 	i1 = i2 = i3;
    86 
    66 
    87 	  bool b;
    67 	bool b;
    88 	  //	  b = (ia == ib) && (ia != ib) && (ia < ib);
    68 	b = (ia == ib) && (ia != ib) && (ia < ib);
    89 	  b = (ia == ib) && (ia != ib);
    69 	b = (ia == INVALID) && (ib != INVALID);
    90 	  b = (ia == INVALID) && (ib != INVALID);
    70       }
    91 	}
    71 
    92 
    72       const GI &ia;
    93 	const _GraphItem &ia;
    73       const GI &ib;
    94 	const _GraphItem &ib;
    74     };
    95       };
    75 
    96     };
    76 
       
    77     template<typename Iter, typename Graph, typename BaseItem>
       
    78     struct GraphIteratorConcept {
       
    79       void constraints() {
       
    80 	function_requires< GraphItemConcept<Iter> >();
       
    81 	Iter it1(g);
       
    82 
       
    83 	/// \todo Do we need NodeIt(Node) kind of constructor?
       
    84 	//	Iter it2(bj);
       
    85 	Iter it2;
       
    86 
       
    87 	it2 = ++it1;
       
    88 	++it2 = it1;
       
    89 	++(++it1);
       
    90 	/// \bug This should be: is_base_and_derived<BaseItem, Iter>
       
    91 	BaseItem bi = it1;
       
    92 	bi = it2;
       
    93       }
       
    94 
       
    95       BaseItem bj;
       
    96       Graph g;
       
    97     };
       
    98 
       
    99     template<typename Iter, typename Graph>
       
   100     struct GraphIncIteratorConcept {
       
   101       typedef typename Graph::Node Node;
       
   102       typedef typename Graph::Edge Edge;
       
   103       void constraints() {
       
   104 	function_requires< GraphItemConcept<Iter> >();
       
   105 	Iter it1(graph, node);
       
   106 	/// \todo Do we need OutEdgeIt(Edge) kind of constructor?
       
   107 	//	Iter it2(edge);
       
   108 	Iter it2;
       
   109 
       
   110 	it2 = ++it1;
       
   111 	++it2 = it1;
       
   112 	++(++it1);
       
   113 	Edge e = it1;
       
   114 	e = it2;
       
   115       }
       
   116 
       
   117       Edge edge;
       
   118       Node node;
       
   119       Graph graph;
       
   120     };
       
   121 
       
   122 
       
   123 
    97 
   124     /// An empty base graph class.
    98     /// An empty base graph class.
   125   
    99   
   126     /// This class provides the minimal set of features needed for a graph
   100     /// This class provides the minimal set of features needed for a graph
   127     /// structure. All graph concepts have to be conform to this base
   101     /// structure. All graph concepts have to be conform to this base
   137       
   111       
   138       /// Node class of the graph.
   112       /// Node class of the graph.
   139 
   113 
   140       /// This class represents the Nodes of the graph. 
   114       /// This class represents the Nodes of the graph. 
   141       ///
   115       ///
   142       class Node {
   116       typedef GraphItem<'n'> Node;
   143       public:
       
   144 
       
   145 	/// Default constructor.
       
   146 
       
   147 	/// @warning The default constructor sets the iterator
       
   148 	/// to an undefined value.
       
   149 
       
   150 	Node() {}
       
   151 	/// Copy constructor.
       
   152 
       
   153 	/// Copy constructor.
       
   154 	///
       
   155 	Node(const Node&) {}
       
   156 
       
   157 	/// Invalid constructor \& conversion.
       
   158 
       
   159 	/// This constructor initializes the iterator to be invalid.
       
   160 	/// \sa Invalid for more details.
       
   161 	Node(Invalid) {}
       
   162 
       
   163 
       
   164 	/// Assign operator for nodes.
       
   165 
       
   166 	/// The nodes are assignable. 
       
   167 	///
       
   168 	Node& operator=(const Node&) { return *this;}
       
   169 
       
   170 	/// Equality operator.
       
   171 
       
   172 	/// Two iterators are equal if and only if they represents the
       
   173 	/// same node in the graph or both are invalid.
       
   174 	bool operator==(const Node&) const { return true;}
       
   175 
       
   176 
       
   177 	/// Inequality operator.
       
   178 	
       
   179 	/// \sa operator==(const Node& n)
       
   180 	///
       
   181 	bool operator!=(const Node&) const { return true;}
       
   182 
       
   183  	/// Comparison operator.
       
   184 
       
   185 	/// This is a strict ordering between the nodes.
       
   186 	///
       
   187 	/// This ordering can be different from the iterating order of nodes.
       
   188 	/// \todo Possibly we don't need it.
       
   189 	bool operator<(const Node&) const { return true;}
       
   190       };
       
   191 
   117 
   192       /// Edge class of the graph.
   118       /// Edge class of the graph.
   193 
   119 
   194       /// This class represents the Edges of the graph. 
   120       /// This class represents the Edges of the graph. 
   195       ///
   121       ///
   196       class Edge {
   122       typedef GraphItem<'e'> Edge;
   197       public:
       
   198 
       
   199 	/// Default constructor.
       
   200 
       
   201 	/// @warning The default constructor sets the iterator
       
   202 	/// to an undefined value.
       
   203 
       
   204 	Edge() {}
       
   205 	/// Copy constructor.
       
   206 
       
   207 	/// Copy constructor.
       
   208 	///
       
   209 	Edge(const Edge&) {}
       
   210 
       
   211 	/// Invalid constructor \& conversion.
       
   212 
       
   213 	/// This constructor initializes the iterator to be invalid.
       
   214 	/// \sa Invalid for more details.
       
   215 	Edge(Invalid) {}
       
   216 
       
   217 	/// Assign operator for edges.
       
   218 
       
   219 	/// The edges are assignable. 
       
   220 	///
       
   221 	Edge& operator=(const Edge&) { return *this;}
       
   222 
       
   223 	/// Equality operator.
       
   224 
       
   225 	/// Two iterators are equal if and only if they represents the
       
   226 	/// same edge in the graph or both are invalid.
       
   227 	bool operator==(const Edge&) const { return true;}
       
   228 
       
   229 
       
   230 	/// Inequality operator.
       
   231 	
       
   232 	/// \sa operator==(const Edge& n)
       
   233 	///
       
   234 	bool operator!=(const Edge&) const { return true;}
       
   235 
       
   236  	/// Comparison operator.
       
   237 
       
   238 	/// This is a strict ordering between the edges.
       
   239 	///
       
   240 	/// This ordering can be different from the iterating order of edges.
       
   241 	/// \todo Possibly we don't need it.
       
   242 	bool operator<(const Edge&) const { return true;}
       
   243       };
       
   244 
   123 
   245       ///Gives back the target node of an edge.
   124       ///Gives back the target node of an edge.
   246 
   125 
   247       ///Gives back the target node of an edge.
   126       ///Gives back the target node of an edge.
   248       ///
   127       ///
   251       ///Gives back the source node of an edge.
   130       ///Gives back the source node of an edge.
   252 
   131 
   253       ///Gives back the source node of an edge.
   132       ///Gives back the source node of an edge.
   254       ///
   133       ///
   255       Node source(const Edge&) const { return INVALID;}
   134       Node source(const Edge&) const { return INVALID;}
   256     };
   135 
   257 
   136 
   258 
   137       template <typename _Graph>
   259     /// Concept check structure for BaseGraph.
   138       struct Constraints {
   260 
   139 	typedef typename _Graph::Node Node;
   261     /// Concept check structure for BaseGraph.
   140 	typedef typename _Graph::Edge Edge;
   262     ///
   141       
   263 
   142 	void constraints() {
   264     template <typename Graph>
   143 	  checkConcept<GraphItem<'n'>, Node>();
   265     struct BaseGraphComponentConcept {
   144 	  checkConcept<GraphItem<'e'>, Edge>();
   266       typedef typename Graph::Node Node;
   145 	  {
   267       typedef typename Graph::Edge Edge;
   146 	    Node n;
   268       
   147 	    Edge e;
   269       void constraints() {
   148 	    n = graph.source(e);
   270 	function_requires< GraphItemConcept<Node> >();
   149 	    n = graph.target(e);
   271 	function_requires< GraphItemConcept<Edge> >();
   150 	  }      
   272 	{
   151 	}
   273 	  Node n;
   152       
   274 	  Edge e;
   153 	const _Graph& graph;
   275 	  n = graph.source(e);
   154       };
   276 	  n = graph.target(e);
       
   277 	}      
       
   278       }
       
   279       
       
   280       const Graph& graph;
       
   281     };
   155     };
   282 
   156 
   283     /// An empty iterable base graph class.
   157     /// An empty iterable base graph class.
   284   
   158   
   285     /// This class provides beside the core graph features
   159     /// This class provides beside the core graph features
   338       /// Gives back the next of the Edges start from the given Node.
   212       /// Gives back the next of the Edges start from the given Node.
   339       
   213       
   340       /// Gives back the next of the Edges start from the given Node.
   214       /// Gives back the next of the Edges start from the given Node.
   341       ///     
   215       ///     
   342       void nextOut(Edge&) const {}
   216       void nextOut(Edge&) const {}
   343     };
   217 
   344 
   218 
   345 
   219       template <typename _Graph>
   346     /// Concept check structure for IterableBaseGraph.
   220       struct Constraints {
   347 
   221       
   348     /// Concept check structure for IterableBaseGraph.
   222 	void constraints() {
   349     ///
   223 	  checkConcept< BaseGraphComponent, _Graph >();
   350     template <typename Graph>
   224 	  typename _Graph::Node node;      
   351     struct BaseIterableGraphComponentConcept {
   225 	  typename _Graph::Edge edge;
   352       
   226 	  {
   353       void constraints() {
   227 	    graph.first(node);
   354 	function_requires< BaseGraphComponentConcept<Graph> >();
   228 	    graph.next(node);
   355 	typename Graph::Node node;      
   229 	  }
   356 	typename Graph::Edge edge;
   230 	  {
   357 	{
   231 	    graph.first(edge);
   358 	  graph.first(node);
   232 	    graph.next(edge);
   359 	  graph.next(node);
   233 	  }
   360 	}
   234 	  {
   361 	{
   235 	    graph.firstIn(edge, node);
   362 	  graph.first(edge);
   236 	    graph.nextIn(edge);
   363 	  graph.next(edge);
   237 	  }
   364 	}
   238 	  {
   365 	{
   239 	    graph.firstOut(edge, node);
   366 	  graph.firstIn(edge, node);
   240 	    graph.nextOut(edge);
   367 	  graph.nextIn(edge);
   241 	  }
   368 	}
   242 	}
   369 	{
   243 
   370 	  graph.firstOut(edge, node);
   244 	const _Graph& graph;
   371 	  graph.nextOut(edge);
   245       };
   372 	}
       
   373       }
       
   374 
       
   375       const Graph& graph;
       
   376     };
   246     };
   377 
   247 
   378     /// An empty idable base graph class.
   248     /// An empty idable base graph class.
   379   
   249   
   380     /// This class provides beside the core graph features
   250     /// This class provides beside the core graph features
   381     /// core id functions for the graph structure.
   251     /// core id functions for the graph structure.
   382     /// The most of the base graphs should be conform to this concept.
   252     /// The most of the base graphs should be conform to this concept.
   383     /// The id's are unique and immutable.
   253     /// The id's are unique and immutable.
   384 
       
   385     class IDableGraphComponent : virtual public BaseGraphComponent {
   254     class IDableGraphComponent : virtual public BaseGraphComponent {
   386     public:
   255     public:
   387 
   256 
   388       typedef BaseGraphComponent::Node Node;
   257       typedef BaseGraphComponent::Node Node;
   389       typedef BaseGraphComponent::Edge Edge;
   258       typedef BaseGraphComponent::Edge Edge;
   397       /// Gives back an unique integer id for the Edge. 
   266       /// Gives back an unique integer id for the Edge. 
   398 
   267 
   399       /// Gives back an unique integer id for the Edge. 
   268       /// Gives back an unique integer id for the Edge. 
   400       ///
   269       ///
   401       int id(const Edge&) const { return -1;}
   270       int id(const Edge&) const { return -1;}
   402     };
   271 
   403 
   272       template <typename _Graph>
   404 
   273       struct Constraints {
   405     /// Concept check structure for IdableBaseGraph.
   274 
   406 
   275 	void constraints() {
   407     /// Concept check structure for IdableBaseGraph.
   276 	  checkConcept< BaseGraphComponent, _Graph >();
   408     ///
   277 	  typename _Graph::Node node;
   409     template <typename Graph>
   278 	  int nid = graph.id(node);
   410     struct IDableGraphComponentConcept {
   279 	  nid = graph.id(node);
   411 
   280 	  typename _Graph::Edge edge;
   412       void constraints() {
   281 	  int eid = graph.id(edge);
   413 	function_requires< BaseGraphComponentConcept<Graph> >();
   282 	  eid = graph.id(edge);
   414 	typename Graph::Node node;
   283 	}
   415 	int nid = graph.id(node);
   284 
   416 	nid = graph.id(node);
   285 	const _Graph& graph;
   417 	typename Graph::Edge edge;
   286       };
   418 	int eid = graph.id(edge);
       
   419 	eid = graph.id(edge);
       
   420       }
       
   421 
       
   422       const Graph& graph;
       
   423     };
   287     };
   424 
   288 
   425 
   289 
   426     /// An empty max-idable base graph class.
   290     /// An empty max-idable base graph class.
   427   
   291   
   441       /// Gives back an integer greater or equal to the maximum Edge id. 
   305       /// Gives back an integer greater or equal to the maximum Edge id. 
   442 
   306 
   443       /// Gives back an integer greater or equal to the maximum Edge id. 
   307       /// Gives back an integer greater or equal to the maximum Edge id. 
   444       ///
   308       ///
   445       int maxId(Edge = INVALID) const { return -1;}
   309       int maxId(Edge = INVALID) const { return -1;}
   446     };
   310 
   447 
   311       template <typename _Graph>
   448     /// Concept check structure for MaxIdableBaseGraph.
   312       struct Constraints {
   449 
   313 
   450     /// Concept check structure for MaxIdableBaseGraph.
   314 	void constraints() {
   451     ///
   315 	  checkConcept<BaseGraphComponent, _Graph>();
   452     template <typename Graph>
   316 	  int nid = graph.maxId(typename _Graph::Node());
   453     struct MaxIDableGraphComponentConcept {
   317 	  ignore_unused_variable_warning(nid);
   454 
   318 	  int eid = graph.maxId(typename _Graph::Edge());
   455       void constraints() {
   319 	  ignore_unused_variable_warning(eid);
   456 	function_requires< BaseGraphComponentConcept<Graph> >();
   320 	}
   457 	int nid = graph.maxId(typename Graph::Node());
   321       
   458 	ignore_unused_variable_warning(nid);
   322 	const _Graph& graph;
   459 	int eid = graph.maxId(typename Graph::Edge());
   323       };
   460 	ignore_unused_variable_warning(eid);
       
   461       }
       
   462 
       
   463       const Graph& graph;
       
   464     };
   324     };
   465 
   325 
   466     /// An empty extendable base graph class.
   326     /// An empty extendable base graph class.
   467   
   327   
   468     /// This class provides beside the core graph features
   328     /// This class provides beside the core graph features
   488       ///
   348       ///
   489       Edge addEdge(const Node& from, const Node& to) {
   349       Edge addEdge(const Node& from, const Node& to) {
   490 	return INVALID;
   350 	return INVALID;
   491       }
   351       }
   492 
   352 
   493     };
   353       template <typename _Graph>
   494 
   354       struct Constraints {
   495     /// Concept check structure for ExtendableBaseGraph.
   355 	void constraints() {
   496 
   356 	  checkConcept<BaseGraphComponent, _Graph >();
   497     /// Concept check structure for ExtendableBaseGraph.
   357 	  typename _Graph::Node node_a, node_b;
   498     ///
   358 	  node_a = graph.addNode();
   499     template <typename Graph>
   359 	  typename _Graph::Edge edge;
   500     struct BaseExtendableGraphComponentConcept {
   360 	  edge = graph.addEdge(node_a, node_b);
   501       void constraints() {
   361 	}
   502 	function_requires< BaseGraphComponentConcept<Graph> >();
   362 
   503 	typename Graph::Node node_a, node_b;
   363 	_Graph& graph;
   504 	node_a = graph.addNode();
   364       };
   505 	typename Graph::Edge edge;
       
   506 	edge = graph.addEdge(node_a, node_b);
       
   507       }
       
   508 
       
   509       Graph& graph;
       
   510     };
   365     };
   511 
   366 
   512     /// An empty erasable base graph class.
   367     /// An empty erasable base graph class.
   513   
   368   
   514     /// This class provides beside the core graph features
   369     /// This class provides beside the core graph features
   530 
   385 
   531       /// Erase an Edge from the graph.
   386       /// Erase an Edge from the graph.
   532       ///
   387       ///
   533       void erase(const Edge&) {}
   388       void erase(const Edge&) {}
   534 
   389 
   535     };
   390       template <typename _Graph>
   536 
   391       struct Constraints {
   537     /// Concept check structure for ErasableBaseGraph.
   392 	void constraints() {
   538 
   393 	  checkConcept<BaseGraphComponent, _Graph>();
   539     /// Concept check structure for ErasableBaseGraph.
   394 	  typename _Graph::Node node;
   540     ///
   395 	  graph.erase(node);
   541     template <typename Graph>
   396 	  typename _Graph::Edge edge;
   542     struct BaseErasableGraphComponentConcept {
   397 	  graph.erase(edge);
   543       void constraints() {
   398 	}
   544 	function_requires< BaseGraphComponentConcept<Graph> >();
   399 
   545 	typename Graph::Node node;
   400 	_Graph& graph;
   546 	graph.erase(node);
   401       };
   547 	typename Graph::Edge edge;
       
   548 	graph.erase(edge);
       
   549       }
       
   550 
       
   551       Graph& graph;
       
   552     };
   402     };
   553 
   403 
   554     /// An empty clearable base graph class.
   404     /// An empty clearable base graph class.
   555   
   405   
   556     /// This class provides beside the core graph features
   406     /// This class provides beside the core graph features
   562       /// Erase all the Nodes and Edges from the graph.
   412       /// Erase all the Nodes and Edges from the graph.
   563 
   413 
   564       /// Erase all the Nodes and Edges from the graph.
   414       /// Erase all the Nodes and Edges from the graph.
   565       ///
   415       ///
   566       void clear() {}    
   416       void clear() {}    
   567     };
   417 
   568 
   418       template <typename _Graph>
   569     /// Concept check function for ErasableBaseGraph.
   419       struct Constraints {
   570 
   420 	void constraints() {
   571     /// Concept check function for ErasableBaseGraph.
   421 	  checkConcept< BaseGraphComponent, _Graph>();
       
   422 	  graph.clear();
       
   423 	}
       
   424 
       
   425 	_Graph& graph;
       
   426       };
       
   427     };
       
   428 
       
   429 
       
   430     /// Skeleton class for graph NodeIt and EdgeIt
       
   431 
       
   432     /// Skeleton class for graph NodeIt and EdgeIt.
   572     ///
   433     ///
   573     template <typename Graph>
   434     template <typename _Graph, typename _Item>
   574     struct BaseClearableGraphComponentConcept {
   435     class GraphIterator : public _Item {
   575       void constraints() {
   436     public:
   576 	function_requires< BaseGraphComponentConcept<Graph> >();
   437       /// \todo Don't we need the Item type as typedef?
   577 	graph.clear();
   438 
   578       }
   439       /// Default constructor.
   579 
   440       
   580       Graph& graph;
   441       /// @warning The default constructor sets the iterator
   581     };
   442       /// to an undefined value.
   582 
   443       GraphIterator() {}
   583 
   444       /// Copy constructor.
   584     class IterableGraphComponent :
   445       
   585       virtual public BaseIterableGraphComponent {
   446       /// Copy constructor.
       
   447       ///
       
   448       GraphIterator(GraphIterator const&) {}
       
   449       /// Sets the iterator to the first item.
       
   450       
       
   451       /// Sets the iterator to the first item of \c the graph.
       
   452       ///
       
   453       explicit GraphIterator(const _Graph&) {}
       
   454       /// Invalid constructor \& conversion.
       
   455 
       
   456       /// This constructor initializes the item to be invalid.
       
   457       /// \sa Invalid for more details.
       
   458       GraphIterator(Invalid) {}
       
   459       /// Assign operator for items.
       
   460 
       
   461       /// The items are assignable. 
       
   462       ///
       
   463       GraphIterator& operator=(GraphIterator const&) { return *this; }      
       
   464       /// Next item.
       
   465 
       
   466       /// Assign the iterator to the next item.
       
   467       ///
       
   468       GraphIterator& operator++() { return *this; }
       
   469       //	Node operator*() const { return INVALID; }
       
   470       /// Equality operator
       
   471 
       
   472       /// Two iterators are equal if and only if they point to the
       
   473       /// same object or both are invalid.
       
   474       bool operator==(const GraphIterator&) const { return true;}
       
   475       /// Inequality operator
       
   476 	
       
   477       /// \sa operator==(Node n)
       
   478       ///
       
   479       bool operator!=(const GraphIterator&) const { return true;}
       
   480       
       
   481       template<typename _GraphIterator>
       
   482       struct Constraints {
       
   483 	void constraints() {
       
   484 	  //	  checkConcept< Item, _GraphIterator >();
       
   485 	  _GraphIterator it1(g);
       
   486 	
       
   487 	  /// \todo Do we need NodeIt(Node) kind of constructor?
       
   488 	  //	_GraphIterator it2(bj);
       
   489 	  _GraphIterator it2;
       
   490 
       
   491 	  it2 = ++it1;
       
   492 	  ++it2 = it1;
       
   493 	  ++(++it1);
       
   494 	  /// \bug This should be: is_base_and_derived<BaseItem, _GraphIterator>
       
   495 	  _Item bi = it1;
       
   496 	  bi = it2;
       
   497 	}
       
   498 	_Graph& g;
       
   499       };
       
   500     };
       
   501 
       
   502     /// Skeleton class for graph InEdgeIt and OutEdgeIt
       
   503 
       
   504     /// \note Because InEdgeIt and OutEdgeIt may not inherit from the same
       
   505     /// base class, the _selector is a additional template parameter. For 
       
   506     /// InEdgeIt you should instantiate it with character 'i' and for 
       
   507     /// OutEdgeIt with 'o'.
       
   508     /// \todo check the name of the concept GraphIncEdgeIterator
       
   509     template <typename _Graph, char _selector>
       
   510     class GraphIncEdgeIterator : public _Graph::Edge {
       
   511     public:
       
   512       /// Default constructor.
       
   513       
       
   514       /// @warning The default constructor sets the iterator
       
   515       /// to an undefined value.
       
   516       GraphIncEdgeIterator() {}
       
   517       /// Copy constructor.
       
   518       
       
   519       /// Copy constructor.
       
   520       ///
       
   521       GraphIncEdgeIterator(GraphIncEdgeIterator const&) {}
       
   522       /// Sets the iterator to the first edge incoming into or outgoing from the node.
       
   523       
       
   524       /// Sets the iterator to the first edge incoming into or outgoing from the node.
       
   525       ///
       
   526       explicit GraphIncEdgeIterator(const _Graph&, const typename _Graph::Node&) {}
       
   527       /// Invalid constructor \& conversion.
       
   528 
       
   529       /// This constructor initializes the item to be invalid.
       
   530       /// \sa Invalid for more details.
       
   531       GraphIncEdgeIterator(Invalid) {}
       
   532       /// Assign operator for nodes.
       
   533 
       
   534       /// The nodes are assignable. 
       
   535       ///
       
   536       GraphIncEdgeIterator& operator=(GraphIncEdgeIterator const&) { return *this; }      
       
   537       /// Next edge.
       
   538 
       
   539       /// Assign the iterator to the next node.
       
   540       ///
       
   541       GraphIncEdgeIterator& operator++() { return *this; }
       
   542       //	Node operator*() const { return INVALID; }
       
   543       /// Equality operator
       
   544 
       
   545       /// Two iterators are equal if and only if they point to the
       
   546       /// same object or both are invalid.
       
   547       bool operator==(const GraphIncEdgeIterator&) const { return true;}
       
   548       /// Inequality operator
       
   549 	
       
   550       /// \sa operator==(Node n)
       
   551       ///
       
   552       bool operator!=(const GraphIncEdgeIterator&) const { return true;}
       
   553 
       
   554       template <typename _GraphIncEdgeIterator>
       
   555       struct Constraints {
       
   556 	typedef typename _Graph::Node Node;
       
   557 	typedef typename _Graph::Edge Edge;
       
   558 	void constraints() {
       
   559 	  checkConcept<GraphItem<'e'>, _GraphIncEdgeIterator>();
       
   560 	  _GraphIncEdgeIterator it1(graph, node);
       
   561 	  /// \todo Do we need OutEdgeIt(Edge) kind of constructor?
       
   562 	  //	_GraphIncEdgeIterator it2(edge);
       
   563 	  _GraphIncEdgeIterator it2;
       
   564 
       
   565 	  it2 = ++it1;
       
   566 	  ++it2 = it1;
       
   567 	  ++(++it1);
       
   568 	  Edge e = it1;
       
   569 	  e = it2;
       
   570 	}
       
   571 
       
   572 	Edge& edge;
       
   573 	Node& node;
       
   574 	_Graph& graph;
       
   575       };
       
   576     };
       
   577     /// An empty iterable base graph class.
       
   578   
       
   579     /// This class provides beside the core graph features
       
   580     /// iterator based iterable interface for the graph structure.
       
   581     /// This concept is part of the StaticGraphConcept.
       
   582     class IterableGraphComponent : virtual public BaseGraphComponent {
   586 
   583 
   587     public:
   584     public:
   588     
   585     
   589       typedef IterableGraphComponent Graph;
   586       typedef IterableGraphComponent Graph;
   590 
   587 
   591       typedef BaseGraphComponent::Node Node;
   588       typedef BaseGraphComponent::Node Node;
   592       typedef BaseGraphComponent::Edge Edge;
   589       typedef BaseGraphComponent::Edge Edge;
   593 
   590 
   594       class NodeIt : public Node {
   591       /// This iterator goes through each node.
   595       public:
   592 
   596 	NodeIt() {}
   593       /// This iterator goes through each node.
   597 	NodeIt(Invalid) {}
   594       ///
   598 	// explicit NodeIt(Node) {}
   595       typedef GraphIterator<Graph, Node> NodeIt;
   599 	explicit NodeIt(const Graph&) {}
   596       /// This iterator goes through each node.
   600 
   597 
   601 	NodeIt& operator++() { return *this; }
   598       /// This iterator goes through each node.
   602 	//	Node operator*() const { return INVALID; }
   599       ///
   603 
   600       typedef GraphIterator<Graph, Edge> EdgeIt;
   604 	bool operator==(const NodeIt&) const { return true;}
   601       /// This iterator goes trough the incoming edges of a node.
   605 	bool operator!=(const NodeIt&) const { return true;}
   602 
   606       };
   603       /// This iterator goes trough the \e inccoming edges of a certain node
   607 
   604       /// of a graph.
   608       class EdgeIt : public Edge {
   605       typedef GraphIncEdgeIterator<Graph, 'i'> InEdgeIt;
   609       public:
   606       /// This iterator goes trough the outgoing edges of a node.
   610 	EdgeIt() {}
   607 
   611 	EdgeIt(Invalid) {}
   608       /// This iterator goes trough the \e outgoing edges of a certain node
   612 	// explicit EdgeIt(Edge) {}
   609       /// of a graph.
   613 	explicit EdgeIt(const Graph&) {}
   610       typedef GraphIncEdgeIterator<Graph, 'o'> OutEdgeIt;
   614 
       
   615 	EdgeIt& operator++() { return *this; }
       
   616 	//	Edge operator*() const { return INVALID; }
       
   617 
       
   618 	bool operator==(const EdgeIt&) const { return true;}
       
   619 	bool operator!=(const EdgeIt&) const { return true;}
       
   620       };
       
   621 
       
   622       class InEdgeIt : public Edge {
       
   623       public:
       
   624 	InEdgeIt() {}
       
   625 	InEdgeIt(Invalid) {}
       
   626 	// explicit InEdgeIt(Edge) {}
       
   627 	explicit InEdgeIt(const Graph&, const Node&) {}
       
   628 
       
   629 	InEdgeIt& operator++() { return *this; }
       
   630 	//	Edge operator*() const { return INVALID; }
       
   631 
       
   632 	bool operator==(const InEdgeIt&) const { return true;}
       
   633 	bool operator!=(const InEdgeIt&) const { return true;}
       
   634       };
       
   635 
       
   636       class OutEdgeIt : public Edge {
       
   637       public:
       
   638 	OutEdgeIt() {}
       
   639 	OutEdgeIt(Invalid) {}
       
   640 	// explicit OutEdgeIt(Edge) {}
       
   641 	explicit OutEdgeIt(const Graph&, const Node&) {}
       
   642 
       
   643 	OutEdgeIt& operator++() { return *this; }
       
   644 	//	Edge operator*() const { return INVALID; }
       
   645 
       
   646 	bool operator==(const OutEdgeIt&) const { return true;}
       
   647 	bool operator!=(const OutEdgeIt&) const { return true;}
       
   648       };
       
   649 
       
   650     };
   611     };
   651     
   612     
   652     template <typename Graph> 
   613     template <typename _Graph> 
   653     struct IterableGraphComponentConcept {
   614     struct Constraints {
   654       void constraints() {
   615       void constraints() {
   655   	function_requires< BaseIterableGraphComponentConcept<Graph> >();
   616   	checkConcept< BaseGraphComponent, _Graph>();
   656 
   617 
   657 	typedef typename Graph::Node Node;
   618 	checkConcept<GraphIterator<_Graph, typename _Graph::Edge>, typename _Graph::EdgeIt >();
   658 	typedef typename Graph::NodeIt NodeIt;
   619 	checkConcept<GraphIterator<_Graph, typename _Graph::Node>, typename _Graph::NodeIt >();
   659 	typedef typename Graph::Edge Edge;
   620 	checkConcept<GraphIncEdgeIterator<_Graph, 'i'>, typename _Graph::InEdgeIt >();
   660 	typedef typename Graph::EdgeIt EdgeIt;
   621 	checkConcept<GraphIncEdgeIterator<_Graph, 'o'>, typename _Graph::OutEdgeIt >();
   661 	typedef typename Graph::InEdgeIt InEdgeIt;
   622       }
   662 	typedef typename Graph::OutEdgeIt OutEdgeIt;
   623     };
       
   624 
       
   625 
       
   626     template <typename Graph, typename Item, typename _Value>
       
   627     class GraphMap : public ReadWriteMap<Item, _Value> {
       
   628     protected:      
       
   629       GraphMap() {}
       
   630     public:
       
   631       explicit GraphMap(const Graph&) {}
       
   632       GraphMap(const Graph&, const _Value&) {}
       
   633       GraphMap(const GraphMap&) {}
       
   634       
       
   635       GraphMap& operator=(const GraphMap&) { return *this;}
       
   636 
       
   637       template<typename _Map>
       
   638       struct Constraints {
       
   639 	void constraints() {
       
   640 	  checkConcept<ReadWriteMap<Item, _Value>, _Map >();
       
   641 	  // Construction with a graph parameter
       
   642 	  _Map a(g);
       
   643 	  // Constructor with a graph and a default value parameter
       
   644 	  _Map a2(g,t);
       
   645 	  // Copy constructor. Do we need it?
       
   646 	  _Map b=c;
       
   647 	  // Copy operator. Do we need it?
       
   648 	  a=b;
       
   649 
       
   650 	  ignore_unused_variable_warning(a2);
       
   651 	}
       
   652 
       
   653 	const _Map &c;
       
   654 	const Graph &g;
       
   655 	const typename GraphMap::Value &t;
       
   656       };
       
   657 
       
   658     };
       
   659 
       
   660     /// An empty mappable base graph class.
   663   
   661   
   664 	function_requires< GraphIteratorConcept<NodeIt, Graph, Node> >();
   662     /// This class provides beside the core graph features
   665 	function_requires< GraphIteratorConcept<EdgeIt, Graph, Edge> >();
   663     /// map interface for the graph structure.
   666 	function_requires< GraphIncIteratorConcept<OutEdgeIt, Graph> >();
   664     /// This concept is part of the StaticGraphConcept.
   667 	function_requires< GraphIncIteratorConcept<InEdgeIt, Graph> >();
       
   668       }
       
   669     };
       
   670 
       
   671 
       
   672     class MappableGraphComponent : virtual public BaseGraphComponent {
   665     class MappableGraphComponent : virtual public BaseGraphComponent {
   673     public:
   666     public:
   674 
   667 
   675       typedef MappableGraphComponent Graph;
   668       typedef MappableGraphComponent Graph;
   676 
   669 
   677       typedef BaseGraphComponent::Node Node;
   670       typedef BaseGraphComponent::Node Node;
   678       typedef BaseGraphComponent::Edge Edge;
   671       typedef BaseGraphComponent::Edge Edge;
   679 
   672 
       
   673       /// ReadWrite map of the nodes.
       
   674     
       
   675       /// ReadWrite map of the nodes.
       
   676       ///
   680       template <typename _Value>
   677       template <typename _Value>
   681       class NodeMap : public ReferenceMap<Node, _Value> {
   678       class NodeMap : public GraphMap<Graph, Node, _Value> {
       
   679       private:
       
   680 	NodeMap();
   682       public:
   681       public:
   683 	NodeMap(const Graph&) {}
   682 	// \todo call the right parent class constructor
       
   683 	explicit NodeMap(const Graph&) {}
   684 	NodeMap(const Graph&, const _Value&) {}
   684 	NodeMap(const Graph&, const _Value&) {}
   685 	NodeMap(const NodeMap&) {}
   685 	NodeMap(const NodeMap&) {}
   686 
   686 
   687 	NodeMap& operator=(const NodeMap&) { return *this;}
   687 	NodeMap& operator=(const NodeMap&) { return *this;}
   688 	
   688 
   689       };
   689       };
   690 
   690 
       
   691       /// ReadWrite map of the edges.
       
   692     
       
   693       /// ReadWrite map of the edges.
       
   694       ///
   691       template <typename _Value>
   695       template <typename _Value>
   692       class EdgeMap : public ReferenceMap<Edge, _Value> {
   696       class EdgeMap : public GraphMap<Graph, Edge, _Value> {
       
   697       private:
       
   698 	EdgeMap();
   693       public:
   699       public:
   694 	EdgeMap(const Graph&) {}
   700 	// \todo call the right parent class constructor
       
   701 	explicit EdgeMap(const Graph&) {}
   695 	EdgeMap(const Graph&, const _Value&) {}
   702 	EdgeMap(const Graph&, const _Value&) {}
   696 	EdgeMap(const EdgeMap&) {}
   703 	EdgeMap(const EdgeMap&) {}
   697 
   704 
   698 	EdgeMap& operator=(const EdgeMap&) { return *this;}
   705 	EdgeMap& operator=(const EdgeMap&) { return *this;}
   699 	
   706 
   700       };
   707       };
   701 
   708 
   702     };
   709       template <typename _Graph>
   703 
   710       struct Constraints {
   704     template <typename Graph>
   711 
   705     struct MappableGraphComponentConcept {
   712 	struct Type {
   706 
   713 	  int value;
   707       struct Type {
   714 	  Type() : value(0) {}
   708 	int value;
   715 	  Type(int _v) : value(_v) {}
   709 	Type() : value(0) {}
   716 	};
   710 	Type(int _v) : value(_v) {}
   717 
   711       };
   718 	void constraints() {
   712 
   719 	  checkConcept<BaseGraphComponent, _Graph>();
   713       void constraints() {
   720 	  { // int map test
   714 	function_requires< BaseGraphComponentConcept<Graph> >();
   721 	    typedef typename _Graph::template NodeMap<int> IntNodeMap;
   715 	{ // int map test
   722 	    checkConcept<GraphMap<_Graph, typename _Graph::Node, int>, IntNodeMap >();
   716 	  typedef typename Graph::template NodeMap<int> IntNodeMap;
   723 	  } { // bool map test
   717 	  function_requires<GraphMapConcept<IntNodeMap,Graph> >();
   724 	    typedef typename _Graph::template NodeMap<bool> BoolNodeMap;
   718 	} { // bool map test
   725 	    checkConcept<GraphMap<_Graph, typename _Graph::Node, bool>, BoolNodeMap >();
   719 	  typedef typename Graph::template NodeMap<bool> BoolNodeMap;
   726 	  } { // Type map test
   720 	  function_requires<GraphMapConcept<BoolNodeMap,Graph> >();
   727 	    typedef typename _Graph::template NodeMap<Type> TypeNodeMap;
   721 	} { // Type map test
   728 	    checkConcept<GraphMap<_Graph, typename _Graph::Node, Type>, TypeNodeMap >();
   722 	  typedef typename Graph::template NodeMap<Type> TypeNodeMap;
   729 	  } 
   723 	  function_requires<GraphMapConcept<TypeNodeMap,Graph> >();
   730 
   724 	} 
   731 	  { // int map test
   725 
   732 	    typedef typename _Graph::template EdgeMap<int> IntEdgeMap;
   726 	{ // int map test
   733 	    checkConcept<GraphMap<_Graph, typename _Graph::Edge, int>, IntEdgeMap >();
   727 	  typedef typename Graph::template EdgeMap<int> IntEdgeMap;
   734 	  } { // bool map test
   728 	  function_requires<GraphMapConcept<IntEdgeMap,Graph> >();
   735 	    typedef typename _Graph::template EdgeMap<bool> BoolEdgeMap;
   729 	} { // bool map test
   736 	    checkConcept<GraphMap<_Graph, typename _Graph::Edge, bool>, BoolEdgeMap >();
   730 	  typedef typename Graph::template EdgeMap<bool> BoolEdgeMap;
   737 	  } { // Type map test
   731 	  function_requires<GraphMapConcept<BoolEdgeMap,Graph> >();
   738 	    typedef typename _Graph::template EdgeMap<Type> TypeEdgeMap;
   732 	} { // Type map test
   739 	    checkConcept<GraphMap<_Graph, typename _Graph::Edge, Type>, TypeEdgeMap >();
   733 	  typedef typename Graph::template EdgeMap<Type> TypeEdgeMap;
   740 	  } 
   734 	  function_requires<GraphMapConcept<TypeEdgeMap,Graph> >();
   741 	}
   735 	} 
   742 
   736       }
   743 	_Graph& graph;
   737 
   744       };
   738       Graph& graph;
       
   739     };
   745     };
   740 
   746 
   741 
   747 
   742     class ExtendableGraphComponent : virtual public BaseGraphComponent {
   748     class ExtendableGraphComponent : virtual public BaseGraphComponent {
   743     public:
   749     public:
   753     
   759     
   754       Edge addEdge(const Node& from, const Node& to) {
   760       Edge addEdge(const Node& from, const Node& to) {
   755 	return INVALID;
   761 	return INVALID;
   756       }
   762       }
   757 
   763 
   758     };
   764       template <typename _Graph>
   759 
   765       struct Constraints {
   760     template <typename Graph>
   766 	void constraints() {
   761     struct ExtendableGraphComponentConcept {
   767 	  checkConcept<BaseGraphComponent, _Graph >();
   762       void constraints() {
   768 	  typename _Graph::Node node_a, node_b;
   763 	function_requires< BaseGraphComponentConcept<Graph> >();
   769 	  node_a = graph.addNode();
   764 	typename Graph::Node node_a, node_b;
   770 	  typename _Graph::Edge edge;
   765 	node_a = graph.addNode();
   771 	  edge = graph.addEdge(node_a, node_b);      
   766 	typename Graph::Edge edge;
   772 	}
   767 	edge = graph.addEdge(node_a, node_b);      
   773 	_Graph& graph;
   768       }
   774       };
   769       Graph& graph;
   775     };
   770     };
       
   771 
       
   772     class ErasableGraphComponent : virtual public BaseGraphComponent {
   776     class ErasableGraphComponent : virtual public BaseGraphComponent {
   773     public:
   777     public:
   774 
   778 
   775       typedef ErasableGraphComponent Graph;
   779       typedef ErasableGraphComponent Graph;
   776 
   780 
   778       typedef BaseGraphComponent::Edge Edge;
   782       typedef BaseGraphComponent::Edge Edge;
   779 
   783 
   780       void erase(const Node&) {}    
   784       void erase(const Node&) {}    
   781       void erase(const Edge&) {}
   785       void erase(const Edge&) {}
   782 
   786 
   783     };
   787       template <typename _Graph>
   784 
   788       struct Constraints {
   785     template <typename Graph>
   789 	void constraints() {
   786     struct ErasableGraphComponentConcept {
   790 	  checkConcept<BaseGraphComponent, _Graph >();
   787       void constraints() {
   791 	  typename _Graph::Node node;
   788 	function_requires< BaseGraphComponentConcept<Graph> >();
   792 	  graph.erase(node);
   789 	typename Graph::Node node;
   793 	  typename _Graph::Edge edge;
   790 	graph.erase(node);
   794 	  graph.erase(edge);      
   791 	typename Graph::Edge edge;
   795 	}
   792 	graph.erase(edge);      
   796 
   793       }
   797 	_Graph& graph;
   794 
   798       };
   795       Graph& graph;
       
   796     };
   799     };
   797 
   800 
   798     class ClearableGraphComponent : virtual public BaseGraphComponent {
   801     class ClearableGraphComponent : virtual public BaseGraphComponent {
   799     public:
   802     public:
   800 
   803 
   803       typedef BaseGraphComponent::Node Node;
   806       typedef BaseGraphComponent::Node Node;
   804       typedef BaseGraphComponent::Edge Edge;
   807       typedef BaseGraphComponent::Edge Edge;
   805 
   808 
   806       void clear() {}    
   809       void clear() {}    
   807 
   810 
   808     };
   811 
   809 
   812       template <typename _Graph>
   810     template <typename Graph>
   813       struct ClearableGraphComponentConcept {
   811     struct ClearableGraphComponentConcept {
   814 	void constraints() {
   812       void constraints() {
   815 	  checkConcept< BaseGraphComponent, _Graph >();
   813 	function_requires< BaseGraphComponentConcept<Graph> >();
   816 	  graph.clear();
   814 	graph.clear();
   817 	}
   815       }
   818 	_Graph& graph;
   816       Graph& graph;
   819       };
   817     };
   820     };
   818 
   821 
   819   }
   822   }
   820 
   823 
   821 }
   824 }