]> git.mxchange.org Git - flightgear.git/commitdiff
Replaced gdbm with metakit. Involves a new simgear version and a new database
authorcurt <curt>
Sat, 27 May 2000 05:54:02 +0000 (05:54 +0000)
committercurt <curt>
Sat, 27 May 2000 05:54:02 +0000 (05:54 +0000)
format for the airports in the base package.

12 files changed:
Thanks
docs-mini/README.JSBsim
src/Airports/Makefile.am
src/Airports/buildsimple.cxx
src/Airports/simple.cxx
src/Airports/simple.hxx
src/Autopilot/auto_gui.cxx
src/GUI/gui.cxx
src/Main/Makefile.am
src/Main/fg_init.cxx
src/Time/fg_timer.cxx
src/Time/timestamp.hxx

diff --git a/Thanks b/Thanks
index 90ab11a3d4ea460a9d37f60ca80a18e680b54739..13420f7afccd5f2b7d3597311890b480e68fdbfb 100644 (file)
--- a/Thanks
+++ b/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, 
index e1fc8dff2508124966e8b1466f75e4bdf2e9f75c..6115d4b361791165dd08fc6d0bd10313277e1bbc 100644 (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
 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
index e3a205af9eed47cddaa972a4c560fcc6a6cb316f..adee6d991ccb9b1b7ec7289f0b830f5688766cc1 100644 (file)
@@ -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
index b4f2b707f0cc6c17725470595be669fb2bfae06f..f3c9a9757d96fbf1197879feab2c82ece15d2e2d 100644 (file)
@@ -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 );
+
 }
index 2c4314159b11614b0f1f5468fc3345d0d2d2cc04..e9a04b9fb19aa643b028bcdd437f3e16adfa22bf 100644 (file)
 #  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>
 
 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;
-
-    key.dptr = (char *)id.c_str();
-    key.dsize = id.length();
+    c4_StringProp pID ("ID");
+    c4_FloatProp pLon ("Longitude");
+    c4_FloatProp pLat ("Latitude");
+    c4_FloatProp pElev ("Elevation");
 
-    content = gdbm_fetch( dbf, key );
+    int idx = vAirport->Find(pID[id.c_str()]);
+    cout << "idx = " << idx << endl;
 
-    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;
 }
index 6543ddce6170fd301e1557e971166eceb248eb62..d0e3fd588ef37b6d55aa1b1f2012045baa0e53dc 100644 (file)
@@ -23,8 +23,8 @@
 // $Id$
 
 
-#ifndef _AIRPORTS_HXX
-#define _AIRPORTS_HXX
+#ifndef _SIMPLE_HXX
+#define _SIMPLE_HXX
 
 
 #ifndef __cplusplus                                                          
 #  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
 #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
 
 
index 02ceeb5f1a6520fe7f43bbc199e346e06f1a9606..e662fadb642220636e4ecf937229ecf03278b6c9 100644 (file)
@@ -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;
         
index 8ce464eacc514f7fe135763dc6e9b5a215f57d2c..eb272e42c86e55ed80e9826d905bf18396c19e64 100644 (file)
@@ -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;
index 762f532362464427102f9f0907763963a66a5a42..2c4695402546f1d8d4b757028d2c17eb9212f7af 100644 (file)
@@ -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)
 
index d0953e7f3b0f4bfbec01aa13601499b31b04e022..06c5535a3158a1d23aa5424e011988c18067dba2 100644 (file)
@@ -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;
 
index 91fa01551db02e32d56ac11d13ab1b6578392ab6..49e2713c720218690aa3002955a5a866b79c6f50 100644 (file)
@@ -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;
 }
 
 
index 00b7352a481d46bb75fef6289a66e41ecfbf4244..1a50c78847e53c9baa7da21c8c362838bc5c84c7 100644 (file)
@@ -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 );