src/hugo/path.h
changeset 831 b6ae3446098a
parent 819 3623e8dbce49
child 834 1dd3167db044
     1.1 --- a/src/hugo/path.h	Sun Sep 12 19:32:21 2004 +0000
     1.2 +++ b/src/hugo/path.h	Sun Sep 12 21:46:26 2004 +0000
     1.3 @@ -29,7 +29,7 @@
     1.4  
     1.5  #include <hugo/invalid.h>
     1.6  #include <hugo/error.h>
     1.7 -#include <hugo/debug.h>
     1.8 +//#include <hugo/debug.h>
     1.9  
    1.10  namespace hugo {
    1.11  
    1.12 @@ -48,7 +48,7 @@
    1.13    //! and \c Edge of the original graph.
    1.14    //!
    1.15    //! \todo Thoroughfully check all the range and consistency tests.
    1.16 -  template<typename Graph, typename DM = DefaultDebugMode>
    1.17 +  template<typename Graph>
    1.18    class DirPath {
    1.19    public:
    1.20      /// Edge type of the underlying graph.
    1.21 @@ -74,7 +74,7 @@
    1.22      /// Subpath defined by two nodes.
    1.23      /// \warning It is an error if the two edges are not in order!
    1.24      DirPath(const DirPath &P, const NodeIt &a, const NodeIt &b) {
    1.25 -      if( DM::range_check && (!a.valid() || !b.valid) ) {
    1.26 +      if(!a.valid() || !b.valid) {
    1.27  	// FIXME: this check should be more elaborate...
    1.28  	fault("DirPath, subpath ctor: invalid bounding nodes");
    1.29        }
    1.30 @@ -87,7 +87,7 @@
    1.31      /// Subpath defined by two edges. Contains edges in [a,b)
    1.32      /// \warning It is an error if the two edges are not in order!
    1.33      DirPath(const DirPath &P, const EdgeIt &a, const EdgeIt &b) {
    1.34 -      if( DM::range_check && (!a.valid() || !b.valid) ) {
    1.35 +      if (!a.valid() || !b.valid) {
    1.36  	// FIXME: this check should be more elaborate...
    1.37  	fault("DirPath, subpath ctor: invalid bounding nodes");
    1.38        }
    1.39 @@ -107,14 +107,14 @@
    1.40      ///
    1.41      /// Starting point of the path.
    1.42      /// Returns INVALID if the path is empty.
    1.43 -    GraphNode from() const {
    1.44 +    GraphNode tail() const {
    1.45        return empty() ? INVALID : gr->tail(edges[0]);
    1.46      }
    1.47      /// \brief End point of the path.
    1.48      ///
    1.49      /// End point of the path.
    1.50      /// Returns INVALID if the path is empty.
    1.51 -    GraphNode to() const {
    1.52 +    GraphNode head() const {
    1.53        return empty() ? INVALID : gr->head(edges[length()-1]);
    1.54      }
    1.55  
    1.56 @@ -127,14 +127,14 @@
    1.57  
    1.58      /// \brief Initializes node iterator to point to the node of a given index.
    1.59      NodeIt& nth(NodeIt &i, int n) const {
    1.60 -      if( DM::range_check && (n<0 || n>int(length())) )
    1.61 +      if(n<0 || n>int(length())) 
    1.62  	fault("DirPath::nth: index out of range");
    1.63        return i=NodeIt(*this, n);
    1.64      }
    1.65  
    1.66      /// \brief Initializes edge iterator to point to the edge of a given index.
    1.67      EdgeIt& nth(EdgeIt &i, int n) const {
    1.68 -      if( DM::range_check && (n<0 || n>=int(length())) )
    1.69 +      if(n<0 || n>=int(length())) 
    1.70  	fault("DirPath::nth: index out of range");
    1.71        return i=EdgeIt(*this, n);
    1.72      }
    1.73 @@ -148,7 +148,7 @@
    1.74      template<typename It>
    1.75      static
    1.76      It& next(It &e) {
    1.77 -      if( DM::range_check && !e.valid() )
    1.78 +      if( !e.valid() )
    1.79  	fault("DirPath::next() on invalid iterator");
    1.80        return ++e;
    1.81      }
    1.82 @@ -156,7 +156,7 @@
    1.83      /// \brief Returns node iterator pointing to the head node of the
    1.84      /// given edge iterator.
    1.85      NodeIt head(const EdgeIt& e) const {
    1.86 -      if( DM::range_check && !e.valid() )
    1.87 +      if( !e.valid() )
    1.88  	fault("DirPath::head() on invalid iterator");
    1.89        return NodeIt(*this, e.idx+1);
    1.90      }
    1.91 @@ -164,7 +164,7 @@
    1.92      /// \brief Returns node iterator pointing to the tail node of the
    1.93      /// given edge iterator.
    1.94      NodeIt tail(const EdgeIt& e) const {
    1.95 -      if( DM::range_check && !e.valid() )
    1.96 +      if( !e.valid() )
    1.97  	fault("DirPath::tail() on invalid iterator");
    1.98        return NodeIt(*this, e.idx);
    1.99      }
   1.100 @@ -252,7 +252,7 @@
   1.101        ///Conversion to Graph::Node
   1.102        operator const GraphNode& () const {
   1.103  	if(idx >= p->length())
   1.104 -	  return p->to();
   1.105 +	  return p->head();
   1.106  	else if(idx >= 0)
   1.107  	  return p->gr->tail(p->edges[idx]);
   1.108  	else
   1.109 @@ -312,7 +312,7 @@
   1.110        ///Push a new edge to the front of the path.
   1.111        ///\sa setStartNode
   1.112        void pushFront(const GraphEdge& e) {
   1.113 -	if( DM::consistensy_check && !empty() && P.gr->head(e)!=from() ) {
   1.114 +	if( !empty() && P.gr->head(e)!=tail() ) {
   1.115  	  fault("DirPath::Builder::pushFront: nonincident edge");
   1.116  	}
   1.117  	front.push_back(e);
   1.118 @@ -323,7 +323,7 @@
   1.119        ///Push a new edge to the back of the path.
   1.120        ///\sa setStartNode
   1.121        void pushBack(const GraphEdge& e) {
   1.122 -	if( DM::consistensy_check && !empty() && P.gr->tail(e)!=to() ) {
   1.123 +	if( !empty() && P.gr->tail(e)!=head() ) {
   1.124  	  fault("DirPath::Builder::pushBack: nonincident edge");
   1.125  	}
   1.126  	back.push_back(e);
   1.127 @@ -355,12 +355,15 @@
   1.128  	back.reserve(r);
   1.129        }
   1.130  
   1.131 +      void reserveFront(size_t r) {}
   1.132 +      void reserveBack(size_t r) {}
   1.133 +
   1.134      private:
   1.135        bool empty() {
   1.136  	return front.empty() && back.empty() && P.empty();
   1.137        }
   1.138  
   1.139 -      GraphNode from() const {
   1.140 +      GraphNode tail() const {
   1.141  	if( ! front.empty() )
   1.142  	  return P.gr->tail(front[front.size()-1]);
   1.143  	else if( ! P.empty() )
   1.144 @@ -370,7 +373,7 @@
   1.145  	else
   1.146  	  return INVALID;
   1.147        }
   1.148 -      GraphNode to() const {
   1.149 +      GraphNode head() const {
   1.150  	if( ! back.empty() )
   1.151  	  return P.gr->head(back[back.size()-1]);
   1.152  	else if( ! P.empty() )
   1.153 @@ -411,7 +414,7 @@
   1.154    //! and \c Edge of the original graph.
   1.155    //!
   1.156    //! \todo Thoroughfully check all the range and consistency tests.
   1.157 -  template<typename Graph, typename DM = DefaultDebugMode>
   1.158 +  template<typename Graph>
   1.159    class UndirPath {
   1.160    public:
   1.161      /// Edge type of the underlying graph.
   1.162 @@ -437,7 +440,7 @@
   1.163      /// Subpath defined by two nodes.
   1.164      /// \warning It is an error if the two edges are not in order!
   1.165      UndirPath(const UndirPath &P, const NodeIt &a, const NodeIt &b) {
   1.166 -      if( DM::range_check && (!a.valid() || !b.valid) ) {
   1.167 +      if(!a.valid() || !b.valid) {
   1.168  	// FIXME: this check should be more elaborate...
   1.169  	fault("UndirPath, subpath ctor: invalid bounding nodes");
   1.170        }
   1.171 @@ -450,7 +453,7 @@
   1.172      /// Subpath defined by two edges. Contains edges in [a,b)
   1.173      /// \warning It is an error if the two edges are not in order!
   1.174      UndirPath(const UndirPath &P, const EdgeIt &a, const EdgeIt &b) {
   1.175 -      if( DM::range_check && (!a.valid() || !b.valid) ) {
   1.176 +      if(!a.valid() || !b.valid) {
   1.177  	// FIXME: this check should be more elaborate...
   1.178  	fault("UndirPath, subpath ctor: invalid bounding nodes");
   1.179        }
   1.180 @@ -470,14 +473,14 @@
   1.181      ///
   1.182      /// Starting point of the path.
   1.183      /// Returns INVALID if the path is empty.
   1.184 -    GraphNode from() const {
   1.185 +    GraphNode tail() const {
   1.186        return empty() ? INVALID : gr->tail(edges[0]);
   1.187      }
   1.188      /// \brief End point of the path.
   1.189      ///
   1.190      /// End point of the path.
   1.191      /// Returns INVALID if the path is empty.
   1.192 -    GraphNode to() const {
   1.193 +    GraphNode head() const {
   1.194        return empty() ? INVALID : gr->head(edges[length()-1]);
   1.195      }
   1.196  
   1.197 @@ -490,14 +493,14 @@
   1.198  
   1.199      /// \brief Initializes node iterator to point to the node of a given index.
   1.200      NodeIt& nth(NodeIt &i, int n) const {
   1.201 -      if( DM::range_check && (n<0 || n>int(length())) )
   1.202 +      if(n<0 || n>int(length()))
   1.203  	fault("UndirPath::nth: index out of range");
   1.204        return i=NodeIt(*this, n);
   1.205      }
   1.206  
   1.207      /// \brief Initializes edge iterator to point to the edge of a given index.
   1.208      EdgeIt& nth(EdgeIt &i, int n) const {
   1.209 -      if( DM::range_check && (n<0 || n>=int(length())) )
   1.210 +      if(n<0 || n>=int(length()))
   1.211  	fault("UndirPath::nth: index out of range");
   1.212        return i=EdgeIt(*this, n);
   1.213      }
   1.214 @@ -511,7 +514,7 @@
   1.215      template<typename It>
   1.216      static
   1.217      It& next(It &e) {
   1.218 -      if( DM::range_check && !e.valid() )
   1.219 +      if( !e.valid() )
   1.220  	fault("UndirPath::next() on invalid iterator");
   1.221        return ++e;
   1.222      }
   1.223 @@ -519,7 +522,7 @@
   1.224      /// \brief Returns node iterator pointing to the head node of the
   1.225      /// given edge iterator.
   1.226      NodeIt head(const EdgeIt& e) const {
   1.227 -      if( DM::range_check && !e.valid() )
   1.228 +      if( !e.valid() )
   1.229  	fault("UndirPath::head() on invalid iterator");
   1.230        return NodeIt(*this, e.idx+1);
   1.231      }
   1.232 @@ -527,7 +530,7 @@
   1.233      /// \brief Returns node iterator pointing to the tail node of the
   1.234      /// given edge iterator.
   1.235      NodeIt tail(const EdgeIt& e) const {
   1.236 -      if( DM::range_check && !e.valid() )
   1.237 +      if( !e.valid() )
   1.238  	fault("UndirPath::tail() on invalid iterator");
   1.239        return NodeIt(*this, e.idx);
   1.240      }
   1.241 @@ -613,7 +616,7 @@
   1.242        ///Conversion to Graph::Node
   1.243        operator const GraphNode& () const {
   1.244  	if(idx >= p->length())
   1.245 -	  return p->to();
   1.246 +	  return p->head();
   1.247  	else if(idx >= 0)
   1.248  	  return p->gr->tail(p->edges[idx]);
   1.249  	else
   1.250 @@ -673,7 +676,7 @@
   1.251        ///Push a new edge to the front of the path.
   1.252        ///\sa setStartNode
   1.253        void pushFront(const GraphEdge& e) {
   1.254 -	if( DM::consistensy_check && !empty() && P.gr->head(e)!=from() ) {
   1.255 +	if( !empty() && P.gr->head(e)!=tail() ) {
   1.256  	  fault("UndirPath::Builder::pushFront: nonincident edge");
   1.257  	}
   1.258  	front.push_back(e);
   1.259 @@ -684,7 +687,7 @@
   1.260        ///Push a new edge to the back of the path.
   1.261        ///\sa setStartNode
   1.262        void pushBack(const GraphEdge& e) {
   1.263 -	if( DM::consistensy_check && !empty() && P.gr->tail(e)!=to() ) {
   1.264 +	if( !empty() && P.gr->tail(e)!=head() ) {
   1.265  	  fault("UndirPath::Builder::pushBack: nonincident edge");
   1.266  	}
   1.267  	back.push_back(e);
   1.268 @@ -716,12 +719,15 @@
   1.269  	back.reserve(r);
   1.270        }
   1.271  
   1.272 +      void reserveFront(size_t r) {}
   1.273 +      void reserveBack(size_t r) {}
   1.274 +
   1.275      private:
   1.276        bool empty() {
   1.277  	return front.empty() && back.empty() && P.empty();
   1.278        }
   1.279  
   1.280 -      GraphNode from() const {
   1.281 +      GraphNode tail() const {
   1.282  	if( ! front.empty() )
   1.283  	  return P.gr->tail(front[front.size()-1]);
   1.284  	else if( ! P.empty() )
   1.285 @@ -731,7 +737,7 @@
   1.286  	else
   1.287  	  return INVALID;
   1.288        }
   1.289 -      GraphNode to() const {
   1.290 +      GraphNode head() const {
   1.291  	if( ! back.empty() )
   1.292  	  return P.gr->head(back[back.size()-1]);
   1.293  	else if( ! P.empty() )
   1.294 @@ -791,8 +797,8 @@
   1.295      DynamicPath(const DynamicPath &P, const EdgeIt &a, const EdgeIt &b);
   1.296      
   1.297      size_t length() const { return edges.size(); }
   1.298 -    GraphNode from() const { return _first; }
   1.299 -    GraphNode to() const { return _last; }
   1.300 +    GraphNode tail() const { return _first; }
   1.301 +    GraphNode head() const { return _last; }
   1.302  
   1.303      NodeIt& first(NodeIt &n) const { return nth(n, 0); }
   1.304      EdgeIt& first(EdgeIt &e) const { return nth(e, 0); }