]> git.mxchange.org Git - flightgear.git/blobdiff - src/Input/FGDeviceConfigurationMap.cxx
replay system: protect from recording multiple records for identical time
[flightgear.git] / src / Input / FGDeviceConfigurationMap.cxx
index b27d6816cf96f4210b0147d138eb9617eb13f4e8..1da399fb5ae5db9dfe38d68fc157cee009b3f69a 100644 (file)
 using simgear::PropertyList;
 using std::string;
 
-FGDeviceConfigurationMap::FGDeviceConfigurationMap( const string& relative_path)
+FGDeviceConfigurationMap::FGDeviceConfigurationMap( const string& relative_path,
+                                                   SGPropertyNode* nodePath,
+                                                   const std::string& nodeName)
 {
+  // scan for over-ride configurations, loaded via joysticks.xml, etc
+  BOOST_FOREACH(SGPropertyNode_ptr preloaded, nodePath->getChildren(nodeName)) {
+    BOOST_FOREACH(SGPropertyNode* nameProp, preloaded->getChildren("name")) {
+      overrideDict[nameProp->getStringValue()] = preloaded;
+    } // of names iteration
+  } // of defined overrides iteration
+  
   scan_dir( SGPath(globals->get_fg_home(), relative_path));
   scan_dir( SGPath(globals->get_fg_root(), relative_path));
 }
@@ -53,6 +62,12 @@ FGDeviceConfigurationMap::~FGDeviceConfigurationMap()
 SGPropertyNode_ptr
 FGDeviceConfigurationMap::configurationForDeviceName(const std::string& name)
 {
+  NameNodeMap::iterator j = overrideDict.find(name);
+  if (j != overrideDict.end()) {
+    return j->second;
+  }
+  
+// no override, check out list of config files
   NamePathMap::iterator it = namePathMap.find(name);
   if (it == namePathMap.end()) {
     return SGPropertyNode_ptr();
@@ -62,7 +77,7 @@ FGDeviceConfigurationMap::configurationForDeviceName(const std::string& name)
   try {
     readProperties(it->second.str(), result);
     result->setStringValue("source", it->second.c_str());
-  } catch (sg_exception& e) {
+  } catch (sg_exception&) {
     SG_LOG(SG_INPUT, SG_WARN, "parse failure reading:" << it->second);
     return NULL;
   }
@@ -71,6 +86,11 @@ FGDeviceConfigurationMap::configurationForDeviceName(const std::string& name)
 
 bool FGDeviceConfigurationMap::hasConfiguration(const std::string& name) const
 {
+  NameNodeMap::const_iterator j = overrideDict.find(name);
+  if (j != overrideDict.end()) {
+    return true;
+  }
+  
   return namePathMap.find(name) != namePathMap.end();
 }
 
@@ -118,7 +138,7 @@ void FGDeviceConfigurationMap::refreshCacheForFile(const SGPath& path)
   SGPropertyNode_ptr n(new SGPropertyNode);
   try {
     readProperties(path.str(), n);
-  } catch (sg_exception& e) {
+  } catch (sg_exception&) {
     SG_LOG(SG_INPUT, SG_WARN, "parse failure reading:" << path);
     return;
   }