2 #define __FG_PROPS_HXX 1
4 #include <simgear/debug/logstream.hxx>
5 #include <simgear/misc/props.hxx>
9 ////////////////////////////////////////////////////////////////////////
10 // Property management.
11 ////////////////////////////////////////////////////////////////////////
13 extern void fgInitProps (); // fixme: how are they untied?
14 extern void fgUpdateProps ();
15 extern bool fgSaveFlight (ostream &output);
16 extern bool fgLoadFlight (istream &input);
20 ////////////////////////////////////////////////////////////////////////
21 // Convenience functions for getting property values.
22 ////////////////////////////////////////////////////////////////////////
26 * Get a property node.
28 * @param path The path of the node, relative to root.
29 * @param create true to create the node if it doesn't exist.
31 inline SGPropertyNode *
32 fgGetNode (const string &path, bool create = false)
34 return globals->get_props()->getNode(path, create);
39 * Get an SGValue pointer that can be queried repeatedly.
41 * If the property value is going to be accessed within the loop,
42 * it is best to use this method for maximum efficiency.
45 fgGetValue (const string &name, bool create = false)
47 return globals->get_props()->getValue(name, create);
50 inline bool fgHasValue (const string &name)
52 return globals->get_props()->hasValue(name);
55 inline bool fgGetBool (const string &name, bool defaultValue = false)
57 return globals->get_props()->getBoolValue(name, defaultValue);
60 inline int fgGetInt (const string &name, int defaultValue = 0)
62 return globals->get_props()->getIntValue(name, defaultValue);
65 inline int fgGetLong (const string &name, long defaultValue = 0L)
67 return globals->get_props()->getLongValue(name, defaultValue);
70 inline float fgGetFloat (const string &name, float defaultValue = 0.0)
72 return globals->get_props()->getFloatValue(name, defaultValue);
75 inline double fgGetDouble (const string &name, double defaultValue = 0.0)
77 return globals->get_props()->getDoubleValue(name, defaultValue);
80 inline string fgGetString (const string &name, string defaultValue = "")
82 return globals->get_props()->getStringValue(name, defaultValue);
85 inline bool fgSetBool (const string &name, bool val)
87 return globals->get_props()->setBoolValue(name, val);
90 inline bool fgSetInt (const string &name, int val)
92 return globals->get_props()->setIntValue(name, val);
95 inline bool fgSetLong (const string &name, long val)
97 return globals->get_props()->setLongValue(name, val);
100 inline bool fgSetFloat (const string &name, float val)
102 return globals->get_props()->setFloatValue(name, val);
105 inline bool fgSetDouble (const string &name, double val)
107 return globals->get_props()->setDoubleValue(name, val);
110 inline bool fgSetString (const string &name, const string &val)
112 return globals->get_props()->setStringValue(name, val);
117 ////////////////////////////////////////////////////////////////////////
118 // Convenience functions for tying properties, with logging.
119 ////////////////////////////////////////////////////////////////////////
122 fgUntie (const string &name)
124 if (!globals->get_props()->untie(name))
125 SG_LOG(SG_GENERAL, SG_WARN, "Failed to untie property " << name);
129 // Templates cause ambiguity here
131 fgTie (const string &name, bool *pointer, bool useDefault = true)
133 if (!globals->get_props()->tie(name, SGRawValuePointer<bool>(pointer),
135 SG_LOG(SG_GENERAL, SG_WARN,
136 "Failed to tie property " << name << " to a pointer");
140 fgTie (const string &name, int *pointer, bool useDefault = true)
142 if (!globals->get_props()->tie(name, SGRawValuePointer<int>(pointer),
144 SG_LOG(SG_GENERAL, SG_WARN,
145 "Failed to tie property " << name << " to a pointer");
149 fgTie (const string &name, long *pointer, bool useDefault = true)
151 if (!globals->get_props()->tie(name, SGRawValuePointer<long>(pointer),
153 SG_LOG(SG_GENERAL, SG_WARN,
154 "Failed to tie property " << name << " to a pointer");
158 fgTie (const string &name, float *pointer, bool useDefault = true)
160 if (!globals->get_props()->tie(name, SGRawValuePointer<float>(pointer),
162 SG_LOG(SG_GENERAL, SG_WARN,
163 "Failed to tie property " << name << " to a pointer");
167 fgTie (const string &name, double *pointer, bool useDefault = true)
169 if (!globals->get_props()->tie(name, SGRawValuePointer<double>(pointer),
171 SG_LOG(SG_GENERAL, SG_WARN,
172 "Failed to tie property " << name << " to a pointer");
176 fgTie (const string &name, string *pointer, bool useDefault = true)
178 if (!globals->get_props()->tie(name, SGRawValuePointer<string>(pointer),
180 SG_LOG(SG_GENERAL, SG_WARN,
181 "Failed to tie property " << name << " to a pointer");
186 fgTie (const string &name, V (*getter)(), void (*setter)(V) = 0,
187 bool useDefault = true)
189 if (!globals->get_props()->tie(name, SGRawValueFunctions<V>(getter, setter),
191 SG_LOG(SG_GENERAL, SG_WARN,
192 "Failed to tie property " << name << " to functions");
197 fgTie (const string &name, int index, V (*getter)(int),
198 void (*setter)(int, V) = 0, bool useDefault = true)
200 if (!globals->get_props()->tie(name,
201 SGRawValueFunctionsIndexed<V>(index,
205 SG_LOG(SG_GENERAL, SG_WARN,
206 "Failed to tie property " << name << " to indexed functions");
209 template <class T, class V>
211 fgTie (const string &name, T * obj, V (T::*getter)() const,
212 void (T::*setter)(V) = 0, bool useDefault = true)
214 if (!globals->get_props()->tie(name,
215 SGRawValueMethods<T,V>(*obj, getter, setter),
217 SG_LOG(SG_GENERAL, SG_WARN,
218 "Failed to tie property " << name << " to object methods");
221 template <class T, class V>
223 fgTie (const string &name, T * obj, int index,
224 V (T::*getter)(int) const, void (T::*setter)(int, V) = 0,
225 bool useDefault = true)
227 if (!globals->get_props()->tie(name,
228 SGRawValueMethodsIndexed<T,V>(*obj,
233 SG_LOG(SG_GENERAL, SG_WARN,
234 "Failed to tie property " << name << " to indexed object methods");
238 #endif // __FG_PROPS_HXX