Extends and partially reverts commit 287cc74965
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.
This commit is contained in:
parent
edfc06119a
commit
ad8d46ba64
4 changed files with 32 additions and 22 deletions
|
@ -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
|
||||
|
|
|
@ -422,28 +422,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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue