]> git.mxchange.org Git - flightgear.git/blob - src/Main/fg_props.hxx
- removed unused reference to bfi.hxx
[flightgear.git] / src / Main / fg_props.hxx
1 #ifndef __FG_PROPS_HXX
2 #define __FG_PROPS_HXX 1
3
4 #include <simgear/debug/logstream.hxx>
5 #include <simgear/misc/props.hxx>
6 #include "globals.hxx"
7
8 \f
9 ////////////////////////////////////////////////////////////////////////
10 // Loading and saving properties.
11 ////////////////////////////////////////////////////////////////////////
12
13 extern bool fgSaveFlight (ostream &output);
14 extern bool fgLoadFlight (istream &input);
15
16
17 \f
18 ////////////////////////////////////////////////////////////////////////
19 // Convenience functions for getting property values.
20 ////////////////////////////////////////////////////////////////////////
21
22
23 /**
24  * Get a property node.
25  *
26  * @param path The path of the node, relative to root.
27  * @param create true to create the node if it doesn't exist.
28  */
29 inline SGPropertyNode * 
30 fgGetNode (const string &path, bool create = false)
31 {
32   return globals->get_props()->getNode(path, create);
33 }
34
35
36 /**
37  * Get an SGValue pointer that can be queried repeatedly.
38  *
39  * If the property value is going to be accessed within the loop,
40  * it is best to use this method for maximum efficiency.
41  */
42 inline SGValue * 
43 fgGetValue (const string &name, bool create = false)
44 {
45   return globals->get_props()->getValue(name, create);
46 }
47
48 inline bool fgHasValue (const string &name)
49 {
50   return globals->get_props()->hasValue(name);
51 }
52
53 inline bool fgGetBool (const string &name, bool defaultValue = false)
54 {
55   return globals->get_props()->getBoolValue(name, defaultValue);
56 }
57
58 inline int fgGetInt (const string &name, int defaultValue = 0)
59 {
60   return globals->get_props()->getIntValue(name, defaultValue);
61 }
62
63 inline int fgGetLong (const string &name, long defaultValue = 0L)
64 {
65   return globals->get_props()->getLongValue(name, defaultValue);
66 }
67
68 inline float fgGetFloat (const string &name, float defaultValue = 0.0)
69 {
70   return globals->get_props()->getFloatValue(name, defaultValue);
71 }
72
73 inline double fgGetDouble (const string &name, double defaultValue = 0.0)
74 {
75   return globals->get_props()->getDoubleValue(name, defaultValue);
76 }
77
78 inline string fgGetString (const string &name, string defaultValue = "")
79 {
80   return globals->get_props()->getStringValue(name, defaultValue);
81 }
82
83 inline bool fgSetBool (const string &name, bool val)
84 {
85   return globals->get_props()->setBoolValue(name, val);
86 }
87
88 inline bool fgSetInt (const string &name, int val)
89 {
90   return globals->get_props()->setIntValue(name, val);
91 }
92
93 inline bool fgSetLong (const string &name, long val)
94 {
95   return globals->get_props()->setLongValue(name, val);
96 }
97
98 inline bool fgSetFloat (const string &name, float val)
99 {
100   return globals->get_props()->setFloatValue(name, val);
101 }
102
103 inline bool fgSetDouble (const string &name, double val)
104 {
105   return globals->get_props()->setDoubleValue(name, val);
106 }
107
108 inline bool fgSetString (const string &name, const string &val)
109 {
110   return globals->get_props()->setStringValue(name, val);
111 }
112
113
114 \f
115 ////////////////////////////////////////////////////////////////////////
116 // Convenience functions for tying properties, with logging.
117 ////////////////////////////////////////////////////////////////////////
118
119 inline void
120 fgUntie (const string &name)
121 {
122   if (!globals->get_props()->untie(name))
123     SG_LOG(SG_GENERAL, SG_WARN, "Failed to untie property " << name);
124 }
125
126
127                                 // Templates cause ambiguity here
128 inline void
129 fgTie (const string &name, bool *pointer, bool useDefault = true)
130 {
131   if (!globals->get_props()->tie(name, SGRawValuePointer<bool>(pointer),
132                                  useDefault))
133     SG_LOG(SG_GENERAL, SG_WARN,
134            "Failed to tie property " << name << " to a pointer");
135 }
136
137 inline void
138 fgTie (const string &name, int *pointer, bool useDefault = true)
139 {
140   if (!globals->get_props()->tie(name, SGRawValuePointer<int>(pointer),
141                                  useDefault))
142     SG_LOG(SG_GENERAL, SG_WARN,
143            "Failed to tie property " << name << " to a pointer");
144 }
145
146 inline void
147 fgTie (const string &name, long *pointer, bool useDefault = true)
148 {
149   if (!globals->get_props()->tie(name, SGRawValuePointer<long>(pointer),
150                                  useDefault))
151     SG_LOG(SG_GENERAL, SG_WARN,
152            "Failed to tie property " << name << " to a pointer");
153 }
154
155 inline void
156 fgTie (const string &name, float *pointer, bool useDefault = true)
157 {
158   if (!globals->get_props()->tie(name, SGRawValuePointer<float>(pointer),
159                                  useDefault))
160     SG_LOG(SG_GENERAL, SG_WARN,
161            "Failed to tie property " << name << " to a pointer");
162 }
163
164 inline void
165 fgTie (const string &name, double *pointer, bool useDefault = true)
166 {
167   if (!globals->get_props()->tie(name, SGRawValuePointer<double>(pointer),
168                                  useDefault))
169     SG_LOG(SG_GENERAL, SG_WARN,
170            "Failed to tie property " << name << " to a pointer");
171 }
172
173 inline void
174 fgTie (const string &name, string *pointer, bool useDefault = true)
175 {
176   if (!globals->get_props()->tie(name, SGRawValuePointer<string>(pointer),
177                                  useDefault))
178     SG_LOG(SG_GENERAL, SG_WARN,
179            "Failed to tie property " << name << " to a pointer");
180 }
181
182 template <class V>
183 inline void
184 fgTie (const string &name, V (*getter)(), void (*setter)(V) = 0,
185        bool useDefault = true)
186 {
187   if (!globals->get_props()->tie(name, SGRawValueFunctions<V>(getter, setter),
188                                  useDefault))
189     SG_LOG(SG_GENERAL, SG_WARN,
190            "Failed to tie property " << name << " to functions");
191 }
192
193 template <class V>
194 inline void
195 fgTie (const string &name, int index, V (*getter)(int),
196        void (*setter)(int, V) = 0, bool useDefault = true)
197 {
198   if (!globals->get_props()->tie(name,
199                                  SGRawValueFunctionsIndexed<V>(index,
200                                                                getter,
201                                                                setter),
202                                  useDefault))
203     SG_LOG(SG_GENERAL, SG_WARN,
204            "Failed to tie property " << name << " to indexed functions");
205 }
206
207 template <class T, class V>
208 inline void
209 fgTie (const string &name, T * obj, V (T::*getter)() const,
210        void (T::*setter)(V) = 0, bool useDefault = true)
211 {
212   if (!globals->get_props()->tie(name,
213                                  SGRawValueMethods<T,V>(*obj, getter, setter),
214                                  useDefault))
215     SG_LOG(SG_GENERAL, SG_WARN,
216            "Failed to tie property " << name << " to object methods");
217 }
218
219 template <class T, class V>
220 inline void 
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)
224 {
225   if (!globals->get_props()->tie(name,
226                                  SGRawValueMethodsIndexed<T,V>(*obj,
227                                                                index,
228                                                                getter,
229                                                                setter),
230                                  useDefault))
231     SG_LOG(SG_GENERAL, SG_WARN,
232            "Failed to tie property " << name << " to indexed object methods");
233 }
234
235
236 #endif // __FG_PROPS_HXX
237