]> git.mxchange.org Git - flightgear.git/blobdiff - src/Input/FGEventInput.cxx
Document that property write-protection is not a security measure
[flightgear.git] / src / Input / FGEventInput.cxx
index 928c20c242a58ddee1ea5e97eafef1f0f89580ff..29bdc6e1d128a8d40337405b0f50c5fd3aa59938 100644 (file)
 #  include <config.h>
 #endif
 
+#include <cstring>
 #include "FGEventInput.hxx"
 #include <Main/fg_props.hxx>
 #include <simgear/io/sg_file.hxx>
+#include <simgear/props/props_io.hxx>
+#include <simgear/math/SGMath.hxx>
 #include <Scripting/NasalSys.hxx>
 
+using simgear::PropertyList;
+using std::cout;
+using std::endl;
+using std::map;
+using std::string;
+
 FGEventSetting::FGEventSetting( SGPropertyNode_ptr base ) :
   value(0.0)
 {
@@ -64,7 +73,7 @@ bool FGEventSetting::Test()
 
 static inline bool StartsWith( string & s, const char * cp )
 {
-  return s.compare( 0, strlen(cp), cp ) == 0;
+  return s.find( cp ) == 0;
 }
 
 FGInputEvent * FGInputEvent::NewObject( FGInputDevice * device, SGPropertyNode_ptr node )
@@ -93,8 +102,8 @@ FGInputEvent::FGInputEvent( FGInputDevice * aDevice, SGPropertyNode_ptr node ) :
   
   read_bindings( node, bindings, KEYMOD_NONE, device->GetNasalModule() );
 
-  vector<SGPropertyNode_ptr> settingNodes = node->getChildren("setting");
-  for( vector<SGPropertyNode_ptr>::iterator it = settingNodes.begin(); it != settingNodes.end(); it++ )
+  PropertyList settingNodes = node->getChildren("setting");
+  for( PropertyList::iterator it = settingNodes.begin(); it != settingNodes.end(); ++it )
     settings.push_back( new FGEventSetting( *it ) );
 }
 
@@ -104,7 +113,7 @@ FGInputEvent::~FGInputEvent()
 
 void FGInputEvent::update( double dt )
 {
-  for( setting_list_t::iterator it = settings.begin(); it != settings.end(); it++ ) {
+  for( setting_list_t::iterator it = settings.begin(); it != settings.end(); ++it ) {
     if( (*it)->Test() ) {
       double value = (*it)->GetValue();
       if( value != lastSettingValue ) {
@@ -120,7 +129,7 @@ void FGInputEvent::fire( FGEventData & eventData )
   lastDt += eventData.dt;
   if( lastDt >= intervalSec ) {
 
-    for( binding_list_t::iterator it = bindings[eventData.modifiers].begin(); it != bindings[eventData.modifiers].end(); it++ )
+    for( binding_list_t::iterator it = bindings[eventData.modifiers].begin(); it != bindings[eventData.modifiers].end(); ++it )
       fire( *it, eventData );
 
     lastDt -= intervalSec;
@@ -221,8 +230,8 @@ FGInputDevice::~FGInputDevice()
     if( nasal ) {
       SGPropertyNode_ptr nasalClose = nasal->getNode("close");
       if (nasalClose) {
-        const char *s = nasalClose->getStringValue();
-        nas->createModule(nasalModule.c_str(), nasalModule.c_str(), s, strlen(s), deviceNode );
+        const string s = nasalClose->getStringValue();
+        nas->createModule(nasalModule.c_str(), nasalModule.c_str(), s.c_str(), s.length(), deviceNode );
       }
     }
     nas->deleteModule(nasalModule.c_str());
@@ -235,8 +244,8 @@ void FGInputDevice::Configure( SGPropertyNode_ptr aDeviceNode )
 
   nasalModule = string("__event:") + GetName();
 
-  vector<SGPropertyNode_ptr> eventNodes = deviceNode->getChildren( "event" );
-  for( vector<SGPropertyNode_ptr>::iterator it = eventNodes.begin(); it != eventNodes.end(); it++ )
+  PropertyList eventNodes = deviceNode->getChildren( "event" );
+  for( PropertyList::iterator it = eventNodes.begin(); it != eventNodes.end(); ++it )
     AddHandledEvent( FGInputEvent::NewObject( this, *it ) );
 
   debugEvents = deviceNode->getBoolValue("debug-events", debugEvents );
@@ -251,10 +260,10 @@ void FGInputDevice::Configure( SGPropertyNode_ptr aDeviceNode )
   if (nasal) {
     SGPropertyNode_ptr open = nasal->getNode("open");
     if (open) {
-      const char *s = open->getStringValue();
+      const string s = open->getStringValue();
       FGNasalSys *nas = (FGNasalSys *)globals->get_subsystem("nasal");
       if (nas)
-        nas->createModule(nasalModule.c_str(), nasalModule.c_str(), s, strlen(s), deviceNode );
+        nas->createModule(nasalModule.c_str(), nasalModule.c_str(), s.c_str(), s.length(), deviceNode );
     }
   }
 
@@ -286,13 +295,13 @@ void FGInputDevice::SetName( string name )
 const char * FGEventInput::PROPERTY_ROOT = "/input/event";
 
 FGEventInput::FGEventInput() : 
-  configMap( "Input/Event", fgGetNode( PROPERTY_ROOT, true ), "device-named" )
+  configMap( "Input/Event", fgGetNode(PROPERTY_ROOT, true), "device-named")
 {
 }
 
 FGEventInput::~FGEventInput()
 {
-  for( map<int,FGInputDevice*>::iterator it = input_devices.begin(); it != input_devices.end(); it++ )
+  for( map<int,FGInputDevice*>::iterator it = input_devices.begin(); it != input_devices.end(); ++it )
     delete (*it).second;
   input_devices.clear();
 }
@@ -311,7 +320,7 @@ void FGEventInput::postinit ()
 void FGEventInput::update( double dt )
 {
   // call each associated device's update() method
-  for( map<int,FGInputDevice*>::iterator it =  input_devices.begin(); it != input_devices.end(); it++ )
+  for( map<int,FGInputDevice*>::iterator it =  input_devices.begin(); it != input_devices.end(); ++it )
     (*it).second->update( dt );
 }
 
@@ -321,7 +330,7 @@ unsigned FGEventInput::AddDevice( FGInputDevice * inputDevice )
   SGPropertyNode_ptr deviceNode = NULL;
 
   // look for configuration in the device map
-  if( configMap.count( inputDevice->GetName() ) > 0 ) {
+  if ( configMap.hasConfiguration( inputDevice->GetName() ) ) {
     // found - copy to /input/event/device[n]
 
     // find a free index
@@ -339,7 +348,7 @@ unsigned FGEventInput::AddDevice( FGInputDevice * inputDevice )
     deviceNode = baseNode->getNode( "device", index, true );
 
     // and copy the properties from the configuration tree
-    copyProperties( configMap[ inputDevice->GetName() ], deviceNode );
+    copyProperties( configMap.configurationForDeviceName(inputDevice->GetName()), deviceNode );
 
   }
 
@@ -377,6 +386,6 @@ void FGEventInput::RemoveDevice( unsigned index )
     delete inputDevice;
     
   }
-  deviceNode = baseNode->removeChild("device", index, false);
+  deviceNode = baseNode->removeChild("device", index);
 }