using std::string;
-FGPropertyList current_properties;
+SGPropertyList current_properties;
static string empty_string;
\f
////////////////////////////////////////////////////////////////////////
-// Implementation of FGValue.
+// Implementation of SGValue.
////////////////////////////////////////////////////////////////////////
/**
* Construct a new value.
*/
-FGValue::FGValue ()
+SGValue::SGValue ()
: _type(UNKNOWN), _tied(false)
{
}
/**
* Destroy a value.
*/
-FGValue::~FGValue ()
+SGValue::~SGValue ()
{
}
* Return a raw boolean value (no type coercion).
*/
bool
-FGValue::getRawBool () const
+SGValue::getRawBool () const
{
if (_tied) {
if (_value.bool_func.getter != 0)
* Return a raw integer value (no type coercion).
*/
int
-FGValue::getRawInt () const
+SGValue::getRawInt () const
{
if (_tied) {
if (_value.int_func.getter != 0)
* Return a raw floating-point value (no type coercion).
*/
float
-FGValue::getRawFloat () const
+SGValue::getRawFloat () const
{
if (_tied) {
if (_value.float_func.getter != 0)
* Return a raw double-precision floating-point value (no type coercion).
*/
double
-FGValue::getRawDouble () const
+SGValue::getRawDouble () const
{
if (_tied) {
if (_value.double_func.getter != 0)
* Return a raw string value (no type coercion).
*/
const string &
-FGValue::getRawString () const
+SGValue::getRawString () const
{
if (_tied && _value.string_func.getter != 0)
return (*(_value.string_func.getter))();
* Return false if the value could not be set, true otherwise.
*/
bool
-FGValue::setRawBool (bool value)
+SGValue::setRawBool (bool value)
{
if (_tied) {
if (_value.bool_func.setter != 0) {
* Return false if the value could not be set, true otherwise.
*/
bool
-FGValue::setRawInt (int value)
+SGValue::setRawInt (int value)
{
if (_tied) {
if (_value.int_func.setter != 0) {
* Return false if the value could not be set, true otherwise.
*/
bool
-FGValue::setRawFloat (float value)
+SGValue::setRawFloat (float value)
{
if (_tied) {
if (_value.float_func.setter != 0) {
* Return false if the value could not be set, true otherwise.
*/
bool
-FGValue::setRawDouble (double value)
+SGValue::setRawDouble (double value)
{
if (_tied) {
if (_value.double_func.setter != 0) {
* Return false if the value could not be set, true otherwise.
*/
bool
-FGValue::setRawString (const string &value)
+SGValue::setRawString (const string &value)
{
if (_tied) {
if (_value.string_func.setter != 0) {
* If the native type is not boolean, attempt to coerce it.
*/
bool
-FGValue::getBoolValue () const
+SGValue::getBoolValue () const
{
switch (_type) {
case BOOL:
* If the native type is not integer, attempt to coerce it.
*/
int
-FGValue::getIntValue () const
+SGValue::getIntValue () const
{
switch (_type) {
case BOOL:
* If the native type is not float, attempt to coerce it.
*/
float
-FGValue::getFloatValue () const
+SGValue::getFloatValue () const
{
switch (_type) {
case UNKNOWN:
* If the native type is not double, attempt to coerce it.
*/
double
-FGValue::getDoubleValue () const
+SGValue::getDoubleValue () const
{
switch (_type) {
case UNKNOWN:
* If the native type is not string, attempt to coerce it.
*/
const string &
-FGValue::getStringValue () const
+SGValue::getStringValue () const
{
char buf[512];
switch (_type) {
* Returns true on success.
*/
bool
-FGValue::setBoolValue (bool value)
+SGValue::setBoolValue (bool value)
{
if (_type == UNKNOWN || _type == BOOL) {
_type = BOOL;
* Returns true on success.
*/
bool
-FGValue::setIntValue (int value)
+SGValue::setIntValue (int value)
{
if (_type == UNKNOWN || _type == INT) {
_type = INT;
* Returns true on success.
*/
bool
-FGValue::setFloatValue (float value)
+SGValue::setFloatValue (float value)
{
if (_type == UNKNOWN || _type == FLOAT) {
_type = FLOAT;
* Returns true on success.
*/
bool
-FGValue::setDoubleValue (double value)
+SGValue::setDoubleValue (double value)
{
if (_type == UNKNOWN || _type == DOUBLE) {
_type = DOUBLE;
* Returns true on success.
*/
bool
-FGValue::setStringValue (const string &value)
+SGValue::setStringValue (const string &value)
{
if (_type == UNKNOWN || _type == STRING) {
_type = STRING;
* Returns true on success.
*/
bool
-FGValue::setUnknownValue (const string &value)
+SGValue::setUnknownValue (const string &value)
{
if (_type == UNKNOWN || _type == STRING) {
return setRawString(value);
* Returns true on success (i.e. the value is not currently tied).
*/
bool
-FGValue::tieBool (bool_getter getter, bool_setter setter = 0,
+SGValue::tieBool (bool_getter getter, bool_setter setter = 0,
bool useDefault = true)
{
if (_tied) {
* Returns true on success (i.e. the value is not currently tied).
*/
bool
-FGValue::tieInt (int_getter getter, int_setter setter = 0,
+SGValue::tieInt (int_getter getter, int_setter setter = 0,
bool useDefault = true)
{
if (_tied) {
* Returns true on success (i.e. the value is not currently tied).
*/
bool
-FGValue::tieFloat (float_getter getter, float_setter setter = 0,
+SGValue::tieFloat (float_getter getter, float_setter setter = 0,
bool useDefault = true)
{
if (_tied) {
* Returns true on success (i.e. the value is not currently tied).
*/
bool
-FGValue::tieDouble (double_getter getter, double_setter setter = 0,
+SGValue::tieDouble (double_getter getter, double_setter setter = 0,
bool useDefault = true)
{
if (_tied) {
* Returns true on success (i.e. the value is not currently tied).
*/
bool
-FGValue::tieString (string_getter getter, string_setter setter = 0,
+SGValue::tieString (string_getter getter, string_setter setter = 0,
bool useDefault = true)
{
if (_tied) {
* Returns true on success (i.e. the value had been tied).
*/
bool
-FGValue::untie ()
+SGValue::untie ()
{
if (!_tied)
return false;
\f
////////////////////////////////////////////////////////////////////////
-// Implementation of FGPropertyList.
+// Implementation of SGPropertyList.
////////////////////////////////////////////////////////////////////////
/**
* Constructor.
*/
-FGPropertyList::FGPropertyList ()
+SGPropertyList::SGPropertyList ()
{
}
/**
* Destructor.
*/
-FGPropertyList::~FGPropertyList ()
+SGPropertyList::~SGPropertyList ()
{
}
/**
- * Look up the FGValue structure associated with a property.
+ * Look up the SGValue structure associated with a property.
*
* Run some basic validity checks on the property name: it must
* not be empty, must begin with '/', must never have two '//' in a row,
* and must not end with '/'.
*/
-FGValue *
-FGPropertyList::getValue (const string &name, bool create = false)
+SGValue *
+SGPropertyList::getValue (const string &name, bool create = false)
{
const_iterator el = _props.find(name);
if (el == _props.end()) {
/**
* Look up a const value (never created).
*/
-const FGValue *
-FGPropertyList::getValue (const string &name) const
+const SGValue *
+SGPropertyList::getValue (const string &name) const
{
value_map::const_iterator el = _props.find(name);
if (el == _props.end())
* Extract a boolean from the value.
*
* Note that this is inefficient for use in a tight loop: it is
- * better to get the FGValue and query it repeatedly.
+ * better to get the SGValue and query it repeatedly.
*/
bool
-FGPropertyList::getBoolValue (const string &name) const
+SGPropertyList::getBoolValue (const string &name) const
{
- const FGValue * val = getValue(name);
+ const SGValue * val = getValue(name);
if (val == 0)
return false;
else
* Extract an integer from the value.
*
* Note that this is inefficient for use in a tight loop: it is
- * better to get the FGValue and query it repeatedly.
+ * better to get the SGValue and query it repeatedly.
*/
int
-FGPropertyList::getIntValue (const string &name) const
+SGPropertyList::getIntValue (const string &name) const
{
- const FGValue * val = getValue(name);
+ const SGValue * val = getValue(name);
if (val == 0)
return 0;
else
* Extract a float from the value.
*
* Note that this is inefficient for use in a tight loop: it is
- * better to get the FGValue and query it repeatedly.
+ * better to get the SGValue and query it repeatedly.
*/
float
-FGPropertyList::getFloatValue (const string &name) const
+SGPropertyList::getFloatValue (const string &name) const
{
- const FGValue * val = getValue(name);
+ const SGValue * val = getValue(name);
if (val == 0)
return 0.0;
else
* Extract a double from the value.
*
* Note that this is inefficient for use in a tight loop: it is
- * better to get the FGValue and query it repeatedly.
+ * better to get the SGValue and query it repeatedly.
*/
double
-FGPropertyList::getDoubleValue (const string &name) const
+SGPropertyList::getDoubleValue (const string &name) const
{
- const FGValue * val = getValue(name);
+ const SGValue * val = getValue(name);
if (val == 0)
return 0.0;
else
* Extract a string from the value.
*
* Note that this is inefficient for use in a tight loop: it is
- * better to save the FGValue and query it repeatedly.
+ * better to save the SGValue and query it repeatedly.
*/
const string &
-FGPropertyList::getStringValue (const string &name) const
+SGPropertyList::getStringValue (const string &name) const
{
- const FGValue * val = getValue(name);
+ const SGValue * val = getValue(name);
if (val == 0)
return empty_string;
else
* Assign a bool to the value and change the type if unknown.
*
* Note that this is inefficient for use in a tight loop: it is
- * better to save the FGValue and modify it repeatedly.
+ * better to save the SGValue and modify it repeatedly.
*
* Returns true on success.
*/
bool
-FGPropertyList::setBoolValue (const string &name, bool value)
+SGPropertyList::setBoolValue (const string &name, bool value)
{
return getValue(name, true)->setBoolValue(value);
}
* Assign an integer to the value and change the type if unknown.
*
* Note that this is inefficient for use in a tight loop: it is
- * better to save the FGValue and modify it repeatedly.
+ * better to save the SGValue and modify it repeatedly.
*
* Returns true on success.
*/
bool
-FGPropertyList::setIntValue (const string &name, int value)
+SGPropertyList::setIntValue (const string &name, int value)
{
return getValue(name, true)->setIntValue(value);
}
* Assign a float to the value and change the type if unknown.
*
* Note that this is inefficient for use in a tight loop: it is
- * better to save the FGValue and modify it repeatedly.
+ * better to save the SGValue and modify it repeatedly.
*
* Returns true on success.
*/
bool
-FGPropertyList::setFloatValue (const string &name, float value)
+SGPropertyList::setFloatValue (const string &name, float value)
{
return getValue(name, true)->setFloatValue(value);
}
* Assign a double to the value and change the type if unknown.
*
* Note that this is inefficient for use in a tight loop: it is
- * better to save the FGValue and modify it repeatedly.
+ * better to save the SGValue and modify it repeatedly.
*
* Returns true on success.
*/
bool
-FGPropertyList::setDoubleValue (const string &name, double value)
+SGPropertyList::setDoubleValue (const string &name, double value)
{
return getValue(name, true)->setDoubleValue(value);
}
* Assign a string to the value and change the type if unknown.
*
* Note that this is inefficient for use in a tight loop: it is
- * better to save the FGValue and modify it repeatedly.
+ * better to save the SGValue and modify it repeatedly.
*
* Returns true on success.
*/
bool
-FGPropertyList::setStringValue (const string &name, const string &value)
+SGPropertyList::setStringValue (const string &name, const string &value)
{
return getValue(name, true)->setStringValue(value);
}
* Assign a string to the value, but don't change the type.
*
* Note that this is inefficient for use in a tight loop: it is
- * better to save the FGValue and modify it repeatedly.
+ * better to save the SGValue and modify it repeatedly.
*
* Returns true on success.
*/
bool
-FGPropertyList::setUnknownValue (const string &name, const string &value)
+SGPropertyList::setUnknownValue (const string &name, const string &value)
{
return getValue(name, true)->setUnknownValue(value);
}
/**
* Tie a boolean value to external functions.
*
- * Invokes FGValue::tieBool
+ * Invokes SGValue::tieBool
*/
bool
-FGPropertyList::tieBool (const string &name,
+SGPropertyList::tieBool (const string &name,
bool_getter getter,
bool_setter setter,
bool useDefault = true)
/**
* Tie an integer value to external functions.
*
- * Invokes FGValue::tieInt
+ * Invokes SGValue::tieInt
*/
bool
-FGPropertyList::tieInt (const string &name,
+SGPropertyList::tieInt (const string &name,
int_getter getter,
int_setter setter,
bool useDefault = true)
/**
* Tie a float value to external functions.
*
- * Invokes FGValue::tieFloat
+ * Invokes SGValue::tieFloat
*/
bool
-FGPropertyList::tieFloat (const string &name,
+SGPropertyList::tieFloat (const string &name,
float_getter getter,
float_setter setter,
bool useDefault = true)
/**
* Tie a double value to external functions.
*
- * Invokes FGValue::tieDouble
+ * Invokes SGValue::tieDouble
*/
bool
-FGPropertyList::tieDouble (const string &name,
+SGPropertyList::tieDouble (const string &name,
double_getter getter,
double_setter setter,
bool useDefault = true)
/**
* Tie a string value to external functions.
*
- * Invokes FGValue::tieString
+ * Invokes SGValue::tieString
*/
bool
-FGPropertyList::tieString (const string &name,
+SGPropertyList::tieString (const string &name,
string_getter getter,
string_setter setter,
bool useDefault = true)
/**
* Untie a value from external functions.
*
- * Invokes FGValue::untie
+ * Invokes SGValue::untie
*/
bool
-FGPropertyList::untie (const string &name)
+SGPropertyList::untie (const string &name)
{
FG_LOG(FG_GENERAL, FG_INFO, "Untying property '" << name << '\'');
return getValue(name, true)->untie();
\f
////////////////////////////////////////////////////////////////////////
-// Implementation of FGPropertyNode.
+// Implementation of SGPropertyNode.
////////////////////////////////////////////////////////////////////////
/**
* Constructor.
*/
-FGPropertyNode::FGPropertyNode (const string &path = "",
- FGPropertyList * props = 0)
+SGPropertyNode::SGPropertyNode (const string &path = "",
+ SGPropertyList * props = 0)
: _props(props)
{
setPath(path);
/**
* Destructor.
*/
-FGPropertyNode::~FGPropertyNode ()
+SGPropertyNode::~SGPropertyNode ()
{
}
* Strip the trailing '/', if any.
*/
void
-FGPropertyNode::setPath (const string &path)
+SGPropertyNode::setPath (const string &path)
{
_path = path;
* The local name is just everything after the last slash.
*/
const string &
-FGPropertyNode::getName () const
+SGPropertyNode::getName () const
{
string::size_type pos = _path.rfind('/');
if (pos != string::npos) {
*
* Note that this will not create the value if it doesn't already exist.
*/
-FGValue *
-FGPropertyNode::getValue ()
+SGValue *
+SGPropertyNode::getValue ()
{
if (_props == 0 || _path.size() == 0)
return 0;
* Return the number of children for the current node.
*/
int
-FGPropertyNode::size () const
+SGPropertyNode::size () const
{
if (_props == 0)
return 0;
string pattern = _path;
pattern += '/';
- FGPropertyList::const_iterator it = _props->begin();
- FGPropertyList::const_iterator end = _props->end();
+ SGPropertyList::const_iterator it = _props->begin();
+ SGPropertyList::const_iterator end = _props->end();
while (it != end) {
if (get_base(pattern, it->first, base) && base != lastBase) {
s++;
* is unmodified.
*/
bool
-FGPropertyNode::getParent (FGPropertyNode &parent) const
+SGPropertyNode::getParent (SGPropertyNode &parent) const
{
string::size_type pos = _path.rfind('/');
if (pos != string::npos) {
* is unmodified.
*/
bool
-FGPropertyNode::getChild (FGPropertyNode &child, int n) const
+SGPropertyNode::getChild (SGPropertyNode &child, int n) const
{
if (_props == 0)
return false;
string pattern = _path;
pattern += '/';
- FGPropertyList::const_iterator it = _props->begin();
- FGPropertyList::const_iterator end = _props->end();
+ SGPropertyList::const_iterator it = _props->begin();
+ SGPropertyList::const_iterator end = _props->end();
while (it != end) {
if (get_base(pattern, it->first, base) && base != lastBase) {
if (s == n) {
* Values also have attributes that control whether they can be read
* from, written to, or archived (i.e. saved to disk).
*/
-class FGValue
+class SGValue
{
public:
STRING // text
};
- FGValue ();
- virtual ~FGValue ();
+ SGValue ();
+ virtual ~SGValue ();
// Meta information.
virtual Type getType () const { return _type; }
* A list of FlightGear properties.
*
* This list associates names (conventional written as paths,
- * i.e. "/foo/bar/hack") with FGValue classes. Once an FGValue
+ * i.e. "/foo/bar/hack") with SGValue classes. Once an SGValue
* object is associated with the name, the association is
* permanent -- it is safe to keep a pointer or reference.
* however, that the type of a value may change if it is tied
*
* When iterating through the list, the value type is
*
- * pair<string,FGValue>
+ * pair<string,SGValue>
*
* To get the name from a const_iterator, use
*
*
* it->second
*/
-class FGPropertyList
+class SGPropertyList
{
public:
- typedef map<string, FGValue> value_map;
+ typedef map<string, SGValue> value_map;
- typedef FGValue::bool_getter bool_getter;
- typedef FGValue::int_getter int_getter;
- typedef FGValue::float_getter float_getter;
- typedef FGValue::double_getter double_getter;
- typedef FGValue::string_getter string_getter;
+ typedef SGValue::bool_getter bool_getter;
+ typedef SGValue::int_getter int_getter;
+ typedef SGValue::float_getter float_getter;
+ typedef SGValue::double_getter double_getter;
+ typedef SGValue::string_getter string_getter;
- typedef FGValue::bool_setter bool_setter;
- typedef FGValue::int_setter int_setter;
- typedef FGValue::float_setter float_setter;
- typedef FGValue::double_setter double_setter;
- typedef FGValue::string_setter string_setter;
+ typedef SGValue::bool_setter bool_setter;
+ typedef SGValue::int_setter int_setter;
+ typedef SGValue::float_setter float_setter;
+ typedef SGValue::double_setter double_setter;
+ typedef SGValue::string_setter string_setter;
typedef value_map::value_type value_type;
typedef value_map::size_type size_type;
typedef value_map::const_iterator const_iterator;
- FGPropertyList ();
- virtual ~FGPropertyList ();
+ SGPropertyList ();
+ virtual ~SGPropertyList ();
virtual size_type size () const { return _props.size(); }
virtual const_iterator begin () const { return _props.begin(); }
virtual const_iterator end () const { return _props.end(); }
- virtual FGValue * getValue (const string &name, bool create = false);
- virtual const FGValue * getValue (const string &name) const;
+ virtual SGValue * getValue (const string &name, bool create = false);
+ virtual const SGValue * getValue (const string &name) const;
virtual bool getBoolValue (const string &name) const;
virtual int getIntValue (const string &name) const;
* example that prints the names of all of the different nodes inside
* "/controls":
*
- * FGPropertyNode controls("/controls", current_property_list);
- * FGPropertyNode child;
+ * SGPropertyNode controls("/controls", current_property_list);
+ * SGPropertyNode child;
* int size = controls.size();
* for (int i = 0; i < size; i++) {
* if (controls.getChild(child, i))
* cerr << "Failed to read child " << i << endl;
* }
*/
-class FGPropertyNode
+class SGPropertyNode
{
public:
// Constructor and destructor
- FGPropertyNode (const string &path = "", FGPropertyList * props = 0);
- virtual ~FGPropertyNode ();
+ SGPropertyNode (const string &path = "", SGPropertyList * props = 0);
+ virtual ~SGPropertyNode ();
// Accessor and setter for the internal
// path.
// Accessor and setter for the real
// property list.
- virtual FGPropertyList * getPropertyList () { return _props; }
- virtual void setPropertyList (FGPropertyList * props) {
+ virtual SGPropertyList * getPropertyList () { return _props; }
+ virtual void setPropertyList (SGPropertyList * props) {
_props = props;
}
// Accessors for derived information.
virtual int size () const;
virtual const string &getName () const;
- virtual FGValue * getValue ();
- virtual bool getParent (FGPropertyNode &parent) const;
- virtual bool getChild (FGPropertyNode &child, int n) const;
+ virtual SGValue * getValue ();
+ virtual bool getParent (SGPropertyNode &parent) const;
+ virtual bool getChild (SGPropertyNode &child, int n) const;
private:
string _path;
mutable string _name; // for pointer persistence only
- FGPropertyList * _props;
+ SGPropertyList * _props;
};
// Global property manager.
////////////////////////////////////////////////////////////////////////
-extern FGPropertyList current_properties;
+extern SGPropertyList current_properties;
#endif __PROPS_HXX