]> git.mxchange.org Git - flightgear.git/commitdiff
Support string-list properties in the cache.
authorJames Turner <zakalawe@mac.com>
Wed, 19 Sep 2012 17:15:49 +0000 (18:15 +0100)
committerJames Turner <zakalawe@mac.com>
Wed, 19 Sep 2012 17:15:49 +0000 (18:15 +0100)
Not used yet, but will aid in caching joystick and dialog configs.

src/Navaids/NavDataCache.cxx
src/Navaids/NavDataCache.hxx

index 4b3cbcee19a920110329ab3d673cbba5282df036..3506d64fe13d86f80f979bc502e3e1d89c714eb2 100644 (file)
@@ -422,6 +422,9 @@ public:
   
   void prepareQueries()
   {
+    clearProperty = prepare("DELETE FROM properties WHERE key=?1");
+    writePropertyMulti = prepare("INSERT INTO properties (key, value) VALUES(?,?)");
+    
 #define POSITIONED_COLS "rowid, type, ident, name, airport, lon, lat, elev_m, octree_node"
 #define AND_TYPED "AND type>=?2 AND type <=?3"
     statCacheCheck = prepare("SELECT stamp FROM stat_cache WHERE path=?");
@@ -748,6 +751,7 @@ public:
     stampFileCache, statCacheCheck,
     loadAirportStmt, loadCommStation, loadPositioned, loadNavaid,
     loadRunwayStmt;
+  sqlite3_stmt_ptr writePropertyMulti, clearProperty;
   
   sqlite3_stmt_ptr insertPositionedQuery, insertAirport, insertTower, insertRunway,
   insertCommStation, insertNavaid;
@@ -1054,7 +1058,32 @@ void NavDataCache::writeDoubleProperty(const string& key, const double& value)
   d->execSelect(d->writePropertyQuery);
 }
 
-
+string_list NavDataCache::readStringListProperty(const string& key)
+{
+  d->reset(d->readPropertyQuery);
+  sqlite_bind_stdstring(d->readPropertyQuery, 1, key);
+  string_list result;
+  while (d->stepSelect(d->readPropertyQuery)) {
+    result.push_back((char*) sqlite3_column_text(d->readPropertyQuery, 1));
+  }
+  
+  return result;
+}
+  
+void NavDataCache::writeStringListProperty(const string& key, const string_list& values)
+{
+  d->reset(d->clearProperty);
+  sqlite_bind_stdstring(d->clearProperty, 1, key);
+  d->execUpdate(d->clearProperty);
+  
+  sqlite_bind_stdstring(d->writePropertyMulti, 1, key);
+  BOOST_FOREACH(string value, values) {
+    d->reset(d->writePropertyMulti);
+    sqlite_bind_stdstring(d->writePropertyMulti, 2, value);
+    d->execInsert(d->writePropertyMulti);
+  }
+}
+  
 bool NavDataCache::isCachedFileModified(const SGPath& path) const
 {
   if (!path.exists()) {
index e0bb0a98c2b16d361642602abddc1293dbfd39dd..19edb91d7d4c7e0381598df88ed5d2ff996d35bb 100644 (file)
@@ -25,6 +25,8 @@
 #define FG_NAVDATACACHE_HXX
 
 #include <memory>
+
+#include <simgear/misc/strutils.hxx> // for string_list
 #include <Navaids/positioned.hxx>
     
 class SGPath;
@@ -78,6 +80,9 @@ public:
   void writeStringProperty(const std::string& key, const std::string& value);
   void writeDoubleProperty(const std::string& key, const double& value);
   
+  string_list readStringListProperty(const std::string& key);
+  void writeStringListProperty(const std::string& key, const string_list& values);
+  
   FGPositioned* loadById(PositionedID guid);
   
   PositionedID insertAirport(FGPositioned::Type ty, const std::string& ident,