]> git.mxchange.org Git - simgear.git/blobdiff - simgear/route/route.hxx
Minor compiler version detection issue.
[simgear.git] / simgear / route / route.hxx
index 7ba4601063869faf257c2a30b9912fd00368ff56..6c5c5c876d8901cb334738a8e007c94e18b0dfcc 100644 (file)
@@ -1,5 +1,8 @@
-// route.hxx -- Class to manage a list of waypoints (route)
-//
+/**
+ * \file route.hxx
+ * Provides a class to manage a list of waypoints (i.e. a route).
+ */
+
 // Written by Curtis Olson, started October 2000.
 //
 // Copyright (C) 2000  Curtis L. Olson  - curt@hfrl.umn.edu
@@ -16,7 +19,7 @@
 //
 // You should have received a copy of the GNU General Public License
 // along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //
 // $Id$
 
 #define _ROUTE_HXX
 
 
-#ifndef __cplusplus                                                          
+#ifndef __cplusplus
 # error This library requires C++
-#endif                                   
-
-
-#ifdef HAVE_CONFIG_H
-#  include <config.h>
 #endif
 
 #include <simgear/compiler.h>
 
-#include STL_STRING
 #include <vector>
 
-FG_USING_STD(string);
-FG_USING_STD(vector);
+using std::vector;
 
-#include "waypoint.hxx"
+#include <simgear/route/waypoint.hxx>
 
+/**
+ * A class to manage a list of waypoints (i.e. a route).
+ */
 
 class SGRoute {
 
@@ -53,26 +52,37 @@ private:
     route_list route;
     int current_wp;
 
+    void update_distance_and_track(int index);
+
 public:
 
+    /** Constructor */
     SGRoute();
+
+    /** Destructor */
     ~SGRoute();
 
-    // clear the entire route
+    /** Clear the entire route */
     inline void clear() {
        route.clear();
        current_wp = 0;
     }
 
-    // add a waypoint
-    inline void add_waypoint( const SGWayPoint &wp ) {
-       route.push_back( wp );
-    }
-
-    // get the number of waypoints
+    /**
+     * Add waypoint (default), or insert waypoint at position n.
+     * @param wp a waypoint
+     */
+    void add_waypoint( const SGWayPoint &wp, int n = -1 );
+    /**
+     * Get the number of waypoints (i.e. route length )
+     * @return route length
+     */
     inline int size() const { return route.size(); }
 
-    // get the front waypoint
+    /**
+     * Get the front waypoint.
+     * @return the first waypoint.
+     */
     inline SGWayPoint get_first() const {
        if ( route.size() ) {
            return route[0];
@@ -81,7 +91,10 @@ public:
        }
     }
 
-    // get the current waypoint
+    /**
+     * Get the current waypoint
+     * @return the current waypoint
+     */
     inline SGWayPoint get_current() const {
        if ( current_wp < (int)route.size() ) {
            return route[current_wp];
@@ -89,22 +102,49 @@ public:
            return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
        }
     }
+    
+    inline SGWayPoint get_previous() const {
+       if ( (current_wp > 0) && (current_wp < (int)route.size()) ) {
+           return route[current_wp - 1];
+       } else {
+           return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
+       }
+    }
 
-    // set the current waypoint
+    inline SGWayPoint get_next() const {
+       if ( (current_wp + 1) < (int)route.size() ) {
+           return route[current_wp+1];
+       } else {
+           return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
+       }
+    }
+
+    /**
+     * Set the current waypoint
+     * @param number of waypoint to make current.
+     */
     inline void set_current( int n ) {
        if ( n >= 0 && n < (int)route.size() ) {
            current_wp = n;
        }
     }
 
-    // increment the current waypoint
+    inline int current_index() const {
+        return current_wp;
+    }
+
+    /** Increment the current waypoint pointer. */
     inline void increment_current() {
        if ( current_wp < (int)route.size() - 1 ) {
            ++current_wp;
        }
     }
 
-    // get the nth waypoint
+    /**
+     * Get the nth waypoint
+     * @param n waypoint number
+     * @return the nth waypoint
+     */
     inline SGWayPoint get_waypoint( const int n ) const {
        if ( n < (int)route.size() ) {
            return route[n];
@@ -113,12 +153,16 @@ public:
        }
     }
 
-    // delete the front waypoint
-    inline void delete_first() {
-       if ( route.size() ) {
-           route.erase( route.begin() );
-       }
-    }
+    /** Delete the front waypoint */
+    inline void delete_first() { delete_waypoint(0); }
+
+    /** Delete waypoint waypoint with index n  (last one if n < 0) */
+    void delete_waypoint( int n = 0 );
+    
+    /**
+     * Helper, sum the distance members of each waypoint
+     */
+    double total_distance() const;
 };