From ad8d46ba648263630b8777c53f852b75cad7ecdd Mon Sep 17 00:00:00 2001 From: ThorstenB Date: Sat, 5 Feb 2011 17:49:26 +0100 Subject: [PATCH] Improved fix for #204 and #222: JSBSim::unbind() needs to untie _all_ its properties Extends and partially reverts commit 287cc74965e11ff3888117a9d9b88ed2bdbb9252 Previous fix did not consider properties outside the /fdm/jsbsim branch. FGPropertyManager now keeps track of all its tied properties - and provides a method to cleanly untie them again. --- src/FDM/JSBSim/FGFDMExec.h | 7 +++++-- src/FDM/JSBSim/JSBSim.cxx | 21 +------------------ .../JSBSim/input_output/FGPropertyManager.cpp | 18 ++++++++++++++++ .../JSBSim/input_output/FGPropertyManager.h | 8 +++++++ 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/FDM/JSBSim/FGFDMExec.h b/src/FDM/JSBSim/FGFDMExec.h index 10736f4a4..c1038c471 100644 --- a/src/FDM/JSBSim/FGFDMExec.h +++ b/src/FDM/JSBSim/FGFDMExec.h @@ -101,8 +101,8 @@ CLASS DOCUMENTATION file: @code - fdmex = new FGFDMExec( … ); - result = fdmex->LoadModel( … ); + fdmex = new FGFDMExec( ... ); + result = fdmex->LoadModel( ... ); @endcode When an aircraft model is loaded, the config file is parsed and for each of the @@ -226,6 +226,9 @@ public: /// Default destructor ~FGFDMExec(); + /** Unbind all tied JSBSim properties. */ + void unbind(void) {instance->unbind();} + /** This routine places a model into the runlist at the specified rate. The "rate" is not really a clock rate. It represents how many calls to the FGFDMExec::Run() method must be made before the model is executed. A diff --git a/src/FDM/JSBSim/JSBSim.cxx b/src/FDM/JSBSim/JSBSim.cxx index a9e9be771..0cc00259a 100644 --- a/src/FDM/JSBSim/JSBSim.cxx +++ b/src/FDM/JSBSim/JSBSim.cxx @@ -422,28 +422,9 @@ void FGJSBsim::init() /******************************************************************************/ -void checkTied ( FGPropertyManager *node ) -{ - int N = node->nChildren(); - string name; - - for (int i=0; igetChild(i)->nChildren() ) { - checkTied( (FGPropertyManager*)node->getChild(i) ); - } - if ( node->getChild(i)->isTied() ) { - name = ((FGPropertyManager*)node->getChild(i))->GetFullyQualifiedName(); - node->Untie(name); - } - } -} - -/******************************************************************************/ - void FGJSBsim::unbind() { - SGPropertyNode* instance = globals->get_props()->getNode("/fdm/jsbsim"); - checkTied((FGPropertyManager*)instance); + fdmex->unbind(); FGInterface::unbind(); } diff --git a/src/FDM/JSBSim/input_output/FGPropertyManager.cpp b/src/FDM/JSBSim/input_output/FGPropertyManager.cpp index 11e566965..899565ed2 100755 --- a/src/FDM/JSBSim/input_output/FGPropertyManager.cpp +++ b/src/FDM/JSBSim/input_output/FGPropertyManager.cpp @@ -49,6 +49,19 @@ COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs] namespace JSBSim { bool FGPropertyManager::suppress_warning = true; +std::vector FGPropertyManager::tied_properties; + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +void FGPropertyManager::unbind(void) +{ + vector::iterator it; + for (it = tied_properties.begin();it < tied_properties.end();it++) + { + Untie(*it); + } + tied_properties.clear(); +} //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -301,6 +314,7 @@ void FGPropertyManager::Untie (const string &name) void FGPropertyManager::Tie (const string &name, bool *pointer, bool useDefault) { + tied_properties.push_back(name); if (!tie(name.c_str(), SGRawValuePointer(pointer), useDefault)) cerr << "Failed to tie property " << name << " to a pointer" << endl; else if (debug_lvl & 0x20) @@ -312,6 +326,7 @@ void FGPropertyManager::Tie (const string &name, bool *pointer, bool useDefault) void FGPropertyManager::Tie (const string &name, int *pointer, bool useDefault ) { + tied_properties.push_back(name); if (!tie(name.c_str(), SGRawValuePointer(pointer), useDefault)) cerr << "Failed to tie property " << name << " to a pointer" << endl; else if (debug_lvl & 0x20) @@ -323,6 +338,7 @@ void FGPropertyManager::Tie (const string &name, int *pointer, void FGPropertyManager::Tie (const string &name, long *pointer, bool useDefault ) { + tied_properties.push_back(name); if (!tie(name.c_str(), SGRawValuePointer(pointer), useDefault)) cerr << "Failed to tie property " << name << " to a pointer" << endl; else if (debug_lvl & 0x20) @@ -334,6 +350,7 @@ void FGPropertyManager::Tie (const string &name, long *pointer, void FGPropertyManager::Tie (const string &name, float *pointer, bool useDefault ) { + tied_properties.push_back(name); if (!tie(name.c_str(), SGRawValuePointer(pointer), useDefault)) cerr << "Failed to tie property " << name << " to a pointer" << endl; else if (debug_lvl & 0x20) @@ -344,6 +361,7 @@ void FGPropertyManager::Tie (const string &name, float *pointer, void FGPropertyManager::Tie (const string &name, double *pointer, bool useDefault) { + tied_properties.push_back(name); if (!tie(name.c_str(), SGRawValuePointer(pointer), useDefault)) cerr << "Failed to tie property " << name << " to a pointer" << endl; else if (debug_lvl & 0x20) diff --git a/src/FDM/JSBSim/input_output/FGPropertyManager.h b/src/FDM/JSBSim/input_output/FGPropertyManager.h index c29b5a412..54ea91874 100644 --- a/src/FDM/JSBSim/input_output/FGPropertyManager.h +++ b/src/FDM/JSBSim/input_output/FGPropertyManager.h @@ -77,6 +77,7 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase { private: static bool suppress_warning; + static std::vector tied_properties; public: /// Constructor FGPropertyManager(void) {suppress_warning = false;} @@ -399,6 +400,13 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase */ void Untie (const std::string &name); + /** + * Unbind all properties bound by this manager to an external data source. + * + * Classes should use this function to release control of any + * properties they have bound using this property manager. + */ + void unbind (void); // Templates cause ambiguity here