]> git.mxchange.org Git - simgear.git/blobdiff - simgear/misc/props.hxx
fg_traits.hxx -> sg_traits.hxx
[simgear.git] / simgear / misc / props.hxx
index a4579732bdc440c19230c4dc2c6fc3749c36b467..1e059090322dccd46521e9a25efe03dc9b05dc78 100644 (file)
@@ -9,16 +9,29 @@
 #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!
@@ -35,6 +48,11 @@ using std::ostream;
 #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
@@ -153,7 +171,7 @@ public:
   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; }
@@ -185,7 +203,7 @@ public:
   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; }
@@ -218,7 +236,7 @@ public:
   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; }
@@ -252,7 +270,7 @@ public:
   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; }
@@ -286,6 +304,7 @@ public:
   enum Type {
     BOOL,
     INT,
+    LONG,
     FLOAT,
     DOUBLE,
     STRING,
@@ -295,16 +314,24 @@ public:
   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);
@@ -314,6 +341,7 @@ public:
 
   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);
@@ -322,15 +350,21 @@ public:
 
 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;
@@ -350,17 +384,26 @@ class SGPropertyNode
 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);
@@ -386,12 +429,14 @@ public:
   
   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);
@@ -401,6 +446,7 @@ public:
 
   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);
@@ -418,6 +464,8 @@ public:
                     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,
@@ -427,6 +475,7 @@ public:
 
   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);
@@ -438,6 +487,8 @@ public:
            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,
@@ -460,6 +511,7 @@ private:
   int _index;
   SGPropertyNode * _parent;
   vector<SGPropertyNode *> _children;
+  mutable SGPropertyNode * _target;
 
 };
 
@@ -469,7 +521,8 @@ private:
 // 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);