JSBSim Flight Dynamics Model  1.1.11 (13 Feb 2022)
An Open Source Flight Dynamics and Control Software Library in C++
FGPropertyManager Class Reference

Detailed Description

Definition at line 373 of file FGPropertyManager.h.

Public Member Functions

 FGPropertyManager (FGPropertyNode *_root)
 Constructor.
 
 FGPropertyManager (void)
 Default constructor.
 
virtual ~FGPropertyManager (void)
 Destructor.
 
template<class T >
simgear::PropertyObject< T > CreatePropertyObject (const std::string &path)
 
FGPropertyNodeGetNode (const std::string &path, bool create=false)
 
FGPropertyNodeGetNode (const std::string &relpath, int index, bool create=false)
 
FGPropertyNodeGetNode (void) const
 
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...
 
template<typename T >
void Tie (const std::string &name, int index, T(*getter)(int), void(*setter)(int, T)=nullptr)
 Tie a property to a pair of indexed functions. 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)=nullptr)
 Tie a property to a pair of indexed object methods. More...
 
template<class T , class V >
void Tie (const std::string &name, T *obj, V(T::*getter)() const, void(T::*setter)(V)=nullptr)
 Tie a property to a pair of object methods. More...
 
template<typename T >
void Tie (const std::string &name, T *pointer)
 Tie a property to an external variable. More...
 
template<typename T >
void Tie (const std::string &name, T(*getter)(), void(*setter)(T)=nullptr)
 Tie a property to a pair of simple functions. 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...
 
void Untie (SGPropertyNode *property)
 Untie a property from an external data source. More...
 

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 64 of file FGPropertyManager.cpp.

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

◆ Tie() [1/5]

void Tie ( const std::string &  name,
int  index,
T(*)(int)  getter,
void(*)(int, T)  setter = nullptr 
)
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.

Definition at line 515 of file FGPropertyManager.h.

517  {
518  SGPropertyNode* property = root->getNode(name.c_str(), true);
519  if (!property) {
520  std::cerr << "Could not get or create property " << name << std::endl;
521  return;
522  }
523 
524  if (!property->tie(SGRawValueFunctionsIndexed<T>(index, getter, setter),
525  false))
526  std::cerr << "Failed to tie property " << name << " to indexed functions"
527  << std::endl;
528  else {
529  if (!setter) property->setAttribute(SGPropertyNode::WRITE, false);
530  if (!getter) property->setAttribute(SGPropertyNode::READ, false);
531  tied_properties.push_back(property);
532  if (FGJSBBase::debug_lvl & 0x20) std::cout << name << std::endl;
533  }
534  }

◆ Tie() [2/5]

void Tie ( const std::string &  name,
T *  obj,
int  index,
V(T::*)(int) const  getter,
void(T::*)(int, V)  setter = nullptr 
)
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.

Definition at line 590 of file FGPropertyManager.h.

592  {
593  SGPropertyNode* property = root->getNode(name.c_str(), true);
594  if (!property) {
595  std::cerr << "Could not get or create property " << name << std::endl;
596  return;
597  }
598 
599  if (!property->tie(SGRawValueMethodsIndexed<T,V>(*obj, index, getter, setter),
600  false))
601  std::cerr << "Failed to tie property " << name
602  << " to indexed object methods" << std::endl;
603  else {
604  if (!setter) property->setAttribute(SGPropertyNode::WRITE, false);
605  if (!getter) 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() [3/5]

void Tie ( const std::string &  name,
T *  obj,
V(T::*)() const  getter,
void(T::*)(V)  setter = nullptr 
)
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.

Definition at line 553 of file FGPropertyManager.h.

555  {
556  SGPropertyNode* property = root->getNode(name.c_str(), true);
557  if (!property) {
558  std::cerr << "Could not get or create property " << name << std::endl;
559  return;
560  }
561 
562  if (!property->tie(SGRawValueMethods<T,V>(*obj, getter, setter), false))
563  std::cerr << "Failed to tie property " << name << " to object methods"
564  << std::endl;
565  else {
566  if (!setter) property->setAttribute(SGPropertyNode::WRITE, false);
567  if (!getter) 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() [4/5]

void Tie ( const std::string &  name,
T *  pointer 
)
inline

Tie a property to an external 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.

Definition at line 449 of file FGPropertyManager.h.

450  {
451  SGPropertyNode* property = root->getNode(name.c_str(), true);
452  if (!property) {
453  cerr << "Could not get or create property " << name << endl;
454  return;
455  }
456 
457  if (!property->tie(SGRawValuePointer<T>(pointer), false))
458  cerr << "Failed to tie property " << name << " to a pointer" << endl;
459  else {
460  tied_properties.push_back(property);
461  if (FGJSBBase::debug_lvl & 0x20) cout << name << endl;
462  }
463  }
+ Here is the caller graph for this function:

◆ Tie() [5/5]

void Tie ( const std::string &  name,
T(*)()  getter,
void(*)(T)  setter = nullptr 
)
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.

Definition at line 480 of file FGPropertyManager.h.

481  {
482  SGPropertyNode* property = root->getNode(name.c_str(), true);
483  if (!property) {
484  std::cerr << "Could not get or create property " << name << std::endl;
485  return;
486  }
487 
488  if (!property->tie(SGRawValueFunctions<T>(getter, setter), false))
489  std::cerr << "Failed to tie property " << name << " to functions"
490  << std::endl;
491  else {
492  if (!setter) property->setAttribute(SGPropertyNode::WRITE, false);
493  if (!getter) property->setAttribute(SGPropertyNode::READ, false);
494  tied_properties.push_back(property);
495  if (FGJSBBase::debug_lvl & 0x20) std::cout << name << std::endl;
496  }
497  }

◆ 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 54 of file FGPropertyManager.cpp.

55 {
56  for(auto& prop: tied_properties)
57  prop->untie();
58 
59  tied_properties.clear();
60 }
+ Here is the caller graph for this function:

◆ Untie() [1/2]

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.

Parameters
nameThe property name to untie (full path).

Definition at line 298 of file FGPropertyManager.cpp.

299 {
300  SGPropertyNode* property = root->getNode(name.c_str());
301  if (!property) {
302  cerr << "Attempt to untie a non-existant property." << name << endl;
303  return;
304  }
305 
306  Untie(property);
307 }
+ Here is the caller graph for this function:

◆ Untie() [2/2]

void Untie ( SGPropertyNode *  property)

Untie a property from an external data source.

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

Parameters
propertyA pointer to the property to untie.

Definition at line 311 of file FGPropertyManager.cpp.

312 {
313  const string& name = property->getNameString();
314 
315  assert(property->isTied());
316 
317  for (auto it = tied_properties.begin(); it != tied_properties.end(); ++it) {
318  if (*it == property) {
319  property->untie();
320  tied_properties.erase(it);
321  if (FGJSBBase::debug_lvl & 0x20) cout << "Untied " << name << endl;
322  return;
323  }
324  }
325 
326  cerr << "Failed to untie property " << name << endl
327  << "JSBSim is not the owner of this property." << endl;
328 }

The documentation for this class was generated from the following files:
JSBSim::FGPropertyManager::Untie
void Untie(const std::string &name)
Untie a property from an external data source.
Definition: FGPropertyManager.cpp:298