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 SG_LOG(SG_GENERAL, SG_WARN, "Failed to untie property " << name);
102 // Templates cause ambiguity here
104 fgTie (const string &name, bool *pointer, bool useDefault = true)
106 if (!globals->get_props()->tie(name, SGRawValuePointer<bool>(pointer),
108 SG_LOG(SG_GENERAL, SG_WARN,
109 "Failed to tie property " << name << " to a pointer");
113 fgTie (const string &name, int *pointer, bool useDefault = true)
115 if (!globals->get_props()->tie(name, SGRawValuePointer<int>(pointer),
117 SG_LOG(SG_GENERAL, SG_WARN,
118 "Failed to tie property " << name << " to a pointer");
122 fgTie (const string &name, float *pointer, bool useDefault = true)
124 if (!globals->get_props()->tie(name, SGRawValuePointer<float>(pointer),
126 SG_LOG(SG_GENERAL, SG_WARN,
127 "Failed to tie property " << name << " to a pointer");
131 fgTie (const string &name, double *pointer, bool useDefault = true)
133 if (!globals->get_props()->tie(name, SGRawValuePointer<double>(pointer),
135 SG_LOG(SG_GENERAL, SG_WARN,
136 "Failed to tie property " << name << " to a pointer");
140 fgTie (const string &name, string *pointer, bool useDefault = true)
142 if (!globals->get_props()->tie(name, SGRawValuePointer<string>(pointer),
144 SG_LOG(SG_GENERAL, SG_WARN,
145 "Failed to tie property " << name << " to a pointer");
150 fgTie (const string &name, V (*getter)(), void (*setter)(V) = 0,
151 bool useDefault = true)
153 if (!globals->get_props()->tie(name, SGRawValueFunctions<V>(getter, setter),
155 SG_LOG(SG_GENERAL, SG_WARN,
156 "Failed to tie property " << name << " to functions");
161 fgTie (const string &name, int index, V (*getter)(int),
162 void (*setter)(int, V) = 0, bool useDefault = true)
164 if (!globals->get_props()->tie(name,
165 SGRawValueFunctionsIndexed<V>(index,
169 SG_LOG(SG_GENERAL, SG_WARN,
170 "Failed to tie property " << name << " to indexed functions");
173 template <class T, class V>
175 fgTie (const string &name, T * obj, V (T::*getter)() const,
176 void (T::*setter)(V) = 0, bool useDefault = true)
178 if (!globals->get_props()->tie(name,
179 SGRawValueMethods<T,V>(*obj, getter, setter),
181 SG_LOG(SG_GENERAL, SG_WARN,
182 "Failed to tie property " << name << " to object methods");
185 template <class T, class V>
187 fgTie (const string &name, T * obj, int index,
188 V (T::*getter)(int) const, void (T::*setter)(int, V) = 0,
189 bool useDefault = true)
191 if (!globals->get_props()->tie(name,
192 SGRawValueMethodsIndexed<T,V>(*obj,
197 SG_LOG(SG_GENERAL, SG_WARN,
198 "Failed to tie property " << name << " to indexed object methods");
202 #endif // __FG_PROPS_HXX