Planeshift
edge.h
Go to the documentation of this file.
1 /*
2  * edge.h
3  *
4  * Copyright (C) 2011 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5  *
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation (version 2 of the License)
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  */
19 #ifndef __EDGE_H__
20 #define __EDGE_H__
21 
22 #include "util/pspath.h"
23 #include "util/pspathnetwork.h"
24 
25 // Forward declaration of types
26 class psPathPoint;
27 
39 class Edge
40 {
41 private:
42 
43  psPath* path;
44  psPath::Direction direction;
45 
46  Waypoint* startWaypoint;
47  Waypoint* endWaypoint;
48 
49 public:
50 
53  Edge(psPath* path, psPath::Direction direction);
54 
55 
58  virtual ~Edge();
59 
60 
64 
68 
71  psPath* GetPath() { return path; }
72 
75  psPath::Direction GetDirection() { return direction; }
76 
80 
84 
87  Edge* GetRandomEdge(const psPathNetwork::RouteFilter* routeFilter);
88 
91  bool IsTeleport() const;
92 
95  bool NoWander() const;
96 
99  class Iterator
100  {
101  public:
103  Iterator(){};
104 
106  virtual ~Iterator(){};
107 
110  virtual bool HasNext() = 0;
111 
118  virtual psPathPoint* Next() = 0;
119  };
120 
128 
129 protected:
130 
133  class ForwardIterator: public Iterator
134  {
135  private:
136  psPath::PathPointArray::Iterator pointIterator;
137  public:
138 
140  pointIterator(edge->path->points.GetIterator())
141  {
142  }
143 
144  virtual bool HasNext()
145  {
146  return pointIterator.HasNext();
147  }
148 
149  virtual psPathPoint* Next()
150  {
151  return pointIterator.Next();
152  }
153  };
154 
157  class ReverseIterator: public Iterator
158  {
159  private:
160  psPath::PathPointArray::ReverseIterator pointIterator;
161  public:
162 
164  pointIterator(edge->path->points.GetReverseIterator())
165  {
166  }
167 
168  virtual bool HasNext()
169  {
170  return pointIterator.HasNext();
171  }
172 
173  virtual psPathPoint* Next()
174  {
175  return pointIterator.Next();
176  }
177  };
178 
179 };
180 
183 #endif
psPath * GetPath()
Return the path.
Definition: edge.h:71
bool NoWander() const
Check if wander is allowed.
virtual bool HasNext()
Check if there is more elements.
Definition: edge.h:168
psPathPoint * GetStartPoint()
Return the first point in this edge.
virtual psPathPoint * Next()=0
Return next element.
Definition: pspath.h:152
virtual bool HasNext()
Check if there is more elements.
Definition: edge.h:144
virtual ~Edge()
Destructor.
ForwardIterator(Edge *edge)
Definition: edge.h:139
Direction
Definition: pspath.h:156
psPathPoint * GetEndPoint()
Return the end point in this edge.
Represents the Edge in a PathNetwork.
Definition: edge.h:39
A waypoint is a specified circle on the map with a name, location, and a list of waypoints it is conn...
Definition: waypoint.h:81
Implementation of Iterator for REVERSE direction.
Definition: edge.h:157
psPath::Direction GetDirection()
Return the direction of path this edge is going.
Definition: edge.h:75
bool IsTeleport() const
Check if this edge a teleport edge.
virtual ~Iterator()
Destructor.
Definition: edge.h:106
Iterator * GetIterator()
Return the iterator for this edge.
Implementation of Iterator for FORWARD direction.
Definition: edge.h:133
Iterator base class for Forward and Reverse Iterators.
Definition: edge.h:99
Waypoint * GetStartWaypoint()
Return the first waypoint in the edge.
virtual psPathPoint * Next()
Return next element.
Definition: edge.h:149
Waypoint * GetEndWaypoint()
Return the last waypoint in the edge.
Edge * GetRandomEdge(const psPathNetwork::RouteFilter *routeFilter)
Get a random edge from this.
Template class for implementing waypoint filtering when calculating routes.
Definition: pspathnetwork.h:49
Iterator()
Constructor.
Definition: edge.h:103
virtual bool HasNext()=0
Check if there is more elements.
Edge(psPath *path, psPath::Direction direction)
Create a new Edge for a path in the given direction.
ReverseIterator(Edge *edge)
Definition: edge.h:163
Represents a point on a path between two waypoints.
Definition: pspath.h:58
virtual psPathPoint * Next()
Return next element.
Definition: edge.h:173