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.
#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"
}
// 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;
}
#endif
#include "kln89_page_int.hxx"
+#include "Navaids/fix.hxx"
KLN89IntPage::KLN89IntPage(KLN89* parent)
: KLN89Page(parent) {
#include "kln89.hxx"
+class FGFix;
+
class KLN89IntPage : public KLN89Page {
public:
#include <simgear/magvar/magvar.hxx>
#include <Main/fg_props.hxx>
+#include <Navaids/fix.hxx>
+
#include <iostream>
using std::cout;
#include <Main/fg_props.hxx>
#include <Main/util.hxx>
#include <Navaids/fixlist.hxx>
+#include <Navaids/fix.hxx>
#include <Navaids/navlist.hxx>
#include "gps.hxx"
}
}
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());
}
}
}
}
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());
}
}
#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>
// 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 )
{
#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
#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 ) {
// 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;
}
// 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;
// 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;
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;
}
}
return NULL;
}
- return &itr->second;
+ return itr->second;
}
class orderingFunctor
return NULL;
}
- return &itr->second;
+ return itr->second;
}
#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;
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);
// 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); }
};
#include <string>
#include <simgear/debug/logstream.hxx>
+#include <simgear/misc/sgstream.hxx>
+
#include <simgear/math/sg_geodesy.hxx>
#include <simgear/misc/strutils.hxx>