JSBSim Flight Dynamics Model  1.0 (02 March 2017)
An Open Source Flight Dynamics and Control Software Library in C++
FGPropertyManager Class Reference

Public Member Functions

 FGPropertyManager (void)
 Default constructor.
 
 FGPropertyManager (FGPropertyNode *_root)
 Constructor.
 
virtual ~FGPropertyManager (void)
 Destructor.
 
template<class T >
simgear::PropertyObject< T > CreatePropertyObject (const std::string &path)
 
FGPropertyNodeGetNode (void) const
 
FGPropertyNodeGetNode (const std::string &path, bool create=false)
 
FGPropertyNodeGetNode (const std::string &relpath, int index, bool create=false)
 
bool HasNode (const std::string &path) const
 
std::string mkPropertyName (std::string name, bool lowercase)
 Property-ify a name replaces spaces with '-' and, optionally, makes name all lower case. More...
 
void Tie (const std::string &name, bool *pointer, bool useDefault=true)
 Tie a property to an external bool variable. More...
 
void Tie (const std::string &name, int *pointer, bool useDefault=true)
 Tie a property to an external int variable. More...
 
void Tie (const std::string &name, long *pointer, bool useDefault=true)
 Tie a property to an external long variable. More...
 
void Tie (const std::string &name, float *pointer, bool useDefault=true)
 Tie a property to an external float variable. More...
 
void Tie (const std::string &name, double *pointer, bool useDefault=true)
 Tie a property to an external double variable. More...
 
template<class V >
void Tie (const std::string &name, V(*getter)(), void(*setter)(V)=0, bool useDefault=true)
 Tie a property to a pair of simple functions. More...
 
template<class V >
void Tie (const std::string &name, int index, V(*getter)(int), void(*setter)(int, V)=0, bool useDefault=true)
 Tie a property to a pair of indexed functions. More...
 
template<class T , class V >
void Tie (const std::string &name, T *obj, V(T::*getter)() const, void(T::*setter)(V)=0, bool useDefault=true)
 Tie a property to a pair of object methods. More...
 
template<class T , class V >
void Tie (const std::string &name, T *obj, int index, V(T::*getter)(int) const, void(T::*setter)(int, V)=0, bool useDefault=true)
 Tie a property to a pair of indexed object methods. More...
 
void Unbind (void)
 Unbind all properties bound by this manager to an external data source. More...
 
void Untie (const std::string &name)
 Untie a property from an external data source. More...
 

Detailed Description

Definition at line 379 of file FGPropertyManager.h.

Member Function Documentation

◆ mkPropertyName()

string mkPropertyName ( std::string  name,
bool  lowercase 
)

Property-ify a name replaces spaces with '-' and, optionally, makes name all lower case.

Parameters
namestring to change
lowercasetrue to change all upper case chars to lower NOTE: this function changes its argument and thus relies on pass by value

Definition at line 65 of file FGPropertyManager.cpp.

65  {
66 
67  /* do this two pass to avoid problems with characters getting skipped
68  because the index changed */
69  unsigned i;
70  for(i=0;i<name.length();i++) {
71  if( lowercase && isupper(name[i]) )
72  name[i]=tolower(name[i]);
73  else if( isspace(name[i]) )
74  name[i]='-';
75  }
76 
77  return name;
78 }
+ Here is the caller graph for this function:

◆ Tie() [1/9]

void Tie ( const std::string &  name,
bool *  pointer,
bool  useDefault = true 
)

Tie a property to an external bool variable.

The property's value will automatically mirror the variable's value, and vice-versa, until the property is untied.

Parameters
nameThe property name to tie (full path).
pointerA pointer to the variable.
useDefaulttrue if any existing property value should be copied to the variable; false if the variable should not be modified; defaults to true.

Definition at line 330 of file FGPropertyManager.cpp.

331 {
332  SGPropertyNode* property = root->getNode(name.c_str(), true);
333  if (!property) {
334  cerr << "Could not get or create property " << name << endl;
335  return;
336  }
337 
338  if (!property->tie(SGRawValuePointer<bool>(pointer), useDefault))
339  cerr << "Failed to tie property " << name << " to a pointer" << endl;
340  else {
341  tied_properties.push_back(property);
342  if (FGJSBBase::debug_lvl & 0x20) cout << name << endl;
343  }
344 }
+ Here is the caller graph for this function:

◆ Tie() [2/9]

void Tie ( const std::string &  name,
int *  pointer,
bool  useDefault = true 
)

Tie a property to an external int variable.

The property's value will automatically mirror the variable's value, and vice-versa, until the property is untied.

Parameters
nameThe property name to tie (full path).
pointerA pointer to the variable.
useDefaulttrue if any existing property value should be copied to the variable; false if the variable should not be modified; defaults to true.

Definition at line 348 of file FGPropertyManager.cpp.

350 {
351  SGPropertyNode* property = root->getNode(name.c_str(), true);
352  if (!property) {
353  cerr << "Could not get or create property " << name << endl;
354  return;
355  }
356 
357  if (!property->tie(SGRawValuePointer<int>(pointer), useDefault))
358  cerr << "Failed to tie property " << name << " to a pointer" << endl;
359  else {
360  tied_properties.push_back(property);
361  if (FGJSBBase::debug_lvl & 0x20) cout << name << endl;
362  }
363 }

◆ Tie() [3/9]

void Tie ( const std::string &  name,
long *  pointer,
bool  useDefault = true 
)

Tie a property to an external long variable.

The property's value will automatically mirror the variable's value, and vice-versa, until the property is untied.

Parameters
nameThe property name to tie (full path).
pointerA pointer to the variable.
useDefaulttrue if any existing property value should be copied to the variable; false if the variable should not be modified; defaults to true.

Definition at line 367 of file FGPropertyManager.cpp.

369 {
370  SGPropertyNode* property = root->getNode(name.c_str(), true);
371  if (!property) {
372  cerr << "Could not get or create property " << name << endl;
373  return;
374  }
375 
376  if (!property->tie(SGRawValuePointer<long>(pointer), useDefault))
377  cerr << "Failed to tie property " << name << " to a pointer" << endl;
378  else {
379  tied_properties.push_back(property);
380  if (FGJSBBase::debug_lvl & 0x20) cout << name << endl;
381  }
382 }

◆ Tie() [4/9]

void Tie ( const std::string &  name,
float *  pointer,
bool  useDefault = true 
)

Tie a property to an external float variable.

The property's value will automatically mirror the variable's value, and vice-versa, until the property is untied.

Parameters
nameThe property name to tie (full path).
pointerA pointer to the variable.
useDefaulttrue if any existing property value should be copied to the variable; false if the variable should not be modified; defaults to true.

Definition at line 386 of file FGPropertyManager.cpp.

388 {
389  SGPropertyNode* property = root->getNode(name.c_str(), true);
390  if (!property) {
391  cerr << "Could not get or create property " << name << endl;
392  return;
393  }
394 
395  if (!property->tie(SGRawValuePointer<float>(pointer), useDefault))
396  cerr << "Failed to tie property " << name << " to a pointer" << endl;
397  else {
398  tied_properties.push_back(property);
399  if (FGJSBBase::debug_lvl & 0x20) cout << name << endl;
400  }
401 }

◆ Tie() [5/9]

void Tie ( const std::string &  name,
double *  pointer,
bool  useDefault = true 
)

Tie a property to an external double variable.

The property's value will automatically mirror the variable's value, and vice-versa, until the property is untied.

Parameters
nameThe property name to tie (full path).
pointerA pointer to the variable.
useDefaulttrue if any existing property value should be copied to the variable; false if the variable should not be modified; defaults to true.

Definition at line 405 of file FGPropertyManager.cpp.

406 {
407  SGPropertyNode* property = root->getNode(name.c_str(), true);
408  if (!property) {
409  cerr << "Could not get or create property " << name << endl;
410  return;
411  }
412 
413  if (!property->tie(SGRawValuePointer<double>(pointer), useDefault))
414  cerr << "Failed to tie property " << name << " to a pointer" << endl;
415  else {
416  tied_properties.push_back(property);
417  if (FGJSBBase::debug_lvl & 0x20) cout << name << endl;
418  }
419 }

◆ Tie() [6/9]

void Tie ( const std::string &  name,
V(*)()  getter,
void(*)(V)  setter = 0,
bool  useDefault = true 
)
inline

Tie a property to a pair of simple functions.

Every time the property value is queried, the getter (if any) will be invoked; every time the property value is modified, the setter (if any) will be invoked. The getter can be 0 to make the property unreadable, and the setter can be 0 to make the property unmodifiable.

Parameters
nameThe property name to tie (full path).
getterThe getter function, or 0 if the value is unreadable.
setterThe setter function, or 0 if the value is unmodifiable.
useDefaulttrue if the setter should be invoked with any existing property value should be; false if the old value should be discarded; defaults to true.

Definition at line 555 of file FGPropertyManager.h.

556  {
557  SGPropertyNode* property = root->getNode(name.c_str(), true);
558  if (!property) {
559  std::cerr << "Could not get or create property " << name << std::endl;
560  return;
561  }
562 
563  if (!property->tie(SGRawValueFunctions<V>(getter, setter), useDefault))
564  std::cerr << "Failed to tie property " << name << " to functions" << std::endl;
565  else {
566  if (setter == 0) property->setAttribute(SGPropertyNode::WRITE, false);
567  if (getter == 0) property->setAttribute(SGPropertyNode::READ, false);
568  tied_properties.push_back(property);
569  if (FGJSBBase::debug_lvl & 0x20) std::cout << name << std::endl;
570  }
571  }

◆ Tie() [7/9]

void Tie ( const std::string &  name,
int  index,
V(*)(int)  getter,
void(*)(int, V)  setter = 0,
bool  useDefault = true 
)
inline

Tie a property to a pair of indexed functions.

Every time the property value is queried, the getter (if any) will be invoked with the index provided; every time the property value is modified, the setter (if any) will be invoked with the index provided. The getter can be 0 to make the property unreadable, and the setter can be 0 to make the property unmodifiable.

Parameters
nameThe property name to tie (full path).
indexThe integer argument to pass to the getter and setter functions.
getterThe getter function, or 0 if the value is unreadable.
setterThe setter function, or 0 if the value is unmodifiable.
useDefaulttrue if the setter should be invoked with any existing property value should there be one; false if the old value should be discarded; defaults to true.

Definition at line 592 of file FGPropertyManager.h.

594  {
595  SGPropertyNode* property = root->getNode(name.c_str(), true);
596  if (!property) {
597  std::cerr << "Could not get or create property " << name << std::endl;
598  return;
599  }
600 
601  if (!property->tie(SGRawValueFunctionsIndexed<V>(index, getter, setter), useDefault))
602  std::cerr << "Failed to tie property " << name << " to indexed functions" << std::endl;
603  else {
604  if (setter == 0) property->setAttribute(SGPropertyNode::WRITE, false);
605  if (getter == 0) property->setAttribute(SGPropertyNode::READ, false);
606  tied_properties.push_back(property);
607  if (FGJSBBase::debug_lvl & 0x20) std::cout << name << std::endl;
608  }
609  }

◆ Tie() [8/9]

void Tie ( const std::string &  name,
T *  obj,
V(T::*)() const  getter,
void(T::*)(V)  setter = 0,
bool  useDefault = true 
)
inline

Tie a property to a pair of object methods.

Every time the property value is queried, the getter (if any) will be invoked; every time the property value is modified, the setter (if any) will be invoked. The getter can be 0 to make the property unreadable, and the setter can be 0 to make the property unmodifiable.

Parameters
nameThe property name to tie (full path).
objThe object whose methods should be invoked.
getterThe object's getter method, or 0 if the value is unreadable.
setterThe object's setter method, or 0 if the value is unmodifiable.
useDefaulttrue if the setter should be invoked with any existing property value should there be one; false if the old value should be discarded; defaults to true.

Definition at line 632 of file FGPropertyManager.h.

634  {
635  SGPropertyNode* property = root->getNode(name.c_str(), true);
636  if (!property) {
637  std::cerr << "Could not get or create property " << name << std::endl;
638  return;
639  }
640 
641  if (!property->tie(SGRawValueMethods<T,V>(*obj, getter, setter), useDefault))
642  std::cerr << "Failed to tie property " << name << " to object methods" << std::endl;
643  else {
644  if (setter == 0) property->setAttribute(SGPropertyNode::WRITE, false);
645  if (getter == 0) property->setAttribute(SGPropertyNode::READ, false);
646  tied_properties.push_back(property);
647  if (FGJSBBase::debug_lvl & 0x20) std::cout << name << std::endl;
648  }
649  }

◆ Tie() [9/9]

void Tie ( const std::string &  name,
T *  obj,
int  index,
V(T::*)(int) const  getter,
void(T::*)(int, V)  setter = 0,
bool  useDefault = true 
)
inline

Tie a property to a pair of indexed object methods.

Every time the property value is queried, the getter (if any) will be invoked with the index provided; every time the property value is modified, the setter (if any) will be invoked with the index provided. The getter can be 0 to make the property unreadable, and the setter can be 0 to make the property unmodifiable.

Parameters
nameThe property name to tie (full path).
objThe object whose methods should be invoked.
indexThe integer argument to pass to the getter and setter methods.
getterThe getter method, or 0 if the value is unreadable.
setterThe setter method, or 0 if the value is unmodifiable.
useDefaulttrue if the setter should be invoked with any existing property value should be; false if the old value should be discarded; defaults to true.

Definition at line 671 of file FGPropertyManager.h.

673  {
674  SGPropertyNode* property = root->getNode(name.c_str(), true);
675  if (!property) {
676  std::cerr << "Could not get or create property " << name << std::endl;
677  return;
678  }
679 
680  if (!property->tie(SGRawValueMethodsIndexed<T,V>(*obj, index, getter, setter), useDefault))
681  std::cerr << "Failed to tie property " << name << " to indexed object methods" << std::endl;
682  else {
683  if (setter == 0) property->setAttribute(SGPropertyNode::WRITE, false);
684  if (getter == 0) property->setAttribute(SGPropertyNode::READ, false);
685  tied_properties.push_back(property);
686  if (FGJSBBase::debug_lvl & 0x20) std::cout << name << std::endl;
687  }
688  }

◆ Unbind()

void Unbind ( void  )

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.

Definition at line 53 of file FGPropertyManager.cpp.

54 {
55  vector<SGPropertyNode_ptr>::iterator it;
56 
57  for (it = tied_properties.begin();it < tied_properties.end();it++)
58  (*it)->untie();
59 
60  tied_properties.clear();
61 }

◆ Untie()

void Untie ( const std::string &  name)

Untie a property from an external data source.

Classes should use this function to release control of any properties they are managing.

Definition at line 306 of file FGPropertyManager.cpp.

307 {
308  SGPropertyNode* property = root->getNode(name.c_str());
309  if (!property) {
310  cerr << "Attempt to untie a non-existant property." << name << endl;
311  return;
312  }
313 
314  vector <SGPropertyNode_ptr>::iterator it;
315  for (it = tied_properties.begin(); it != tied_properties.end(); ++it) {
316  if (*it == property) {
317  property->untie();
318  tied_properties.erase(it);
319  if (FGJSBBase::debug_lvl & 0x20) cout << "Untied " << name << endl;
320  return;
321  }
322  }
323 
324  cerr << "Failed to untie property " << name << endl
325  << "JSBSim is not the owner of this property." << endl;
326 }

The documentation for this class was generated from the following files: