Howto:Work with the Property Tree API: Difference between revisions

Jump to navigation Jump to search
m
no edit summary
mNo edit summary
mNo edit summary
Line 6: Line 6:
This article is meant to introduce you to the C++ API that is used by FlightGear to work with the Property Tree.
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. The property tree implementation itself is to be found in the SimGear sources ([http://simgear.org/doxygen/props_8cxx-source.html] see specifically [http://simgear.org/doxygen/classSGPropertyNode.html SGPropertyNode]).
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 ([http://simgear.org/doxygen/props_8cxx-source.html] see specifically [http://simgear.org/doxygen/classSGPropertyNode.html 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);
}




[[Category:Core Documentation]]
[[Category:Core Documentation]]
2,561

edits

Navigation menu