COIN-OR::LEMON - Graph Library

source: lemon-0.x/lemon/concept/graph_component.h @ 1993:2115143eceea

Last change on this file since 1993:2115143eceea was 1993:2115143eceea, checked in by Balazs Dezso, 14 years ago

utility, invalid and traits moved to bits

File size: 28.9 KB
Line 
1/* -*- C++ -*-
2 *
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
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
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
19///\ingroup graph_concepts
20///\file
21///\brief The graph components.
22
23
24#ifndef LEMON_CONCEPT_GRAPH_COMPONENT_H
25#define LEMON_CONCEPT_GRAPH_COMPONENT_H
26
27#include <lemon/bits/invalid.h>
28#include <lemon/concept/maps.h>
29
30#include <lemon/bits/alteration_notifier.h>
31
32namespace lemon {
33  namespace concept {
34
35    /****************   Graph iterator concepts   ****************/
36
37    /// Skeleton class for graph Node and Edge types
38
39    /// This class describes the interface of Node and Edge (and UEdge
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'.
47
48#ifndef DOXYGEN
49    template <char _selector = '0'>
50#endif
51    class GraphItem {
52    public:
53      /// Default constructor.
54     
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.
58      GraphItem() {}
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.
68      GraphItem(Invalid) {}
69      /// Assign operator for nodes.
70
71      /// The nodes are assignable.
72      ///
73      GraphItem& operator=(GraphItem const&) { return *this; }
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.
78      bool operator==(GraphItem) const { return false; }
79      /// Inequality operator.
80       
81      /// \sa operator==(const Node& n)
82      ///
83      bool operator!=(GraphItem) const { return false; }
84
85      /// Artificial ordering operator.
86
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; }
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);
110          //      b = (ia < ib);
111        }
112
113        const _GraphItem &ia;
114        const _GraphItem &ib;
115      };
116    };
117
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
133    /// An empty base graph class.
134 
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.
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      ///
151      typedef GraphItem<'n'> Node;
152
153      /// Edge class of the graph.
154
155      /// This class represents the Edges of the graph.
156      ///
157      typedef GraphItem<'e'> Edge;
158
159      ///Gives back the target node of an edge.
160
161      ///Gives back the target node of an edge.
162      ///
163      Node target(const Edge&) const { return INVALID;}
164
165      ///Gives back the source node of an edge.
166
167      ///Gives back the source node of an edge.
168      ///
169      Node source(const Edge&) const { return INVALID;}
170
171
172      template <typename _Graph>
173      struct Constraints {
174        typedef typename _Graph::Node Node;
175        typedef typename _Graph::Edge Edge;
176     
177        void constraints() {
178          checkConcept<GraphItem<'n'>, Node>();
179          checkConcept<GraphItem<'e'>, Edge>();
180          {
181            Node n;
182            Edge e(INVALID);
183            n = graph.source(e);
184            n = graph.target(e);
185          }     
186        }
187     
188        const _Graph& graph;
189      };
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
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        }
278
279        const _Graph& graph;
280      };
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
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.
306      Node fromId(int , Node) const { return INVALID;}
307
308      /// \brief Gives back an unique integer id for the Edge.
309      ///
310      /// Gives back an unique integer id for the Edge.
311      ///
312      int id(const Edge&) const { return -1;}
313
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.
319      Edge fromId(int, Edge) const { return INVALID;}
320
321      template <typename _Graph>
322      struct Constraints {
323
324        void constraints() {
325          checkConcept< BaseGraphComponent, _Graph >();
326          typename _Graph::Node node;
327          int nid = graph.id(node);
328          nid = graph.id(node);
329          node = graph.fromId(nid, Node());
330          typename _Graph::Edge edge;
331          int eid = graph.id(edge);
332          eid = graph.id(edge);
333          edge = graph.fromId(eid, Edge());
334        }
335
336        const _Graph& graph;
337      };
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      ///
354      int maxId(Node = INVALID) const { return -1;}
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      ///
360      int maxId(Edge = INVALID) const { return -1;}
361
362      template <typename _Graph>
363      struct Constraints {
364
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      };
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      ///
400      Edge addEdge(const Node&, const Node&) {
401        return INVALID;
402      }
403
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();
410          node_b = graph.addNode();
411          typename _Graph::Edge edge;
412          edge = graph.addEdge(node_a, node_b);
413        }
414
415        _Graph& graph;
416      };
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
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        }
451
452        _Graph& graph;
453      };
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.
461    class ClearableGraphComponent : virtual public BaseGraphComponent {
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() {}   
469
470      template <typename _Graph>
471      struct Constraints {
472        void constraints() {
473          checkConcept<BaseGraphComponent, _Graph>();
474          graph.clear();
475        }
476
477        _Graph graph;
478      };
479    };
480
481
482    /// Skeleton class for graph NodeIt and EdgeIt
483
484    /// Skeleton class for graph NodeIt and EdgeIt.
485    ///
486    template <typename _Graph, typename _Item>
487    class GraphIterator : public _Item {
488    public:
489      /// \todo Don't we need the Item type as typedef?
490
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      };
552    };
553
554    /// Skeleton class for graph InEdgeIt and OutEdgeIt
555
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'.
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 {
565    public:
566      /// Default constructor.
567     
568      /// @warning The default constructor sets the iterator
569      /// to an undefined value.
570      GraphIncIterator() {}
571      /// Copy constructor.
572     
573      /// Copy constructor.
574      ///
575      GraphIncIterator(GraphIncIterator const& gi) :Edge(gi) {}
576      /// Sets the iterator to the first edge incoming into or outgoing
577      /// from the node.
578     
579      /// Sets the iterator to the first edge incoming into or outgoing
580      /// from the node.
581      ///
582      explicit GraphIncIterator(const Graph&, const typename Graph::Node&) {}
583      /// Invalid constructor \& conversion.
584
585      /// This constructor initializes the item to be invalid.
586      /// \sa Invalid for more details.
587      GraphIncIterator(Invalid) {}
588      /// Assign operator for nodes.
589
590      /// The nodes are assignable.
591      ///
592      GraphIncIterator& operator=(GraphIncIterator const&) { return *this; }     
593      /// Next edge.
594
595      /// Assign the iterator to the next node.
596      ///
597      GraphIncIterator& operator++() { return *this; }
598
599      //        Node operator*() const { return INVALID; }
600
601      /// Equality operator
602
603      /// Two iterators are equal if and only if they point to the
604      /// same object or both are invalid.
605      bool operator==(const GraphIncIterator&) const { return true;}
606
607      /// Inequality operator
608       
609      /// \sa operator==(Node n)
610      ///
611      bool operator!=(const GraphIncIterator&) const { return true;}
612
613      template <typename _GraphIncIterator>
614      struct Constraints {
615        typedef typename Graph::Node Node;
616        void constraints() {
617          checkConcept<GraphItem<'e'>, _GraphIncIterator>();
618          _GraphIncIterator it1(graph, node);
619          /// \todo Do we need OutEdgeIt(Edge) kind of constructor?
620          //    _GraphIncIterator it2(edge);
621          _GraphIncIterator it2;
622
623          it2 = ++it1;
624          ++it2 = it1;
625          ++(++it1);
626          Edge e = it1;
627          e = it2;
628
629          const_constraits();
630        }
631
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;
641      };
642    };
643
644
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 {
651
652    public:
653   
654      typedef IterableGraphComponent Graph;
655
656      typedef BaseGraphComponent::Node Node;
657      typedef BaseGraphComponent::Edge Edge;
658
659      /// This iterator goes through each node.
660
661      /// This iterator goes through each node.
662      ///
663      typedef GraphIterator<Graph, Node> NodeIt;
664      /// This iterator goes through each node.
665
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.
670
671      /// This iterator goes trough the \e inccoming edges of a certain node
672      /// of a graph.
673      typedef GraphIncIterator<Graph, Edge, 'i'> InEdgeIt;
674      /// This iterator goes trough the outgoing edges of a node.
675
676      /// This iterator goes trough the \e outgoing edges of a certain node
677      /// of a graph.
678      typedef GraphIncIterator<Graph, Edge, 'o'> OutEdgeIt;
679
680      /// \brief The base node of the iterator.
681      ///
682      /// Gives back the base node of the iterator.
683      /// It is always the target of the pointed edge.
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.
689      /// It is always the source of the pointed edge.
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.
695      /// It is always the source of the pointed edge.
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.
701      /// It is always the target of the pointed edge.
702      Node runningNode(const OutEdgeIt&) const { return INVALID; }
703
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
710   
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>();
722
723          typename _Graph::Node n(INVALID);
724          typename _Graph::Edge e(INVALID);
725          n = graph.oppositeNode(n, e);
726        }
727       
728        const _Graph& graph;
729       
730      };
731    };
732
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.
740    class AlterableGraphComponent : virtual public BaseGraphComponent {
741    public:
742
743      /// The edge observer registry.
744      typedef AlterationNotifier<Edge> EdgeNotifier;
745      /// The node observer registry.
746      typedef AlterationNotifier<Node> NodeNotifier;
747     
748      /// \brief Gives back the edge alteration notifier.
749      ///
750      /// Gives back the edge alteration notifier.
751      EdgeNotifier getNotifier(Edge) const {
752        return EdgeNotifier();
753      }
754     
755      /// \brief Gives back the node alteration notifier.
756      ///
757      /// Gives back the node alteration notifier.
758      NodeNotifier getNotifier(Node) const {
759        return NodeNotifier();
760      }
761     
762    };
763
764
765    /// Class describing the concept of graph maps
766
767    /// This class describes the common interface of the graph maps
768    /// (NodeMap, EdgeMap), that is \ref maps-page "maps" which can be used to
769    /// associate data to graph descriptors (nodes or edges).
770    template <typename Graph, typename Item, typename _Value>
771    class GraphMap : public ReadWriteMap<Item, _Value> {
772    protected:     
773      GraphMap() {}
774    public:
775      /// \brief Construct a new map.
776      ///
777      /// Construct a new map for the graph.
778      explicit GraphMap(const Graph&) {}
779      /// \brief Construct a new map with default value.
780      ///
781      /// Construct a new map for the graph and initalise the values.
782      GraphMap(const Graph&, const _Value&) {}
783      /// \brief Copy constructor.
784      ///
785      /// Copy Constructor.
786      GraphMap(const GraphMap& gm) :ReadWriteMap<Item, _Value>(gm) {}
787     
788      /// \brief Assign operator.
789      ///
790      /// Assign operator.
791      GraphMap& operator=(const GraphMap&) { return *this;}
792
793      template<typename _Map>
794      struct Constraints {
795        void constraints() {
796          checkConcept<ReadWriteMap<Item, _Value>, _Map >();
797          // Construction with a graph parameter
798          _Map a(g);
799          // Constructor with a graph and a default value parameter
800          _Map a2(g,t);
801          // Copy constructor. Do we need it?
802          _Map b=c;
803
804          ignore_unused_variable_warning(a2);
805        }
806
807        const _Map &c;
808        const Graph &g;
809        const typename GraphMap::Value &t;
810      };
811
812    };
813
814    /// An empty mappable base graph class.
815 
816    /// This class provides beside the core graph features
817    /// map interface for the graph structure.
818    /// This concept is part of the StaticGraphConcept.
819    class MappableGraphComponent : virtual public BaseGraphComponent {
820    public:
821
822      typedef MappableGraphComponent Graph;
823
824      typedef BaseGraphComponent::Node Node;
825      typedef BaseGraphComponent::Edge Edge;
826
827      /// ReadWrite map of the nodes.
828   
829      /// ReadWrite map of the nodes.
830      ///
831      template <typename _Value>
832      class NodeMap : public GraphMap<Graph, Node, _Value> {
833      private:
834        NodeMap();
835      public:
836        /// \brief Construct a new map.
837        ///
838        /// Construct a new map for the graph.
839        /// \todo call the right parent class constructor
840        explicit NodeMap(const Graph&) {}
841        /// \brief Construct a new map with default value.
842        ///
843        /// Construct a new map for the graph and initalise the values.
844        NodeMap(const Graph&, const _Value&) {}
845        /// \brief Copy constructor.
846        ///
847        /// Copy Constructor.
848        NodeMap(const NodeMap& nm) : GraphMap<Graph, Node, _Value>(nm) {}
849
850        /// \brief Assign operator.
851        ///
852        /// Assign operator.
853        NodeMap& operator=(const NodeMap&) { return *this;}
854
855      };
856
857      /// ReadWrite map of the edges.
858   
859      /// ReadWrite map of the edges.
860      ///
861      template <typename _Value>
862      class EdgeMap : public GraphMap<Graph, Edge, _Value> {
863      private:
864        EdgeMap();
865      public:
866        /// \brief Construct a new map.
867        ///
868        /// Construct a new map for the graph.
869        /// \todo call the right parent class constructor
870        explicit EdgeMap(const Graph&) {}
871        /// \brief Construct a new map with default value.
872        ///
873        /// Construct a new map for the graph and initalise the values.
874        EdgeMap(const Graph&, const _Value&) {}
875        /// \brief Copy constructor.
876        ///
877        /// Copy Constructor.
878        EdgeMap(const EdgeMap& em) :GraphMap<Graph, Edge, _Value>(em) {}
879
880        /// \brief Assign operator.
881        ///
882        /// Assign operator.
883        EdgeMap& operator=(const EdgeMap&) { return *this;}
884
885      };
886
887      template <typename _Graph>
888      struct Constraints {
889
890        struct Type {
891          int value;
892          Type() : value(0) {}
893          Type(int _v) : value(_v) {}
894        };
895
896        void constraints() {
897          checkConcept<BaseGraphComponent, _Graph>();
898          { // int map test
899            typedef typename _Graph::template NodeMap<int> IntNodeMap;
900            checkConcept<GraphMap<_Graph, typename _Graph::Node, int>,
901              IntNodeMap >();
902          } { // bool map test
903            typedef typename _Graph::template NodeMap<bool> BoolNodeMap;
904            checkConcept<GraphMap<_Graph, typename _Graph::Node, bool>,
905              BoolNodeMap >();
906          } { // Type map test
907            typedef typename _Graph::template NodeMap<Type> TypeNodeMap;
908            checkConcept<GraphMap<_Graph, typename _Graph::Node, Type>,
909              TypeNodeMap >();
910          }
911
912          { // int map test
913            typedef typename _Graph::template EdgeMap<int> IntEdgeMap;
914            checkConcept<GraphMap<_Graph, typename _Graph::Edge, int>,
915              IntEdgeMap >();
916          } { // bool map test
917            typedef typename _Graph::template EdgeMap<bool> BoolEdgeMap;
918            checkConcept<GraphMap<_Graph, typename _Graph::Edge, bool>,
919              BoolEdgeMap >();
920          } { // Type map test
921            typedef typename _Graph::template EdgeMap<Type> TypeEdgeMap;
922            checkConcept<GraphMap<_Graph, typename _Graph::Edge, Type>,
923              TypeEdgeMap >();
924          }
925        }
926
927        _Graph& graph;
928      };
929    };
930
931    /// \brief An empty extendable extended graph class.
932    ///
933    /// This class provides beside the core graph features
934    /// item addition interface for the graph structure.
935    /// The difference between this class and the
936    /// \c BaseExtendableGraphComponent is that it should
937    /// notify the item alteration observers.
938    class ExtendableGraphComponent : virtual public BaseGraphComponent {
939    public:
940
941      typedef ExtendableGraphComponent Graph;
942
943      typedef BaseGraphComponent::Node Node;
944      typedef BaseGraphComponent::Edge Edge;
945
946      /// \brief Add a node to the graph.
947      ///
948      /// Add a node to the graph and notify the observers.
949      Node addNode() {
950        return INVALID;
951      }
952   
953      /// \brief Add an edge to the graph.
954      ///
955      /// Add an edge to the graph and notify the observers.
956      Edge addEdge(const Node&, const Node&) {
957        return INVALID;
958      }
959
960      template <typename _Graph>
961      struct Constraints {
962        void constraints() {
963          checkConcept<BaseGraphComponent, _Graph >();
964          typename _Graph::Node node_a, node_b;
965          node_a = graph.addNode();
966          node_b = graph.addNode();
967          typename _Graph::Edge edge;
968          edge = graph.addEdge(node_a, node_b);     
969        }
970        _Graph& graph;
971      };
972    };
973
974    /// \brief An empty erasable extended graph class.
975    ///
976    /// This class provides beside the core graph features
977    /// item erase interface for the graph structure.
978    /// The difference between this class and the
979    /// \c BaseErasableGraphComponent is that it should
980    /// notify the item alteration observers.
981    class ErasableGraphComponent : virtual public BaseGraphComponent {
982    public:
983
984      typedef ErasableGraphComponent Graph;
985
986      typedef BaseGraphComponent::Node Node;
987      typedef BaseGraphComponent::Edge Edge;
988
989      /// \brief Erase the Node and notify the node alteration observers.
990      ///
991      ///  Erase the Node and notify the node alteration observers.
992      void erase(const Node&) {}   
993
994      /// \brief Erase the Edge and notify the edge alteration observers.
995      ///
996      ///  Erase the Edge and notify the edge alteration observers.
997      void erase(const Edge&) {}
998
999      template <typename _Graph>
1000      struct Constraints {
1001        void constraints() {
1002          checkConcept<BaseGraphComponent, _Graph >();
1003          typename _Graph::Node node;
1004          graph.erase(node);
1005          typename _Graph::Edge edge;
1006          graph.erase(edge);     
1007        }
1008
1009        _Graph& graph;
1010      };
1011    };
1012
1013  }
1014
1015}
1016
1017#endif
Note: See TracBrowser for help on using the repository browser.