KrisLibrary  1.0.0
Edge.h
1 #ifndef GRAPH_EDGE_H
2 #define GRAPH_EDGE_H
3 
4 #include <map>
5 #include <list>
6 
7 namespace Graph {
8 
9 /****************************************************************
10  * EdgeIterator() classes
11  * ---------------------------------------
12  * source() returns the source (tail) of the edge.
13  * target() returns the target (head) of the edge.
14  * *() returns a reference to the satellite data.
15  * ->() returns a pointer to the satellite data.
16  * ++ proceeds to the next item.
17  * end() returns true if the iteration has ended.
18  *
19  * Iteration is done as follows:
20  * EdgeIterator<Data> it;
21  * for(graph.Begin(it,n);!it.end();it++) {
22  * //do something
23  * }
24  *
25  ****************************************************************/
26 
27 template <class Data>
29 {
30 public:
31  typedef typename std::list<Data>::iterator DataPtr;
32  typedef const std::map<int,DataPtr> EdgeList;
33  typedef typename EdgeList::const_iterator EdgeListIterator;
34 
35  EdgeIterator()
36  : n(-1), edges(NULL)
37  {}
38  inline void init(EdgeList& _edges,EdgeList& _co_edges) {
39  edges = &_edges;
40  e = _edges.begin();
41  }
42  inline int source() const { return n; }
43  inline int target() const { return e->first; }
44  inline bool end() const { return e==edges->end(); }
45  inline void operator++() { ++e; }
46  inline void operator++(int) { ++e; }
47  inline void operator--() { --e; }
48  inline void operator--(int) { --e; }
49  inline Data* operator->() const { return &(*e->second); }
50  inline Data& operator*() const { return *e->second; }
51 
52  int n;
53  EdgeListIterator e;
54  EdgeList *edges, *co_edges;
55 };
56 
57 template <class Data>
59 {
60  typedef typename std::list<Data>::iterator DataPtr;
61  typedef const std::map<int,DataPtr> EdgeList;
62  typedef typename EdgeList::const_iterator EdgeListIterator;
63 
65  : n(-1), co_edges(NULL)
66  {}
67  inline void init(EdgeList& _edges,EdgeList& _co_edges) {
68  co_edges = &_co_edges;
69  e = _co_edges.begin();
70  }
71  inline int source() const { return n; }
72  inline int target() const { return e->first; }
73  inline bool end() const { return e==co_edges->end(); }
74  inline void operator++() { ++e; }
75  inline void operator++(int) { ++e; }
76  inline void operator--() { --e; }
77  inline void operator--(int) { --e; }
78  inline Data* operator->() const { return &(*e->second); }
79  inline Data& operator*() const { return *e->second; }
80  inline Data& operator*() { return *e->second; }
81 
82  int n;
83  EdgeListIterator e;
84  EdgeList *co_edges;
85 };
86 
87 template <class Data>
89 {
90 public:
91  typedef typename std::list<Data>::iterator DataPtr;
92  typedef const std::map<int,DataPtr> EdgeList;
93  typedef typename EdgeList::const_iterator EdgeListIterator;
94 
96  : n(-1), edges(NULL), co_edges(NULL)
97  {}
98  inline void init(EdgeList& _edges,EdgeList& _co_edges) {
99  edges = &_edges;
100  co_edges = &_co_edges;
101  e = (_edges.empty() ? _co_edges.begin() : _edges.begin());
102  }
103  inline int source() const { return n; }
104  inline int target() const { return e->first; }
105  inline bool end() const { return e==co_edges->end(); }
106  inline void operator++() {
107  ++e;
108  if(e == edges->end()) e=co_edges->begin();
109  }
110  inline void operator++(int) { operator++(); }
111  inline void operator--() {
112  if(e == co_edges->begin())
113  e = --edges->end();
114  else --e;
115  }
116  inline void operator--(int) { operator--(); }
117  inline Data* operator->() const { return &(*e->second); }
118  inline Data& operator*() const { return *e->second; }
119 
120  int n;
121  EdgeListIterator e;
122  const EdgeList *edges,*co_edges;
123 };
124 
125 
126 typedef double Weight;
127 
128 template <class Edge>
129 inline Weight ConstantWeight(const Edge& e) { return 1.0; }
130 template <class Edge>
131 inline Weight StandardWeight(const Edge& e) { return e.weight; }
132 
133 } //namespace Graph
134 
135 #endif
Definition: Edge.h:28
Abstract base class for an edge planner / edge checker (i.e., local planner).
Definition: EdgePlanner.h:49
Definition: Edge.h:58
Namespace for all classes and functions in the Graph subdirectory.
Definition: ApproximateShortestPaths.h:7
Definition: Edge.h:88