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 int fgGetLong (const string &name, long defaultValue = 0L)
50 return globals->get_props()->getLongValue(name, defaultValue);
53 inline float fgGetFloat (const string &name, float defaultValue = 0.0)
55 return globals->get_props()->getFloatValue(name, defaultValue);
58 inline double fgGetDouble (const string &name, double defaultValue = 0.0)
60 return globals->get_props()->getDoubleValue(name, defaultValue);
63 inline string fgGetString (const string &name, string defaultValue = "")
65 return globals->get_props()->getStringValue(name, defaultValue);
68 inline bool fgSetBool (const string &name, bool val)
70 return globals->get_props()->setBoolValue(name, val);
73 inline bool fgSetInt (const string &name, int val)
75 return globals->get_props()->setIntValue(name, val);
78 inline bool fgSetLong (const string &name, long val)
80 return globals->get_props()->setLongValue(name, val);
83 inline bool fgSetFloat (const string &name, float val)
85 return globals->get_props()->setFloatValue(name, val);
88 inline bool fgSetDouble (const string &name, double val)
90 return globals->get_props()->setDoubleValue(name, val);
93 inline bool fgSetString (const string &name, const string &val)
95 return globals->get_props()->setStringValue(name, val);
100 ////////////////////////////////////////////////////////////////////////
101 // Convenience functions for tying properties, with logging.
102 ////////////////////////////////////////////////////////////////////////
105 fgUntie (const string &name)
107 if (!globals->get_props()->untie(name))
108 SG_LOG(SG_GENERAL, SG_WARN, "Failed to untie property " << name);
112 // Templates cause ambiguity here
114 fgTie (const string &name, bool *pointer, bool useDefault = true)
116 if (!globals->get_props()->tie(name, SGRawValuePointer<bool>(pointer),
118 SG_LOG(SG_GENERAL, SG_WARN,
119 "Failed to tie property " << name << " to a pointer");
123 fgTie (const string &name, int *pointer, bool useDefault = true)
125 if (!globals->get_props()->tie(name, SGRawValuePointer<int>(pointer),
127 SG_LOG(SG_GENERAL, SG_WARN,
128 "Failed to tie property " << name << " to a pointer");
132 fgTie (const string &name, long *pointer, bool useDefault = true)
134 if (!globals->get_props()->tie(name, SGRawValuePointer<long>(pointer),
136 SG_LOG(SG_GENERAL, SG_WARN,
137 "Failed to tie property " << name << " to a pointer");
141 fgTie (const string &name, float *pointer, bool useDefault = true)
143 if (!globals->get_props()->tie(name, SGRawValuePointer<float>(pointer),
145 SG_LOG(SG_GENERAL, SG_WARN,
146 "Failed to tie property " << name << " to a pointer");
150 fgTie (const string &name, double *pointer, bool useDefault = true)
152 if (!globals->get_props()->tie(name, SGRawValuePointer<double>(pointer),
154 SG_LOG(SG_GENERAL, SG_WARN,
155 "Failed to tie property " << name << " to a pointer");
159 fgTie (const string &name, string *pointer, bool useDefault = true)
161 if (!globals->get_props()->tie(name, SGRawValuePointer<string>(pointer),
163 SG_LOG(SG_GENERAL, SG_WARN,
164 "Failed to tie property " << name << " to a pointer");
169 fgTie (const string &name, V (*getter)(), void (*setter)(V) = 0,
170 bool useDefault = true)
172 if (!globals->get_props()->tie(name, SGRawValueFunctions<V>(getter, setter),
174 SG_LOG(SG_GENERAL, SG_WARN,
175 "Failed to tie property " << name << " to functions");
180 fgTie (const string &name, int index, V (*getter)(int),
181 void (*setter)(int, V) = 0, bool useDefault = true)
183 if (!globals->get_props()->tie(name,
184 SGRawValueFunctionsIndexed<V>(index,
188 SG_LOG(SG_GENERAL, SG_WARN,
189 "Failed to tie property " << name << " to indexed functions");
192 template <class T, class V>
194 fgTie (const string &name, T * obj, V (T::*getter)() const,
195 void (T::*setter)(V) = 0, bool useDefault = true)
197 if (!globals->get_props()->tie(name,
198 SGRawValueMethods<T,V>(*obj, getter, setter),
200 SG_LOG(SG_GENERAL, SG_WARN,
201 "Failed to tie property " << name << " to object methods");
204 template <class T, class V>
206 fgTie (const string &name, T * obj, int index,
207 V (T::*getter)(int) const, void (T::*setter)(int, V) = 0,
208 bool useDefault = true)
210 if (!globals->get_props()->tie(name,
211 SGRawValueMethodsIndexed<T,V>(*obj,
216 SG_LOG(SG_GENERAL, SG_WARN,
217 "Failed to tie property " << name << " to indexed object methods");
221 #endif // __FG_PROPS_HXX