31#ifndef FGPROPERTYMANAGER_H
32#define FGPROPERTYMANAGER_H
40#if defined( HAVE_CONFIG_H )
49# include "simgear/math/SGMath.hxx"
60JSBSIM_API std::string GetPrintableName(
const SGPropertyNode* node);
61JSBSIM_API std::string GetFullyQualifiedName(
const SGPropertyNode* node);
62JSBSIM_API std::string GetRelativeName(
const SGPropertyNode* node,
const std::string &path);
89 SGPropertyNode* GetNode(
const std::string &path,
bool create =
false)
90 {
return root->
getNode(path, create); }
91 SGPropertyNode* GetNode(
const std::string &relpath,
int index,
bool create =
false)
92 {
return root->
getNode(relpath, index, create); }
93 bool HasNode(
const std::string& path)
const
95 std::string newPath = path;
96 if (newPath[0] ==
'-') newPath.erase(0,1);
98 return prop !=
nullptr;
108 std::string mkPropertyName(std::string name,
bool lowercase);
123 void Untie (
const std::string &name);
145 void Unbind(
const void* instance);
155 template <
typename T>
void Unbind(
const std::shared_ptr<T>& instance) {
156 Unbind(instance.get());
168 template <
typename T>
void
169 Tie (
const std::string &name, T *pointer)
173 std::cerr <<
"Could not get or create property " << name << std::endl;
178 std::cerr <<
"Failed to tie property " << name <<
" to a pointer" << std::endl;
180 tied_properties.push_back(PropertyState(property,
nullptr));
181 if (FGJSBBase::debug_lvl & 0x20) std::cout << name << std::endl;
199 template <
typename T>
void
200 Tie (
const std::string &name, T (*getter)(),
void (*setter)(T) =
nullptr)
204 std::cerr <<
"Could not get or create property " << name << std::endl;
209 std::cerr <<
"Failed to tie property " << name <<
" to functions"
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;
234 template <
typename T>
void
235 Tie (
const std::string &name,
int index, T (*getter)(
int),
236 void (*setter)(
int, T) =
nullptr)
240 std::cerr <<
"Could not get or create property " << name << std::endl;
246 std::cerr <<
"Failed to tie property " << name <<
" to indexed functions"
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;
272 template <
class T,
class V>
void
273 Tie (
const std::string &name, T * obj, V (T::*getter)() const,
274 void (T::*setter)(V) = nullptr)
278 std::cerr <<
"Could not get or create property " << name << std::endl;
283 std::cerr <<
"Failed to tie property " << name <<
" to object methods"
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;
309 template <
class T,
class V>
void
310 Tie (
const std::string &name, T * obj,
int index, V (T::*getter)(int) const,
311 void (T::*setter)(int, V) = nullptr)
315 std::cerr <<
"Could not get or create property " << name << std::endl;
321 std::cerr <<
"Failed to tie property " << name
322 <<
" to indexed object methods" << std::endl;
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;
332 struct PropertyState {
333 SGPropertyNode_ptr node;
334 const void* BindingInstance =
nullptr;
335 bool WriteAttribute =
true;
336 bool ReadAttribute =
true;
338 : node(property), BindingInstance(instance) {
339 WriteAttribute = node->getAttribute(SGPropertyNode::WRITE);
340 ReadAttribute = node->getAttribute(SGPropertyNode::READ);
343 node->setAttribute(SGPropertyNode::WRITE, WriteAttribute);
344 node->setAttribute(SGPropertyNode::READ, ReadAttribute);
348 std::list<PropertyState> tied_properties;
349 SGPropertyNode_ptr root;
Class wrapper for property handling.
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.
virtual ~FGPropertyManager(void)
Destructor.
void Tie(const std::string &name, T(*getter)(), void(*setter)(T)=nullptr)
Tie a property to a pair of simple functions.
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.
void Tie(const std::string &name, T *pointer)
Tie a property to an external variable.
void Unbind(const std::shared_ptr< T > &instance)
Unbind all properties bound by this manager to an instance.
FGPropertyManager(SGPropertyNode *_root)
Constructor.
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.
FGPropertyManager(void)
Default constructor.
A node in a property tree.
void setAttribute(Attribute attr, bool state)
Set a single mode attribute for the property node.
SGPropertyNode * getNode(const char *relative_path, bool create=false)
Get a pointer to another node by relative path.
An indexed value bound to static functions.
A value managed through static functions.
An indexed value managed through an object and access methods.
A value managed through an object and access methods.
A raw value bound to a pointer.
Interface definition for a property list.