From 50e25151e1bba447fe24c356a95d53f326863007 Mon Sep 17 00:00:00 2001 From: david Date: Sat, 30 Mar 2002 12:51:42 +0000 Subject: [PATCH] Patch from Melchior Franz: My last patch fixed the initialization problem only for the main branch, but ignored the _MWERKS_ branch. - merged the branches, only the loop head needs different treatment; - don't access n.type before it is initialized (valgrind complaint) - created a constructor; the operator>> wouldn't have initialized all variables in case of a broken default.nav.gz entry, so we would have got a mixture of the broken one and the previous one; in case of the first entry, that would have made nice random values ... ;-) - move the automatic FGNav variable into the loop, so that the gets cleanly constructed for every database entry. - commented out the frequency min/max exploration, which isn't used at all - updated the commented out debug output statements, which were simply copied over from the nav* files, but never adapted (I needed them :-) --- src/Navaids/ils.hxx | 38 +++++++++++++++++++++++++++++++++++++- src/Navaids/ilslist.cxx | 40 ++++++++++++++-------------------------- src/Navaids/nav.hxx | 20 +++++++++++++++++++- src/Navaids/navlist.cxx | 30 ++++++++++-------------------- 4 files changed, 80 insertions(+), 48 deletions(-) diff --git a/src/Navaids/ils.hxx b/src/Navaids/ils.hxx index b97b2882e..8ec84d8c0 100644 --- a/src/Navaids/ils.hxx +++ b/src/Navaids/ils.hxx @@ -83,7 +83,7 @@ class FGILS { public: - inline FGILS(void) {} + inline FGILS(void); inline ~FGILS(void) {} inline char get_ilstype() const { return ilstype; } @@ -124,6 +124,42 @@ public: }; +inline +FGILS::FGILS(void) + : ilstype(0), + locfreq(0), + locheading(0.0), + loclat(0.0), + loclon(0.0), + x(0.0), y(0.0), z(0.0), + has_gs(false), + gselev(0.0), + gsangle(0.0), + gslat(0.0), + gslon(0.0), + gs_x(0.0), gs_y(0.0), gs_z(0.0), + has_dme(false), + dmelat(0.0), + dmelon(0.0), + dme_x(0.0), dme_y(0.0), dme_z(0.0), + omlat(0.0), + omlon(0.0), + mmlat(0.0), + mmlon(0.0), + imlat(0.0), + imlon(0.0), + trans_ident(""), + loc_failed(false), + gs_failed(false), + dme_failed(false) +{ + ilstypename[0] = '\0'; + aptcode[0] = '\0'; + rwyno[0] = '\0'; + locident[0] = '\0'; +} + + inline istream& operator >> ( istream& in, FGILS& i ) { diff --git a/src/Navaids/ilslist.cxx b/src/Navaids/ilslist.cxx index e7bd0994e..6b7dcfc35 100644 --- a/src/Navaids/ilslist.cxx +++ b/src/Navaids/ilslist.cxx @@ -48,7 +48,6 @@ FGILSList::~FGILSList( void ) { // load the navaids and build the map bool FGILSList::init( SGPath path ) { - FGILS ils; ilslist.erase( ilslist.begin(), ilslist.end() ); @@ -63,47 +62,38 @@ bool FGILSList::init( SGPath path ) { in >> skipeol; in >> skipcomment; -#ifdef __MWERKS__ + // double min = 1000000.0; + // double max = 0.0; +#ifdef __MWERKS__ char c = 0; - while ( in.get(c) && c != '\0' && ils.get_ilstype() != '[' ) { + while ( in.get(c) && c != '\0' ) { in.putback(c); - in >> ils; - if ( ils.get_ilstype() != '[' ) { - ilslist[ils.get_locfreq()].push_back(ils); - } - in >> skipcomment; - } - #else - - double min = 1000000.0; - double max = 0.0; - while ( ! in.eof() ) { - in >> ils; +#endif + FGILS ils; + in >> ils; if ( ils.get_ilstype() == '[' ) { break; } - /* cout << "id = " << n.get_ident() << endl; - cout << " type = " << n.get_type() << endl; - cout << " lon = " << n.get_lon() << endl; - cout << " lat = " << n.get_lat() << endl; - cout << " elev = " << n.get_elev() << endl; - cout << " freq = " << n.get_freq() << endl; - cout << " range = " << n.get_range() << endl; */ + /* cout << "typename = " << ils.get_ilstypename() << endl; + cout << " aptcode = " << ils.get_aptcode() << endl; + cout << " twyno = " << ils.get_rwyno() << endl; + cout << " locfreq = " << ils.get_locfreq() << endl; + cout << " locident = " << ils.get_locident() << endl << endl; */ ilslist[ils.get_locfreq()].push_back(ils); in >> skipcomment; - if ( ils.get_locfreq() < min ) { + /* if ( ils.get_locfreq() < min ) { min = ils.get_locfreq(); } if ( ils.get_locfreq() > max ) { max = ils.get_locfreq(); - } + } */ // update the marker beacon list if ( fabs(ils.get_omlon()) > SG_EPSILON || @@ -126,8 +116,6 @@ bool FGILSList::init( SGPath path ) { // cout << "min freq = " << min << endl; // cout << "max freq = " << max << endl; -#endif - return true; } diff --git a/src/Navaids/nav.hxx b/src/Navaids/nav.hxx index 8eaf3fa5f..fb963b10b 100644 --- a/src/Navaids/nav.hxx +++ b/src/Navaids/nav.hxx @@ -66,7 +66,7 @@ class FGNav { public: - inline FGNav(void) {} + inline FGNav(void); inline ~FGNav(void) {} inline char get_type() const { return type; } @@ -96,6 +96,24 @@ public: }; +inline +FGNav::FGNav(void) : + type(0), + lon(0.0), lat(0.0), + elev(0.0), + x(0.0), y(0.0), z(0.0), + freq(0), + range(0), + has_dme(false), + ident(""), + magvar(0.0), + trans_ident(""), + nav_failed(false), + dme_failed(false) +{ +} + + inline istream& operator >> ( istream& in, FGNav& n ) { diff --git a/src/Navaids/navlist.cxx b/src/Navaids/navlist.cxx index 3892dcb8d..005668913 100644 --- a/src/Navaids/navlist.cxx +++ b/src/Navaids/navlist.cxx @@ -47,7 +47,6 @@ FGNavList::~FGNavList( void ) { // load the navaids and build the map bool FGNavList::init( SGPath path ) { - FGNav n; navaids.erase( navaids.begin(), navaids.end() ); @@ -62,26 +61,19 @@ bool FGNavList::init( SGPath path ) { in >> skipeol; in >> skipcomment; -#ifdef __MWERKS__ + // double min = 100000; + // double max = 0; +#ifdef __MWERKS__ char c = 0; - while ( in.get(c) && c != '\0' && n.get_type() != '[' ) { + while ( in.get(c) && c != '\0' ) { in.putback(c); - in >> n; - if ( n.get_type() != '[' ) { - navaids[n.get_freq()].push_back(n); - } - in >> skipcomment; - } - #else - - double min = 100000; - double max = 0; - while ( ! in.eof() ) { - in >> n; +#endif + FGNav n; + in >> n; if ( n.get_type() == '[' ) { break; } @@ -92,26 +84,24 @@ bool FGNavList::init( SGPath path ) { cout << " lat = " << n.get_lat() << endl; cout << " elev = " << n.get_elev() << endl; cout << " freq = " << n.get_freq() << endl; - cout << " range = " << n.get_range() << endl; */ + cout << " range = " << n.get_range() << endl << endl; */ navaids[n.get_freq()].push_back(n); in >> skipcomment; - if ( n.get_type() != 'N' ) { + /* if ( n.get_type() != 'N' ) { if ( n.get_freq() < min ) { min = n.get_freq(); } if ( n.get_freq() > max ) { max = n.get_freq(); } - } + } */ } // cout << "min freq = " << min << endl; // cout << "max freq = " << max << endl; -#endif - return true; } -- 2.39.5