Use shared property pointers instead of path strings, adapt method names to JSBSim style, catch all property ties, proper error handling when tieing failed.
This commit is contained in:
parent
6b6d7059de
commit
ac71778319
5 changed files with 41 additions and 44 deletions
|
@ -78,22 +78,6 @@ static const char *IdHdr = ID_FDMEXEC;
|
||||||
CLASS IMPLEMENTATION
|
CLASS IMPLEMENTATION
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
// Constructor
|
// Constructor
|
||||||
|
|
||||||
|
@ -185,7 +169,7 @@ FGFDMExec::FGFDMExec(FGPropertyManager* root, unsigned int* fdmctr) : Root(root)
|
||||||
FGFDMExec::~FGFDMExec()
|
FGFDMExec::~FGFDMExec()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
checkTied( instance );
|
Unbind();
|
||||||
DeAllocate();
|
DeAllocate();
|
||||||
|
|
||||||
if (IdFDM == 0) { // Meaning this is no child FDM
|
if (IdFDM == 0) { // Meaning this is no child FDM
|
||||||
|
|
|
@ -227,7 +227,7 @@ public:
|
||||||
~FGFDMExec();
|
~FGFDMExec();
|
||||||
|
|
||||||
/** Unbind all tied JSBSim properties. */
|
/** Unbind all tied JSBSim properties. */
|
||||||
void unbind(void) {instance->unbind();}
|
void Unbind(void) {instance->Unbind();}
|
||||||
|
|
||||||
/** This routine places a model into the runlist at the specified rate. The
|
/** 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
|
"rate" is not really a clock rate. It represents how many calls to the
|
||||||
|
|
|
@ -426,7 +426,7 @@ void FGJSBsim::init()
|
||||||
|
|
||||||
void FGJSBsim::unbind()
|
void FGJSBsim::unbind()
|
||||||
{
|
{
|
||||||
fdmex->unbind();
|
fdmex->Unbind();
|
||||||
FGInterface::unbind();
|
FGInterface::unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ std::vector<std::string> FGPropertyManager::tied_properties;
|
||||||
|
|
||||||
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
void FGPropertyManager::unbind(void)
|
void FGPropertyManager::Unbind(void)
|
||||||
{
|
{
|
||||||
vector<string>::iterator it;
|
vector<string>::iterator it;
|
||||||
for (it = tied_properties.begin();it < tied_properties.end();it++)
|
for (it = tied_properties.begin();it < tied_properties.end();it++)
|
||||||
|
@ -314,11 +314,12 @@ void FGPropertyManager::Untie (const string &name)
|
||||||
|
|
||||||
void FGPropertyManager::Tie (const string &name, bool *pointer, bool useDefault)
|
void FGPropertyManager::Tie (const string &name, bool *pointer, bool useDefault)
|
||||||
{
|
{
|
||||||
tied_properties.push_back(name);
|
|
||||||
if (!tie(name.c_str(), SGRawValuePointer<bool>(pointer), useDefault))
|
if (!tie(name.c_str(), SGRawValuePointer<bool>(pointer), useDefault))
|
||||||
cerr << "Failed to tie property " << name << " to a pointer" << endl;
|
cerr << "Failed to tie property " << name << " to a pointer" << endl;
|
||||||
else if (debug_lvl & 0x20)
|
else {
|
||||||
cout << name << endl;
|
tied_properties.push_back(name);
|
||||||
|
if (debug_lvl & 0x20) std::cout << name << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
@ -326,11 +327,12 @@ void FGPropertyManager::Tie (const string &name, bool *pointer, bool useDefault)
|
||||||
void FGPropertyManager::Tie (const string &name, int *pointer,
|
void FGPropertyManager::Tie (const string &name, int *pointer,
|
||||||
bool useDefault )
|
bool useDefault )
|
||||||
{
|
{
|
||||||
tied_properties.push_back(name);
|
|
||||||
if (!tie(name.c_str(), SGRawValuePointer<int>(pointer), useDefault))
|
if (!tie(name.c_str(), SGRawValuePointer<int>(pointer), useDefault))
|
||||||
cerr << "Failed to tie property " << name << " to a pointer" << endl;
|
cerr << "Failed to tie property " << name << " to a pointer" << endl;
|
||||||
else if (debug_lvl & 0x20)
|
else {
|
||||||
cout << name << endl;
|
tied_properties.push_back(name);
|
||||||
|
if (debug_lvl & 0x20) std::cout << name << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
@ -338,11 +340,12 @@ void FGPropertyManager::Tie (const string &name, int *pointer,
|
||||||
void FGPropertyManager::Tie (const string &name, long *pointer,
|
void FGPropertyManager::Tie (const string &name, long *pointer,
|
||||||
bool useDefault )
|
bool useDefault )
|
||||||
{
|
{
|
||||||
tied_properties.push_back(name);
|
|
||||||
if (!tie(name.c_str(), SGRawValuePointer<long>(pointer), useDefault))
|
if (!tie(name.c_str(), SGRawValuePointer<long>(pointer), useDefault))
|
||||||
cerr << "Failed to tie property " << name << " to a pointer" << endl;
|
cerr << "Failed to tie property " << name << " to a pointer" << endl;
|
||||||
else if (debug_lvl & 0x20)
|
else {
|
||||||
cout << name << endl;
|
tied_properties.push_back(name);
|
||||||
|
if (debug_lvl & 0x20) std::cout << name << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
@ -350,22 +353,24 @@ void FGPropertyManager::Tie (const string &name, long *pointer,
|
||||||
void FGPropertyManager::Tie (const string &name, float *pointer,
|
void FGPropertyManager::Tie (const string &name, float *pointer,
|
||||||
bool useDefault )
|
bool useDefault )
|
||||||
{
|
{
|
||||||
tied_properties.push_back(name);
|
|
||||||
if (!tie(name.c_str(), SGRawValuePointer<float>(pointer), useDefault))
|
if (!tie(name.c_str(), SGRawValuePointer<float>(pointer), useDefault))
|
||||||
cerr << "Failed to tie property " << name << " to a pointer" << endl;
|
cerr << "Failed to tie property " << name << " to a pointer" << endl;
|
||||||
else if (debug_lvl & 0x20)
|
else {
|
||||||
cout << name << endl;
|
tied_properties.push_back(name);
|
||||||
|
if (debug_lvl & 0x20) std::cout << name << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
void FGPropertyManager::Tie (const string &name, double *pointer, bool useDefault)
|
void FGPropertyManager::Tie (const string &name, double *pointer, bool useDefault)
|
||||||
{
|
{
|
||||||
tied_properties.push_back(name);
|
|
||||||
if (!tie(name.c_str(), SGRawValuePointer<double>(pointer), useDefault))
|
if (!tie(name.c_str(), SGRawValuePointer<double>(pointer), useDefault))
|
||||||
cerr << "Failed to tie property " << name << " to a pointer" << endl;
|
cerr << "Failed to tie property " << name << " to a pointer" << endl;
|
||||||
else if (debug_lvl & 0x20)
|
else {
|
||||||
cout << name << endl;
|
tied_properties.push_back(name);
|
||||||
|
if (debug_lvl & 0x20) std::cout << name << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace JSBSim
|
} // namespace JSBSim
|
||||||
|
|
|
@ -406,7 +406,7 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase
|
||||||
* Classes should use this function to release control of any
|
* Classes should use this function to release control of any
|
||||||
* properties they have bound using this property manager.
|
* properties they have bound using this property manager.
|
||||||
*/
|
*/
|
||||||
void unbind (void);
|
void Unbind (void);
|
||||||
|
|
||||||
// Templates cause ambiguity here
|
// Templates cause ambiguity here
|
||||||
|
|
||||||
|
@ -534,8 +534,10 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase
|
||||||
{
|
{
|
||||||
if (!tie(name.c_str(), SGRawValueFunctions<V>(getter, setter), useDefault))
|
if (!tie(name.c_str(), SGRawValueFunctions<V>(getter, setter), useDefault))
|
||||||
std::cout << "Failed to tie property " << name << " to functions" << std::endl;
|
std::cout << "Failed to tie property " << name << " to functions" << std::endl;
|
||||||
else if (debug_lvl & 0x20)
|
else {
|
||||||
std::cout << name << std::endl;
|
tied_properties.push_back(name);
|
||||||
|
if (debug_lvl & 0x20) std::cout << name << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -562,8 +564,10 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase
|
||||||
{
|
{
|
||||||
if (!tie(name.c_str(), SGRawValueFunctionsIndexed<V>(index, getter, setter), useDefault))
|
if (!tie(name.c_str(), SGRawValueFunctionsIndexed<V>(index, getter, setter), useDefault))
|
||||||
std::cout << "Failed to tie property " << name << " to indexed functions" << std::endl;
|
std::cout << "Failed to tie property " << name << " to indexed functions" << std::endl;
|
||||||
else if (debug_lvl & 0x20)
|
else {
|
||||||
std::cout << name << std::endl;
|
tied_properties.push_back(name);
|
||||||
|
if (debug_lvl & 0x20) std::cout << name << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -592,8 +596,10 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase
|
||||||
{
|
{
|
||||||
if (!tie(name.c_str(), SGRawValueMethods<T,V>(*obj, getter, setter), useDefault))
|
if (!tie(name.c_str(), SGRawValueMethods<T,V>(*obj, getter, setter), useDefault))
|
||||||
std::cout << "Failed to tie property " << name << " to object methods" << std::endl;
|
std::cout << "Failed to tie property " << name << " to object methods" << std::endl;
|
||||||
else if (debug_lvl & 0x20)
|
else {
|
||||||
std::cout << name << std::endl;
|
tied_properties.push_back(name);
|
||||||
|
if (debug_lvl & 0x20) std::cout << name << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -621,8 +627,10 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase
|
||||||
{
|
{
|
||||||
if (!tie(name.c_str(), SGRawValueMethodsIndexed<T,V>(*obj, index, getter, setter), useDefault))
|
if (!tie(name.c_str(), SGRawValueMethodsIndexed<T,V>(*obj, index, getter, setter), useDefault))
|
||||||
std::cout << "Failed to tie property " << name << " to indexed object methods" << std::endl;
|
std::cout << "Failed to tie property " << name << " to indexed object methods" << std::endl;
|
||||||
else if (debug_lvl & 0x20)
|
else {
|
||||||
std::cout << name << std::endl;
|
tied_properties.push_back(name);
|
||||||
|
if (debug_lvl & 0x20) std::cout << name << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue