 |
JSBSim Flight Dynamics Model
1.1.11 (13 Feb 2022)
An Open Source Flight Dynamics and Control Software Library in C++
|
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"
84 GetNode (
const std::string &path,
bool create =
false);
87 GetNode (
const std::string &relpath,
int index,
bool create =
false);
95 bool HasNode (
const std::string &path);
100 const std::string&
GetName(
void )
const {
return getNameString(); }
120 std::string
GetRelativeName(
const std::string &path =
"/fdm/jsbsim/" )
const;
136 bool GetBool (
const std::string &name,
bool defaultValue =
false)
const;
153 int GetInt (
const std::string &name,
int defaultValue = 0)
const;
170 int GetLong (
const std::string &name,
long defaultValue = 0L)
const;
187 float GetFloat (
const std::string &name,
float defaultValue = 0.0)
const;
204 double GetDouble (
const std::string &name,
double defaultValue = 0.0)
const;
221 std::string
GetString (
const std::string &name, std::string defaultValue =
"")
const;
237 bool SetBool (
const std::string &name,
bool val);
253 bool SetInt (
const std::string &name,
int val);
269 bool SetLong (
const std::string &name,
long val);
285 bool SetFloat (
const std::string &name,
float val);
301 bool SetDouble (
const std::string &name,
double val);
317 bool SetString (
const std::string &name,
const std::string &val);
337 void SetArchivable (
const std::string &name,
bool state =
true);
352 void SetReadable (
const std::string &name,
bool state =
true);
367 void SetWritable (
const std::string &name,
bool state =
true);
370 typedef SGSharedPtr<FGPropertyNode> FGPropertyNode_ptr;
371 typedef SGSharedPtr<const FGPropertyNode> FGConstPropertyNode_ptr;
386 FGPropertyNode* GetNode(
const std::string &path,
bool create =
false)
387 {
return root->GetNode(path, create); }
388 FGPropertyNode* GetNode(
const std::string &relpath,
int index,
bool create =
false)
389 {
return root->GetNode(relpath, index, create); }
390 bool HasNode(
const std::string& path)
const
392 std::string newPath = path;
393 if (newPath[0] ==
'-') newPath.erase(0,1);
394 return root->HasNode(newPath);
419 void Untie (
const std::string &name);
429 void Untie (SGPropertyNode* property);
448 template <
typename T>
void
449 Tie (
const std::string &name, T *pointer)
451 SGPropertyNode*
property = root->getNode(name.c_str(),
true);
453 cerr <<
"Could not get or create property " << name << endl;
457 if (!property->tie(SGRawValuePointer<T>(pointer),
false))
458 cerr <<
"Failed to tie property " << name <<
" to a pointer" << endl;
460 tied_properties.push_back(property);
461 if (FGJSBBase::debug_lvl & 0x20) cout << name << endl;
479 template <
typename T>
void
480 Tie (
const std::string &name, T (*getter)(),
void (*setter)(T) =
nullptr)
482 SGPropertyNode*
property = root->getNode(name.c_str(),
true);
484 std::cerr <<
"Could not get or create property " << name << std::endl;
488 if (!property->tie(SGRawValueFunctions<T>(getter, setter),
false))
489 std::cerr <<
"Failed to tie property " << name <<
" to functions"
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;
514 template <
typename T>
void
515 Tie (
const std::string &name,
int index, T (*getter)(
int),
516 void (*setter)(
int, T) =
nullptr)
518 SGPropertyNode*
property = root->getNode(name.c_str(),
true);
520 std::cerr <<
"Could not get or create property " << name << std::endl;
524 if (!property->tie(SGRawValueFunctionsIndexed<T>(index, getter, setter),
526 std::cerr <<
"Failed to tie property " << name <<
" to indexed functions"
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;
552 template <
class T,
class V>
void
553 Tie (
const std::string &name, T * obj, V (T::*getter)()
const,
554 void (T::*setter)(V) =
nullptr)
556 SGPropertyNode*
property = root->getNode(name.c_str(),
true);
558 std::cerr <<
"Could not get or create property " << name << std::endl;
562 if (!property->tie(SGRawValueMethods<T,V>(*obj, getter, setter),
false))
563 std::cerr <<
"Failed to tie property " << name <<
" to object methods"
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;
589 template <
class T,
class V>
void
590 Tie (
const std::string &name, T * obj,
int index, V (T::*getter)(
int)
const,
591 void (T::*setter)(
int, V) =
nullptr)
593 SGPropertyNode*
property = root->getNode(name.c_str(),
true);
595 std::cerr <<
"Could not get or create property " << name << std::endl;
599 if (!property->tie(SGRawValueMethodsIndexed<T,V>(*obj, index, getter, setter),
601 std::cerr <<
"Failed to tie property " << name
602 <<
" to indexed object methods" << std::endl;
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;
611 template <
class T> simgear::PropertyObject<T>
612 CreatePropertyObject(
const std::string &path)
613 {
return simgear::PropertyObject<T>(root->GetNode(path,
true)); }
616 std::vector<SGPropertyNode_ptr> tied_properties;
617 FGPropertyNode_ptr root;
620 #endif // FGPROPERTYMANAGER_H
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.
FGPropertyManager(void)
Default constructor.
const std::string & GetName(void) const
Get the name of a node.
bool SetFloat(const std::string &name, float val)
Set a float value for a property.
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.
bool GetBool(const std::string &name, bool defaultValue=false) const
Get a bool value for a property.
float GetFloat(const std::string &name, float defaultValue=0.0) const
Get 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)=nullptr)
Tie a property to a pair of indexed object methods.
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.
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.
bool SetInt(const std::string &name, int val)
Set an int value for a property.
Class wrapper for property handling.
void Tie(const std::string &name, T(*getter)(), void(*setter)(T)=nullptr)
Tie a property to a pair of simple functions.
bool SetBool(const std::string &name, bool val)
Set a bool value for a property.
double GetDouble(const std::string &name, double defaultValue=0.0) const
Get a double value for a property.
int GetInt(const std::string &name, int defaultValue=0) const
Get an int value for a property.
FGPropertyManager(FGPropertyNode *_root)
Constructor.
std::string GetString(const std::string &name, std::string defaultValue="") const
Get a string value for a property.
virtual ~FGPropertyNode(void)
Destructor.
void Unbind(void)
Unbind all properties bound by this manager to an external data source.
bool SetString(const std::string &name, const std::string &val)
Set a string value for a property.
void Untie(const std::string &name)
Untie a property from an external data source.
void SetArchivable(const std::string &name, bool state=true)
Set the state of the archive attribute for a property.
std::string mkPropertyName(std::string name, bool lowercase)
Property-ify a name replaces spaces with '-' and, optionally, makes name all lower case.
virtual ~FGPropertyManager(void)
Destructor.
int GetLong(const std::string &name, long defaultValue=0L) const
Get a long value for a property.
bool SetDouble(const std::string &name, double val)
Set a double value for a property.
void SetReadable(const std::string &name, bool state=true)
Set the state of the read attribute for a property.
bool HasNode(const std::string &path)
Test whether a given node exists.
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 Tie(const std::string &name, T *pointer)
Tie a property to an external variable.
FGPropertyNode * GetNode(const std::string &path, bool create=false)
Get a property node.