Changeset 831:b6ae3446098a in lemon-0.x for src/hugo/path.h
- Timestamp:
- 09/12/04 23:46:26 (21 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1129
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/hugo/path.h
r819 r831 30 30 #include <hugo/invalid.h> 31 31 #include <hugo/error.h> 32 #include <hugo/debug.h>32 //#include <hugo/debug.h> 33 33 34 34 namespace hugo { … … 49 49 //! 50 50 //! \todo Thoroughfully check all the range and consistency tests. 51 template<typename Graph , typename DM = DefaultDebugMode>51 template<typename Graph> 52 52 class DirPath { 53 53 public: … … 75 75 /// \warning It is an error if the two edges are not in order! 76 76 DirPath(const DirPath &P, const NodeIt &a, const NodeIt &b) { 77 if( DM::range_check && (!a.valid() || !b.valid)) {77 if(!a.valid() || !b.valid) { 78 78 // FIXME: this check should be more elaborate... 79 79 fault("DirPath, subpath ctor: invalid bounding nodes"); … … 88 88 /// \warning It is an error if the two edges are not in order! 89 89 DirPath(const DirPath &P, const EdgeIt &a, const EdgeIt &b) { 90 if ( DM::range_check && (!a.valid() || !b.valid)) {90 if (!a.valid() || !b.valid) { 91 91 // FIXME: this check should be more elaborate... 92 92 fault("DirPath, subpath ctor: invalid bounding nodes"); … … 108 108 /// Starting point of the path. 109 109 /// Returns INVALID if the path is empty. 110 GraphNode from() const {110 GraphNode tail() const { 111 111 return empty() ? INVALID : gr->tail(edges[0]); 112 112 } … … 115 115 /// End point of the path. 116 116 /// Returns INVALID if the path is empty. 117 GraphNode to() const {117 GraphNode head() const { 118 118 return empty() ? INVALID : gr->head(edges[length()-1]); 119 119 } … … 128 128 /// \brief Initializes node iterator to point to the node of a given index. 129 129 NodeIt& nth(NodeIt &i, int n) const { 130 if( DM::range_check && (n<0 || n>int(length())) )130 if(n<0 || n>int(length())) 131 131 fault("DirPath::nth: index out of range"); 132 132 return i=NodeIt(*this, n); … … 135 135 /// \brief Initializes edge iterator to point to the edge of a given index. 136 136 EdgeIt& nth(EdgeIt &i, int n) const { 137 if( DM::range_check && (n<0 || n>=int(length())) )137 if(n<0 || n>=int(length())) 138 138 fault("DirPath::nth: index out of range"); 139 139 return i=EdgeIt(*this, n); … … 149 149 static 150 150 It& next(It &e) { 151 if( DM::range_check &&!e.valid() )151 if( !e.valid() ) 152 152 fault("DirPath::next() on invalid iterator"); 153 153 return ++e; … … 157 157 /// given edge iterator. 158 158 NodeIt head(const EdgeIt& e) const { 159 if( DM::range_check &&!e.valid() )159 if( !e.valid() ) 160 160 fault("DirPath::head() on invalid iterator"); 161 161 return NodeIt(*this, e.idx+1); … … 165 165 /// given edge iterator. 166 166 NodeIt tail(const EdgeIt& e) const { 167 if( DM::range_check &&!e.valid() )167 if( !e.valid() ) 168 168 fault("DirPath::tail() on invalid iterator"); 169 169 return NodeIt(*this, e.idx); … … 253 253 operator const GraphNode& () const { 254 254 if(idx >= p->length()) 255 return p-> to();255 return p->head(); 256 256 else if(idx >= 0) 257 257 return p->gr->tail(p->edges[idx]); … … 313 313 ///\sa setStartNode 314 314 void pushFront(const GraphEdge& e) { 315 if( DM::consistensy_check && !empty() && P.gr->head(e)!=from() ) {315 if( !empty() && P.gr->head(e)!=tail() ) { 316 316 fault("DirPath::Builder::pushFront: nonincident edge"); 317 317 } … … 324 324 ///\sa setStartNode 325 325 void pushBack(const GraphEdge& e) { 326 if( DM::consistensy_check && !empty() && P.gr->tail(e)!=to() ) {326 if( !empty() && P.gr->tail(e)!=head() ) { 327 327 fault("DirPath::Builder::pushBack: nonincident edge"); 328 328 } … … 356 356 } 357 357 358 void reserveFront(size_t r) {} 359 void reserveBack(size_t r) {} 360 358 361 private: 359 362 bool empty() { … … 361 364 } 362 365 363 GraphNode from() const {366 GraphNode tail() const { 364 367 if( ! front.empty() ) 365 368 return P.gr->tail(front[front.size()-1]); … … 371 374 return INVALID; 372 375 } 373 GraphNode to() const {376 GraphNode head() const { 374 377 if( ! back.empty() ) 375 378 return P.gr->head(back[back.size()-1]); … … 412 415 //! 413 416 //! \todo Thoroughfully check all the range and consistency tests. 414 template<typename Graph , typename DM = DefaultDebugMode>417 template<typename Graph> 415 418 class UndirPath { 416 419 public: … … 438 441 /// \warning It is an error if the two edges are not in order! 439 442 UndirPath(const UndirPath &P, const NodeIt &a, const NodeIt &b) { 440 if( DM::range_check && (!a.valid() || !b.valid)) {443 if(!a.valid() || !b.valid) { 441 444 // FIXME: this check should be more elaborate... 442 445 fault("UndirPath, subpath ctor: invalid bounding nodes"); … … 451 454 /// \warning It is an error if the two edges are not in order! 452 455 UndirPath(const UndirPath &P, const EdgeIt &a, const EdgeIt &b) { 453 if( DM::range_check && (!a.valid() || !b.valid)) {456 if(!a.valid() || !b.valid) { 454 457 // FIXME: this check should be more elaborate... 455 458 fault("UndirPath, subpath ctor: invalid bounding nodes"); … … 471 474 /// Starting point of the path. 472 475 /// Returns INVALID if the path is empty. 473 GraphNode from() const {476 GraphNode tail() const { 474 477 return empty() ? INVALID : gr->tail(edges[0]); 475 478 } … … 478 481 /// End point of the path. 479 482 /// Returns INVALID if the path is empty. 480 GraphNode to() const {483 GraphNode head() const { 481 484 return empty() ? INVALID : gr->head(edges[length()-1]); 482 485 } … … 491 494 /// \brief Initializes node iterator to point to the node of a given index. 492 495 NodeIt& nth(NodeIt &i, int n) const { 493 if( DM::range_check && (n<0 || n>int(length())))496 if(n<0 || n>int(length())) 494 497 fault("UndirPath::nth: index out of range"); 495 498 return i=NodeIt(*this, n); … … 498 501 /// \brief Initializes edge iterator to point to the edge of a given index. 499 502 EdgeIt& nth(EdgeIt &i, int n) const { 500 if( DM::range_check && (n<0 || n>=int(length())))503 if(n<0 || n>=int(length())) 501 504 fault("UndirPath::nth: index out of range"); 502 505 return i=EdgeIt(*this, n); … … 512 515 static 513 516 It& next(It &e) { 514 if( DM::range_check &&!e.valid() )517 if( !e.valid() ) 515 518 fault("UndirPath::next() on invalid iterator"); 516 519 return ++e; … … 520 523 /// given edge iterator. 521 524 NodeIt head(const EdgeIt& e) const { 522 if( DM::range_check &&!e.valid() )525 if( !e.valid() ) 523 526 fault("UndirPath::head() on invalid iterator"); 524 527 return NodeIt(*this, e.idx+1); … … 528 531 /// given edge iterator. 529 532 NodeIt tail(const EdgeIt& e) const { 530 if( DM::range_check &&!e.valid() )533 if( !e.valid() ) 531 534 fault("UndirPath::tail() on invalid iterator"); 532 535 return NodeIt(*this, e.idx); … … 614 617 operator const GraphNode& () const { 615 618 if(idx >= p->length()) 616 return p-> to();619 return p->head(); 617 620 else if(idx >= 0) 618 621 return p->gr->tail(p->edges[idx]); … … 674 677 ///\sa setStartNode 675 678 void pushFront(const GraphEdge& e) { 676 if( DM::consistensy_check && !empty() && P.gr->head(e)!=from() ) {679 if( !empty() && P.gr->head(e)!=tail() ) { 677 680 fault("UndirPath::Builder::pushFront: nonincident edge"); 678 681 } … … 685 688 ///\sa setStartNode 686 689 void pushBack(const GraphEdge& e) { 687 if( DM::consistensy_check && !empty() && P.gr->tail(e)!=to() ) {690 if( !empty() && P.gr->tail(e)!=head() ) { 688 691 fault("UndirPath::Builder::pushBack: nonincident edge"); 689 692 } … … 717 720 } 718 721 722 void reserveFront(size_t r) {} 723 void reserveBack(size_t r) {} 724 719 725 private: 720 726 bool empty() { … … 722 728 } 723 729 724 GraphNode from() const {730 GraphNode tail() const { 725 731 if( ! front.empty() ) 726 732 return P.gr->tail(front[front.size()-1]); … … 732 738 return INVALID; 733 739 } 734 GraphNode to() const {740 GraphNode head() const { 735 741 if( ! back.empty() ) 736 742 return P.gr->head(back[back.size()-1]); … … 792 798 793 799 size_t length() const { return edges.size(); } 794 GraphNode from() const { return _first; }795 GraphNode to() const { return _last; }800 GraphNode tail() const { return _first; } 801 GraphNode head() const { return _last; } 796 802 797 803 NodeIt& first(NodeIt &n) const { return nth(n, 0); }
Note: See TracChangeset
for help on using the changeset viewer.