JSBSim Flight Dynamics Model 1.2.3 (07 Jun 2025)
An Open Source Flight Dynamics and Control Software Library in C++
Loading...
Searching...
No Matches
FGPropertyManager Class Reference

Detailed Description

Class wrapper for property handling.

Author
David Megginson, Tony Peden

Definition at line 76 of file FGPropertyManager.h.

#include <FGPropertyManager.h>

Public Member Functions

 FGPropertyManager (SGPropertyNode *_root)
 Constructor.
 
 FGPropertyManager (void)
 Default constructor.
 
virtual ~FGPropertyManager (void)
 Destructor.
 
SGPropertyNodeGetNode (const std::string &path, bool create=false)
 
SGPropertyNodeGetNode (const std::string &relpath, int index, bool create=false)
 
SGPropertyNodeGetNode (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.
 
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.
 
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.
 
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.
 
template<typename T >
void Tie (const std::string &name, T *pointer)
 Tie a property to an external variable.
 
template<typename T >
void Tie (const std::string &name, T(*getter)(), void(*setter)(T)=nullptr)
 Tie a property to a pair of simple functions.
 
template<typename T >
void Unbind (const std::shared_ptr< T > &instance)
 Unbind all properties bound by this manager to an instance.
 
void Unbind (const void *instance)
 Unbind all properties bound by this manager to an instance.
 
void Unbind (void)
 Unbind all properties bound by this manager to an external data source.
 
void Untie (const std::string &name)
 Untie a property from an external data source.
 
void Untie (SGPropertyNode *property)
 Untie a property from an external data source.
 

Constructor & Destructor Documentation

◆ FGPropertyManager() [1/2]

FGPropertyManager ( void  )
inline

Default constructor.

Definition at line 80 of file FGPropertyManager.h.

80{ root = new SGPropertyNode; }
A node in a property tree.
Definition props.hxx:754

◆ FGPropertyManager() [2/2]

FGPropertyManager ( SGPropertyNode _root)
inlineexplicit

Constructor.

Definition at line 83 of file FGPropertyManager.h.

83: root(_root) {};

◆ ~FGPropertyManager()

virtual ~FGPropertyManager ( void  )
inlinevirtual

Destructor.

Definition at line 86 of file FGPropertyManager.h.

86{ Unbind(); }
void Unbind(void)
Unbind all properties bound by this manager to an external data source.

Member Function Documentation

◆ GetNode() [1/3]

SGPropertyNode * GetNode ( const std::string &  path,
bool  create = false 
)
inline

Definition at line 89 of file FGPropertyManager.h.

90 { return root->getNode(path, create); }

◆ GetNode() [2/3]

SGPropertyNode * GetNode ( const std::string &  relpath,
int  index,
bool  create = false 
)
inline

Definition at line 91 of file FGPropertyManager.h.

92 { return root->getNode(relpath, index, create); }

◆ GetNode() [3/3]

SGPropertyNode * GetNode ( void  ) const
inline

Definition at line 88 of file FGPropertyManager.h.

88{ return root; }

◆ HasNode()

bool HasNode ( const std::string &  path) const
inline

Definition at line 93 of file FGPropertyManager.h.

94 {
95 std::string newPath = path;
96 if (newPath[0] == '-') newPath.erase(0,1);
97 SGPropertyNode* prop = root->getNode(newPath);
98 return prop != nullptr;
99 }

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

79 {
80
81 /* do this two pass to avoid problems with characters getting skipped
82 because the index changed */
83 unsigned i;
84 for(i=0;i<name.length();i++) {
85 if( lowercase && isupper(name[i]) )
86 name[i]=tolower(name[i]);
87 else if( isspace(name[i]) )
88 name[i]='-';
89 }
90
91 return name;
92}

◆ Tie() [1/5]

template<typename T >
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 235 of file FGPropertyManager.h.

237 {
238 SGPropertyNode* property = root->getNode(name.c_str(), true);
239 if (!property) {
240 std::cerr << "Could not get or create property " << name << std::endl;
241 return;
242 }
243
244 if (!property->tie(SGRawValueFunctionsIndexed<T>(index, getter, setter),
245 false))
246 std::cerr << "Failed to tie property " << name << " to indexed functions"
247 << std::endl;
248 else {
249 tied_properties.push_back(PropertyState(property, nullptr));
250 if (!setter) property->setAttribute(SGPropertyNode::WRITE, false);
251 if (!getter) property->setAttribute(SGPropertyNode::READ, false);
252 if (FGJSBBase::debug_lvl & 0x20) std::cout << name << std::endl;
253 }
254 }
An indexed value bound to static functions.
Definition props.hxx:550
+ Here is the call graph for this function:

◆ Tie() [2/5]

template<class T , class V >
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 310 of file FGPropertyManager.h.

312 {
313 SGPropertyNode* property = root->getNode(name.c_str(), true);
314 if (!property) {
315 std::cerr << "Could not get or create property " << name << std::endl;
316 return;
317 }
318
319 if (!property->tie(SGRawValueMethodsIndexed<T,V>(*obj, index, getter, setter),
320 false))
321 std::cerr << "Failed to tie property " << name
322 << " to indexed object methods" << std::endl;
323 else {
324 tied_properties.push_back(PropertyState(property, obj));
325 if (!setter) property->setAttribute(SGPropertyNode::WRITE, false);
326 if (!getter) property->setAttribute(SGPropertyNode::READ, false);
327 if (FGJSBBase::debug_lvl & 0x20) std::cout << name << std::endl;
328 }
329 }
An indexed value managed through an object and access methods.
Definition props.hxx:616
+ Here is the call graph for this function:

◆ Tie() [3/5]

template<class T , class V >
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 273 of file FGPropertyManager.h.

275 {
276 SGPropertyNode* property = root->getNode(name.c_str(), true);
277 if (!property) {
278 std::cerr << "Could not get or create property " << name << std::endl;
279 return;
280 }
281
282 if (!property->tie(SGRawValueMethods<T,V>(*obj, getter, setter), false))
283 std::cerr << "Failed to tie property " << name << " to object methods"
284 << std::endl;
285 else {
286 tied_properties.push_back(PropertyState(property, obj));
287 if (!setter) property->setAttribute(SGPropertyNode::WRITE, false);
288 if (!getter) property->setAttribute(SGPropertyNode::READ, false);
289 if (FGJSBBase::debug_lvl & 0x20) std::cout << name << std::endl;
290 }
291 }
A value managed through an object and access methods.
Definition props.hxx:583
+ Here is the call graph for this function:

◆ Tie() [4/5]

template<typename T >
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 169 of file FGPropertyManager.h.

170 {
171 SGPropertyNode* property = root->getNode(name.c_str(), true);
172 if (!property) {
173 std::cerr << "Could not get or create property " << name << std::endl;
174 return;
175 }
176
177 if (!property->tie(SGRawValuePointer<T>(pointer), false))
178 std::cerr << "Failed to tie property " << name << " to a pointer" << std::endl;
179 else {
180 tied_properties.push_back(PropertyState(property, nullptr));
181 if (FGJSBBase::debug_lvl & 0x20) std::cout << name << std::endl;
182 }
183 }
A raw value bound to a pointer.
Definition props.hxx:413
+ Here is the call graph for this function:

◆ Tie() [5/5]

template<typename T >
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 200 of file FGPropertyManager.h.

201 {
202 SGPropertyNode* property = root->getNode(name.c_str(), true);
203 if (!property) {
204 std::cerr << "Could not get or create property " << name << std::endl;
205 return;
206 }
207
208 if (!property->tie(SGRawValueFunctions<T>(getter, setter), false))
209 std::cerr << "Failed to tie property " << name << " to functions"
210 << std::endl;
211 else {
212 tied_properties.push_back(PropertyState(property, nullptr));
213 if (!setter) property->setAttribute(SGPropertyNode::WRITE, false);
214 if (!getter) property->setAttribute(SGPropertyNode::READ, false);
215 if (FGJSBBase::debug_lvl & 0x20) std::cout << name << std::endl;
216 }
217 }
A value managed through static functions.
Definition props.hxx:470
+ Here is the call graph for this function:

◆ Unbind() [1/3]

template<typename T >
void Unbind ( const std::shared_ptr< T > &  instance)
inline

Unbind all properties bound by this manager to an instance.

Classes should use this function to release control of any properties they have bound using this property manager. Helper function for shared_ptr

See also
Unbind(const void*)

Definition at line 155 of file FGPropertyManager.h.

155 {
156 Unbind(instance.get());
157 }

◆ Unbind() [2/3]

void Unbind ( const void *  instance)

Unbind all properties bound by this manager to an instance.

Classes should use this function to release control of any properties they have bound using this property manager.

Parameters
instanceThe instance which properties shall be unbound.

Definition at line 64 of file FGPropertyManager.cpp.

65{
66 auto it = tied_properties.begin();
67
68 while(it != tied_properties.end()) {
69 auto property = it++;
70 if (property->BindingInstance == instance) {
71 property->untie();
72 tied_properties.erase(property);
73 }
74 }
75}

◆ Unbind() [3/3]

void Unbind ( void  )

Unbind all properties bound by this manager to an external data source.

Definition at line 54 of file FGPropertyManager.cpp.

55{
56 for(auto& property: tied_properties)
57 property.untie();
58
59 tied_properties.clear();
60}

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

146{
147 SGPropertyNode* property = root->getNode(name.c_str());
148 if (!property) {
149 cerr << "Attempt to untie a non-existant property." << name << endl;
150 return;
151 }
152
153 Untie(property);
154}
void Untie(const std::string &name)
Untie a property from an external data source.
+ Here is the call graph for this function:
+ 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 158 of file FGPropertyManager.cpp.

159{
160 const string& name = property->getNameString();
161
162 assert(property->isTied());
163
164 for (auto it = tied_properties.begin(); it != tied_properties.end(); ++it) {
165 if (it->node.ptr() == property) {
166 it->untie();
167 tied_properties.erase(it);
168 if (FGJSBBase::debug_lvl & 0x20) cout << "Untied " << name << endl;
169 return;
170 }
171 }
172
173 cerr << "Failed to untie property " << name << endl
174 << "JSBSim is not the owner of this property." << endl;
175}
bool isTied() const
Test whether this node is bound to an external data source.
Definition props.hxx:1356
+ Here is the call graph for this function:

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