2 #define __FG_PROPS_HXX 1
4 #include <simgear/debug/logstream.hxx>
5 #include <simgear/misc/props.hxx>
9 ////////////////////////////////////////////////////////////////////////
10 // Loading and saving properties.
11 ////////////////////////////////////////////////////////////////////////
13 extern bool fgSaveFlight (ostream &output);
14 extern bool fgLoadFlight (istream &input);
18 ////////////////////////////////////////////////////////////////////////
19 // Convenience functions for getting property values.
20 ////////////////////////////////////////////////////////////////////////
23 * Get an SGValue pointer that can be queried repeatedly.
25 * If the property value is going to be accessed within the loop,
26 * it is best to use this method for maximum efficiency.
28 inline SGValue * fgGetValue (const string &name, bool create = false)
30 return globals->get_props()->getValue(name, create);
33 inline bool fgHasValue (const string &name)
35 return globals->get_props()->hasValue(name);
38 inline bool fgGetBool (const string &name, bool defaultValue = false)
40 return globals->get_props()->getBoolValue(name, defaultValue);
43 inline int fgGetInt (const string &name, int defaultValue = 0)
45 return globals->get_props()->getIntValue(name, defaultValue);
48 inline float fgGetFloat (const string &name, float defaultValue = 0.0)
50 return globals->get_props()->getFloatValue(name, defaultValue);
53 inline double fgGetDouble (const string &name, double defaultValue = 0.0)
55 return globals->get_props()->getDoubleValue(name, defaultValue);
58 inline string fgGetString (const string &name, string defaultValue = "")
60 return globals->get_props()->getStringValue(name, defaultValue);
63 inline bool fgSetBool (const string &name, bool val)
65 return globals->get_props()->setBoolValue(name, val);
68 inline bool fgSetInt (const string &name, int val)
70 return globals->get_props()->setIntValue(name, val);
73 inline bool fgSetFloat (const string &name, float val)
75 return globals->get_props()->setFloatValue(name, val);
78 inline bool fgSetDouble (const string &name, double val)
80 return globals->get_props()->setDoubleValue(name, val);
83 inline bool fgSetString (const string &name, const string &val)
85 return globals->get_props()->setStringValue(name, val);
90 ////////////////////////////////////////////////////////////////////////
91 // Convenience functions for tying properties, with logging.
92 ////////////////////////////////////////////////////////////////////////
95 fgUntie (const string &name)
97 if (!globals->get_props()->untie(name))
98 FG_LOG(FG_GENERAL, FG_WARN, "Failed to untie property " << name);
102 // Templates cause ambiguity here
104 fgTie (const string &name, bool *pointer)
106 if (!globals->get_props()->tie(name, SGRawValuePointer<bool>(pointer)))
107 FG_LOG(FG_GENERAL, FG_WARN,
108 "Failed to tie property " << name << " to a pointer");
112 fgTie (const string &name, int *pointer)
114 if (!globals->get_props()->tie(name, SGRawValuePointer<int>(pointer)))
115 FG_LOG(FG_GENERAL, FG_WARN,
116 "Failed to tie property " << name << " to a pointer");
120 fgTie (const string &name, float *pointer)
122 if (!globals->get_props()->tie(name, SGRawValuePointer<float>(pointer)))
123 FG_LOG(FG_GENERAL, FG_WARN,
124 "Failed to tie property " << name << " to a pointer");
128 fgTie (const string &name, double *pointer)
130 if (!globals->get_props()->tie(name, SGRawValuePointer<double>(pointer)))
131 FG_LOG(FG_GENERAL, FG_WARN,
132 "Failed to tie property " << name << " to a pointer");
136 fgTie (const string &name, string *pointer)
138 if (!globals->get_props()->tie(name, SGRawValuePointer<string>(pointer)))
139 FG_LOG(FG_GENERAL, FG_WARN,
140 "Failed to tie property " << name << " to a pointer");
145 fgTie (const string &name, V (*getter)(), void (*setter)(V) = 0)
147 if (!globals->get_props()->tie(name, SGRawValueFunctions<V>(getter, setter)))
148 FG_LOG(FG_GENERAL, FG_WARN,
149 "Failed to tie property " << name << " to functions");
154 fgTie (const string &name, int index, V (*getter)(int),
155 void (*setter)(int, V) = 0)
157 if (!globals->get_props()->tie(name,
158 SGRawValueFunctionsIndexed<V>(index,
161 FG_LOG(FG_GENERAL, FG_WARN,
162 "Failed to tie property " << name << " to indexed functions");
165 template <class T, class V>
167 fgTie (const string &name, T * obj, V (T::*getter)() const,
168 void (T::*setter)(V) = 0)
170 if (!globals->get_props()->tie(name,
171 SGRawValueMethods<T,V>(*obj, getter, setter)))
172 FG_LOG(FG_GENERAL, FG_WARN,
173 "Failed to tie property " << name << " to object methods");
176 template <class T, class V>
178 fgTie (const string &name, T * obj, int index,
179 V (T::*getter)(int) const, void (T::*setter)(int, V) = 0)
181 if (!globals->get_props()->tie(name,
182 SGRawValueMethodsIndexed<T,V>(*obj,
186 FG_LOG(FG_GENERAL, FG_WARN,
187 "Failed to tie property " << name << " to indexed object methods");
191 #endif // __FG_PROPS_HXX