COIN-OR::LEMON - Graph Library

source: lemon-1.2/lemon/concepts/graph_components.h @ 969:7e368d9b67f7

Last change on this file since 969:7e368d9b67f7 was 969:7e368d9b67f7, checked in by Alpar Juttner <alpar@…>, 7 years ago

Avoid GCC 4.7 compiler warnings (#453)

File size: 48.6 KB
RevLine 
[209]1/* -*- mode: C++; indent-tabs-mode: nil; -*-
[57]2 *
[209]3 * This file is a part of LEMON, a generic C++ optimization library.
[57]4 *
[440]5 * Copyright (C) 2003-2009
[57]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 concept of graph components.
22
[529]23#ifndef LEMON_CONCEPTS_GRAPH_COMPONENTS_H
24#define LEMON_CONCEPTS_GRAPH_COMPONENTS_H
[57]25
[220]26#include <lemon/core.h>
[57]27#include <lemon/concepts/maps.h>
28
29#include <lemon/bits/alteration_notifier.h>
30
31namespace lemon {
32  namespace concepts {
33
[579]34    /// \brief Concept class for \c Node, \c Arc and \c Edge types.
[57]35    ///
[579]36    /// This class describes the concept of \c Node, \c Arc and \c Edge
37    /// subtypes of digraph and graph types.
[57]38    ///
39    /// \note This class is a template class so that we can use it to
[579]40    /// create graph skeleton classes. The reason for this is that \c Node
41    /// and \c Arc (or \c Edge) types should \e not derive from the same
42    /// base class. For \c Node you should instantiate it with character
43    /// \c 'n', for \c Arc with \c 'a' and for \c Edge with \c 'e'.
[57]44#ifndef DOXYGEN
[559]45    template <char sel = '0'>
[57]46#endif
47    class GraphItem {
48    public:
49      /// \brief Default constructor.
[209]50      ///
[579]51      /// Default constructor.
[57]52      /// \warning The default constructor is not required to set
53      /// the item to some well-defined value. So you should consider it
54      /// as uninitialized.
55      GraphItem() {}
[579]56
[57]57      /// \brief Copy constructor.
58      ///
59      /// Copy constructor.
[579]60      GraphItem(const GraphItem &) {}
61
62      /// \brief Constructor for conversion from \c INVALID.
[57]63      ///
[579]64      /// Constructor for conversion from \c INVALID.
65      /// It initializes the item to be invalid.
[57]66      /// \sa Invalid for more details.
67      GraphItem(Invalid) {}
[579]68
69      /// \brief Assignment operator.
[57]70      ///
[579]71      /// Assignment operator for the item.
72      GraphItem& operator=(const GraphItem&) { return *this; }
73
[666]74      /// \brief Assignment operator for INVALID.
75      ///
76      /// This operator makes the item invalid.
77      GraphItem& operator=(Invalid) { return *this; }
78
[57]79      /// \brief Equality operator.
80      ///
[579]81      /// Equality operator.
82      bool operator==(const GraphItem&) const { return false; }
83
[57]84      /// \brief Inequality operator.
85      ///
[579]86      /// Inequality operator.
87      bool operator!=(const GraphItem&) const { return false; }
88
89      /// \brief Ordering operator.
[57]90      ///
[579]91      /// This operator defines an ordering of the items.
92      /// It makes possible to use graph item types as key types in
93      /// associative containers (e.g. \c std::map).
[57]94      ///
95      /// \note This operator only have to define some strict ordering of
96      /// the items; this order has nothing to do with the iteration
97      /// ordering of the items.
[579]98      bool operator<(const GraphItem&) const { return false; }
[57]99
100      template<typename _GraphItem>
101      struct Constraints {
[209]102        void constraints() {
103          _GraphItem i1;
[666]104          i1=INVALID;
[209]105          _GraphItem i2 = i1;
106          _GraphItem i3 = INVALID;
[57]107
[209]108          i1 = i2 = i3;
109
110          bool b;
[969]111          ignore_unused_variable_warning(b);
112
[209]113          b = (ia == ib) && (ia != ib);
114          b = (ia == INVALID) && (ib != INVALID);
[57]115          b = (ia < ib);
[209]116        }
[57]117
[209]118        const _GraphItem &ia;
119        const _GraphItem &ib;
[953]120        Constraints() {}
[57]121      };
122    };
123
[579]124    /// \brief Base skeleton class for directed graphs.
[209]125    ///
[579]126    /// This class describes the base interface of directed graph types.
127    /// All digraph %concepts have to conform to this class.
128    /// It just provides types for nodes and arcs and functions
129    /// to get the source and the target nodes of arcs.
[57]130    class BaseDigraphComponent {
131    public:
132
133      typedef BaseDigraphComponent Digraph;
[209]134
[57]135      /// \brief Node class of the digraph.
136      ///
[579]137      /// This class represents the nodes of the digraph.
[57]138      typedef GraphItem<'n'> Node;
139
140      /// \brief Arc class of the digraph.
141      ///
[579]142      /// This class represents the arcs of the digraph.
143      typedef GraphItem<'a'> Arc;
144
145      /// \brief Return the source node of an arc.
[57]146      ///
[579]147      /// This function returns the source node of an arc.
148      Node source(const Arc&) const { return INVALID; }
[57]149
[579]150      /// \brief Return the target node of an arc.
[57]151      ///
[579]152      /// This function returns the target node of an arc.
153      Node target(const Arc&) const { return INVALID; }
154
155      /// \brief Return the opposite node on the given arc.
[57]156      ///
[579]157      /// This function returns the opposite node on the given arc.
[57]158      Node oppositeNode(const Node&, const Arc&) const {
159        return INVALID;
160      }
161
162      template <typename _Digraph>
163      struct Constraints {
[209]164        typedef typename _Digraph::Node Node;
165        typedef typename _Digraph::Arc Arc;
166
167        void constraints() {
168          checkConcept<GraphItem<'n'>, Node>();
169          checkConcept<GraphItem<'a'>, Arc>();
170          {
171            Node n;
172            Arc e(INVALID);
173            n = digraph.source(e);
174            n = digraph.target(e);
[57]175            n = digraph.oppositeNode(n, e);
[209]176          }
177        }
178
179        const _Digraph& digraph;
[953]180        Constraints() {}
[57]181      };
182    };
183
[579]184    /// \brief Base skeleton class for undirected graphs.
[209]185    ///
[579]186    /// This class describes the base interface of undirected graph types.
187    /// All graph %concepts have to conform to this class.
188    /// It extends the interface of \ref BaseDigraphComponent with an
189    /// \c Edge type and functions to get the end nodes of edges,
190    /// to convert from arcs to edges and to get both direction of edges.
[57]191    class BaseGraphComponent : public BaseDigraphComponent {
192    public:
[617]193
194      typedef BaseGraphComponent Graph;
195
[57]196      typedef BaseDigraphComponent::Node Node;
197      typedef BaseDigraphComponent::Arc Arc;
[579]198
199      /// \brief Undirected edge class of the graph.
[57]200      ///
[579]201      /// This class represents the undirected edges of the graph.
202      /// Undirected graphs can be used as directed graphs, each edge is
203      /// represented by two opposite directed arcs.
204      class Edge : public GraphItem<'e'> {
205        typedef GraphItem<'e'> Parent;
206
[617]207      public:
[57]208        /// \brief Default constructor.
[209]209        ///
[579]210        /// Default constructor.
[57]211        /// \warning The default constructor is not required to set
212        /// the item to some well-defined value. So you should consider it
213        /// as uninitialized.
214        Edge() {}
[579]215
[57]216        /// \brief Copy constructor.
217        ///
218        /// Copy constructor.
[579]219        Edge(const Edge &) : Parent() {}
220
221        /// \brief Constructor for conversion from \c INVALID.
[57]222        ///
[579]223        /// Constructor for conversion from \c INVALID.
224        /// It initializes the item to be invalid.
[57]225        /// \sa Invalid for more details.
226        Edge(Invalid) {}
[579]227
228        /// \brief Constructor for conversion from an arc.
[57]229        ///
[579]230        /// Constructor for conversion from an arc.
[57]231        /// Besides the core graph item functionality each arc should
[209]232        /// be convertible to the represented edge.
[57]233        Edge(const Arc&) {}
[666]234     };
[57]235
[579]236      /// \brief Return one end node of an edge.
237      ///
238      /// This function returns one end node of an edge.
239      Node u(const Edge&) const { return INVALID; }
240
241      /// \brief Return the other end node of an edge.
242      ///
243      /// This function returns the other end node of an edge.
244      Node v(const Edge&) const { return INVALID; }
245
246      /// \brief Return a directed arc related to an edge.
247      ///
248      /// This function returns a directed arc from its direction and the
249      /// represented edge.
250      Arc direct(const Edge&, bool) const { return INVALID; }
251
252      /// \brief Return a directed arc related to an edge.
253      ///
254      /// This function returns a directed arc from its source node and the
255      /// represented edge.
256      Arc direct(const Edge&, const Node&) const { return INVALID; }
257
258      /// \brief Return the direction of the arc.
[57]259      ///
260      /// Returns the direction of the arc. Each arc represents an
261      /// edge with a direction. It gives back the
262      /// direction.
263      bool direction(const Arc&) const { return true; }
264
[579]265      /// \brief Return the opposite arc.
[57]266      ///
[579]267      /// This function returns the opposite arc, i.e. the arc representing
268      /// the same edge and has opposite direction.
269      Arc oppositeArc(const Arc&) const { return INVALID; }
[209]270
[57]271      template <typename _Graph>
272      struct Constraints {
[209]273        typedef typename _Graph::Node Node;
274        typedef typename _Graph::Arc Arc;
275        typedef typename _Graph::Edge Edge;
276
277        void constraints() {
[57]278          checkConcept<BaseDigraphComponent, _Graph>();
[579]279          checkConcept<GraphItem<'e'>, Edge>();
[209]280          {
281            Node n;
282            Edge ue(INVALID);
[57]283            Arc e;
[209]284            n = graph.u(ue);
285            n = graph.v(ue);
[57]286            e = graph.direct(ue, true);
[579]287            e = graph.direct(ue, false);
[57]288            e = graph.direct(ue, n);
289            e = graph.oppositeArc(e);
290            ue = e;
291            bool d = graph.direction(e);
292            ignore_unused_variable_warning(d);
[209]293          }
294        }
295
296        const _Graph& graph;
[953]297      Constraints() {}
[57]298      };
299
300    };
301
[579]302    /// \brief Skeleton class for \e idable directed graphs.
[209]303    ///
[579]304    /// This class describes the interface of \e idable directed graphs.
305    /// It extends \ref BaseDigraphComponent with the core ID functions.
306    /// The ids of the items must be unique and immutable.
307    /// This concept is part of the Digraph concept.
[559]308    template <typename BAS = BaseDigraphComponent>
309    class IDableDigraphComponent : public BAS {
[57]310    public:
311
[559]312      typedef BAS Base;
[57]313      typedef typename Base::Node Node;
314      typedef typename Base::Arc Arc;
315
[579]316      /// \brief Return a unique integer id for the given node.
[57]317      ///
[579]318      /// This function returns a unique integer id for the given node.
319      int id(const Node&) const { return -1; }
320
321      /// \brief Return the node by its unique id.
[57]322      ///
[579]323      /// This function returns the node by its unique id.
324      /// If the digraph does not contain a node with the given id,
325      /// then the result of the function is undefined.
326      Node nodeFromId(int) const { return INVALID; }
[57]327
[579]328      /// \brief Return a unique integer id for the given arc.
[57]329      ///
[579]330      /// This function returns a unique integer id for the given arc.
331      int id(const Arc&) const { return -1; }
[57]332
[579]333      /// \brief Return the arc by its unique id.
[57]334      ///
[579]335      /// This function returns the arc by its unique id.
336      /// If the digraph does not contain an arc with the given id,
337      /// then the result of the function is undefined.
338      Arc arcFromId(int) const { return INVALID; }
339
340      /// \brief Return an integer greater or equal to the maximum
341      /// node id.
[57]342      ///
[579]343      /// This function returns an integer greater or equal to the
344      /// maximum node id.
345      int maxNodeId() const { return -1; }
[57]346
[579]347      /// \brief Return an integer greater or equal to the maximum
348      /// arc id.
[57]349      ///
[579]350      /// This function returns an integer greater or equal to the
351      /// maximum arc id.
352      int maxArcId() const { return -1; }
[57]353
354      template <typename _Digraph>
355      struct Constraints {
356
[209]357        void constraints() {
358          checkConcept<Base, _Digraph >();
359          typename _Digraph::Node node;
[666]360          node=INVALID;
[209]361          int nid = digraph.id(node);
362          nid = digraph.id(node);
363          node = digraph.nodeFromId(nid);
364          typename _Digraph::Arc arc;
[666]365          arc=INVALID;
[209]366          int eid = digraph.id(arc);
367          eid = digraph.id(arc);
368          arc = digraph.arcFromId(eid);
[57]369
[209]370          nid = digraph.maxNodeId();
371          ignore_unused_variable_warning(nid);
372          eid = digraph.maxArcId();
373          ignore_unused_variable_warning(eid);
374        }
[57]375
[209]376        const _Digraph& digraph;
[953]377        Constraints() {}
[57]378      };
379    };
380
[579]381    /// \brief Skeleton class for \e idable undirected graphs.
[209]382    ///
[579]383    /// This class describes the interface of \e idable undirected
384    /// graphs. It extends \ref IDableDigraphComponent with the core ID
385    /// functions of undirected graphs.
386    /// The ids of the items must be unique and immutable.
387    /// This concept is part of the Graph concept.
[559]388    template <typename BAS = BaseGraphComponent>
389    class IDableGraphComponent : public IDableDigraphComponent<BAS> {
[57]390    public:
391
[559]392      typedef BAS Base;
[57]393      typedef typename Base::Edge Edge;
394
[559]395      using IDableDigraphComponent<Base>::id;
[57]396
[579]397      /// \brief Return a unique integer id for the given edge.
[57]398      ///
[579]399      /// This function returns a unique integer id for the given edge.
400      int id(const Edge&) const { return -1; }
401
402      /// \brief Return the edge by its unique id.
[57]403      ///
[579]404      /// This function returns the edge by its unique id.
405      /// If the graph does not contain an edge with the given id,
406      /// then the result of the function is undefined.
407      Edge edgeFromId(int) const { return INVALID; }
[57]408
[579]409      /// \brief Return an integer greater or equal to the maximum
410      /// edge id.
[57]411      ///
[579]412      /// This function returns an integer greater or equal to the
413      /// maximum edge id.
414      int maxEdgeId() const { return -1; }
[57]415
416      template <typename _Graph>
417      struct Constraints {
418
[209]419        void constraints() {
420          checkConcept<IDableDigraphComponent<Base>, _Graph >();
421          typename _Graph::Edge edge;
422          int ueid = graph.id(edge);
423          ueid = graph.id(edge);
424          edge = graph.edgeFromId(ueid);
425          ueid = graph.maxEdgeId();
426          ignore_unused_variable_warning(ueid);
427        }
[57]428
[209]429        const _Graph& graph;
[953]430        Constraints() {}
[57]431      };
432    };
433
[579]434    /// \brief Concept class for \c NodeIt, \c ArcIt and \c EdgeIt types.
[57]435    ///
[579]436    /// This class describes the concept of \c NodeIt, \c ArcIt and
437    /// \c EdgeIt subtypes of digraph and graph types.
[559]438    template <typename GR, typename Item>
439    class GraphItemIt : public Item {
[57]440    public:
441      /// \brief Default constructor.
442      ///
[579]443      /// Default constructor.
444      /// \warning The default constructor is not required to set
445      /// the iterator to some well-defined value. So you should consider it
446      /// as uninitialized.
[57]447      GraphItemIt() {}
[579]448
[57]449      /// \brief Copy constructor.
450      ///
451      /// Copy constructor.
[579]452      GraphItemIt(const GraphItemIt& it) : Item(it) {}
453
454      /// \brief Constructor that sets the iterator to the first item.
[57]455      ///
[579]456      /// Constructor that sets the iterator to the first item.
457      explicit GraphItemIt(const GR&) {}
458
459      /// \brief Constructor for conversion from \c INVALID.
[57]460      ///
[579]461      /// Constructor for conversion from \c INVALID.
462      /// It initializes the iterator to be invalid.
[57]463      /// \sa Invalid for more details.
464      GraphItemIt(Invalid) {}
[579]465
466      /// \brief Assignment operator.
[57]467      ///
[579]468      /// Assignment operator for the iterator.
469      GraphItemIt& operator=(const GraphItemIt&) { return *this; }
470
471      /// \brief Increment the iterator.
[57]472      ///
[579]473      /// This operator increments the iterator, i.e. assigns it to the
474      /// next item.
[57]475      GraphItemIt& operator++() { return *this; }
[579]476 
[57]477      /// \brief Equality operator
[209]478      ///
[579]479      /// Equality operator.
[57]480      /// Two iterators are equal if and only if they point to the
481      /// same object or both are invalid.
482      bool operator==(const GraphItemIt&) const { return true;}
[579]483
[57]484      /// \brief Inequality operator
[209]485      ///
[579]486      /// Inequality operator.
487      /// Two iterators are equal if and only if they point to the
488      /// same object or both are invalid.
[57]489      bool operator!=(const GraphItemIt&) const { return true;}
[209]490
[57]491      template<typename _GraphItemIt>
492      struct Constraints {
[209]493        void constraints() {
[579]494          checkConcept<GraphItem<>, _GraphItemIt>();
[209]495          _GraphItemIt it1(g);
496          _GraphItemIt it2;
[579]497          _GraphItemIt it3 = it1;
498          _GraphItemIt it4 = INVALID;
[963]499          ignore_unused_variable_warning(it3);
500          ignore_unused_variable_warning(it4);
[57]501
[209]502          it2 = ++it1;
503          ++it2 = it1;
504          ++(++it1);
[57]505
[559]506          Item bi = it1;
[209]507          bi = it2;
508        }
[579]509        const GR& g;
[953]510        Constraints() {}
[57]511      };
512    };
513
[579]514    /// \brief Concept class for \c InArcIt, \c OutArcIt and
515    /// \c IncEdgeIt types.
[57]516    ///
[579]517    /// This class describes the concept of \c InArcIt, \c OutArcIt
518    /// and \c IncEdgeIt subtypes of digraph and graph types.
519    ///
520    /// \note Since these iterator classes do not inherit from the same
521    /// base class, there is an additional template parameter (selector)
522    /// \c sel. For \c InArcIt you should instantiate it with character
523    /// \c 'i', for \c OutArcIt with \c 'o' and for \c IncEdgeIt with \c 'e'.
[559]524    template <typename GR,
525              typename Item = typename GR::Arc,
526              typename Base = typename GR::Node,
527              char sel = '0'>
528    class GraphIncIt : public Item {
[57]529    public:
530      /// \brief Default constructor.
531      ///
[579]532      /// Default constructor.
533      /// \warning The default constructor is not required to set
534      /// the iterator to some well-defined value. So you should consider it
535      /// as uninitialized.
[57]536      GraphIncIt() {}
[579]537
[57]538      /// \brief Copy constructor.
539      ///
540      /// Copy constructor.
[579]541      GraphIncIt(const GraphIncIt& it) : Item(it) {}
542
543      /// \brief Constructor that sets the iterator to the first
544      /// incoming or outgoing arc.
[57]545      ///
[579]546      /// Constructor that sets the iterator to the first arc
547      /// incoming to or outgoing from the given node.
548      explicit GraphIncIt(const GR&, const Base&) {}
549
550      /// \brief Constructor for conversion from \c INVALID.
[57]551      ///
[579]552      /// Constructor for conversion from \c INVALID.
553      /// It initializes the iterator to be invalid.
[57]554      /// \sa Invalid for more details.
555      GraphIncIt(Invalid) {}
[579]556
557      /// \brief Assignment operator.
[57]558      ///
[579]559      /// Assignment operator for the iterator.
560      GraphIncIt& operator=(const GraphIncIt&) { return *this; }
561
562      /// \brief Increment the iterator.
[57]563      ///
[579]564      /// This operator increments the iterator, i.e. assigns it to the
565      /// next arc incoming to or outgoing from the given node.
[57]566      GraphIncIt& operator++() { return *this; }
567
568      /// \brief Equality operator
569      ///
[579]570      /// Equality operator.
[57]571      /// Two iterators are equal if and only if they point to the
572      /// same object or both are invalid.
573      bool operator==(const GraphIncIt&) const { return true;}
574
575      /// \brief Inequality operator
576      ///
[579]577      /// Inequality operator.
578      /// Two iterators are equal if and only if they point to the
579      /// same object or both are invalid.
[57]580      bool operator!=(const GraphIncIt&) const { return true;}
581
582      template <typename _GraphIncIt>
583      struct Constraints {
[209]584        void constraints() {
[559]585          checkConcept<GraphItem<sel>, _GraphIncIt>();
[209]586          _GraphIncIt it1(graph, node);
587          _GraphIncIt it2;
[579]588          _GraphIncIt it3 = it1;
589          _GraphIncIt it4 = INVALID;
[963]590          ignore_unused_variable_warning(it3);
591          ignore_unused_variable_warning(it4);
[57]592
[209]593          it2 = ++it1;
594          ++it2 = it1;
595          ++(++it1);
[559]596          Item e = it1;
[209]597          e = it2;
598        }
[579]599        const Base& node;
600        const GR& graph;
[953]601        Constraints() {}
[57]602      };
603    };
604
[579]605    /// \brief Skeleton class for iterable directed graphs.
[57]606    ///
[579]607    /// This class describes the interface of iterable directed
608    /// graphs. It extends \ref BaseDigraphComponent with the core
609    /// iterable interface.
[57]610    /// This concept is part of the Digraph concept.
[559]611    template <typename BAS = BaseDigraphComponent>
612    class IterableDigraphComponent : public BAS {
[57]613
614    public:
[209]615
[559]616      typedef BAS Base;
[57]617      typedef typename Base::Node Node;
618      typedef typename Base::Arc Arc;
619
620      typedef IterableDigraphComponent Digraph;
621
[584]622      /// \name Base Iteration
[209]623      ///
[579]624      /// This interface provides functions for iteration on digraph items.
[57]625      ///
[209]626      /// @{
[57]627
[579]628      /// \brief Return the first node.
[209]629      ///
[579]630      /// This function gives back the first node in the iteration order.
[57]631      void first(Node&) const {}
632
[579]633      /// \brief Return the next node.
[57]634      ///
[579]635      /// This function gives back the next node in the iteration order.
[57]636      void next(Node&) const {}
637
[579]638      /// \brief Return the first arc.
[57]639      ///
[579]640      /// This function gives back the first arc in the iteration order.
[57]641      void first(Arc&) const {}
642
[579]643      /// \brief Return the next arc.
[57]644      ///
[579]645      /// This function gives back the next arc in the iteration order.
[57]646      void next(Arc&) const {}
647
[579]648      /// \brief Return the first arc incomming to the given node.
[57]649      ///
[579]650      /// This function gives back the first arc incomming to the
651      /// given node.
[57]652      void firstIn(Arc&, const Node&) const {}
653
[579]654      /// \brief Return the next arc incomming to the given node.
[57]655      ///
[579]656      /// This function gives back the next arc incomming to the
657      /// given node.
[57]658      void nextIn(Arc&) const {}
659
[579]660      /// \brief Return the first arc outgoing form the given node.
661      ///
662      /// This function gives back the first arc outgoing form the
[57]663      /// given node.
664      void firstOut(Arc&, const Node&) const {}
665
[579]666      /// \brief Return the next arc outgoing form the given node.
[57]667      ///
[579]668      /// This function gives back the next arc outgoing form the
669      /// given node.
[57]670      void nextOut(Arc&) const {}
671
672      /// @}
673
[584]674      /// \name Class Based Iteration
[209]675      ///
[579]676      /// This interface provides iterator classes for digraph items.
[57]677      ///
678      /// @{
679
680      /// \brief This iterator goes through each node.
681      ///
682      /// This iterator goes through each node.
683      ///
684      typedef GraphItemIt<Digraph, Node> NodeIt;
685
[579]686      /// \brief This iterator goes through each arc.
[57]687      ///
[579]688      /// This iterator goes through each arc.
[57]689      ///
690      typedef GraphItemIt<Digraph, Arc> ArcIt;
691
692      /// \brief This iterator goes trough the incoming arcs of a node.
693      ///
[579]694      /// This iterator goes trough the \e incoming arcs of a certain node
[57]695      /// of a digraph.
696      typedef GraphIncIt<Digraph, Arc, Node, 'i'> InArcIt;
697
698      /// \brief This iterator goes trough the outgoing arcs of a node.
699      ///
700      /// This iterator goes trough the \e outgoing arcs of a certain node
701      /// of a digraph.
702      typedef GraphIncIt<Digraph, Arc, Node, 'o'> OutArcIt;
703
704      /// \brief The base node of the iterator.
705      ///
[579]706      /// This function gives back the base node of the iterator.
707      /// It is always the target node of the pointed arc.
[57]708      Node baseNode(const InArcIt&) const { return INVALID; }
709
710      /// \brief The running node of the iterator.
711      ///
[579]712      /// This function gives back the running node of the iterator.
713      /// It is always the source node of the pointed arc.
[57]714      Node runningNode(const InArcIt&) const { return INVALID; }
715
716      /// \brief The base node of the iterator.
717      ///
[579]718      /// This function gives back the base node of the iterator.
719      /// It is always the source node of the pointed arc.
[57]720      Node baseNode(const OutArcIt&) const { return INVALID; }
721
722      /// \brief The running node of the iterator.
723      ///
[579]724      /// This function gives back the running node of the iterator.
725      /// It is always the target node of the pointed arc.
[57]726      Node runningNode(const OutArcIt&) const { return INVALID; }
727
728      /// @}
729
[209]730      template <typename _Digraph>
[57]731      struct Constraints {
[209]732        void constraints() {
733          checkConcept<Base, _Digraph>();
[57]734
735          {
[209]736            typename _Digraph::Node node(INVALID);
[57]737            typename _Digraph::Arc arc(INVALID);
738            {
739              digraph.first(node);
740              digraph.next(node);
741            }
742            {
743              digraph.first(arc);
744              digraph.next(arc);
745            }
746            {
747              digraph.firstIn(arc, node);
748              digraph.nextIn(arc);
749            }
750            {
751              digraph.firstOut(arc, node);
752              digraph.nextOut(arc);
753            }
[209]754          }
[57]755
756          {
757            checkConcept<GraphItemIt<_Digraph, typename _Digraph::Arc>,
758              typename _Digraph::ArcIt >();
759            checkConcept<GraphItemIt<_Digraph, typename _Digraph::Node>,
760              typename _Digraph::NodeIt >();
[209]761            checkConcept<GraphIncIt<_Digraph, typename _Digraph::Arc,
[57]762              typename _Digraph::Node, 'i'>, typename _Digraph::InArcIt>();
[209]763            checkConcept<GraphIncIt<_Digraph, typename _Digraph::Arc,
[57]764              typename _Digraph::Node, 'o'>, typename _Digraph::OutArcIt>();
765
766            typename _Digraph::Node n;
[579]767            const typename _Digraph::InArcIt iait(INVALID);
768            const typename _Digraph::OutArcIt oait(INVALID);
769            n = digraph.baseNode(iait);
770            n = digraph.runningNode(iait);
771            n = digraph.baseNode(oait);
772            n = digraph.runningNode(oait);
[57]773            ignore_unused_variable_warning(n);
774          }
775        }
[209]776
777        const _Digraph& digraph;
[953]778        Constraints() {}
[57]779      };
780    };
781
[579]782    /// \brief Skeleton class for iterable undirected graphs.
[57]783    ///
[579]784    /// This class describes the interface of iterable undirected
785    /// graphs. It extends \ref IterableDigraphComponent with the core
786    /// iterable interface of undirected graphs.
[57]787    /// This concept is part of the Graph concept.
[559]788    template <typename BAS = BaseGraphComponent>
789    class IterableGraphComponent : public IterableDigraphComponent<BAS> {
[57]790    public:
791
[559]792      typedef BAS Base;
[57]793      typedef typename Base::Node Node;
794      typedef typename Base::Arc Arc;
795      typedef typename Base::Edge Edge;
796
[209]797
[57]798      typedef IterableGraphComponent Graph;
799
[584]800      /// \name Base Iteration
[209]801      ///
[579]802      /// This interface provides functions for iteration on edges.
803      ///
[209]804      /// @{
[57]805
[559]806      using IterableDigraphComponent<Base>::first;
807      using IterableDigraphComponent<Base>::next;
[57]808
[579]809      /// \brief Return the first edge.
[57]810      ///
[579]811      /// This function gives back the first edge in the iteration order.
[57]812      void first(Edge&) const {}
813
[579]814      /// \brief Return the next edge.
[57]815      ///
[579]816      /// This function gives back the next edge in the iteration order.
[57]817      void next(Edge&) const {}
818
[579]819      /// \brief Return the first edge incident to the given node.
820      ///
821      /// This function gives back the first edge incident to the given
822      /// node. The bool parameter gives back the direction for which the
823      /// source node of the directed arc representing the edge is the
[57]824      /// given node.
825      void firstInc(Edge&, bool&, const Node&) const {}
826
827      /// \brief Gives back the next of the edges from the
828      /// given node.
829      ///
[579]830      /// This function gives back the next edge incident to the given
831      /// node. The bool parameter should be used as \c firstInc() use it.
[57]832      void nextInc(Edge&, bool&) const {}
833
[559]834      using IterableDigraphComponent<Base>::baseNode;
835      using IterableDigraphComponent<Base>::runningNode;
[57]836
837      /// @}
838
[584]839      /// \name Class Based Iteration
[209]840      ///
[579]841      /// This interface provides iterator classes for edges.
[57]842      ///
843      /// @{
844
[579]845      /// \brief This iterator goes through each edge.
[57]846      ///
[579]847      /// This iterator goes through each edge.
[57]848      typedef GraphItemIt<Graph, Edge> EdgeIt;
[579]849
850      /// \brief This iterator goes trough the incident edges of a
[57]851      /// node.
852      ///
[579]853      /// This iterator goes trough the incident edges of a certain
[57]854      /// node of a graph.
[579]855      typedef GraphIncIt<Graph, Edge, Node, 'e'> IncEdgeIt;
856
[57]857      /// \brief The base node of the iterator.
858      ///
[579]859      /// This function gives back the base node of the iterator.
[78]860      Node baseNode(const IncEdgeIt&) const { return INVALID; }
[57]861
862      /// \brief The running node of the iterator.
863      ///
[579]864      /// This function gives back the running node of the iterator.
[78]865      Node runningNode(const IncEdgeIt&) const { return INVALID; }
[57]866
867      /// @}
868
[209]869      template <typename _Graph>
[57]870      struct Constraints {
[209]871        void constraints() {
872          checkConcept<IterableDigraphComponent<Base>, _Graph>();
[57]873
874          {
875            typename _Graph::Node node(INVALID);
876            typename _Graph::Edge edge(INVALID);
877            bool dir;
878            {
879              graph.first(edge);
880              graph.next(edge);
881            }
882            {
883              graph.firstInc(edge, dir, node);
884              graph.nextInc(edge, dir);
885            }
[209]886
887          }
888
[57]889          {
890            checkConcept<GraphItemIt<_Graph, typename _Graph::Edge>,
891              typename _Graph::EdgeIt >();
[209]892            checkConcept<GraphIncIt<_Graph, typename _Graph::Edge,
[579]893              typename _Graph::Node, 'e'>, typename _Graph::IncEdgeIt>();
[209]894
[57]895            typename _Graph::Node n;
[579]896            const typename _Graph::IncEdgeIt ieit(INVALID);
897            n = graph.baseNode(ieit);
898            n = graph.runningNode(ieit);
[57]899          }
900        }
[209]901
902        const _Graph& graph;
[953]903        Constraints() {}
[57]904      };
905    };
906
[579]907    /// \brief Skeleton class for alterable directed graphs.
[209]908    ///
[579]909    /// This class describes the interface of alterable directed
910    /// graphs. It extends \ref BaseDigraphComponent with the alteration
911    /// notifier interface. It implements
[57]912    /// an observer-notifier pattern for each digraph item. More
913    /// obsevers can be registered into the notifier and whenever an
[579]914    /// alteration occured in the digraph all the observers will be
[57]915    /// notified about it.
[559]916    template <typename BAS = BaseDigraphComponent>
917    class AlterableDigraphComponent : public BAS {
[57]918    public:
919
[559]920      typedef BAS Base;
[57]921      typedef typename Base::Node Node;
922      typedef typename Base::Arc Arc;
923
924
[579]925      /// Node alteration notifier class.
[209]926      typedef AlterationNotifier<AlterableDigraphComponent, Node>
[57]927      NodeNotifier;
[579]928      /// Arc alteration notifier class.
[209]929      typedef AlterationNotifier<AlterableDigraphComponent, Arc>
[57]930      ArcNotifier;
[209]931
[579]932      /// \brief Return the node alteration notifier.
[57]933      ///
[579]934      /// This function gives back the node alteration notifier.
[57]935      NodeNotifier& notifier(Node) const {
[579]936         return NodeNotifier();
[57]937      }
[209]938
[579]939      /// \brief Return the arc alteration notifier.
[57]940      ///
[579]941      /// This function gives back the arc alteration notifier.
[57]942      ArcNotifier& notifier(Arc) const {
[209]943        return ArcNotifier();
[57]944      }
945
[209]946      template <typename _Digraph>
[57]947      struct Constraints {
[209]948        void constraints() {
949          checkConcept<Base, _Digraph>();
950          typename _Digraph::NodeNotifier& nn
[57]951            = digraph.notifier(typename _Digraph::Node());
952
[209]953          typename _Digraph::ArcNotifier& en
[57]954            = digraph.notifier(typename _Digraph::Arc());
[209]955
[57]956          ignore_unused_variable_warning(nn);
957          ignore_unused_variable_warning(en);
[209]958        }
959
960        const _Digraph& digraph;
[953]961        Constraints() {}
[57]962      };
963    };
964
[579]965    /// \brief Skeleton class for alterable undirected graphs.
[209]966    ///
[579]967    /// This class describes the interface of alterable undirected
968    /// graphs. It extends \ref AlterableDigraphComponent with the alteration
969    /// notifier interface of undirected graphs. It implements
970    /// an observer-notifier pattern for the edges. More
[57]971    /// obsevers can be registered into the notifier and whenever an
[579]972    /// alteration occured in the graph all the observers will be
[57]973    /// notified about it.
[559]974    template <typename BAS = BaseGraphComponent>
975    class AlterableGraphComponent : public AlterableDigraphComponent<BAS> {
[57]976    public:
977
[559]978      typedef BAS Base;
[57]979      typedef typename Base::Edge Edge;
980
981
[579]982      /// Edge alteration notifier class.
[209]983      typedef AlterationNotifier<AlterableGraphComponent, Edge>
[57]984      EdgeNotifier;
[209]985
[579]986      /// \brief Return the edge alteration notifier.
[57]987      ///
[579]988      /// This function gives back the edge alteration notifier.
[57]989      EdgeNotifier& notifier(Edge) const {
[209]990        return EdgeNotifier();
[57]991      }
992
[209]993      template <typename _Graph>
[57]994      struct Constraints {
[209]995        void constraints() {
[579]996          checkConcept<AlterableDigraphComponent<Base>, _Graph>();
[209]997          typename _Graph::EdgeNotifier& uen
[57]998            = graph.notifier(typename _Graph::Edge());
999          ignore_unused_variable_warning(uen);
[209]1000        }
1001
1002        const _Graph& graph;
[953]1003        Constraints() {}
[57]1004      };
1005    };
1006
[579]1007    /// \brief Concept class for standard graph maps.
[209]1008    ///
[579]1009    /// This class describes the concept of standard graph maps, i.e.
1010    /// the \c NodeMap, \c ArcMap and \c EdgeMap subtypes of digraph and
1011    /// graph types, which can be used for associating data to graph items.
[580]1012    /// The standard graph maps must conform to the ReferenceMap concept.
[559]1013    template <typename GR, typename K, typename V>
[580]1014    class GraphMap : public ReferenceMap<K, V, V&, const V&> {
[617]1015      typedef ReferenceMap<K, V, V&, const V&> Parent;
1016
[57]1017    public:
1018
1019      /// The key type of the map.
[559]1020      typedef K Key;
[57]1021      /// The value type of the map.
[559]1022      typedef V Value;
[580]1023      /// The reference type of the map.
1024      typedef Value& Reference;
1025      /// The const reference type of the map.
1026      typedef const Value& ConstReference;
1027
1028      // The reference map tag.
1029      typedef True ReferenceMapTag;
[57]1030
1031      /// \brief Construct a new map.
1032      ///
1033      /// Construct a new map for the graph.
[617]1034      explicit GraphMap(const GR&) {}
[57]1035      /// \brief Construct a new map with default value.
1036      ///
[579]1037      /// Construct a new map for the graph and initalize the values.
[617]1038      GraphMap(const GR&, const Value&) {}
[263]1039
1040    private:
[57]1041      /// \brief Copy constructor.
1042      ///
1043      /// Copy Constructor.
1044      GraphMap(const GraphMap&) : Parent() {}
[209]1045
[579]1046      /// \brief Assignment operator.
[57]1047      ///
[579]1048      /// Assignment operator. It does not mofify the underlying graph,
[57]1049      /// it just iterates on the current item set and set the  map
[209]1050      /// with the value returned by the assigned map.
[57]1051      template <typename CMap>
[209]1052      GraphMap& operator=(const CMap&) {
[57]1053        checkConcept<ReadMap<Key, Value>, CMap>();
1054        return *this;
1055      }
1056
[263]1057    public:
[57]1058      template<typename _Map>
1059      struct Constraints {
[209]1060        void constraints() {
[580]1061          checkConcept
1062            <ReferenceMap<Key, Value, Value&, const Value&>, _Map>();
[579]1063          _Map m1(g);
1064          _Map m2(g,t);
1065         
1066          // Copy constructor
1067          // _Map m3(m);
[209]1068
[579]1069          // Assignment operator
[263]1070          // ReadMap<Key, Value> cmap;
[579]1071          // m3 = cmap;
[57]1072
[579]1073          ignore_unused_variable_warning(m1);
1074          ignore_unused_variable_warning(m2);
1075          // ignore_unused_variable_warning(m3);
[209]1076        }
[57]1077
[579]1078        const _Map &m;
[617]1079        const GR &g;
[209]1080        const typename GraphMap::Value &t;
[953]1081        Constraints() {}
[57]1082      };
1083
1084    };
1085
[579]1086    /// \brief Skeleton class for mappable directed graphs.
[57]1087    ///
[579]1088    /// This class describes the interface of mappable directed graphs.
1089    /// It extends \ref BaseDigraphComponent with the standard digraph
1090    /// map classes, namely \c NodeMap and \c ArcMap.
[57]1091    /// This concept is part of the Digraph concept.
[559]1092    template <typename BAS = BaseDigraphComponent>
1093    class MappableDigraphComponent : public BAS  {
[57]1094    public:
1095
[559]1096      typedef BAS Base;
[57]1097      typedef typename Base::Node Node;
1098      typedef typename Base::Arc Arc;
1099
1100      typedef MappableDigraphComponent Digraph;
1101
[579]1102      /// \brief Standard graph map for the nodes.
[57]1103      ///
[579]1104      /// Standard graph map for the nodes.
[580]1105      /// It conforms to the ReferenceMap concept.
[559]1106      template <typename V>
[579]1107      class NodeMap : public GraphMap<MappableDigraphComponent, Node, V> {
[559]1108        typedef GraphMap<MappableDigraphComponent, Node, V> Parent;
[57]1109
[617]1110      public:
[209]1111        /// \brief Construct a new map.
1112        ///
1113        /// Construct a new map for the digraph.
1114        explicit NodeMap(const MappableDigraphComponent& digraph)
[57]1115          : Parent(digraph) {}
1116
[209]1117        /// \brief Construct a new map with default value.
1118        ///
[579]1119        /// Construct a new map for the digraph and initalize the values.
[559]1120        NodeMap(const MappableDigraphComponent& digraph, const V& value)
[57]1121          : Parent(digraph, value) {}
1122
[263]1123      private:
[209]1124        /// \brief Copy constructor.
1125        ///
1126        /// Copy Constructor.
1127        NodeMap(const NodeMap& nm) : Parent(nm) {}
[57]1128
[579]1129        /// \brief Assignment operator.
[209]1130        ///
[579]1131        /// Assignment operator.
[57]1132        template <typename CMap>
[209]1133        NodeMap& operator=(const CMap&) {
[559]1134          checkConcept<ReadMap<Node, V>, CMap>();
[57]1135          return *this;
1136        }
1137
1138      };
1139
[579]1140      /// \brief Standard graph map for the arcs.
[57]1141      ///
[579]1142      /// Standard graph map for the arcs.
[580]1143      /// It conforms to the ReferenceMap concept.
[559]1144      template <typename V>
[579]1145      class ArcMap : public GraphMap<MappableDigraphComponent, Arc, V> {
[559]1146        typedef GraphMap<MappableDigraphComponent, Arc, V> Parent;
[57]1147
[617]1148      public:
[209]1149        /// \brief Construct a new map.
1150        ///
1151        /// Construct a new map for the digraph.
1152        explicit ArcMap(const MappableDigraphComponent& digraph)
[57]1153          : Parent(digraph) {}
1154
[209]1155        /// \brief Construct a new map with default value.
1156        ///
[579]1157        /// Construct a new map for the digraph and initalize the values.
[559]1158        ArcMap(const MappableDigraphComponent& digraph, const V& value)
[57]1159          : Parent(digraph, value) {}
1160
[263]1161      private:
[209]1162        /// \brief Copy constructor.
1163        ///
1164        /// Copy Constructor.
1165        ArcMap(const ArcMap& nm) : Parent(nm) {}
[57]1166
[579]1167        /// \brief Assignment operator.
[209]1168        ///
[579]1169        /// Assignment operator.
[57]1170        template <typename CMap>
[209]1171        ArcMap& operator=(const CMap&) {
[559]1172          checkConcept<ReadMap<Arc, V>, CMap>();
[57]1173          return *this;
1174        }
1175
1176      };
1177
1178
1179      template <typename _Digraph>
1180      struct Constraints {
1181
[209]1182        struct Dummy {
1183          int value;
1184          Dummy() : value(0) {}
1185          Dummy(int _v) : value(_v) {}
1186        };
[57]1187
[209]1188        void constraints() {
1189          checkConcept<Base, _Digraph>();
1190          { // int map test
1191            typedef typename _Digraph::template NodeMap<int> IntNodeMap;
1192            checkConcept<GraphMap<_Digraph, typename _Digraph::Node, int>,
1193              IntNodeMap >();
1194          } { // bool map test
1195            typedef typename _Digraph::template NodeMap<bool> BoolNodeMap;
1196            checkConcept<GraphMap<_Digraph, typename _Digraph::Node, bool>,
1197              BoolNodeMap >();
1198          } { // Dummy map test
1199            typedef typename _Digraph::template NodeMap<Dummy> DummyNodeMap;
1200            checkConcept<GraphMap<_Digraph, typename _Digraph::Node, Dummy>,
1201              DummyNodeMap >();
1202          }
[57]1203
[209]1204          { // int map test
1205            typedef typename _Digraph::template ArcMap<int> IntArcMap;
1206            checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, int>,
1207              IntArcMap >();
1208          } { // bool map test
1209            typedef typename _Digraph::template ArcMap<bool> BoolArcMap;
1210            checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, bool>,
1211              BoolArcMap >();
1212          } { // Dummy map test
1213            typedef typename _Digraph::template ArcMap<Dummy> DummyArcMap;
1214            checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, Dummy>,
1215              DummyArcMap >();
1216          }
1217        }
[57]1218
[579]1219        const _Digraph& digraph;
[953]1220        Constraints() {}
[57]1221      };
1222    };
1223
[579]1224    /// \brief Skeleton class for mappable undirected graphs.
[57]1225    ///
[579]1226    /// This class describes the interface of mappable undirected graphs.
1227    /// It extends \ref MappableDigraphComponent with the standard graph
1228    /// map class for edges (\c EdgeMap).
[57]1229    /// This concept is part of the Graph concept.
[559]1230    template <typename BAS = BaseGraphComponent>
1231    class MappableGraphComponent : public MappableDigraphComponent<BAS>  {
[57]1232    public:
1233
[559]1234      typedef BAS Base;
[57]1235      typedef typename Base::Edge Edge;
1236
1237      typedef MappableGraphComponent Graph;
1238
[579]1239      /// \brief Standard graph map for the edges.
[57]1240      ///
[579]1241      /// Standard graph map for the edges.
[580]1242      /// It conforms to the ReferenceMap concept.
[559]1243      template <typename V>
[579]1244      class EdgeMap : public GraphMap<MappableGraphComponent, Edge, V> {
[559]1245        typedef GraphMap<MappableGraphComponent, Edge, V> Parent;
[57]1246
[617]1247      public:
[209]1248        /// \brief Construct a new map.
1249        ///
1250        /// Construct a new map for the graph.
1251        explicit EdgeMap(const MappableGraphComponent& graph)
[57]1252          : Parent(graph) {}
1253
[209]1254        /// \brief Construct a new map with default value.
1255        ///
[579]1256        /// Construct a new map for the graph and initalize the values.
[559]1257        EdgeMap(const MappableGraphComponent& graph, const V& value)
[57]1258          : Parent(graph, value) {}
1259
[263]1260      private:
[209]1261        /// \brief Copy constructor.
1262        ///
1263        /// Copy Constructor.
1264        EdgeMap(const EdgeMap& nm) : Parent(nm) {}
[57]1265
[579]1266        /// \brief Assignment operator.
[209]1267        ///
[579]1268        /// Assignment operator.
[57]1269        template <typename CMap>
[209]1270        EdgeMap& operator=(const CMap&) {
[559]1271          checkConcept<ReadMap<Edge, V>, CMap>();
[57]1272          return *this;
1273        }
1274
1275      };
1276
1277
1278      template <typename _Graph>
1279      struct Constraints {
1280
[209]1281        struct Dummy {
1282          int value;
1283          Dummy() : value(0) {}
1284          Dummy(int _v) : value(_v) {}
1285        };
[57]1286
[209]1287        void constraints() {
[579]1288          checkConcept<MappableDigraphComponent<Base>, _Graph>();
[57]1289
[209]1290          { // int map test
1291            typedef typename _Graph::template EdgeMap<int> IntEdgeMap;
1292            checkConcept<GraphMap<_Graph, typename _Graph::Edge, int>,
1293              IntEdgeMap >();
1294          } { // bool map test
1295            typedef typename _Graph::template EdgeMap<bool> BoolEdgeMap;
1296            checkConcept<GraphMap<_Graph, typename _Graph::Edge, bool>,
1297              BoolEdgeMap >();
1298          } { // Dummy map test
1299            typedef typename _Graph::template EdgeMap<Dummy> DummyEdgeMap;
1300            checkConcept<GraphMap<_Graph, typename _Graph::Edge, Dummy>,
1301              DummyEdgeMap >();
1302          }
1303        }
[57]1304
[579]1305        const _Graph& graph;
[953]1306        Constraints() {}
[57]1307      };
1308    };
1309
[579]1310    /// \brief Skeleton class for extendable directed graphs.
[57]1311    ///
[579]1312    /// This class describes the interface of extendable directed graphs.
1313    /// It extends \ref BaseDigraphComponent with functions for adding
1314    /// nodes and arcs to the digraph.
1315    /// This concept requires \ref AlterableDigraphComponent.
[559]1316    template <typename BAS = BaseDigraphComponent>
1317    class ExtendableDigraphComponent : public BAS {
[57]1318    public:
[559]1319      typedef BAS Base;
[57]1320
[559]1321      typedef typename Base::Node Node;
1322      typedef typename Base::Arc Arc;
[57]1323
[579]1324      /// \brief Add a new node to the digraph.
[57]1325      ///
[579]1326      /// This function adds a new node to the digraph.
[57]1327      Node addNode() {
[209]1328        return INVALID;
[57]1329      }
[209]1330
[579]1331      /// \brief Add a new arc connecting the given two nodes.
[57]1332      ///
[579]1333      /// This function adds a new arc connecting the given two nodes
1334      /// of the digraph.
[57]1335      Arc addArc(const Node&, const Node&) {
[209]1336        return INVALID;
[57]1337      }
1338
1339      template <typename _Digraph>
1340      struct Constraints {
[209]1341        void constraints() {
[57]1342          checkConcept<Base, _Digraph>();
[209]1343          typename _Digraph::Node node_a, node_b;
1344          node_a = digraph.addNode();
1345          node_b = digraph.addNode();
1346          typename _Digraph::Arc arc;
1347          arc = digraph.addArc(node_a, node_b);
1348        }
[57]1349
[209]1350        _Digraph& digraph;
[953]1351        Constraints() {}
[57]1352      };
1353    };
1354
[579]1355    /// \brief Skeleton class for extendable undirected graphs.
[57]1356    ///
[579]1357    /// This class describes the interface of extendable undirected graphs.
1358    /// It extends \ref BaseGraphComponent with functions for adding
1359    /// nodes and edges to the graph.
1360    /// This concept requires \ref AlterableGraphComponent.
[559]1361    template <typename BAS = BaseGraphComponent>
1362    class ExtendableGraphComponent : public BAS {
[57]1363    public:
1364
[559]1365      typedef BAS Base;
1366      typedef typename Base::Node Node;
1367      typedef typename Base::Edge Edge;
[57]1368
[579]1369      /// \brief Add a new node to the digraph.
[57]1370      ///
[579]1371      /// This function adds a new node to the digraph.
[57]1372      Node addNode() {
[209]1373        return INVALID;
[57]1374      }
[209]1375
[579]1376      /// \brief Add a new edge connecting the given two nodes.
[57]1377      ///
[579]1378      /// This function adds a new edge connecting the given two nodes
1379      /// of the graph.
1380      Edge addEdge(const Node&, const Node&) {
[209]1381        return INVALID;
[57]1382      }
1383
1384      template <typename _Graph>
1385      struct Constraints {
[209]1386        void constraints() {
1387          checkConcept<Base, _Graph>();
1388          typename _Graph::Node node_a, node_b;
1389          node_a = graph.addNode();
1390          node_b = graph.addNode();
1391          typename _Graph::Edge edge;
1392          edge = graph.addEdge(node_a, node_b);
1393        }
[57]1394
[209]1395        _Graph& graph;
[953]1396        Constraints() {}
[57]1397      };
1398    };
1399
[579]1400    /// \brief Skeleton class for erasable directed graphs.
[209]1401    ///
[579]1402    /// This class describes the interface of erasable directed graphs.
1403    /// It extends \ref BaseDigraphComponent with functions for removing
1404    /// nodes and arcs from the digraph.
1405    /// This concept requires \ref AlterableDigraphComponent.
[559]1406    template <typename BAS = BaseDigraphComponent>
1407    class ErasableDigraphComponent : public BAS {
[57]1408    public:
1409
[559]1410      typedef BAS Base;
[57]1411      typedef typename Base::Node Node;
1412      typedef typename Base::Arc Arc;
1413
1414      /// \brief Erase a node from the digraph.
1415      ///
[579]1416      /// This function erases the given node from the digraph and all arcs
1417      /// connected to the node.
[209]1418      void erase(const Node&) {}
[57]1419
1420      /// \brief Erase an arc from the digraph.
1421      ///
[579]1422      /// This function erases the given arc from the digraph.
[57]1423      void erase(const Arc&) {}
1424
1425      template <typename _Digraph>
1426      struct Constraints {
[209]1427        void constraints() {
[57]1428          checkConcept<Base, _Digraph>();
[579]1429          const typename _Digraph::Node node(INVALID);
[209]1430          digraph.erase(node);
[579]1431          const typename _Digraph::Arc arc(INVALID);
[209]1432          digraph.erase(arc);
1433        }
[57]1434
[209]1435        _Digraph& digraph;
[953]1436        Constraints() {}
[57]1437      };
1438    };
1439
[579]1440    /// \brief Skeleton class for erasable undirected graphs.
[209]1441    ///
[579]1442    /// This class describes the interface of erasable undirected graphs.
1443    /// It extends \ref BaseGraphComponent with functions for removing
1444    /// nodes and edges from the graph.
1445    /// This concept requires \ref AlterableGraphComponent.
[559]1446    template <typename BAS = BaseGraphComponent>
1447    class ErasableGraphComponent : public BAS {
[57]1448    public:
1449
[559]1450      typedef BAS Base;
[57]1451      typedef typename Base::Node Node;
1452      typedef typename Base::Edge Edge;
1453
1454      /// \brief Erase a node from the graph.
1455      ///
[579]1456      /// This function erases the given node from the graph and all edges
1457      /// connected to the node.
[209]1458      void erase(const Node&) {}
[57]1459
[579]1460      /// \brief Erase an edge from the digraph.
[57]1461      ///
[579]1462      /// This function erases the given edge from the digraph.
[57]1463      void erase(const Edge&) {}
1464
1465      template <typename _Graph>
1466      struct Constraints {
[209]1467        void constraints() {
[57]1468          checkConcept<Base, _Graph>();
[579]1469          const typename _Graph::Node node(INVALID);
[209]1470          graph.erase(node);
[579]1471          const typename _Graph::Edge edge(INVALID);
[209]1472          graph.erase(edge);
1473        }
[57]1474
[209]1475        _Graph& graph;
[953]1476        Constraints() {}
[57]1477      };
1478    };
1479
[579]1480    /// \brief Skeleton class for clearable directed graphs.
[57]1481    ///
[579]1482    /// This class describes the interface of clearable directed graphs.
1483    /// It extends \ref BaseDigraphComponent with a function for clearing
1484    /// the digraph.
1485    /// This concept requires \ref AlterableDigraphComponent.
[559]1486    template <typename BAS = BaseDigraphComponent>
1487    class ClearableDigraphComponent : public BAS {
[57]1488    public:
1489
[559]1490      typedef BAS Base;
[57]1491
1492      /// \brief Erase all nodes and arcs from the digraph.
1493      ///
[579]1494      /// This function erases all nodes and arcs from the digraph.
[209]1495      void clear() {}
[57]1496
1497      template <typename _Digraph>
1498      struct Constraints {
[209]1499        void constraints() {
[57]1500          checkConcept<Base, _Digraph>();
[209]1501          digraph.clear();
1502        }
[57]1503
[579]1504        _Digraph& digraph;
[953]1505        Constraints() {}
[57]1506      };
1507    };
1508
[579]1509    /// \brief Skeleton class for clearable undirected graphs.
[57]1510    ///
[579]1511    /// This class describes the interface of clearable undirected graphs.
1512    /// It extends \ref BaseGraphComponent with a function for clearing
1513    /// the graph.
1514    /// This concept requires \ref AlterableGraphComponent.
[559]1515    template <typename BAS = BaseGraphComponent>
1516    class ClearableGraphComponent : public ClearableDigraphComponent<BAS> {
[57]1517    public:
1518
[559]1519      typedef BAS Base;
[57]1520
[579]1521      /// \brief Erase all nodes and edges from the graph.
1522      ///
1523      /// This function erases all nodes and edges from the graph.
1524      void clear() {}
1525
[57]1526      template <typename _Graph>
1527      struct Constraints {
[209]1528        void constraints() {
[579]1529          checkConcept<Base, _Graph>();
1530          graph.clear();
[209]1531        }
[57]1532
[579]1533        _Graph& graph;
[953]1534        Constraints() {}
[57]1535      };
1536    };
1537
1538  }
1539
1540}
1541
1542#endif
Note: See TracBrowser for help on using the repository browser.