src/hugo/skeletons/path.h
author deba
Wed, 08 Sep 2004 12:06:45 +0000
changeset 822 88226d9fe821
parent 807 ce85435185c3
child 823 afba7fbbb239
permissions -rw-r--r--
The MapFactories have been removed from the code because
if we use macros then they increases only the complexity.

The pair iterators of the maps are separeted from the maps.

Some macros and comments has been changed.
hegyi@818
     1
#define SKELETON
alpar@797
     2
// -*- c++ -*- //
alpar@797
     3
alpar@807
     4
///\ingroup skeletons
alpar@797
     5
///\file
alpar@797
     6
///\brief Classes for representing paths in graphs.
alpar@797
     7
alpar@797
     8
#ifndef HUGO_PATH_H
alpar@797
     9
#define HUGO_PATH_H
alpar@797
    10
alpar@797
    11
#include <hugo/invalid.h>
alpar@797
    12
alpar@797
    13
namespace hugo {
alpar@803
    14
  namespace skeleton {
alpar@803
    15
    /// \addtogroup skeletons
alpar@803
    16
    /// @{
alpar@803
    17
    
alpar@803
    18
    
alpar@806
    19
    //! \brief A skeletom structure for representing directed paths in a graph.
alpar@803
    20
    //!
alpar@806
    21
    //! A skeleton structure for representing directed paths in a graph.
alpar@803
    22
    //! \param GR The graph type in which the path is.
alpar@803
    23
    //! 
alpar@803
    24
    //! In a sense, the path can be treated as a graph, for is has \c NodeIt
alpar@803
    25
    //! and \c EdgeIt with the same usage. These types converts to the \c Node
alpar@803
    26
    //! and \c Edge of the original graph.
alpar@803
    27
    template<typename GR>
alpar@803
    28
    class Path {
alpar@803
    29
    public:
alpar@803
    30
      
alpar@803
    31
      /// Type of the underlying graph.
hegyi@818
    32
      typedef /*typename*/ GR Graph;
alpar@803
    33
      /// Edge type of the underlying graph.
alpar@803
    34
      typedef typename Graph::Edge GraphEdge; 
alpar@803
    35
      /// Node type of the underlying graph.
hegyi@818
    36
     typedef typename Graph::Node GraphNode;
alpar@803
    37
      class NodeIt;
alpar@803
    38
      class EdgeIt;
alpar@803
    39
      
alpar@803
    40
      /// \param _G The graph in which the path is.
alpar@803
    41
      ///
alpar@803
    42
      Path(const Graph &_G) {}
alpar@803
    43
      
alpar@803
    44
      /// Length of the path.
hegyi@818
    45
      size_t length() const {return 0;}
alpar@803
    46
      /// Returns whether the path is empty.
alpar@803
    47
      bool empty() const {}
alpar@803
    48
      
alpar@803
    49
      /// Resets the path to an empty path.
alpar@803
    50
      void clear() {}
alpar@797
    51
alpar@803
    52
      /// \brief Starting point of the path.
alpar@803
    53
      ///
alpar@803
    54
      /// Starting point of the path.
alpar@803
    55
      /// Returns INVALID if the path is empty.
hegyi@818
    56
      GraphNode/*It*/ head() const {return INVALID;}
alpar@803
    57
      /// \brief End point of the path.
alpar@803
    58
      ///
alpar@803
    59
      /// End point of the path.
alpar@803
    60
      /// Returns INVALID if the path is empty.
hegyi@818
    61
      GraphNode/*It*/ tail() const {return INVALID;}
alpar@797
    62
alpar@803
    63
      /// \brief First NodeIt/EdgeIt.
alpar@803
    64
      ///
alpar@803
    65
      /// Initializes node or edge iterator to point to the first
alpar@803
    66
      /// node or edge.
alpar@803
    67
      template<typename It>
alpar@803
    68
      It& first(It &i) const { return i=It(*this); }
alpar@797
    69
alpar@803
    70
      /// \brief The head of an edge.
alpar@803
    71
      ///
alpar@803
    72
      /// Returns node iterator pointing to the head node of the
alpar@803
    73
      /// given edge iterator.
alpar@803
    74
      NodeIt head(const EdgeIt& e) const {}
alpar@797
    75
alpar@803
    76
      /// \brief The tail of an edge.
alpar@803
    77
      ///
alpar@803
    78
      /// Returns node iterator pointing to the tail node of the
alpar@803
    79
      /// given edge iterator.
alpar@803
    80
      NodeIt tail(const EdgeIt& e) const {}
alpar@797
    81
alpar@797
    82
alpar@803
    83
      /* Iterator classes */
alpar@797
    84
alpar@803
    85
      /**
alpar@803
    86
       * \brief Iterator class to iterate on the edges of the paths
alpar@803
    87
       * 
alpar@803
    88
       * \ingroup skeletons
alpar@803
    89
       * This class is used to iterate on the edges of the paths
alpar@803
    90
       *
alpar@803
    91
       * Of course it converts to Graph::Edge
alpar@803
    92
       * 
alpar@803
    93
       */
alpar@803
    94
      class EdgeIt {
alpar@803
    95
      public:
alpar@803
    96
	/// Default constructor
alpar@803
    97
	EdgeIt() {}
alpar@803
    98
	/// Invalid constructor
alpar@803
    99
	EdgeIt(Invalid) {}
alpar@803
   100
	/// Constructor with starting point
alpar@803
   101
	EdgeIt(const Path &_p) {}
alpar@797
   102
alpar@803
   103
	operator GraphEdge () const {}
alpar@797
   104
alpar@803
   105
	/// Next edge
alpar@803
   106
	EdgeIt& operator++() {}
alpar@797
   107
alpar@803
   108
	/// Comparison operator
alpar@803
   109
	bool operator==(const EdgeIt& e) const {}
alpar@803
   110
	/// Comparison operator
alpar@803
   111
	bool operator!=(const EdgeIt& e) const {}
alpar@803
   112
// 	/// Comparison operator
alpar@803
   113
//      /// \todo It is not clear what is the "natural" ordering.
alpar@803
   114
// 	bool operator<(const EdgeIt& e) const {}
alpar@797
   115
alpar@803
   116
      };
alpar@797
   117
alpar@803
   118
      /**
alpar@803
   119
       * \brief Iterator class to iterate on the nodes of the paths
alpar@803
   120
       * 
alpar@803
   121
       * \ingroup skeletons
alpar@803
   122
       * This class is used to iterate on the nodes of the paths
alpar@803
   123
       *
alpar@803
   124
       * Of course it converts to Graph::Node.
alpar@803
   125
       * 
alpar@803
   126
       */
alpar@803
   127
      class NodeIt {
alpar@803
   128
      public:
alpar@803
   129
	/// Default constructor
alpar@803
   130
	NodeIt() {}
alpar@803
   131
	/// Invalid constructor
alpar@803
   132
	NodeIt(Invalid) {}
alpar@803
   133
	/// Constructor with starting point
alpar@803
   134
	NodeIt(const Path &_p) {}
alpar@797
   135
alpar@803
   136
	///Conversion to Graph::Node
alpar@803
   137
	operator const GraphNode& () const {}
alpar@803
   138
	/// Next node
alpar@803
   139
	NodeIt& operator++() {}
alpar@797
   140
alpar@803
   141
	/// Comparison operator
alpar@803
   142
	bool operator==(const NodeIt& e) const {}
alpar@803
   143
	/// Comparison operator
alpar@803
   144
	bool operator!=(const NodeIt& e) const {}
alpar@803
   145
// 	/// Comparison operator
alpar@803
   146
//      /// \todo It is not clear what is the "natural" ordering.
alpar@803
   147
// 	bool operator<(const NodeIt& e) const {}
alpar@797
   148
alpar@803
   149
      };
alpar@797
   150
alpar@803
   151
      friend class Builder;    
alpar@797
   152
alpar@803
   153
      /**
alpar@803
   154
       * \brief Class to build paths
alpar@803
   155
       * 
alpar@803
   156
       * \ingroup skeletons
alpar@803
   157
       * This class is used to fill a path with edges.
alpar@803
   158
       *
alpar@803
   159
       * You can push new edges to the front and to the back of the path in
alpar@803
   160
       * arbitrary order then you should commit these changes to the graph.
alpar@803
   161
       *
alpar@803
   162
       * While the builder is active (after the first modifying
alpar@803
   163
       * operation and until the call of \ref commit())
alpar@803
   164
       * the underlining Path is in a
alpar@803
   165
       * "transitional" state (operations on it have undefined result).
alpar@803
   166
       */
alpar@803
   167
      class Builder {
alpar@803
   168
      public:
hegyi@818
   169
hegyi@818
   170
        Path &P;
hegyi@818
   171
alpar@803
   172
	///\param _P the path you want to fill in.
alpar@803
   173
	///
alpar@803
   174
	Builder(Path &_P) : P(_P) {}
alpar@797
   175
alpar@803
   176
	/// Sets the starting node of the path.
alpar@803
   177
      
alpar@803
   178
	/// Sets the starting node of the path. Edge added to the path
alpar@803
   179
	/// afterwards have to be incident to this node.
alpar@803
   180
	/// You \em must start building an empry path with this functions.
alpar@803
   181
	/// (And you \em must \em not use it later).
alpar@803
   182
	/// \sa pushFront()
alpar@803
   183
	/// \sa pushBack()
alpar@803
   184
	void setStartNode(const GraphNode &) {}
alpar@797
   185
alpar@803
   186
	///Push a new edge to the front of the path
alpar@797
   187
alpar@803
   188
	///Push a new edge to the front of the path.
alpar@803
   189
	///If the path is empty, you \em must call \ref setStartNode() before
alpar@803
   190
	///the first use of \ref pushFront().
alpar@803
   191
	void pushFront(const GraphEdge& e) {}
alpar@797
   192
alpar@803
   193
	///Push a new edge to the back of the path
alpar@797
   194
alpar@803
   195
	///Push a new edge to the back of the path.
alpar@803
   196
	///If the path is empty, you \em must call \ref setStartNode() before
alpar@803
   197
	///the first use of \ref pushBack().
alpar@803
   198
	void pushBack(const GraphEdge& e) {}
alpar@797
   199
alpar@803
   200
	///Commit the changes to the path.
alpar@803
   201
	void commit() {}
alpar@797
   202
alpar@803
   203
	///Reserve (front) storage for the builder in advance.
alpar@797
   204
alpar@803
   205
	///If you know an reasonable upper bound of the number of the edges
alpar@803
   206
	///to add to the front of the path,
alpar@803
   207
	///using this function you may speed up the building.
alpar@803
   208
	void reserveFront(size_t r) {}
alpar@803
   209
	///Reserve (back) storage for the builder in advance.
alpar@797
   210
alpar@803
   211
	///If you know an reasonable upper bound of the number of the edges
alpar@803
   212
	///to add to the back of the path,
alpar@803
   213
	///using this function you may speed up the building.
alpar@803
   214
	void reserveBack(size_t r) {}
alpar@803
   215
      };
alpar@797
   216
    };
alpar@797
   217
alpar@803
   218
  ///@}
alpar@797
   219
  }
alpar@797
   220
  
alpar@797
   221
} // namespace hugo
alpar@797
   222
alpar@797
   223
#endif // HUGO_PATH_H