]> git.mxchange.org Git - flightgear.git/commitdiff
Improved fix for #204 and #222: JSBSim::unbind() needs to untie _all_ its properties
authorThorstenB <brehmt@gmail.com>
Sat, 5 Feb 2011 16:49:26 +0000 (17:49 +0100)
committerThorstenB <brehmt@gmail.com>
Sun, 6 Feb 2011 14:34:16 +0000 (15:34 +0100)
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
src/FDM/JSBSim/JSBSim.cxx
src/FDM/JSBSim/input_output/FGPropertyManager.cpp
src/FDM/JSBSim/input_output/FGPropertyManager.h

index 10736f4a439cb1c86cfbd60cca6ef072b8db66a9..c1038c471dcc8622f07403ec7e2bffb944afbe7d 100644 (file)
@@ -101,8 +101,8 @@ CLASS DOCUMENTATION
     file:
 
     @code
-    fdmex = new FGFDMExec( \85 );
-    result = fdmex->LoadModel( \85 );
+    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
index a2d217ba2989dbc8774f296fc7c0cc62d4ed30b2..ba35d6900b238805aadc8d11a21818479002c5b1 100644 (file)
@@ -424,28 +424,9 @@ void FGJSBsim::init()
 
 /******************************************************************************/
 
-void checkTied ( FGPropertyManager *node )
-{
-  int N = node->nChildren();
-  string name;
-
-  for (int i=0; i<N; i++) {
-    if (node->getChild(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();
 }
 
index 11e566965259e1b58ec854de18892233a718b209..899565ed2e9263278cbec3b56c6313a6b43b9562 100755 (executable)
@@ -49,6 +49,19 @@ COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
 namespace JSBSim {
 
 bool FGPropertyManager::suppress_warning = true;
+std::vector<std::string> FGPropertyManager::tied_properties;
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+void FGPropertyManager::unbind(void)
+{
+    vector<string>::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<bool>(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<int>(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<long>(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<float>(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<double>(pointer), useDefault))
     cerr << "Failed to tie property " << name << " to a pointer" << endl;
   else if (debug_lvl & 0x20)
index c29b5a412e55b9a72e786a2d675e4efeb1acd133..54ea918746fb30fa30732b778728cb994a72fbce 100644 (file)
@@ -77,6 +77,7 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase
 {
   private:
     static bool suppress_warning;
+    static std::vector<std::string> 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