]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/fg_props.hxx
- /sim/model/h-rotation renamed to /sim/model/heading-offset-deg
[flightgear.git] / src / Main / fg_props.hxx
index 8dd28cea452ca2830d3417c9f01b17d3dc4a7e20..2eae51b8fd27d7813726270d8825518ea02035c6 100644 (file)
@@ -7,9 +7,11 @@
 
 \f
 ////////////////////////////////////////////////////////////////////////
-// Loading and saving properties.
+// Property management.
 ////////////////////////////////////////////////////////////////////////
 
+extern void fgInitProps ();    // fixme: how are they untied?
+extern void fgUpdateProps ();
 extern bool fgSaveFlight (ostream &output);
 extern bool fgLoadFlight (istream &input);
 
@@ -19,22 +21,34 @@ extern bool fgLoadFlight (istream &input);
 // Convenience functions for getting property values.
 ////////////////////////////////////////////////////////////////////////
 
+
 /**
- * Get an SGValue pointer that can be queried repeatedly.
+ * Get a property node.
  *
- * If the property value is going to be accessed within the loop,
- * it is best to use this method for maximum efficiency.
+ * @param path The path of the node, relative to root.
+ * @param create true to create the node if it doesn't exist.
+ * @return The node, or 0 if none exists and none was created.
  */
-inline SGValue * fgGetValue (const string &name, bool create = false)
+inline SGPropertyNode * 
+fgGetNode (const string &path, bool create = false)
 {
-  return globals->get_props()->getValue(name, create);
+  return globals->get_props()->getNode(path, create);
 }
 
-inline bool fgHasValue (const string &name)
+
+/**
+ * Test whether a given node exists.
+ *
+ * @param path The path of the node, relative to root.
+ * @return true if the node exists, false otherwise.
+ */
+inline bool
+fgHasNode (const string &path)
 {
-  return globals->get_props()->hasValue(name);
+  return (fgGetNode(path, false) != 0);
 }
 
+
 inline bool fgGetBool (const string &name, bool defaultValue = false)
 {
   return globals->get_props()->getBoolValue(name, defaultValue);
@@ -45,6 +59,11 @@ inline int fgGetInt (const string &name, int defaultValue = 0)
   return globals->get_props()->getIntValue(name, defaultValue);
 }
 
+inline int fgGetLong (const string &name, long defaultValue = 0L)
+{
+  return globals->get_props()->getLongValue(name, defaultValue);
+}
+
 inline float fgGetFloat (const string &name, float defaultValue = 0.0)
 {
   return globals->get_props()->getFloatValue(name, defaultValue);
@@ -70,6 +89,11 @@ inline bool fgSetInt (const string &name, int val)
   return globals->get_props()->setIntValue(name, val);
 }
 
+inline bool fgSetLong (const string &name, long val)
+{
+  return globals->get_props()->setLongValue(name, val);
+}
+
 inline bool fgSetFloat (const string &name, float val)
 {
   return globals->get_props()->setFloatValue(name, val);
@@ -95,95 +119,115 @@ inline void
 fgUntie (const string &name)
 {
   if (!globals->get_props()->untie(name))
-    FG_LOG(FG_GENERAL, FG_WARN, "Failed to untie property " << name);
+    SG_LOG(SG_GENERAL, SG_WARN, "Failed to untie property " << name);
 }
 
 
                                // Templates cause ambiguity here
 inline void
-fgTie (const string &name, bool *pointer)
+fgTie (const string &name, bool *pointer, bool useDefault = true)
+{
+  if (!globals->get_props()->tie(name, SGRawValuePointer<bool>(pointer),
+                                useDefault))
+    SG_LOG(SG_GENERAL, SG_WARN,
+          "Failed to tie property " << name << " to a pointer");
+}
+
+inline void
+fgTie (const string &name, int *pointer, bool useDefault = true)
 {
-  if (!globals->get_props()->tie(name, SGRawValuePointer<bool>(pointer)))
-    FG_LOG(FG_GENERAL, FG_WARN,
+  if (!globals->get_props()->tie(name, SGRawValuePointer<int>(pointer),
+                                useDefault))
+    SG_LOG(SG_GENERAL, SG_WARN,
           "Failed to tie property " << name << " to a pointer");
 }
 
 inline void
-fgTie (const string &name, int *pointer)
+fgTie (const string &name, long *pointer, bool useDefault = true)
 {
-  if (!globals->get_props()->tie(name, SGRawValuePointer<int>(pointer)))
-    FG_LOG(FG_GENERAL, FG_WARN,
+  if (!globals->get_props()->tie(name, SGRawValuePointer<long>(pointer),
+                                useDefault))
+    SG_LOG(SG_GENERAL, SG_WARN,
           "Failed to tie property " << name << " to a pointer");
 }
 
 inline void
-fgTie (const string &name, float *pointer)
+fgTie (const string &name, float *pointer, bool useDefault = true)
 {
-  if (!globals->get_props()->tie(name, SGRawValuePointer<float>(pointer)))
-    FG_LOG(FG_GENERAL, FG_WARN,
+  if (!globals->get_props()->tie(name, SGRawValuePointer<float>(pointer),
+                                useDefault))
+    SG_LOG(SG_GENERAL, SG_WARN,
           "Failed to tie property " << name << " to a pointer");
 }
 
 inline void
-fgTie (const string &name, double *pointer)
+fgTie (const string &name, double *pointer, bool useDefault = true)
 {
-  if (!globals->get_props()->tie(name, SGRawValuePointer<double>(pointer)))
-    FG_LOG(FG_GENERAL, FG_WARN,
+  if (!globals->get_props()->tie(name, SGRawValuePointer<double>(pointer),
+                                useDefault))
+    SG_LOG(SG_GENERAL, SG_WARN,
           "Failed to tie property " << name << " to a pointer");
 }
 
 inline void
-fgTie (const string &name, string *pointer)
+fgTie (const string &name, string *pointer, bool useDefault = true)
 {
-  if (!globals->get_props()->tie(name, SGRawValuePointer<string>(pointer)))
-    FG_LOG(FG_GENERAL, FG_WARN,
+  if (!globals->get_props()->tie(name, SGRawValuePointer<string>(pointer),
+                                useDefault))
+    SG_LOG(SG_GENERAL, SG_WARN,
           "Failed to tie property " << name << " to a pointer");
 }
 
 template <class V>
 inline void
-fgTie (const string &name, V (*getter)(), void (*setter)(V) = 0)
+fgTie (const string &name, V (*getter)(), void (*setter)(V) = 0,
+       bool useDefault = true)
 {
-  if (!globals->get_props()->tie(name, SGRawValueFunctions<V>(getter, setter)))
-    FG_LOG(FG_GENERAL, FG_WARN,
+  if (!globals->get_props()->tie(name, SGRawValueFunctions<V>(getter, setter),
+                                useDefault))
+    SG_LOG(SG_GENERAL, SG_WARN,
           "Failed to tie property " << name << " to functions");
 }
 
 template <class V>
 inline void
 fgTie (const string &name, int index, V (*getter)(int),
-       void (*setter)(int, V) = 0)
+       void (*setter)(int, V) = 0, bool useDefault = true)
 {
   if (!globals->get_props()->tie(name,
                                 SGRawValueFunctionsIndexed<V>(index,
                                                               getter,
-                                                              setter)))
-    FG_LOG(FG_GENERAL, FG_WARN,
+                                                              setter),
+                                useDefault))
+    SG_LOG(SG_GENERAL, SG_WARN,
           "Failed to tie property " << name << " to indexed functions");
 }
 
 template <class T, class V>
 inline void
 fgTie (const string &name, T * obj, V (T::*getter)() const,
-       void (T::*setter)(V) = 0)
+       void (T::*setter)(V) = 0, bool useDefault = true)
 {
   if (!globals->get_props()->tie(name,
-                                SGRawValueMethods<T,V>(*obj, getter, setter)))
-    FG_LOG(FG_GENERAL, FG_WARN,
+                                SGRawValueMethods<T,V>(*obj, getter, setter),
+                                useDefault))
+    SG_LOG(SG_GENERAL, SG_WARN,
           "Failed to tie property " << name << " to object methods");
 }
 
 template <class T, class V>
 inline void 
 fgTie (const string &name, T * obj, int index,
-       V (T::*getter)(int) const, void (T::*setter)(int, V) = 0)
+       V (T::*getter)(int) const, void (T::*setter)(int, V) = 0,
+       bool useDefault = true)
 {
   if (!globals->get_props()->tie(name,
                                 SGRawValueMethodsIndexed<T,V>(*obj,
                                                               index,
                                                               getter,
-                                                              setter)))
-    FG_LOG(FG_GENERAL, FG_WARN,
+                                                              setter),
+                                useDefault))
+    SG_LOG(SG_GENERAL, SG_WARN,
           "Failed to tie property " << name << " to indexed object methods");
 }