Replaced gdbm with metakit. Involves a new simgear version and a new database
format for the airports in the base package.
This commit is contained in:
parent
e12e81dd23
commit
d4d10fad6b
12 changed files with 91 additions and 100 deletions
8
Thanks
8
Thanks
|
@ -375,6 +375,14 @@ Ed Williams <Ed_Williams@compuserve.com>
|
|||
http://www.best.com/~williams/index.html
|
||||
|
||||
|
||||
Jean-Claude Wippler <jcw@equi4.com>
|
||||
Author of MetaKit - a portable, embeddible database with a portable
|
||||
data file format. This software is not GPL'd but the author is kindly
|
||||
allowing us to bundle MetaKit with our code. MetaKit has a liberal
|
||||
X/MIT-style license. Please see the following URL for more info:
|
||||
http://www.equi4.com/metakit
|
||||
|
||||
|
||||
WoodSoup Project http://www.woodsoup.org
|
||||
Provided computing resources and services so that the Flight Gear
|
||||
project could have real home. This includes, web services,
|
||||
|
|
|
@ -22,8 +22,7 @@ Currently, for JSBSim only the X-15 is available, and possibly the C-172.
|
|||
Here is an example command line used to start up FlightGear using JSBSim as
|
||||
the FDM:
|
||||
|
||||
fgfs --fdm=jsb --aircraft=X15 --units-feet --altitude=60000 --uBody=2000 --w
|
||||
Body=120
|
||||
fgfs --fdm=jsb --aircraft=X15 --units-feet --altitude=60000 --uBody=2000 --wBody=120
|
||||
|
||||
[Note: uBody is the forward velocity of the aircraft, wBody is the downward
|
||||
velocity - from the aircraft point of view. This essentially means that the
|
||||
|
|
|
@ -8,6 +8,6 @@ libAirports_a_SOURCES = \
|
|||
|
||||
buildsimple_SOURCES = buildsimple.cxx
|
||||
|
||||
buildsimple_LDADD = libAirports.a -lsgdebug -lsgmisc -lgdbm -lz
|
||||
buildsimple_LDADD = libAirports.a -lsgdebug -lsgmisc -lmk4 -lz
|
||||
|
||||
INCLUDES += -I$(top_builddir) -I$(top_builddir)/src
|
||||
|
|
|
@ -8,8 +8,12 @@ int main( int argc, char **argv ) {
|
|||
|
||||
if ( argc == 3 ) {
|
||||
airports.load( argv[1] );
|
||||
airports.dump_gdbm( argv[2] );
|
||||
airports.dump_mk4( argv[2] );
|
||||
} else {
|
||||
cout << "usage: " << argv[0] << " <in> <out>" << endl;
|
||||
}
|
||||
|
||||
// FGAirports airport_db( argv[2] );
|
||||
// airport_db.search( "KANEZZZ", &a );
|
||||
|
||||
}
|
||||
|
|
|
@ -28,14 +28,14 @@
|
|||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h> // for gdbm open flags
|
||||
#include <sys/stat.h> // for gdbm open flags
|
||||
// #include <sys/types.h> // for gdbm open flags
|
||||
// #include <sys/stat.h> // for gdbm open flags
|
||||
|
||||
#ifdef HAVE_GDBM
|
||||
# include <gdbm.h>
|
||||
#else
|
||||
# include <simgear/gdbm/gdbm.h>
|
||||
#endif
|
||||
// #ifdef HAVE_GDBM
|
||||
// # include <gdbm.h>
|
||||
// #else
|
||||
// # include <simgear/gdbm/gdbm.h>
|
||||
// #endif
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
|
||||
|
@ -53,13 +53,14 @@
|
|||
FG_USING_NAMESPACE(std);
|
||||
|
||||
FGAirports::FGAirports( const string& file ) {
|
||||
dbf = gdbm_open( (char *)file.c_str(), 0, GDBM_READER, 0, NULL );
|
||||
if ( dbf == NULL ) {
|
||||
cout << "Error opening " << file << endl;
|
||||
exit(-1);
|
||||
} else {
|
||||
cout << "successfully opened " << file << endl;
|
||||
}
|
||||
// open the specified database readonly
|
||||
storage = new c4_Storage( file.c_str(), false );
|
||||
|
||||
// need to do something about error handling here!
|
||||
|
||||
vAirport = new c4_View;
|
||||
*vAirport =
|
||||
storage->GetAs("airport[ID:S,Longitude:F,Latitude:F,Elevation:F]");
|
||||
}
|
||||
|
||||
|
||||
|
@ -67,31 +68,24 @@ FGAirports::FGAirports( const string& file ) {
|
|||
bool
|
||||
FGAirports::search( const string& id, FGAirport* a ) const
|
||||
{
|
||||
FGAirport *tmp;
|
||||
datum content;
|
||||
datum key;
|
||||
c4_StringProp pID ("ID");
|
||||
c4_FloatProp pLon ("Longitude");
|
||||
c4_FloatProp pLat ("Latitude");
|
||||
c4_FloatProp pElev ("Elevation");
|
||||
|
||||
key.dptr = (char *)id.c_str();
|
||||
key.dsize = id.length();
|
||||
int idx = vAirport->Find(pID[id.c_str()]);
|
||||
cout << "idx = " << idx << endl;
|
||||
|
||||
content = gdbm_fetch( dbf, key );
|
||||
|
||||
cout << "gdbm_fetch() finished" << endl;
|
||||
|
||||
if ( content.dptr != NULL ) {
|
||||
tmp = (FGAirport *)content.dptr;
|
||||
|
||||
// a->id = tmp->id;
|
||||
a->longitude = tmp->longitude;
|
||||
a->latitude = tmp->latitude;
|
||||
a->elevation = tmp->elevation;
|
||||
|
||||
free( content.dptr );
|
||||
|
||||
} else {
|
||||
if ( idx == -1 ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
c4_RowRef r = vAirport->GetAt(idx);
|
||||
|
||||
a->longitude = (double) pLon(r);
|
||||
a->latitude = (double) pLat(r);
|
||||
a->elevation = (double) pElev(r);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -99,27 +93,15 @@ FGAirports::search( const string& id, FGAirport* a ) const
|
|||
FGAirport
|
||||
FGAirports::search( const string& id ) const
|
||||
{
|
||||
FGAirport a, *tmp;
|
||||
datum content;
|
||||
datum key;
|
||||
|
||||
key.dptr = (char *)id.c_str();
|
||||
key.dsize = id.length();
|
||||
|
||||
content = gdbm_fetch( dbf, key );
|
||||
|
||||
if ( content.dptr != NULL ) {
|
||||
tmp = (FGAirport *)content.dptr;
|
||||
a = *tmp;
|
||||
}
|
||||
|
||||
FGAirport a;
|
||||
search( id, &a );
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
// Destructor
|
||||
FGAirports::~FGAirports( void ) {
|
||||
gdbm_close( dbf );
|
||||
// gdbm_close( dbf );
|
||||
}
|
||||
|
||||
|
||||
|
@ -177,44 +159,40 @@ int FGAirportsUtil::load( const string& file ) {
|
|||
|
||||
|
||||
// save the data in gdbm format
|
||||
bool FGAirportsUtil::dump_gdbm( const string& file ) {
|
||||
bool FGAirportsUtil::dump_mk4( const string& file ) {
|
||||
|
||||
GDBM_FILE dbf;
|
||||
// open database for writing
|
||||
c4_Storage storage( file.c_str(), true );
|
||||
|
||||
#if defined( MACOS ) || defined( _MSC_VER )
|
||||
dbf = gdbm_open( (char *)file.c_str(), 0, GDBM_NEWDB | GDBM_FAST,
|
||||
NULL, NULL );
|
||||
#else
|
||||
dbf = gdbm_open( (char *)file.c_str(), 0, GDBM_NEWDB | GDBM_FAST,
|
||||
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH,
|
||||
NULL );
|
||||
#endif
|
||||
// need to do something about error handling here!
|
||||
|
||||
if ( dbf == NULL ) {
|
||||
cout << "Error opening " << file << endl;
|
||||
exit(-1);
|
||||
} else {
|
||||
cout << "successfully opened " << file << endl;
|
||||
}
|
||||
// define the properties
|
||||
c4_StringProp pID ("ID");
|
||||
c4_FloatProp pLon ("Longitude");
|
||||
c4_FloatProp pLat ("Latitude");
|
||||
c4_FloatProp pElev ("Elevation");
|
||||
|
||||
// Start with an empty view of the proper structure.
|
||||
c4_View vAirport =
|
||||
storage.GetAs("airport[ID:S,Longitude:F,Latitude:F,Elevation:F]");
|
||||
|
||||
c4_Row row;
|
||||
|
||||
iterator current = airports.begin();
|
||||
const_iterator end = airports.end();
|
||||
while ( current != end ) {
|
||||
datum key;
|
||||
key.dptr = (char *)current->id.c_str();
|
||||
key.dsize = current->id.length();
|
||||
|
||||
datum content;
|
||||
FGAirport tmp = *current;
|
||||
content.dptr = (char *)(& tmp);
|
||||
content.dsize = sizeof( *current );
|
||||
|
||||
gdbm_store( dbf, key, content, GDBM_REPLACE );
|
||||
// add each airport record
|
||||
pID (row) = current->id.c_str();
|
||||
pLon (row) = current->longitude;
|
||||
pLat (row) = current->latitude;
|
||||
pElev (row) = current->elevation;
|
||||
vAirport.Add(row);
|
||||
|
||||
++current;
|
||||
}
|
||||
|
||||
gdbm_close( dbf );
|
||||
// commit our changes
|
||||
storage.Commit();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
// $Id$
|
||||
|
||||
|
||||
#ifndef _AIRPORTS_HXX
|
||||
#define _AIRPORTS_HXX
|
||||
#ifndef _SIMPLE_HXX
|
||||
#define _SIMPLE_HXX
|
||||
|
||||
|
||||
#ifndef __cplusplus
|
||||
|
@ -36,12 +36,6 @@
|
|||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_GDBM
|
||||
# include <gdbm.h>
|
||||
#else
|
||||
# include <simgear/gdbm/gdbm.h>
|
||||
#endif
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
|
||||
#ifdef FG_HAVE_STD_INCLUDES
|
||||
|
@ -57,6 +51,11 @@
|
|||
#include STL_STRING
|
||||
#include <set>
|
||||
|
||||
#define NDEBUG // she don't work without it.
|
||||
#include <mk4.h>
|
||||
#include <mk4str.h>
|
||||
#undef NDEBUG
|
||||
|
||||
FG_USING_STD(string);
|
||||
FG_USING_STD(set);
|
||||
|
||||
|
@ -99,7 +98,8 @@ class FGAirports {
|
|||
|
||||
private:
|
||||
|
||||
GDBM_FILE dbf;
|
||||
c4_Storage *storage;
|
||||
c4_View *vAirport;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -112,7 +112,7 @@ public:
|
|||
// search for the specified id.
|
||||
// Returns true if successful, otherwise returns false.
|
||||
// On success, airport data is returned thru "airport" pointer.
|
||||
// "airport" is not changed if "id" is not found.
|
||||
// "airport" is not changed if "apt" is not found.
|
||||
bool search( const string& id, FGAirport* airport ) const;
|
||||
FGAirport search( const string& id ) const;
|
||||
};
|
||||
|
@ -142,8 +142,8 @@ public:
|
|||
// load the data
|
||||
int load( const string& file );
|
||||
|
||||
// save the data in gdbm format
|
||||
bool dump_gdbm( const string& file );
|
||||
// save the data in metakit format
|
||||
bool dump_mk4( const string& file );
|
||||
|
||||
// search for the specified id.
|
||||
// Returns true if successful, otherwise returns false.
|
||||
|
@ -154,6 +154,6 @@ public:
|
|||
};
|
||||
|
||||
|
||||
#endif /* _AIRPORTS_HXX */
|
||||
#endif // _SIMPLE_HXX
|
||||
|
||||
|
||||
|
|
|
@ -595,7 +595,7 @@ void TgtAptDialog_OK (puObject *)
|
|||
|
||||
FGPath path( current_options.get_fg_root() );
|
||||
path.append( "Airports" );
|
||||
path.append( "simple.gdbm" );
|
||||
path.append( "simple.mk4" );
|
||||
FGAirports airports( path.c_str() );
|
||||
FGAirport a;
|
||||
|
||||
|
|
|
@ -756,7 +756,7 @@ void reInit(puObject *cb)
|
|||
|
||||
static void toggleClouds(puObject *cb)
|
||||
{
|
||||
FGBFI::setClouds(!FGBFI::getClouds());
|
||||
FGBFI::setClouds( !FGBFI::getClouds() );
|
||||
}
|
||||
|
||||
// This is the accessor function
|
||||
|
@ -1034,8 +1034,9 @@ void AptDialog_OK (puObject *)
|
|||
{
|
||||
FGPath path( current_options.get_fg_root() );
|
||||
path.append( "Airports" );
|
||||
path.append( "simple.gdbm" );
|
||||
path.append( "simple.mk4" );
|
||||
FGAirports airports( path.c_str() );
|
||||
|
||||
FGAirport a;
|
||||
|
||||
FGTime *t = FGTime::cur_time_params;
|
||||
|
|
|
@ -70,7 +70,7 @@ fgfs_LDADD = \
|
|||
$(SERIAL_LIBS) \
|
||||
-lsgscreen -lsgmath -lsgbucket -lsgdebug -lsgmagvar -lsgmisc \
|
||||
-lplibpu -lplibfnt -lplibssg -lplibsg \
|
||||
-lgdbm -lz \
|
||||
-lmk4 -lz \
|
||||
$(opengl_LIBS) \
|
||||
$(audio_LIBS)
|
||||
|
||||
|
|
|
@ -146,7 +146,7 @@ bool fgInitPosition( void ) {
|
|||
|
||||
FGPath path( current_options.get_fg_root() );
|
||||
path.append( "Airports" );
|
||||
path.append( "simple.gdbm" );
|
||||
path.append( "simple.mk4" );
|
||||
FGAirports airports( path.c_str() );
|
||||
FGAirport a;
|
||||
|
||||
|
|
|
@ -103,6 +103,7 @@ int fgGetTimeInterval( void ) {
|
|||
static FGTimeStamp last;
|
||||
FGTimeStamp current;
|
||||
|
||||
|
||||
if ( ! inited ) {
|
||||
inited = 1;
|
||||
last.stamp();
|
||||
|
@ -113,7 +114,7 @@ int fgGetTimeInterval( void ) {
|
|||
last = current;
|
||||
}
|
||||
|
||||
return(interval);
|
||||
return interval;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -154,7 +154,7 @@ inline void FGTimeStamp::stamp() {
|
|||
#endif
|
||||
}
|
||||
|
||||
// difference between time stamps in microseconds (usec)
|
||||
// increment the time stamp by the number of microseconds (usec)
|
||||
inline FGTimeStamp operator + (const FGTimeStamp& t, const long& m) {
|
||||
#ifdef WIN32
|
||||
return FGTimeStamp( 0, t.usec + m );
|
||||
|
|
Loading…
Reference in a new issue