31 #ifndef FGPROPERTYMANAGER_H 32 #define FGPROPERTYMANAGER_H 40 #if defined( HAVE_CONFIG_H ) 45 #include "simgear/props/propertyObject.hxx" 47 # include "simgear/math/SGMath.hxx" 50 #include "FGJSBBase.h" 56 #define ID_PROPERTYMANAGER "$Id: FGPropertyManager.h,v 1.30 2016/05/05 15:32:42 bcoconni Exp $" 90 GetNode (
const std::string &path,
bool create =
false);
93 GetNode (
const std::string &relpath,
int index,
bool create =
false);
101 bool HasNode (
const std::string &path);
106 std::string
GetName(
void )
const;
126 std::string
GetRelativeName(
const std::string &path =
"/fdm/jsbsim/" )
const;
142 bool GetBool (
const std::string &name,
bool defaultValue =
false)
const;
159 int GetInt (
const std::string &name,
int defaultValue = 0)
const;
176 int GetLong (
const std::string &name,
long defaultValue = 0L)
const;
193 float GetFloat (
const std::string &name,
float defaultValue = 0.0)
const;
210 double GetDouble (
const std::string &name,
double defaultValue = 0.0)
const;
227 std::string
GetString (
const std::string &name, std::string defaultValue =
"")
const;
243 bool SetBool (
const std::string &name,
bool val);
259 bool SetInt (
const std::string &name,
int val);
275 bool SetLong (
const std::string &name,
long val);
291 bool SetFloat (
const std::string &name,
float val);
307 bool SetDouble (
const std::string &name,
double val);
323 bool SetString (
const std::string &name,
const std::string &val);
343 void SetArchivable (
const std::string &name,
bool state =
true);
358 void SetReadable (
const std::string &name,
bool state =
true);
373 void SetWritable (
const std::string &name,
bool state =
true);
376 typedef SGSharedPtr<FGPropertyNode> FGPropertyNode_ptr;
377 typedef SGSharedPtr<const FGPropertyNode> FGConstPropertyNode_ptr;
393 {
return root->
GetNode(path, create); }
395 {
return root->
GetNode(relpath, index, create); }
396 bool HasNode(
const std::string& path)
const 398 std::string newPath = path;
399 if (newPath[0] ==
'-') newPath.erase(0,1);
400 return root->HasNode(newPath);
410 std::string mkPropertyName(std::string name,
bool lowercase);
423 void Untie (
const std::string &name);
448 Tie (
const std::string &name,
bool *pointer,
bool useDefault =
true);
464 Tie (
const std::string &name,
int *pointer,
bool useDefault =
true);
480 Tie (
const std::string &name,
long *pointer,
bool useDefault =
true);
496 Tie (
const std::string &name,
float *pointer,
bool useDefault =
true);
511 Tie (
const std::string &name,
double *pointer,
bool useDefault =
true);
554 template <
class V>
inline void 555 Tie (
const std::string &name, V (*getter)(),
void (*setter)(V) = 0,
bool useDefault =
true)
557 SGPropertyNode*
property = root->getNode(name.c_str(),
true);
559 std::cerr <<
"Could not get or create property " << name << std::endl;
563 if (!property->tie(SGRawValueFunctions<V>(getter, setter), useDefault))
564 std::cerr <<
"Failed to tie property " << name <<
" to functions" << std::endl;
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;
592 template <
class V>
inline void Tie (
const std::string &name,
int index, V (*getter)(
int),
593 void (*setter)(
int, V) = 0,
bool useDefault =
true)
595 SGPropertyNode*
property = root->getNode(name.c_str(),
true);
597 std::cerr <<
"Could not get or create property " << name << std::endl;
601 if (!property->tie(SGRawValueFunctionsIndexed<V>(index, getter, setter), useDefault))
602 std::cerr <<
"Failed to tie property " << name <<
" to indexed functions" << std::endl;
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;
631 template <
class T,
class V>
inline void 632 Tie (
const std::string &name, T * obj, V (T::*getter)()
const,
633 void (T::*setter)(V) = 0,
bool useDefault =
true)
635 SGPropertyNode*
property = root->getNode(name.c_str(),
true);
637 std::cerr <<
"Could not get or create property " << name << std::endl;
641 if (!property->tie(SGRawValueMethods<T,V>(*obj, getter, setter), useDefault))
642 std::cerr <<
"Failed to tie property " << name <<
" to object methods" << std::endl;
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;
670 template <
class T,
class V>
inline void 671 Tie (
const std::string &name, T * obj,
int index, V (T::*getter)(
int)
const,
672 void (T::*setter)(
int, V) = 0,
bool useDefault =
true)
674 SGPropertyNode*
property = root->getNode(name.c_str(),
true);
676 std::cerr <<
"Could not get or create property " << name << std::endl;
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;
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;
690 template <
class T> simgear::PropertyObject<T>
691 CreatePropertyObject(
const std::string &path)
692 {
return simgear::PropertyObject<T>(root->GetNode(path,
true)); }
695 std::vector<SGPropertyNode_ptr> tied_properties;
696 FGPropertyNode_ptr root;
699 #endif // FGPROPERTYMANAGER_H 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.
FGPropertyManager(FGPropertyNode *_root)
Constructor.
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 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.
bool HasNode(const std::string &path)
Test whether a given node exists.
bool SetString(const std::string &name, const std::string &val)
Set a string value for a property.
void SetArchivable(const std::string &name, bool state=true)
Set the state of the archive attribute for a property.
virtual ~FGPropertyManager(void)
Destructor.
std::string GetName(void) const
Get the name of a node.
FGPropertyNode * GetNode(const std::string &path, bool create=false)
Get a property node.
Class wrapper for property handling.
bool SetDouble(const std::string &name, double val)
Set a double value for a property.
float GetFloat(const std::string &name, float defaultValue=0.0) const
Get a float value for a property.
int GetLong(const std::string &name, long defaultValue=0L) const
Get 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...
bool SetLong(const std::string &name, long val)
Set a long value for a property.
void SetReadable(const std::string &name, bool state=true)
Set the state of the read attribute for a property.
virtual ~FGPropertyNode(void)
Destructor.
void Tie(const std::string &name, V(*getter)(), void(*setter)(V)=0, bool useDefault=true)
Tie a property to a pair of simple functions.
void SetWritable(const std::string &name, bool state=true)
Set the state of the write attribute for a property.
std::string GetPrintableName(void) const
Get the name of a node without underscores, etc.
bool GetBool(const std::string &name, bool defaultValue=false) const
Get a bool value for a property.
bool SetFloat(const std::string &name, float val)
Set a float value for a property.
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.
double GetDouble(const std::string &name, double defaultValue=0.0) const
Get a double value for a property.
FGPropertyManager(void)
Default constructor.
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.
bool SetInt(const std::string &name, int val)
Set an int value for a property.
bool SetBool(const std::string &name, bool val)
Set a bool value for a property.