Planeshift

edge.h

Go to the documentation of this file.
00001 /*
00002  * edge.h
00003  *
00004  * Copyright (C) 2011 Atomic Blue ([email protected], http://www.atomicblue.org) 
00005  *
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation (version 2 of the License)
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017  *
00018  */
00019 #ifndef __EDGE_H__
00020 #define __EDGE_H__
00021 
00022 #include "util/pspath.h"
00023 #include "util/pspathnetwork.h"
00024 
00025 // Forward declaration of types
00026 class psPathPoint;
00027 
00039 class Edge
00040 {
00041 private:
00042 
00043     psPath*            path;          
00044     psPath::Direction  direction;     
00045 
00046     Waypoint*          startWaypoint; 
00047     Waypoint*          endWaypoint;   
00048 
00049 public:
00050 
00053     Edge(psPath* path, psPath::Direction direction);
00054     
00055 
00058     virtual ~Edge();
00059 
00060 
00063     psPathPoint* GetStartPoint();
00064 
00067     psPathPoint* GetEndPoint();
00068 
00071     psPath* GetPath() { return path; }
00072 
00075     psPath::Direction GetDirection() { return direction; }
00076     
00079     Waypoint* GetStartWaypoint();
00080 
00083     Waypoint* GetEndWaypoint();
00084 
00087     Edge* GetRandomEdge(const psPathNetwork::RouteFilter* routeFilter);
00088 
00091     bool IsTeleport() const;
00092 
00095     bool NoWander() const;
00096 
00099     class Iterator
00100     {
00101       public:
00103         Iterator(){};
00104 
00106         virtual ~Iterator(){};
00107 
00110         virtual bool HasNext() = 0;
00111 
00118         virtual psPathPoint* Next() = 0;
00119     };
00120 
00127     Iterator* GetIterator();
00128 
00129 protected:
00130 
00133     class ForwardIterator: public Iterator
00134     {
00135       private:
00136         psPath::PathPointArray::Iterator pointIterator;
00137       public:
00138 
00139         ForwardIterator(Edge* edge):
00140             pointIterator(edge->path->points.GetIterator())
00141         {
00142         }
00143 
00144         virtual bool HasNext()
00145         {
00146             return pointIterator.HasNext();
00147         }
00148 
00149         virtual psPathPoint* Next()
00150         {
00151             return pointIterator.Next();
00152         }
00153     };
00154 
00157     class ReverseIterator: public Iterator
00158     {
00159       private:
00160         psPath::PathPointArray::ReverseIterator pointIterator;
00161       public:
00162 
00163         ReverseIterator(Edge* edge):
00164             pointIterator(edge->path->points.GetReverseIterator())
00165         {
00166         }
00167 
00168         virtual bool HasNext()
00169         {
00170             return pointIterator.HasNext();
00171         }
00172 
00173         virtual psPathPoint* Next()
00174         {
00175             return pointIterator.Next();
00176         }
00177     };
00178 
00179 };
00180 
00183 #endif