COIN-OR::LEMON - Graph Library

source: lemon-0.x/lemon/concept/graph_component.h @ 1999:2ff283124dfc

Last change on this file since 1999:2ff283124dfc was 1999:2ff283124dfc, checked in by Balazs Dezso, 18 years ago

Clarifing alteration observing system
It is directly connected now to a container

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