#include <string>
#include <map>
+#include <iostream>
using std::string;
using std::map;
+using std::istream;
+using std::ostream;
+
+#ifdef UNKNOWN
+#pragma warn A sloppy coder has defined UNKNOWN as a macro!
+#undef UNKNOWN
+#endif
+
+#ifdef BOOL
+#pragma warn A sloppy coder has defined BOOL as a macro!
+#undef BOOL
+#endif
+
+#ifdef INT
+#pragma warn A sloppy coder has defined INT as a macro!
+#undef INT
+#endif
+
+#ifdef FLOAT
+#pragma warn A sloppy coder has defined FLOAT as a macro!
+#undef FLOAT
+#endif
+
+#ifdef DOUBLE
+#pragma warn A sloppy coder has defined DOUBLE as a macro!
+#undef DOUBLE
+#endif
+
+#ifdef STRING
+#pragma warn A sloppy coder has defined STRING as a macro!
+#undef STRING
+#endif
\f
* 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; }
virtual int getIntValue () const;
virtual float getFloatValue () const;
virtual double getDoubleValue () const;
- virtual const string &getStringValue () const;
+ virtual const string & getStringValue () const;
// Setters.
virtual bool setBoolValue (bool value);
* 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 bool hasValue (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;
- virtual float getFloatValue (const string &name) const;
- virtual double getDoubleValue (const string &name) const;
- virtual const string &getStringValue (const string &name) const;
+ virtual bool getBoolValue (const string &name,
+ bool defaultValue = false) const;
+ virtual int getIntValue (const string &name,
+ int defaultValue = 0) const;
+ virtual float getFloatValue (const string &name,
+ float defaultValue = 0.0) const;
+ virtual double getDoubleValue (const string &name,
+ double defaultValue = 0.0L) const;
+ virtual const string & getStringValue (const string &name,
+ const string &defaultValue = "")
+ const;
virtual bool setBoolValue (const string &name, bool value);
virtual bool setIntValue (const string &name, int value);
* 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 SGPropertyNode &getParent () const;
+ virtual SGPropertyNode &getChild (int n) const;
+ virtual SGPropertyNode &getSubNode (const string &subpath) const;
+
+ // Check for a value.
+ virtual bool hasValue (const string &subpath = "") const;
+
+ // Get values directly.
+ virtual SGValue * getValue (const string &subpath = "");
+ virtual bool getBoolValue (const string &subpath = "",
+ bool defaultValue = false) const;
+ virtual int getIntValue (const string &subpath = "",
+ int defaultValue = 0) const;
+ virtual float getFloatValue (const string &subpath = "",
+ float defaultValue = 0.0) const;
+ virtual double getDoubleValue (const string &subpath = "",
+ double defaultValue = 0.0L) const;
+ virtual const string &
+ getStringValue (const string &subpath = "",
+ const string &defaultValue = "") const;
private:
string _path;
- mutable string _name; // for pointer persistence only
- FGPropertyList * _props;
+ SGPropertyList * _props;
+ // for pointer persistence...
+ // NOT THREAD SAFE!!!
+ // (each thread must have its own node
+ // object)
+ mutable string _name;
+ mutable SGPropertyNode * _node;
};
+\f
+////////////////////////////////////////////////////////////////////////
+// Input and output.
+////////////////////////////////////////////////////////////////////////
+
+extern bool readPropertyList (istream &input, SGPropertyList * props);
+extern bool readPropertyList (const string &file, SGPropertyList * props);
+extern bool writePropertyList (ostream &output, const SGPropertyList * props);
+extern bool writePropertyList (const string &file,
+ const SGPropertyList * props);
+
+
\f
////////////////////////////////////////////////////////////////////////
// Global property manager.
////////////////////////////////////////////////////////////////////////
-extern FGPropertyList current_properties;
+extern SGPropertyList current_properties;
-#endif __PROPS_HXX
+#endif // __PROPS_HXX
// end of props.hxx