1
0
Fork 0

fix.dat parser: new class FixesLoader; change loadFixes() into a method

- loadFixes() becomes FixesLoader::loadFixes();
- the previous 'cache' variable (NavDataCache *) is now a private member
  of FixesLoader, named '_cache'.
This commit is contained in:
Florent Rougon 2016-04-28 11:33:59 +02:00
parent cf9759f78f
commit d9c879ff30
3 changed files with 26 additions and 9 deletions

View file

@ -1178,7 +1178,7 @@ void NavDataCache::doRebuild()
stampCacheFile(d->metarDatPath);
st.stamp();
loadFixes(d->fixDatPath);
FixesLoader().loadFixes(d->fixDatPath);
stampCacheFile(d->fixDatPath);
SG_LOG(SG_NAVCACHE, SG_INFO, "fix.dat load took:" << st.elapsedMSec());

View file

@ -51,8 +51,15 @@ namespace flightgear
{
const unsigned int LINES_IN_FIX_DAT = 119724;
void loadFixes(const SGPath& path)
FixesLoader::FixesLoader() : _cache(NavDataCache::instance())
{ }
FixesLoader::~FixesLoader()
{ }
// Load fixes from the specified fix.dat (or fix.dat.gz) file
void FixesLoader::loadFixes(const SGPath& path)
{
sg_gzifstream in( path );
const std::string utf8path = path.utf8Str();
@ -65,7 +72,6 @@ void loadFixes(const SGPath& path)
in >> skipeol;
in >> skipeol;
NavDataCache* cache = NavDataCache::instance();
unsigned int lineNumber = 3;
// read in each remaining line of the file
@ -94,12 +100,12 @@ void loadFixes(const SGPath& path)
lat = atof(fields[0].c_str());
lon = atof(fields[1].c_str());
cache->insertFix(fields[2], SGGeod::fromDeg(lon, lat));
_cache->insertFix(fields[2], SGGeod::fromDeg(lon, lat));
if ((lineNumber % 100) == 0) {
// every 100 lines
unsigned int percent = (lineNumber * 100) / LINES_IN_FIX_DAT;
cache->setRebuildPhaseProgress(NavDataCache::REBUILD_FIXES, percent);
_cache->setRebuildPhaseProgress(NavDataCache::REBUILD_FIXES, percent);
}
}

View file

@ -31,9 +31,20 @@ class SGPath;
namespace flightgear
{
void loadFixes(const SGPath& path);
class NavDataCache; // forward declaration
class FixesLoader
{
public:
FixesLoader();
~FixesLoader();
// Load fixes from the specified fix.dat (or fix.dat.gz) file
void loadFixes(const SGPath& path);
private:
NavDataCache* _cache;
};
}
#endif // _FG_FIXLIST_HXX