1
0
Fork 0

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:
curt 2000-05-27 05:54:02 +00:00
parent e12e81dd23
commit d4d10fad6b
12 changed files with 91 additions and 100 deletions

8
Thanks
View file

@ -375,6 +375,14 @@ Ed Williams <Ed_Williams@compuserve.com>
http://www.best.com/~williams/index.html 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 WoodSoup Project http://www.woodsoup.org
Provided computing resources and services so that the Flight Gear Provided computing resources and services so that the Flight Gear
project could have real home. This includes, web services, project could have real home. This includes, web services,

View file

@ -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 Here is an example command line used to start up FlightGear using JSBSim as
the FDM: the FDM:
fgfs --fdm=jsb --aircraft=X15 --units-feet --altitude=60000 --uBody=2000 --w fgfs --fdm=jsb --aircraft=X15 --units-feet --altitude=60000 --uBody=2000 --wBody=120
Body=120
[Note: uBody is the forward velocity of the aircraft, wBody is the downward [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 velocity - from the aircraft point of view. This essentially means that the

View file

@ -8,6 +8,6 @@ libAirports_a_SOURCES = \
buildsimple_SOURCES = buildsimple.cxx 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 INCLUDES += -I$(top_builddir) -I$(top_builddir)/src

View file

@ -8,8 +8,12 @@ int main( int argc, char **argv ) {
if ( argc == 3 ) { if ( argc == 3 ) {
airports.load( argv[1] ); airports.load( argv[1] );
airports.dump_gdbm( argv[2] ); airports.dump_mk4( argv[2] );
} else { } else {
cout << "usage: " << argv[0] << " <in> <out>" << endl; cout << "usage: " << argv[0] << " <in> <out>" << endl;
} }
// FGAirports airport_db( argv[2] );
// airport_db.search( "KANEZZZ", &a );
} }

View file

@ -28,14 +28,14 @@
# include <config.h> # include <config.h>
#endif #endif
#include <sys/types.h> // for gdbm open flags // #include <sys/types.h> // for gdbm open flags
#include <sys/stat.h> // for gdbm open flags // #include <sys/stat.h> // for gdbm open flags
#ifdef HAVE_GDBM // #ifdef HAVE_GDBM
# include <gdbm.h> // # include <gdbm.h>
#else // #else
# include <simgear/gdbm/gdbm.h> // # include <simgear/gdbm/gdbm.h>
#endif // #endif
#include <simgear/compiler.h> #include <simgear/compiler.h>
@ -53,13 +53,14 @@
FG_USING_NAMESPACE(std); FG_USING_NAMESPACE(std);
FGAirports::FGAirports( const string& file ) { FGAirports::FGAirports( const string& file ) {
dbf = gdbm_open( (char *)file.c_str(), 0, GDBM_READER, 0, NULL ); // open the specified database readonly
if ( dbf == NULL ) { storage = new c4_Storage( file.c_str(), false );
cout << "Error opening " << file << endl;
exit(-1); // need to do something about error handling here!
} else {
cout << "successfully opened " << file << endl; 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 bool
FGAirports::search( const string& id, FGAirport* a ) const FGAirports::search( const string& id, FGAirport* a ) const
{ {
FGAirport *tmp; c4_StringProp pID ("ID");
datum content; c4_FloatProp pLon ("Longitude");
datum key; c4_FloatProp pLat ("Latitude");
c4_FloatProp pElev ("Elevation");
key.dptr = (char *)id.c_str(); int idx = vAirport->Find(pID[id.c_str()]);
key.dsize = id.length(); cout << "idx = " << idx << endl;
content = gdbm_fetch( dbf, key ); if ( idx == -1 ) {
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 {
return false; 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; return true;
} }
@ -99,27 +93,15 @@ FGAirports::search( const string& id, FGAirport* a ) const
FGAirport FGAirport
FGAirports::search( const string& id ) const FGAirports::search( const string& id ) const
{ {
FGAirport a, *tmp; FGAirport a;
datum content; search( id, &a );
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;
}
return a; return a;
} }
// Destructor // Destructor
FGAirports::~FGAirports( void ) { 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 // 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 ) // need to do something about error handling here!
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
if ( dbf == NULL ) { // define the properties
cout << "Error opening " << file << endl; c4_StringProp pID ("ID");
exit(-1); c4_FloatProp pLon ("Longitude");
} else { c4_FloatProp pLat ("Latitude");
cout << "successfully opened " << file << endl; 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(); iterator current = airports.begin();
const_iterator end = airports.end(); const_iterator end = airports.end();
while ( current != end ) { while ( current != end ) {
datum key; // add each airport record
key.dptr = (char *)current->id.c_str(); pID (row) = current->id.c_str();
key.dsize = current->id.length(); pLon (row) = current->longitude;
pLat (row) = current->latitude;
datum content; pElev (row) = current->elevation;
FGAirport tmp = *current; vAirport.Add(row);
content.dptr = (char *)(& tmp);
content.dsize = sizeof( *current );
gdbm_store( dbf, key, content, GDBM_REPLACE );
++current; ++current;
} }
gdbm_close( dbf ); // commit our changes
storage.Commit();
return true; return true;
} }

View file

@ -23,8 +23,8 @@
// $Id$ // $Id$
#ifndef _AIRPORTS_HXX #ifndef _SIMPLE_HXX
#define _AIRPORTS_HXX #define _SIMPLE_HXX
#ifndef __cplusplus #ifndef __cplusplus
@ -36,12 +36,6 @@
# include <config.h> # include <config.h>
#endif #endif
#ifdef HAVE_GDBM
# include <gdbm.h>
#else
# include <simgear/gdbm/gdbm.h>
#endif
#include <simgear/compiler.h> #include <simgear/compiler.h>
#ifdef FG_HAVE_STD_INCLUDES #ifdef FG_HAVE_STD_INCLUDES
@ -57,6 +51,11 @@
#include STL_STRING #include STL_STRING
#include <set> #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(string);
FG_USING_STD(set); FG_USING_STD(set);
@ -99,7 +98,8 @@ class FGAirports {
private: private:
GDBM_FILE dbf; c4_Storage *storage;
c4_View *vAirport;
public: public:
@ -112,7 +112,7 @@ public:
// search for the specified id. // search for the specified id.
// Returns true if successful, otherwise returns false. // Returns true if successful, otherwise returns false.
// On success, airport data is returned thru "airport" pointer. // 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; bool search( const string& id, FGAirport* airport ) const;
FGAirport search( const string& id ) const; FGAirport search( const string& id ) const;
}; };
@ -142,8 +142,8 @@ public:
// load the data // load the data
int load( const string& file ); int load( const string& file );
// save the data in gdbm format // save the data in metakit format
bool dump_gdbm( const string& file ); bool dump_mk4( const string& file );
// search for the specified id. // search for the specified id.
// Returns true if successful, otherwise returns false. // Returns true if successful, otherwise returns false.
@ -154,6 +154,6 @@ public:
}; };
#endif /* _AIRPORTS_HXX */ #endif // _SIMPLE_HXX

View file

@ -595,7 +595,7 @@ void TgtAptDialog_OK (puObject *)
FGPath path( current_options.get_fg_root() ); FGPath path( current_options.get_fg_root() );
path.append( "Airports" ); path.append( "Airports" );
path.append( "simple.gdbm" ); path.append( "simple.mk4" );
FGAirports airports( path.c_str() ); FGAirports airports( path.c_str() );
FGAirport a; FGAirport a;

View file

@ -756,7 +756,7 @@ void reInit(puObject *cb)
static void toggleClouds(puObject *cb) static void toggleClouds(puObject *cb)
{ {
FGBFI::setClouds(!FGBFI::getClouds()); FGBFI::setClouds( !FGBFI::getClouds() );
} }
// This is the accessor function // This is the accessor function
@ -1034,8 +1034,9 @@ void AptDialog_OK (puObject *)
{ {
FGPath path( current_options.get_fg_root() ); FGPath path( current_options.get_fg_root() );
path.append( "Airports" ); path.append( "Airports" );
path.append( "simple.gdbm" ); path.append( "simple.mk4" );
FGAirports airports( path.c_str() ); FGAirports airports( path.c_str() );
FGAirport a; FGAirport a;
FGTime *t = FGTime::cur_time_params; FGTime *t = FGTime::cur_time_params;

View file

@ -70,7 +70,7 @@ fgfs_LDADD = \
$(SERIAL_LIBS) \ $(SERIAL_LIBS) \
-lsgscreen -lsgmath -lsgbucket -lsgdebug -lsgmagvar -lsgmisc \ -lsgscreen -lsgmath -lsgbucket -lsgdebug -lsgmagvar -lsgmisc \
-lplibpu -lplibfnt -lplibssg -lplibsg \ -lplibpu -lplibfnt -lplibssg -lplibsg \
-lgdbm -lz \ -lmk4 -lz \
$(opengl_LIBS) \ $(opengl_LIBS) \
$(audio_LIBS) $(audio_LIBS)

View file

@ -146,7 +146,7 @@ bool fgInitPosition( void ) {
FGPath path( current_options.get_fg_root() ); FGPath path( current_options.get_fg_root() );
path.append( "Airports" ); path.append( "Airports" );
path.append( "simple.gdbm" ); path.append( "simple.mk4" );
FGAirports airports( path.c_str() ); FGAirports airports( path.c_str() );
FGAirport a; FGAirport a;

View file

@ -103,6 +103,7 @@ int fgGetTimeInterval( void ) {
static FGTimeStamp last; static FGTimeStamp last;
FGTimeStamp current; FGTimeStamp current;
if ( ! inited ) { if ( ! inited ) {
inited = 1; inited = 1;
last.stamp(); last.stamp();
@ -113,7 +114,7 @@ int fgGetTimeInterval( void ) {
last = current; last = current;
} }
return(interval); return interval;
} }

View file

@ -154,7 +154,7 @@ inline void FGTimeStamp::stamp() {
#endif #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) { inline FGTimeStamp operator + (const FGTimeStamp& t, const long& m) {
#ifdef WIN32 #ifdef WIN32
return FGTimeStamp( 0, t.usec + m ); return FGTimeStamp( 0, t.usec + m );