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