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