Howto:Work with the Property Tree API: Difference between revisions
Jump to navigation
Jump to search
m (→Strings) |
m (→Persistance) |
||
Line 47: | Line 47: | ||
= Attributes = | = Attributes = | ||
== Persistance == | == Persistance == | ||
void fgSetArchivable (const char * name, bool state); | void fgSetArchivable (const char * name, bool state); | ||
== Access == | == Access == |
Revision as of 00:54, 17 May 2009
This article is a stub. You can help the wiki by expanding it. |
Work in progress This article or section will be worked on in the upcoming hours or days. See history for the latest developments. |
Most FlightGear systems communicate internally using the so called Property Tree (see Property Tree Intro for an introduction).
This article is meant to introduce you to the C++ API that is used by FlightGear to work with the Property Tree.
Most of the high level API can be found in the $FG_SRC/Main folder, specifically the files fg_props.cxx and the corresponding fg_props.hxx header are relevant (this is the one, that you'll want to include when working with the property tree).
The property tree implementation itself is to be found in the SimGear sources ([1] see specifically SGPropertyNode).
Checking for Property Existence
bool fgHasNode (const char * path);
Getters
SGPropertyNode * fgGetNode (const char * path, bool create); SGPropertyNode * fgGetNode (const char * path, int index, bool create);
Boolean Values
bool fgSetBool (const char * name, bool val); bool fgGetBool (const char * name, bool defaultValue);
Integers
bool fgSetInt (const char * name, int val); int fgGetInt (const char * name, int defaultValue);
Floats
bool fgSetFloat (const char * name, float val); float fgGetFloat (const char * name, float defaultValue);
Doubles
bool fgSetDouble (const char * name, double val); double fgGetDouble (const char * name, double defaultValue);
Longs
long fgGetLong (const char * name, long defaultValue); fgSetLong (const char * name, long val);
Strings
bool fgSetString (const char * name, const char * val); const char * fgGetString (const char * name, const char * defaultValue);
Using Listeners
void fgAddChangeListener (SGPropertyChangeListener * listener, const char * path); void fgAddChangeListener (SGPropertyChangeListener * listener, const char * path, int index);
Attributes
Persistance
void fgSetArchivable (const char * name, bool state);
Access
void fgSetReadable (const char * name, bool state) { SGPropertyNode * node = globals->get_props()->getNode(name); if (node == 0) SG_LOG(SG_GENERAL, SG_DEBUG,
"Attempt to set read flag for non-existant property " << name);
else node->setAttribute(SGPropertyNode::READ, state); }
void fgSetWritable (const char * name, bool state) { SGPropertyNode * node = globals->get_props()->getNode(name); if (node == 0) SG_LOG(SG_GENERAL, SG_DEBUG,
"Attempt to set write flag for non-existant property " << name);
else node->setAttribute(SGPropertyNode::WRITE, state); }
Tied Properties
void fgUntie (const char * name) { if (!globals->get_props()->untie(name)) SG_LOG(SG_GENERAL, SG_WARN, "Failed to untie property " << name); }