#ifndef __PROPS_HXX
#define __PROPS_HXX
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <simgear/compiler.h>
+
#include <stdio.h>
-#include <string>
+#include STL_STRING
#include <vector>
-#include <iostream>
+#include STL_IOSTREAM
-using std::string;
-using std::vector;
-using std::istream;
-using std::ostream;
+SG_USING_STD(string);
+SG_USING_STD(vector);
+#if !defined(SG_HAVE_NATIVE_SGI_COMPILERS)
+SG_USING_STD(istream);
+SG_USING_STD(ostream);
+#endif
+
+#ifdef ALIAS
+#pragma warn A sloppy coder has defined ALIAS as a macro!
+#undef ALIAS
+#endif
#ifdef UNKNOWN
#pragma warn A sloppy coder has defined UNKNOWN as a macro!
#undef INT
#endif
+#ifdef LONG
+#pragma warn A sloppy coder has defined LONG as a macro!
+#undef LONG
+#endif
+
#ifdef FLOAT
#pragma warn A sloppy coder has defined FLOAT as a macro!
#undef FLOAT
virtual ~SGRawValueFunctions () {}
virtual T getValue () const {
if (_getter) return (*_getter)();
- else return DefaultValue;
+ else return SGRawValue<T>::DefaultValue;
}
virtual bool setValue (T value) {
if (_setter) { (*_setter)(value); return true; }
virtual ~SGRawValueFunctionsIndexed () {}
virtual T getValue () const {
if (_getter) return (*_getter)(_index);
- else return DefaultValue;
+ else return SGRawValue<T>::DefaultValue;
}
virtual bool setValue (T value) {
if (_setter) { (*_setter)(_index, value); return true; }
virtual ~SGRawValueMethods () {}
virtual T getValue () const {
if (_getter) { return (_obj.*_getter)(); }
- else { return DefaultValue; }
+ else { return SGRawValue<T>::DefaultValue; }
}
virtual bool setValue (T value) {
if (_setter) { (_obj.*_setter)(value); return true; }
virtual ~SGRawValueMethodsIndexed () {}
virtual T getValue () const {
if (_getter) { return (_obj.*_getter)(_index); }
- else { return DefaultValue; }
+ else { return SGRawValue<T>::DefaultValue; }
}
virtual bool setValue (T value) {
if (_setter) { (_obj.*_setter)(_index, value); return true; }
enum Type {
BOOL,
INT,
+ LONG,
FLOAT,
DOUBLE,
STRING,
SGValue (const SGValue &value);
~SGValue ();
- Type getType () const { return _type; }
+ Type getType () const;
+
+ SGValue * getAlias ();
+ const SGValue * getAlias () const;
+ bool alias (SGValue * alias);
+ bool unalias ();
+ bool isAlias () const { return _type == ALIAS; }
bool getBoolValue () const;
int getIntValue () const;
+ long getLongValue () const;
float getFloatValue () const;
double getDoubleValue () const;
string getStringValue () const;
bool setBoolValue (bool value);
bool setIntValue (int value);
+ bool setLongValue (long value);
bool setFloatValue (float value);
bool setDoubleValue (double value);
bool setStringValue (string value);
bool tie (const SGRawValue<bool> &rawValue, bool useDefault = true);
bool tie (const SGRawValue<int> &rawValue, bool useDefault = true);
+ bool tie (const SGRawValue<long> &rawValue, bool useDefault = true);
bool tie (const SGRawValue<float> &rawValue, bool useDefault = true);
bool tie (const SGRawValue<double> &rawValue, bool useDefault = true);
bool tie (const SGRawValue<string> &rawValue, bool useDefault = true);
private:
+ enum {
+ ALIAS = -1
+ };
+
void clear_value ();
- Type _type;
+ int _type;
bool _tied;
// The right kind of pointer...
union {
+ SGValue * alias;
SGRawValue<bool> * bool_val;
SGRawValue<int> * int_val;
+ SGRawValue<long> * long_val;
SGRawValue<float> * float_val;
SGRawValue<double> * double_val;
SGRawValue<string> * string_val;
public:
SGPropertyNode ();
- virtual ~SGPropertyNode ();
+ virtual ~SGPropertyNode ();
// Basic properties.
bool hasValue () const { return (_value != 0); }
SGValue * getValue () { return _value; }
+ SGValue * getValue (bool create);
const SGValue * getValue () const { return _value; }
const string &getName () const { return _name; }
const int getIndex () const { return _index; }
SGPropertyNode * getParent () { return _parent; }
const SGPropertyNode * getParent () const { return _parent; }
+ // Alias support.
+ bool alias (SGPropertyNode * target);
+ bool alias (const string &path);
+ bool unalias ();
+ bool isAlias () const;
+ SGPropertyNode * getAliasTarget ();
+ const SGPropertyNode * getAliasTarget () const;
+
// Children.
const int nChildren () const { return _children.size(); }
SGPropertyNode * getChild (int position);
bool getBoolValue () const;
int getIntValue () const;
+ long getLongValue () const;
float getFloatValue () const;
double getDoubleValue () const;
string getStringValue () const;
bool setBoolValue (bool value);
bool setIntValue (int value);
+ bool setLongValue (long value);
bool setFloatValue (float value);
bool setDoubleValue (double value);
bool setStringValue (string value);
bool tie (const SGRawValue<bool> &rawValue, bool useDefault = true);
bool tie (const SGRawValue<int> &rawValue, bool useDefault = true);
+ bool tie (const SGRawValue<long> &rawValue, bool useDefault = true);
bool tie (const SGRawValue<float> &rawValue, bool useDefault = true);
bool tie (const SGRawValue<double> &rawValue, bool useDefault = true);
bool tie (const SGRawValue<string> &rawValue, bool useDefault = true);
bool defaultValue = false) const;
int getIntValue (const string &relative_path,
int defaultValue = 0) const;
+ long getLongValue (const string &relative_path,
+ long defaultValue = 0L) const;
float getFloatValue (const string &relative_path,
float defaultValue = 0.0) const;
double getDoubleValue (const string &relative_path,
bool setBoolValue (const string &relative_path, bool value);
bool setIntValue (const string &relative_path, int value);
+ bool setLongValue (const string &relative_path, long value);
bool setFloatValue (const string &relative_path, float value);
bool setDoubleValue (const string &relative_path, double value);
bool setStringValue (const string &relative_path, string value);
bool useDefault = true);
bool tie (const string &relative_path, const SGRawValue<int> &rawValue,
bool useDefault = true);
+ bool tie (const string &relative_path, const SGRawValue<long> &rawValue,
+ bool useDefault = true);
bool tie (const string &relative_path, const SGRawValue<float> &rawValue,
bool useDefault = true);
bool tie (const string &relative_path, const SGRawValue<double> &rawValue,
int _index;
SGPropertyNode * _parent;
vector<SGPropertyNode *> _children;
+ mutable SGPropertyNode * _target;
};
// I/O functions.
////////////////////////////////////////////////////////////////////////
-bool readProperties (istream &input, SGPropertyNode * start_node);
+bool readProperties (istream &input, SGPropertyNode * start_node,
+ const string &base = "");
bool readProperties (const string &file, SGPropertyNode * start_node);
bool writeProperties (ostream &output, const SGPropertyNode * start_node);
bool writeProperties (const string &file, const SGPropertyNode * start_node);