]> git.mxchange.org Git - flightgear.git/blob - src/Main/fg_props.hxx
Fixed a problem with autodetecting if we need to draw our own mouse cursor
[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  * Get an SGValue pointer that can be queried repeatedly.
24  *
25  * If the property value is going to be accessed within the loop,
26  * it is best to use this method for maximum efficiency.
27  */
28 inline SGValue * fgGetValue (const string &name, bool create = false)
29 {
30   return globals->get_props()->getValue(name, create);
31 }
32
33 inline bool fgHasValue (const string &name)
34 {
35   return globals->get_props()->hasValue(name);
36 }
37
38 inline bool fgGetBool (const string &name, bool defaultValue = false)
39 {
40   return globals->get_props()->getBoolValue(name, defaultValue);
41 }
42
43 inline int fgGetInt (const string &name, int defaultValue = 0)
44 {
45   return globals->get_props()->getIntValue(name, defaultValue);
46 }
47
48 inline float fgGetFloat (const string &name, float defaultValue = 0.0)
49 {
50   return globals->get_props()->getFloatValue(name, defaultValue);
51 }
52
53 inline double fgGetDouble (const string &name, double defaultValue = 0.0)
54 {
55   return globals->get_props()->getDoubleValue(name, defaultValue);
56 }
57
58 inline string fgGetString (const string &name, string defaultValue = "")
59 {
60   return globals->get_props()->getStringValue(name, defaultValue);
61 }
62
63 inline bool fgSetBool (const string &name, bool val)
64 {
65   return globals->get_props()->setBoolValue(name, val);
66 }
67
68 inline bool fgSetInt (const string &name, int val)
69 {
70   return globals->get_props()->setIntValue(name, val);
71 }
72
73 inline bool fgSetFloat (const string &name, float val)
74 {
75   return globals->get_props()->setFloatValue(name, val);
76 }
77
78 inline bool fgSetDouble (const string &name, double val)
79 {
80   return globals->get_props()->setDoubleValue(name, val);
81 }
82
83 inline bool fgSetString (const string &name, const string &val)
84 {
85   return globals->get_props()->setStringValue(name, val);
86 }
87
88
89 \f
90 ////////////////////////////////////////////////////////////////////////
91 // Convenience functions for tying properties, with logging.
92 ////////////////////////////////////////////////////////////////////////
93
94 inline void
95 fgUntie (const string &name)
96 {
97   if (!globals->get_props()->untie(name))
98     FG_LOG(FG_GENERAL, FG_WARN, "Failed to untie property " << name);
99 }
100
101
102                                 // Templates cause ambiguity here
103 inline void
104 fgTie (const string &name, bool *pointer, bool useDefault = true)
105 {
106   if (!globals->get_props()->tie(name, SGRawValuePointer<bool>(pointer),
107                                  useDefault))
108     FG_LOG(FG_GENERAL, FG_WARN,
109            "Failed to tie property " << name << " to a pointer");
110 }
111
112 inline void
113 fgTie (const string &name, int *pointer, bool useDefault = true)
114 {
115   if (!globals->get_props()->tie(name, SGRawValuePointer<int>(pointer),
116                                  useDefault))
117     FG_LOG(FG_GENERAL, FG_WARN,
118            "Failed to tie property " << name << " to a pointer");
119 }
120
121 inline void
122 fgTie (const string &name, float *pointer, bool useDefault = true)
123 {
124   if (!globals->get_props()->tie(name, SGRawValuePointer<float>(pointer),
125                                  useDefault))
126     FG_LOG(FG_GENERAL, FG_WARN,
127            "Failed to tie property " << name << " to a pointer");
128 }
129
130 inline void
131 fgTie (const string &name, double *pointer, bool useDefault = true)
132 {
133   if (!globals->get_props()->tie(name, SGRawValuePointer<double>(pointer),
134                                  useDefault))
135     FG_LOG(FG_GENERAL, FG_WARN,
136            "Failed to tie property " << name << " to a pointer");
137 }
138
139 inline void
140 fgTie (const string &name, string *pointer, bool useDefault = true)
141 {
142   if (!globals->get_props()->tie(name, SGRawValuePointer<string>(pointer),
143                                  useDefault))
144     FG_LOG(FG_GENERAL, FG_WARN,
145            "Failed to tie property " << name << " to a pointer");
146 }
147
148 template <class V>
149 inline void
150 fgTie (const string &name, V (*getter)(), void (*setter)(V) = 0,
151        bool useDefault = true)
152 {
153   if (!globals->get_props()->tie(name, SGRawValueFunctions<V>(getter, setter),
154                                  useDefault))
155     FG_LOG(FG_GENERAL, FG_WARN,
156            "Failed to tie property " << name << " to functions");
157 }
158
159 template <class V>
160 inline void
161 fgTie (const string &name, int index, V (*getter)(int),
162        void (*setter)(int, V) = 0, bool useDefault = true)
163 {
164   if (!globals->get_props()->tie(name,
165                                  SGRawValueFunctionsIndexed<V>(index,
166                                                                getter,
167                                                                setter),
168                                  useDefault))
169     FG_LOG(FG_GENERAL, FG_WARN,
170            "Failed to tie property " << name << " to indexed functions");
171 }
172
173 template <class T, class V>
174 inline void
175 fgTie (const string &name, T * obj, V (T::*getter)() const,
176        void (T::*setter)(V) = 0, bool useDefault = true)
177 {
178   if (!globals->get_props()->tie(name,
179                                  SGRawValueMethods<T,V>(*obj, getter, setter),
180                                  useDefault))
181     FG_LOG(FG_GENERAL, FG_WARN,
182            "Failed to tie property " << name << " to object methods");
183 }
184
185 template <class T, class V>
186 inline void 
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)
190 {
191   if (!globals->get_props()->tie(name,
192                                  SGRawValueMethodsIndexed<T,V>(*obj,
193                                                                index,
194                                                                getter,
195                                                                setter),
196                                  useDefault))
197     FG_LOG(FG_GENERAL, FG_WARN,
198            "Failed to tie property " << name << " to indexed object methods");
199 }
200
201
202 #endif // __FG_PROPS_HXX
203