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