]> git.mxchange.org Git - flightgear.git/commitdiff
James Turner:
authorehofman <ehofman>
Wed, 10 Sep 2008 08:54:49 +0000 (08:54 +0000)
committerehofman <ehofman>
Wed, 10 Sep 2008 08:54:49 +0000 (08:54 +0000)
Here's part 2 - converting FGFix (the simplest one) to be both heap-based and inherit FGPositioned. One minor benefit from this is replacing some dangerous code in FGFixList which used to return the address of an iterator member ('&it->second'). To keep the diff a sensible size, I'm not updating the callers to use the richer FGPositioned types - i.e replacing separate lat/lon handling with SGGeod. I will make those cleanups, but in future patches.

src/Autopilot/route_mgr.cxx
src/Instrumentation/KLN89/kln89_page_int.cxx
src/Instrumentation/KLN89/kln89_page_int.hxx
src/Instrumentation/dclgps.cxx
src/Instrumentation/gps.cxx
src/Main/fg_init.cxx
src/Navaids/fix.hxx
src/Navaids/fixlist.cxx
src/Navaids/fixlist.hxx
src/Navaids/navdb.cxx

index 79566bbdbff057098703ef632c3e6c822cd97da7..e657f2d634be58fd1a77f715904a4b1933fb03ea 100644 (file)
@@ -33,6 +33,7 @@
 #include <FDM/flight.hxx>
 #include <Main/fg_props.hxx>
 #include <Navaids/fixlist.hxx>
+#include <Navaids/fix.hxx>
 #include <Navaids/navlist.hxx>
 
 #include "route_mgr.hxx"
@@ -347,13 +348,13 @@ int FGRouteMgr::make_waypoint( SGWayPoint **wp, const string& tgt ) {
     }
 
     // check for fix id
-    FGFix f;
+    FGFix* f;
     double heading;
     double dist;
 
-    if ( globals->get_fixlist()->query_and_offset( target, lon, lat, 0, &f, &heading, &dist ) ) {
+    if ( globals->get_fixlist()->query_and_offset( target, lon, lat, 0, f, &heading, &dist ) ) {
         SG_LOG( SG_GENERAL, SG_INFO, "Adding waypoint (fix) = " << target );
-        *wp = new SGWayPoint( f.get_lon(), f.get_lat(), alt, SGWayPoint::WGS84, target );
+        *wp = new SGWayPoint( f->get_lon(), f->get_lat(), alt, SGWayPoint::WGS84, target );
         return 3;
     }
 
index ba7c7b6e5de2d85a75bb10cd73b0fab4fbe0e83b..581580f2a5433584fbaa6bda81dc7c42c9d112b1 100644 (file)
@@ -26,6 +26,7 @@
 #endif
 
 #include "kln89_page_int.hxx"
+#include "Navaids/fix.hxx"
 
 KLN89IntPage::KLN89IntPage(KLN89* parent) 
 : KLN89Page(parent) {
index 902e5c1254c1016b8c5f5ebc8cabc63c70363e5c..2b990225f9ad021f32f9a55e946f088cad450b51 100644 (file)
@@ -26,6 +26,8 @@
 
 #include "kln89.hxx"
 
+class FGFix;
+
 class KLN89IntPage : public KLN89Page {
 
 public:
index bff360b9441fe2c3e45d489feb63683e0c7c713b..ecd4b2211a32f619141c96502bc72483d4aee54a 100644 (file)
@@ -31,6 +31,8 @@
 #include <simgear/magvar/magvar.hxx>
 
 #include <Main/fg_props.hxx>
+#include <Navaids/fix.hxx>
+
 #include <iostream>
 using std::cout;
 
index b56bd29749119236910b37020f3118ddf75d31c0..2a11ab9bc04b7483d4d5092cd894cfc5a791c740 100644 (file)
@@ -22,6 +22,7 @@
 #include <Main/fg_props.hxx>
 #include <Main/util.hxx>
 #include <Navaids/fixlist.hxx>
+#include <Navaids/fix.hxx>
 #include <Navaids/navlist.hxx>
 
 #include "gps.hxx"
@@ -350,11 +351,11 @@ GPS::update (double delta_time_sec)
                 }
             }
             else if (waypont_type == "fix") {
-                FGFix f;
-                if ( globals->get_fixlist()->query(wp0_ID, &f) ) {
+                FGFix* f;
+                if ( globals->get_fixlist()->query(wp0_ID, f) ) {
                     //cout << "Fix found" << endl;
-                    wp0_longitude_deg = f.get_lon();
-                    wp0_latitude_deg = f.get_lat();
+                    wp0_longitude_deg = f->get_lon();
+                    wp0_latitude_deg = f->get_lat();
                     _wp0_name_node->setStringValue(wp0_ID.c_str());
                 }
             }
@@ -387,11 +388,11 @@ GPS::update (double delta_time_sec)
                 }
             }
             else if (waypont_type == "fix") {
-                FGFix f;
-                if ( globals->get_fixlist()->query(wp1_ID, &f) ) {
+                FGFix* f;
+                if ( globals->get_fixlist()->query(wp1_ID, f) ) {
                     //cout << "Fix found" << endl;
-                    wp1_longitude_deg = f.get_lon();
-                    wp1_latitude_deg = f.get_lat();
+                    wp1_longitude_deg = f->get_lon();
+                    wp1_latitude_deg = f->get_lat();
                     _wp1_name_node->setStringValue(wp1_ID.c_str());
                 }
             }
index 20b2f2447179922e6a349d79b3eeec3b809cfbf0..1ec3e2960119f604be379e15e47471d6b5bafc48 100644 (file)
@@ -99,6 +99,7 @@
 #include <AIModel/AIManager.hxx>
 #include <Navaids/navdb.hxx>
 #include <Navaids/navlist.hxx>
+#include <Navaids/fix.hxx>
 #include <Scenery/scenery.hxx>
 #include <Scenery/tilemgr.hxx>
 #include <Scripting/NasalSys.hxx>
@@ -1083,15 +1084,15 @@ static bool fgSetPosFromCarrier( const string& carrier, const string& posid ) {
  
 // Set current_options lon/lat given an airport id and heading (degrees)
 static bool fgSetPosFromFix( const string& id ) {
-    FGFix fix;
+    FGFix* fix;
 
     // set initial position from runway and heading
-    if ( globals->get_fixlist()->query( id.c_str(), &fix ) ) {
+    if ( globals->get_fixlist()->query( id.c_str(), fix ) ) {
         SG_LOG( SG_GENERAL, SG_INFO, "Attempting to set starting position for "
                 << id );
 
-        double lon = fix.get_lon();
-        double lat = fix.get_lat();
+        double lon = fix->get_lon();
+        double lat = fix->get_lat();
 
         if ( fabs( fgGetDouble("/sim/presets/offset-distance-nm") ) > SG_EPSILON )
         {
index c5451be573dde2aa3b490d6d743ec390edb58039..d6ee8da17ee83af3d220d22284e7b0b2bf93c0a6 100644 (file)
 #ifndef _FG_FIX_HXX
 #define _FG_FIX_HXX
 
-
-#ifdef HAVE_CONFIG_H
-#  include <config.h>
-#endif
-
 #include <simgear/compiler.h>
-#include <simgear/misc/sgstream.hxx>
-
-#  include <istream>
 
 #include <string>
 
-// using std::cout;
-// using std::endl;
-
-
-class FGFix {
-
-    std::string ident;
-    double lon, lat;
+#include "positioned.hxx"
 
+class FGFix : public FGPositioned
+{
 public:
+  FGFix(const std::string& aIdent, const SGGeod& aPos);
+  inline ~FGFix(void) {}
 
-    inline FGFix(void);
-    inline ~FGFix(void) {}
-
-    inline const std::string& get_ident() const { return ident; }
-    inline double get_lon() const { return lon; }
-    inline double get_lat() const { return lat; }
-
-    friend std::istream& operator>> ( std::istream&, FGFix& );
+  inline const std::string& get_ident() const { return ident(); }
+  inline double get_lon() const { return longitude(); }
+  inline double get_lat() const { return latitude(); }
 };
 
-
-inline
-FGFix::FGFix()
-  : ident(""),
-    lon(0.0),
-    lat(0.0)
-{
-}
-
-
-inline std::istream&
-operator >> ( std::istream& in, FGFix& f )
-{
-    in >> f.lat;
-
-    if ( f.lat > 95.0 ) {
-        return in >> skipeol;
-    }
-    in >> f.lon >> f.ident;
-
-    // cout << "id = " << f.ident << endl;
-
-    return in >> skipeol;
-}
-
-
 #endif // _FG_FIX_HXX
index a07429f061b40115d702be1678305ec91d431071..b189613e247359faddac886eb978be4e8b15f778 100644 (file)
 #include <simgear/math/sg_geodesy.hxx>
 
 #include "fixlist.hxx"
+#include "Navaids/fix.hxx"
 #include "Airports/simple.hxx"
 
-using std::pair;
-
+FGFix::FGFix(const std::string& aIdent, const SGGeod& aPos) :
+  FGPositioned(FIX, aIdent, aPos)
+{
+}
 
 // Constructor
 FGFixList::FGFixList( void ) {
@@ -63,19 +66,14 @@ bool FGFixList::init( SGPath path ) {
 
     // read in each remaining line of the file
     while ( ! in.eof() ) {
-
-        FGFix fix;
-        in >> fix;
-        if ( fix.get_lat() > 95.0 ) {
-            break;
-        }
-
-        /* cout << "ident=" << fix.get_ident()
-             << ", lat=" << fix.get_lat()
-             << ", lon=" << fix.get_lon() << endl; */
-
-        fixlist.insert(pair<string, FGFix>(fix.get_ident(), fix));
-        in >> skipcomment;
+      double lat, lon;
+      string ident;
+      in >> lat >> lon >> ident;
+      if (lat > 95) break;
+
+      FGFix* fix = new FGFix(ident, SGGeod::fromDeg(lon, lat));
+      fixlist.insert(std::make_pair(fix->ident(), fix));
+      in >> skipcomment;
     }
     return true;
 }
@@ -83,10 +81,10 @@ bool FGFixList::init( SGPath path ) {
 
 // query the database for the specified fix, lon and lat are in
 // degrees, elev is in meters
-bool FGFixList::query( const string& ident, FGFix *fix ) {
+bool FGFixList::query( const string& ident, FGFix* &fix ) {
     fix_map_const_iterator it = fixlist.find(ident);
     if ( it != fixlist.end() ) {
-        *fix = it->second;
+        fix = it->second;
         return true;
     } else {
         return false;
@@ -97,10 +95,10 @@ bool FGFixList::query( const string& ident, FGFix *fix ) {
 // query the database for the specified fix, lon and lat are in
 // degrees, elev is in meters
 bool FGFixList::query_and_offset( const string& ident, double lon, double lat,
-                                  double elev, FGFix *fix, double *heading,
+                                  double elev, FGFix* &fix, double *heading,
                                   double *dist )
 {
-    pair<fix_map_const_iterator, fix_map_const_iterator> range = fixlist.equal_range(ident);
+    std::pair<fix_map_const_iterator, fix_map_const_iterator> range = fixlist.equal_range(ident);
 
     if (range.first == range.second) {
         return false;
@@ -110,14 +108,14 @@ bool FGFixList::query_and_offset( const string& ident, double lon, double lat,
     for (fix_map_const_iterator current = range.first; current != range.second; ++current) {
         double az1, az2, s;
         geo_inverse_wgs_84( elev, lat, lon,
-                        current->second.get_lat(), current->second.get_lon(),
+                        current->second->get_lat(), current->second->get_lon(),
                         &az1, &az2, &s );
         // cout << "  dist = " << s << endl;
         if (min_s < 0 || s < min_s) {
             *heading = az2;
             *dist = s;
             min_s = s;
-            *fix = current->second;
+            fix = current->second;
         }
     }
 
@@ -131,7 +129,7 @@ const FGFix* FGFixList::search(const string& ident)
     return NULL;
   }
   
-  return &itr->second;
+  return itr->second;
 }
 
 class orderingFunctor
@@ -174,5 +172,5 @@ const FGFix* FGFixList::findFirstByIdent( const string& ident, FGIdentOrdering*
     return NULL;
   }
   
-  return &itr->second;
+  return itr->second;
 }
index d0b32eb80468e122bc54b2c909593b429965312a..7377769712d79a02d3daa673798fe464e9967925 100644 (file)
 #include <vector>
 #include <string>
 
-#include "fix.hxx"
+class FGFix;
 
 using std::multimap;
 using std::vector;
 using std::string;
 
 // fix names may be globally non-unique.  Allow for this.
-typedef multimap < string, FGFix > fix_map_type;
+typedef multimap < string, FGFix* > fix_map_type;
 typedef fix_map_type::iterator fix_map_iterator;
 typedef fix_map_type::const_iterator fix_map_const_iterator;
 
@@ -58,7 +58,7 @@ public:
     bool init( SGPath path );
 
     // query the database for the specified fix
-    bool query( const string& ident, FGFix *f );
+    bool query( const string& ident, FGFix* &f );
 
     const FGFix* search(const string& ident);
 
@@ -71,11 +71,11 @@ public:
     // query the database for the specified fix, lon and lat are
     // in degrees, elev is in meters
     bool query_and_offset( const string& ident, double lon, double lat,
-                           double elev, FGFix *f, double *heading,
+                           double elev, FGFix* &f, double *heading,
                            double *dist );
 
     // Return a pointer to the master fixlist
-    inline const fix_map_type* getFixList() { return(&fixlist); }
+   // inline const fix_map_type* getFixList() { return(&fixlist); }
 };
 
 
index a8d2fbdd71c9ad4acd8e5d388c9c82358546c6ac..54ab04b17d19594b4684b2f2f63204a4f916edc6 100644 (file)
@@ -29,6 +29,8 @@
 #include <string>
 
 #include <simgear/debug/logstream.hxx>
+#include <simgear/misc/sgstream.hxx>
+
 #include <simgear/math/sg_geodesy.hxx>
 #include <simgear/misc/strutils.hxx>