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 ////////////////////////////////////////////////////////////////////////
24 * Get a property node.
26 * @param path The path of the node, relative to root.
27 * @param create true to create the node if it doesn't exist.
29 inline SGPropertyNode *
30 fgGetNode (const string &path, bool create = false)
32 return globals->get_props()->getNode(path, create);
37 * Get an SGValue pointer that can be queried repeatedly.
39 * If the property value is going to be accessed within the loop,
40 * it is best to use this method for maximum efficiency.
43 fgGetValue (const string &name, bool create = false)
45 return globals->get_props()->getValue(name, create);
48 inline bool fgHasValue (const string &name)
50 return globals->get_props()->hasValue(name);
53 inline bool fgGetBool (const string &name, bool defaultValue = false)
55 return globals->get_props()->getBoolValue(name, defaultValue);
58 inline int fgGetInt (const string &name, int defaultValue = 0)
60 return globals->get_props()->getIntValue(name, defaultValue);
63 inline int fgGetLong (const string &name, long defaultValue = 0L)
65 return globals->get_props()->getLongValue(name, defaultValue);
68 inline float fgGetFloat (const string &name, float defaultValue = 0.0)
70 return globals->get_props()->getFloatValue(name, defaultValue);
73 inline double fgGetDouble (const string &name, double defaultValue = 0.0)
75 return globals->get_props()->getDoubleValue(name, defaultValue);
78 inline string fgGetString (const string &name, string defaultValue = "")
80 return globals->get_props()->getStringValue(name, defaultValue);
83 inline bool fgSetBool (const string &name, bool val)
85 return globals->get_props()->setBoolValue(name, val);
88 inline bool fgSetInt (const string &name, int val)
90 return globals->get_props()->setIntValue(name, val);
93 inline bool fgSetLong (const string &name, long val)
95 return globals->get_props()->setLongValue(name, val);
98 inline bool fgSetFloat (const string &name, float val)
100 return globals->get_props()->setFloatValue(name, val);
103 inline bool fgSetDouble (const string &name, double val)
105 return globals->get_props()->setDoubleValue(name, val);
108 inline bool fgSetString (const string &name, const string &val)
110 return globals->get_props()->setStringValue(name, val);
115 ////////////////////////////////////////////////////////////////////////
116 // Convenience functions for tying properties, with logging.
117 ////////////////////////////////////////////////////////////////////////
120 fgUntie (const string &name)
122 if (!globals->get_props()->untie(name))
123 SG_LOG(SG_GENERAL, SG_WARN, "Failed to untie property " << name);
127 // Templates cause ambiguity here
129 fgTie (const string &name, bool *pointer, bool useDefault = true)
131 if (!globals->get_props()->tie(name, SGRawValuePointer<bool>(pointer),
133 SG_LOG(SG_GENERAL, SG_WARN,
134 "Failed to tie property " << name << " to a pointer");
138 fgTie (const string &name, int *pointer, bool useDefault = true)
140 if (!globals->get_props()->tie(name, SGRawValuePointer<int>(pointer),
142 SG_LOG(SG_GENERAL, SG_WARN,
143 "Failed to tie property " << name << " to a pointer");
147 fgTie (const string &name, long *pointer, bool useDefault = true)
149 if (!globals->get_props()->tie(name, SGRawValuePointer<long>(pointer),
151 SG_LOG(SG_GENERAL, SG_WARN,
152 "Failed to tie property " << name << " to a pointer");
156 fgTie (const string &name, float *pointer, bool useDefault = true)
158 if (!globals->get_props()->tie(name, SGRawValuePointer<float>(pointer),
160 SG_LOG(SG_GENERAL, SG_WARN,
161 "Failed to tie property " << name << " to a pointer");
165 fgTie (const string &name, double *pointer, bool useDefault = true)
167 if (!globals->get_props()->tie(name, SGRawValuePointer<double>(pointer),
169 SG_LOG(SG_GENERAL, SG_WARN,
170 "Failed to tie property " << name << " to a pointer");
174 fgTie (const string &name, string *pointer, bool useDefault = true)
176 if (!globals->get_props()->tie(name, SGRawValuePointer<string>(pointer),
178 SG_LOG(SG_GENERAL, SG_WARN,
179 "Failed to tie property " << name << " to a pointer");
184 fgTie (const string &name, V (*getter)(), void (*setter)(V) = 0,
185 bool useDefault = true)
187 if (!globals->get_props()->tie(name, SGRawValueFunctions<V>(getter, setter),
189 SG_LOG(SG_GENERAL, SG_WARN,
190 "Failed to tie property " << name << " to functions");
195 fgTie (const string &name, int index, V (*getter)(int),
196 void (*setter)(int, V) = 0, bool useDefault = true)
198 if (!globals->get_props()->tie(name,
199 SGRawValueFunctionsIndexed<V>(index,
203 SG_LOG(SG_GENERAL, SG_WARN,
204 "Failed to tie property " << name << " to indexed functions");
207 template <class T, class V>
209 fgTie (const string &name, T * obj, V (T::*getter)() const,
210 void (T::*setter)(V) = 0, bool useDefault = true)
212 if (!globals->get_props()->tie(name,
213 SGRawValueMethods<T,V>(*obj, getter, setter),
215 SG_LOG(SG_GENERAL, SG_WARN,
216 "Failed to tie property " << name << " to object methods");
219 template <class T, class V>
221 fgTie (const string &name, T * obj, int index,
222 V (T::*getter)(int) const, void (T::*setter)(int, V) = 0,
223 bool useDefault = true)
225 if (!globals->get_props()->tie(name,
226 SGRawValueMethodsIndexed<T,V>(*obj,
231 SG_LOG(SG_GENERAL, SG_WARN,
232 "Failed to tie property " << name << " to indexed object methods");
236 #endif // __FG_PROPS_HXX