Changeset 1021:fd1d073b6557 in lemon-0.x
- Timestamp:
- 11/25/04 15:48:24 (20 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1411
- Location:
- src/lemon
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/lemon/concept/graph_component.h
r989 r1021 506 506 /// InEdgeIt you should instantiate it with character 'i' and for 507 507 /// OutEdgeIt with 'o'. 508 /// \todo check the name of the concept GraphIncEdgeIterator 509 template <typename _Graph, char _selector> 510 class GraphIncEdgeIterator : public _Graph::Edge { 508 /// \todo Is this a good name for this concept? 509 template <typename Graph, 510 typename Edge = typename Graph::Edge, 511 char _selector = '0'> 512 class GraphIncIterator : public Edge { 511 513 public: 512 514 /// Default constructor. … … 514 516 /// @warning The default constructor sets the iterator 515 517 /// to an undefined value. 516 GraphInc EdgeIterator() {}518 GraphIncIterator() {} 517 519 /// Copy constructor. 518 520 519 521 /// Copy constructor. 520 522 /// 521 GraphInc EdgeIterator(GraphIncEdgeIterator const&) {}523 GraphIncIterator(GraphIncIterator const&) {} 522 524 /// Sets the iterator to the first edge incoming into or outgoing from the node. 523 525 524 526 /// Sets the iterator to the first edge incoming into or outgoing from the node. 525 527 /// 526 explicit GraphInc EdgeIterator(const _Graph&, const typename _Graph::Node&) {}528 explicit GraphIncIterator(const Graph&, const typename Graph::Node&) {} 527 529 /// Invalid constructor \& conversion. 528 530 529 531 /// This constructor initializes the item to be invalid. 530 532 /// \sa Invalid for more details. 531 GraphInc EdgeIterator(Invalid) {}533 GraphIncIterator(Invalid) {} 532 534 /// Assign operator for nodes. 533 535 534 536 /// The nodes are assignable. 535 537 /// 536 GraphInc EdgeIterator& operator=(GraphIncEdgeIterator const&) { return *this; }538 GraphIncIterator& operator=(GraphIncIterator const&) { return *this; } 537 539 /// Next edge. 538 540 539 541 /// Assign the iterator to the next node. 540 542 /// 541 GraphIncEdgeIterator& operator++() { return *this; } 543 GraphIncIterator& operator++() { return *this; } 544 542 545 // Node operator*() const { return INVALID; } 546 543 547 /// Equality operator 544 548 545 549 /// Two iterators are equal if and only if they point to the 546 550 /// same object or both are invalid. 547 bool operator==(const GraphIncEdgeIterator&) const { return true;} 551 bool operator==(const GraphIncIterator&) const { return true;} 552 548 553 /// Inequality operator 549 554 550 555 /// \sa operator==(Node n) 551 556 /// 552 bool operator!=(const GraphIncEdgeIterator&) const { return true;} 553 554 template <typename _GraphIncEdgeIterator> 555 struct Constraints { 556 typedef typename _Graph::Node Node; 557 typedef typename _Graph::Edge Edge; 558 void constraints() { 559 checkConcept<GraphItem<'e'>, _GraphIncEdgeIterator>(); 560 _GraphIncEdgeIterator it1(graph, node); 557 bool operator!=(const GraphIncIterator&) const { return true;} 558 559 template <typename _GraphIncIterator> 560 struct Constraints { 561 typedef typename Graph::Node Node; 562 void constraints() { 563 checkConcept<GraphItem<'e'>, _GraphIncIterator>(); 564 _GraphIncIterator it1(graph, node); 561 565 /// \todo Do we need OutEdgeIt(Edge) kind of constructor? 562 // _GraphInc EdgeIterator it2(edge);563 _GraphInc EdgeIterator it2;566 // _GraphIncIterator it2(edge); 567 _GraphIncIterator it2; 564 568 565 569 it2 = ++it1; … … 572 576 Edge& edge; 573 577 Node& node; 574 _Graph& graph; 575 }; 576 }; 578 Graph& graph; 579 }; 580 }; 581 582 577 583 /// An empty iterable base graph class. 578 584 … … 603 609 /// This iterator goes trough the \e inccoming edges of a certain node 604 610 /// of a graph. 605 typedef GraphInc EdgeIterator<Graph, 'i'> InEdgeIt;611 typedef GraphIncIterator<Graph, Edge, 'i'> InEdgeIt; 606 612 /// This iterator goes trough the outgoing edges of a node. 607 613 608 614 /// This iterator goes trough the \e outgoing edges of a certain node 609 615 /// of a graph. 610 typedef GraphInc EdgeIterator<Graph, 'o'> OutEdgeIt;616 typedef GraphIncIterator<Graph, Edge, 'o'> OutEdgeIt; 611 617 }; 612 618 … … 618 624 checkConcept<GraphIterator<_Graph, typename _Graph::Edge>, typename _Graph::EdgeIt >(); 619 625 checkConcept<GraphIterator<_Graph, typename _Graph::Node>, typename _Graph::NodeIt >(); 620 checkConcept<GraphInc EdgeIterator<_Graph, 'i'>, typename _Graph::InEdgeIt >();621 checkConcept<GraphInc EdgeIterator<_Graph, 'o'>, typename _Graph::OutEdgeIt >();626 checkConcept<GraphIncIterator<_Graph>, typename _Graph::InEdgeIt >(); 627 checkConcept<GraphIncIterator<_Graph>, typename _Graph::OutEdgeIt >(); 622 628 } 623 629 }; -
src/lemon/concept/undir_graph.h
r989 r1021 68 68 typedef typename Graph::UndirEdge UndirEdge; 69 69 typedef typename Graph::UndirEdgeIt UndirEdgeIt; 70 typedef typename Graph::UndirIncEdgeIt UndirIncEdgeIt; 70 71 71 72 checkConcept< GraphIterator<Graph, UndirEdge>, UndirEdgeIt >(); 73 74 checkConcept< 75 GraphIncIterator<Graph, UndirEdge>, 76 UndirIncEdgeIt >(); 72 77 } 73 78 }; -
src/lemon/iterable_graph_extender.h
r962 r1021 132 132 typedef IterableGraphExtender<_Base> Parent; 133 133 typedef IterableUndirGraphExtender<_Base> Graph; 134 typedef typename Parent::Node Node; 134 135 135 136 typedef typename Parent::UndirEdge UndirEdge; … … 157 158 }; 158 159 160 class UndirIncEdgeIt : public UndirEdge { 161 const Graph* graph; 162 bool forward; 163 friend class IterableUndirGraphExtender; 164 template <typename G> 165 friend class UndirGraphExtender; 166 public: 167 168 UndirIncEdgeIt() { } 169 170 UndirIncEdgeIt(Invalid i) : UndirEdge(i), forward(false) { } 171 172 explicit UndirIncEdgeIt(const Graph& _graph, const Node &n) 173 : graph(&_graph) 174 { 175 _graph._dirFirstOut(*this, n); 176 } 177 178 // FIXME: Do we need this type of constructor here? 179 // UndirIncEdgeIt(const Graph& _graph, const UndirEdge& e) : 180 // UndirEdge(e), graph(&_graph) { } 181 182 UndirIncEdgeIt& operator++() { 183 graph->_dirNextOut(*this); 184 return *this; 185 } 186 }; 187 188 Node source(const UndirIncEdgeIt &e) const { 189 return _dirSource(e); 190 } 191 192 /// \todo Shouldn't the "source" of an undirected edge be called "aNode" 193 /// or something??? 194 using Parent::source; 195 196 /// Target of the given Edge. 197 Node target(const UndirIncEdgeIt &e) const { 198 return _dirTarget(e); 199 } 200 201 /// \todo Shouldn't the "target" of an undirected edge be called "bNode" 202 /// or something??? 203 using Parent::target; 159 204 160 205 }; -
src/lemon/undir_graph_extender.h
r986 r1021 71 71 } 72 72 73 /// Source of the given Edge. 74 Node source(const Edge &e) const { 73 protected: 74 75 template <typename E> 76 Node _dirSource(const E &e) const { 75 77 return e.forward ? Parent::source(e) : Parent::target(e); 76 78 } 77 79 80 template <typename E> 81 Node _dirTarget(const E &e) const { 82 return e.forward ? Parent::target(e) : Parent::source(e); 83 } 84 85 public: 78 86 /// \todo Shouldn't the "source" of an undirected edge be called "aNode" 79 87 /// or something??? 80 88 using Parent::source; 81 89 82 /// Targetof the given Edge.83 Node target(const Edge &e) const {84 return e.forward ? Parent::target(e) : Parent::source(e);90 /// Source of the given Edge. 91 Node source(const Edge &e) const { 92 return _dirSource(e); 85 93 } 86 94 … … 88 96 /// or something??? 89 97 using Parent::target; 98 99 /// Target of the given Edge. 100 Node target(const Edge &e) const { 101 return _dirTarget(e); 102 } 90 103 91 104 /// Returns whether the given directed edge is same orientation as the … … 123 136 } 124 137 125 void firstOut(Edge &e, const Node &n) const { 138 139 protected: 140 141 template <typename E> 142 void _dirFirstOut(E &e, const Node &n) const { 126 143 Parent::firstOut(e,n); 127 144 if( UndirEdge(e) != INVALID ) { … … 133 150 } 134 151 } 135 void firstIn(Edge &e, const Node &n) const { 152 template <typename E> 153 void _dirFirstIn(E &e, const Node &n) const { 136 154 Parent::firstIn(e,n); 137 155 if( UndirEdge(e) != INVALID ) { … … 144 162 } 145 163 146 void nextOut(Edge &e) const { 164 template <typename E> 165 void _dirNextOut(E &e) const { 147 166 if( e.forward ) { 148 167 Parent::nextOut(e); … … 156 175 } 157 176 } 158 void nextIn(Edge &e) const { 177 template <typename E> 178 void _dirNextIn(E &e) const { 159 179 if( e.forward ) { 160 180 Parent::nextIn(e); … … 169 189 } 170 190 191 public: 192 193 void firstOut(Edge &e, const Node &n) const { 194 _dirFirstOut(e, n); 195 } 196 void firstIn(Edge &e, const Node &n) const { 197 _dirFirstIn(e, n); 198 } 199 200 void nextOut(Edge &e) const { 201 _dirNextOut(e); 202 } 203 void nextIn(Edge &e) const { 204 _dirNextIn(e); 205 } 206 171 207 // Miscellaneous stuff: 172 208 … … 174 210 /// Extender 175 211 176 using Parent::id; 212 // using Parent::id; 213 // Using "using" is not a good idea, cause it could be that there is 214 // no "id" in Parent... 215 216 int id(const Node &n) const { 217 return Parent::id(n); 218 } 219 220 int id(const UndirEdge &e) const { 221 return Parent::id(e); 222 } 177 223 178 224 int id(const Edge &e) const { … … 180 226 } 181 227 182 int maxId(Edge = INVALID) const { 228 229 int maxId(Node n) const { 230 return Parent::maxId(Node()); 231 } 232 233 int maxId(Edge) const { 183 234 return 2 * Parent::maxId(typename Parent::Edge()) + 1; 184 235 } 185 int maxId(UndirEdge = INVALID) const {236 int maxId(UndirEdge) const { 186 237 return Parent::maxId(typename Parent::Edge()); 187 238 }
Note: See TracChangeset
for help on using the changeset viewer.