20#if defined(HAVE_CONFIG_H)
26#include "simgear/props/propertyObject.hxx"
28#include "simgear/math/SGMath.hxx"
65 GetNode(
const std::string& path,
bool create =
false);
68 GetNode(
const std::string& relpath,
int index,
bool create =
false);
76 bool HasNode(
const std::string& path);
81 const std::string&
GetName(
void)
const {
return getNameString(); }
101 std::string
GetRelativeName(
const std::string& path =
"/fdm/jsbsim/")
const;
117 bool GetBool(
const std::string&
name,
bool defaultValue =
false)
const;
134 int GetInt(
const std::string&
name,
int defaultValue = 0)
const;
151 int GetLong(
const std::string&
name,
long defaultValue = 0L)
const;
168 float GetFloat(
const std::string&
name,
float defaultValue = 0.0)
const;
185 double GetDouble(
const std::string&
name,
double defaultValue = 0.0)
const;
202 std::string
GetString(
const std::string&
name, std::string defaultValue =
"")
const;
234 bool SetInt(
const std::string&
name,
int val);
298 bool SetString(
const std::string&
name,
const std::string& val);
369 return root->
GetNode(path, create);
373 return root->
GetNode(relpath, index, create);
377 std::string newPath = path;
378 if (newPath[0] ==
'-') newPath.erase(0, 1);
379 return root->HasNode(newPath);
414 void Untie(SGPropertyNode* property);
433 template <
typename T>
437 SGPropertyNode*
property = root->getNode(
name.c_str(),
true);
439 std::cerr <<
"Could not get or create property " <<
name << std::endl;
443 if (!property->tie(SGRawValuePointer<T>(pointer),
false))
444 std::cerr <<
"Failed to tie property " <<
name <<
" to a pointer" << std::endl;
446 tied_properties.push_back(property);
465 template <
typename T>
467 Tie(
const std::string&
name, T (*getter)(),
void (*setter)(T) =
nullptr)
469 SGPropertyNode*
property = root->getNode(
name.c_str(),
true);
471 std::cerr <<
"Could not get or create property " <<
name << std::endl;
475 if (!property->tie(SGRawValueFunctions<T>(getter, setter),
false))
476 std::cerr <<
"Failed to tie property " <<
name <<
" to functions"
479 if (!setter)
property->setAttribute(SGPropertyNode::WRITE,
false);
480 if (!getter)
property->setAttribute(SGPropertyNode::READ,
false);
481 tied_properties.push_back(property);
501 template <
typename T>
503 Tie(
const std::string&
name,
int index, T (*getter)(
int),
504 void (*setter)(
int, T) =
nullptr)
506 SGPropertyNode*
property = root->getNode(
name.c_str(),
true);
508 std::cerr <<
"Could not get or create property " <<
name << std::endl;
512 if (!property->tie(SGRawValueFunctionsIndexed<T>(index, getter, setter),
514 std::cerr <<
"Failed to tie property " <<
name <<
" to indexed functions"
517 if (!setter)
property->setAttribute(SGPropertyNode::WRITE,
false);
518 if (!getter)
property->setAttribute(SGPropertyNode::READ,
false);
519 tied_properties.push_back(property);
540 template <
class T,
class V>
542 Tie(
const std::string&
name, T* obj, V (T::*getter)()
const,
543 void (T::*setter)(V) =
nullptr)
545 SGPropertyNode*
property = root->getNode(
name.c_str(),
true);
547 std::cerr <<
"Could not get or create property " <<
name << std::endl;
551 if (!property->tie(SGRawValueMethods<T, V>(*obj, getter, setter),
false))
552 std::cerr <<
"Failed to tie property " <<
name <<
" to object methods"
555 if (!setter)
property->setAttribute(SGPropertyNode::WRITE,
false);
556 if (!getter)
property->setAttribute(SGPropertyNode::READ,
false);
557 tied_properties.push_back(property);
578 template <
class T,
class V>
580 Tie(
const std::string&
name, T* obj,
int index, V (T::*getter)(
int)
const,
581 void (T::*setter)(
int, V) =
nullptr)
583 SGPropertyNode*
property = root->getNode(
name.c_str(),
true);
585 std::cerr <<
"Could not get or create property " <<
name << std::endl;
589 if (!property->tie(SGRawValueMethodsIndexed<T, V>(*obj, index, getter, setter),
591 std::cerr <<
"Failed to tie property " <<
name
592 <<
" to indexed object methods" << std::endl;
594 if (!setter)
property->setAttribute(SGPropertyNode::WRITE,
false);
595 if (!getter)
property->setAttribute(SGPropertyNode::READ,
false);
596 tied_properties.push_back(property);
602 simgear::PropertyObject<T>
605 return simgear::PropertyObject<T>(root->GetNode(path,
true));
609 std::vector<SGPropertyNode_ptr> tied_properties;
void Untie(const std::string &name)
Untie a property from an external data source.
FGPropertyNode * GetNode(void) const
std::string mkPropertyName(std::string name, bool lowercase)
Property-ify a name replaces spaces with '-' and, optionally, makes name all lower case.
void Tie(const std::string &name, T(*getter)(), void(*setter)(T)=nullptr)
Tie a property to a pair of simple functions.
FGPropertyManager(FGPropertyNode *_root)
Constructor.
virtual ~FGPropertyManager(void)
Destructor.
void Tie(const std::string &name, T *pointer)
Tie a property to an external variable.
FGPropertyNode * GetNode(const std::string &path, bool create=false)
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.
FGPropertyNode * GetNode(const std::string &relpath, int index, bool create=false)
bool HasNode(const std::string &path) const
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.
simgear::PropertyObject< T > CreatePropertyObject(const std::string &path)
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 Unbind(void)
Unbind all properties bound by this manager to an external data source.
FGPropertyManager(void)
Default constructor.
Class wrapper for property handling.
bool SetLong(const std::string &name, long val)
Set a long value for a property.
std::string GetFullyQualifiedName(void) const
Get the fully qualified name of a node This function is very slow, so is probably useful for debuggin...
void SetWritable(const std::string &name, bool state=true)
Set the state of the write attribute for a property.
bool SetBool(const std::string &name, bool val)
Set a bool value for a property.
int GetLong(const std::string &name, long defaultValue=0L) const
Get a long value for a property.
virtual ~FGPropertyNode(void)
Destructor.
bool HasNode(const std::string &path)
Test whether a given node exists.
bool SetFloat(const std::string &name, float val)
Set a float value for a property.
bool SetInt(const std::string &name, int val)
Set an int value for a property.
FGPropertyNode * GetNode(const std::string &relpath, int index, bool create=false)
float GetFloat(const std::string &name, float defaultValue=0.0) const
Get a float value for a property.
void SetArchivable(const std::string &name, bool state=true)
Set the state of the archive attribute for a property.
int GetInt(const std::string &name, int defaultValue=0) const
Get an int value for a property.
std::string GetString(const std::string &name, std::string defaultValue="") const
Get a string value for a property.
bool GetBool(const std::string &name, bool defaultValue=false) const
Get a bool value for a property.
FGPropertyNode * GetNode(const std::string &path, bool create=false)
Get a property node.
std::string GetPrintableName(void) const
Get the name of a node without underscores, etc.
const std::string & GetName(void) const
Get the name of a node.
bool SetString(const std::string &name, const std::string &val)
Set a string value for a property.
std::string GetRelativeName(const std::string &path="/fdm/jsbsim/") const
Get the qualified name of a node relative to given base path, otherwise the fully qualified name.
void SetReadable(const std::string &name, bool state=true)
Set the state of the read attribute for a property.
bool SetDouble(const std::string &name, double val)
Set a double value for a property.
double GetDouble(const std::string &name, double defaultValue=0.0) const
Get a double value for a property.
SGSharedPtr< const FGPropertyNode > FGConstPropertyNode_ptr
SGSharedPtr< FGPropertyNode > FGPropertyNode_ptr