]> git.mxchange.org Git - simgear.git/blob - simgear/route/route.hxx
Added route.[ch]xx which maintains a list of waypoints (i.e. a route)
[simgear.git] / simgear / route / route.hxx
1 // route.hxx -- Class to manage a list of waypoints (route)
2 //
3 // Written by Curtis Olson, started October 2000.
4 //
5 // Copyright (C) 2000  Curtis L. Olson  - curt@hfrl.umn.edu
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 as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23
24 #ifndef _ROUTE_HXX
25 #define _ROUTE_HXX
26
27
28 #ifndef __cplusplus                                                          
29 # error This library requires C++
30 #endif                                   
31
32
33 #ifdef HAVE_CONFIG_H
34 #  include <config.h>
35 #endif
36
37 #include <simgear/compiler.h>
38
39 #include STL_STRING
40 #include <vector>
41
42 FG_USING_STD(string);
43 FG_USING_STD(vector);
44
45 #include "waypoint.hxx"
46
47
48 class SGRoute {
49
50 private:
51
52     typedef vector < SGWayPoint > route_list;
53     route_list route;
54     int current_wp;
55
56 public:
57
58     SGRoute();
59     ~SGRoute();
60
61     // clear the entire route
62     inline void clear() {
63         route.clear();
64         current_wp = 0;
65     }
66
67     // add a waypoint
68     inline void add_waypoint( const SGWayPoint &wp ) {
69         route.push_back( wp );
70     }
71
72     // get the number of waypoints
73     inline int size() const { return route.size(); }
74
75     // get the front waypoint
76     inline SGWayPoint get_first() const {
77         if ( route.size() ) {
78             return route[0];
79         } else {
80             return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
81         }
82     }
83
84     // get the current waypoint
85     inline SGWayPoint get_current() const {
86         if ( current_wp < (int)route.size() ) {
87             return route[current_wp];
88         } else {
89             return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
90         }
91     }
92
93     // set the current waypoint
94     inline void set_current( int n ) {
95         if ( n >= 0 && n < (int)route.size() ) {
96             current_wp = n;
97         }
98     }
99
100     // increment the current waypoint
101     inline void increment_current() {
102         if ( current_wp < (int)route.size() - 1 ) {
103             ++current_wp;
104         }
105     }
106
107     // get the nth waypoint
108     inline SGWayPoint get_waypoint( const int n ) const {
109         if ( n < (int)route.size() ) {
110             return route[n];
111         } else {
112             return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
113         }
114     }
115
116     // delete the front waypoint
117     inline void delete_first() {
118         if ( route.size() ) {
119             route.erase( route.begin() );
120         }
121     }
122 };
123
124
125 #endif // _ROUTE_HXX