]> git.mxchange.org Git - flightgear.git/blob - src/Main/fg_props.hxx
Minor tweaks.
[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 tying properties, with logging.
20 ////////////////////////////////////////////////////////////////////////
21
22 inline void
23 fgUntie (const string &name)
24 {
25   if (!globals->get_props()->untie(name))
26     FG_LOG(FG_GENERAL, FG_WARN, "Failed to untie property " << name);
27 }
28
29
30                                 // Templates cause ambiguity here
31 inline void
32 fgTie (const string &name, bool *pointer)
33 {
34   if (!globals->get_props()->tie(name, SGRawValuePointer<bool>(pointer)))
35     FG_LOG(FG_GENERAL, FG_WARN,
36            "Failed to tie property " << name << " to a pointer");
37 }
38
39 inline void
40 fgTie (const string &name, int *pointer)
41 {
42   if (!globals->get_props()->tie(name, SGRawValuePointer<int>(pointer)))
43     FG_LOG(FG_GENERAL, FG_WARN,
44            "Failed to tie property " << name << " to a pointer");
45 }
46
47 inline void
48 fgTie (const string &name, float *pointer)
49 {
50   if (!globals->get_props()->tie(name, SGRawValuePointer<float>(pointer)))
51     FG_LOG(FG_GENERAL, FG_WARN,
52            "Failed to tie property " << name << " to a pointer");
53 }
54
55 inline void
56 fgTie (const string &name, double *pointer)
57 {
58   if (!globals->get_props()->tie(name, SGRawValuePointer<double>(pointer)))
59     FG_LOG(FG_GENERAL, FG_WARN,
60            "Failed to tie property " << name << " to a pointer");
61 }
62
63 inline void
64 fgTie (const string &name, string *pointer)
65 {
66   if (!globals->get_props()->tie(name, SGRawValuePointer<string>(pointer)))
67     FG_LOG(FG_GENERAL, FG_WARN,
68            "Failed to tie property " << name << " to a pointer");
69 }
70
71 template <class V>
72 inline void
73 fgTie (const string &name, V (*getter)(), void (*setter)(V) = 0)
74 {
75   if (!globals->get_props()->tie(name, SGRawValueFunctions<V>(getter, setter)))
76     FG_LOG(FG_GENERAL, FG_WARN,
77            "Failed to tie property " << name << " to functions");
78 }
79
80 template <class V>
81 inline void
82 fgTie (const string &name, int index, V (*getter)(int),
83        void (*setter)(int, V) = 0)
84 {
85   if (!globals->get_props()->tie(name,
86                                  SGRawValueFunctionsIndexed<V>(index,
87                                                                getter,
88                                                                setter)))
89     FG_LOG(FG_GENERAL, FG_WARN,
90            "Failed to tie property " << name << " to indexed functions");
91 }
92
93 template <class T, class V>
94 inline void
95 fgTie (const string &name, T * obj, V (T::*getter)() const,
96        void (T::*setter)(V) = 0)
97 {
98   if (!globals->get_props()->tie(name,
99                                  SGRawValueMethods<T,V>(*obj, getter, setter)))
100     FG_LOG(FG_GENERAL, FG_WARN,
101            "Failed to tie property " << name << " to object methods");
102 }
103
104 template <class T, class V>
105 inline void 
106 fgTie (const string &name, T * obj, int index,
107        V (T::*getter)(int) const, void (T::*setter)(int, V) = 0)
108 {
109   if (!globals->get_props()->tie(name,
110                                  SGRawValueMethodsIndexed<T,V>(*obj,
111                                                                index,
112                                                                getter,
113                                                                setter)))
114     FG_LOG(FG_GENERAL, FG_WARN,
115            "Failed to tie property " << name << " to indexed object methods");
116 }
117
118
119 #endif // __FG_PROPS_HXX
120