1 | |
---|
2 | #ifndef _LOAD_PARAM_H |
---|
3 | #define _LOAD_PARAM_H |
---|
4 | |
---|
5 | #include "factory.h" |
---|
6 | #include "debug.h" |
---|
7 | #include "substring.h" |
---|
8 | |
---|
9 | // abstract base class |
---|
10 | class baseLoadParam |
---|
11 | { |
---|
12 | public: |
---|
13 | // virtual void Call(const char* string)=0; // call using function |
---|
14 | }; |
---|
15 | |
---|
16 | |
---|
17 | // derived template class |
---|
18 | template<class T> class LoadParam : public baseLoadParam |
---|
19 | { |
---|
20 | public: |
---|
21 | // 1. CONST CHAR* |
---|
22 | LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(const char*)) |
---|
23 | { |
---|
24 | const char* loadString = grabParameter(root, paramName); |
---|
25 | if (loadString != NULL) |
---|
26 | (*pt2Object.*function)(loadString); |
---|
27 | else |
---|
28 | PRINTF(2)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); |
---|
29 | }; |
---|
30 | |
---|
31 | // 2. CONST CHAR* |
---|
32 | LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(const char*, const char*)) |
---|
33 | { |
---|
34 | const char* loadString = grabParameter(root, paramName); |
---|
35 | if (loadString != NULL) |
---|
36 | { |
---|
37 | SubString subLoads(loadString); |
---|
38 | if (subLoads.getCount() == 2) |
---|
39 | (*pt2Object.*function)(subLoads.getString(0), subLoads.getString(1)); |
---|
40 | else |
---|
41 | PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", |
---|
42 | paramName, pt2Object->getClassName(), 2, subLoads.getCount()); |
---|
43 | } |
---|
44 | else |
---|
45 | PRINTF(2)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); |
---|
46 | }; |
---|
47 | |
---|
48 | // 3. CONST CHAR* |
---|
49 | LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(const char*, const char*, const char*)) |
---|
50 | { |
---|
51 | const char* loadString = grabParameter(root, paramName); |
---|
52 | if (loadString != NULL) |
---|
53 | { |
---|
54 | SubString subLoads(loadString); |
---|
55 | if (subLoads.getCount() == 3) |
---|
56 | (*pt2Object.*function)(subLoads.getString(0), subLoads.getString(1), subLoads.getString(2)); |
---|
57 | else |
---|
58 | PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", |
---|
59 | paramName, pt2Object->getClassName(), 3, subLoads.getCount()); |
---|
60 | } |
---|
61 | else |
---|
62 | PRINTF(2)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); |
---|
63 | }; |
---|
64 | |
---|
65 | // 4. CONST CHAR* |
---|
66 | LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(const char*, const char*, const char*, const char*)) |
---|
67 | { |
---|
68 | const char* loadString = grabParameter(root, paramName); |
---|
69 | if (loadString != NULL) |
---|
70 | { |
---|
71 | SubString subLoads(loadString); |
---|
72 | if (subLoads.getCount() == 4) |
---|
73 | (*pt2Object.*function)(subLoads.getString(0), subLoads.getString(1), subLoads.getString(2), subLoads.getString(3)); |
---|
74 | else |
---|
75 | PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", |
---|
76 | paramName, pt2Object->getClassName(), 4, subLoads.getCount()); |
---|
77 | } |
---|
78 | else |
---|
79 | PRINTF(2)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); |
---|
80 | }; |
---|
81 | |
---|
82 | // 1. FLOAT |
---|
83 | LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(float)) |
---|
84 | { |
---|
85 | const char* loadString = grabParameter(root, paramName); |
---|
86 | if (loadString != NULL) |
---|
87 | (*pt2Object.*function)(atof(loadString)); |
---|
88 | else |
---|
89 | PRINTF(2)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); |
---|
90 | }; |
---|
91 | |
---|
92 | // 2. FLOAT |
---|
93 | LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(float, float)) |
---|
94 | { |
---|
95 | const char* loadString = grabParameter(root, paramName); |
---|
96 | if (loadString != NULL) |
---|
97 | { |
---|
98 | SubString subLoads(loadString); |
---|
99 | if (subLoads.getCount() == 2) |
---|
100 | (*pt2Object.*function)(atof(subLoads.getString(0)), atof(subLoads.getString(1))); |
---|
101 | else |
---|
102 | PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", |
---|
103 | paramName, pt2Object->getClassName(), 2, subLoads.getCount()); |
---|
104 | |
---|
105 | } |
---|
106 | else |
---|
107 | PRINTF(2)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); |
---|
108 | }; |
---|
109 | |
---|
110 | // 3. FLOAT |
---|
111 | LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(float, float, float)) |
---|
112 | { |
---|
113 | const char* loadString = grabParameter(root, paramName); |
---|
114 | if (loadString != NULL) |
---|
115 | { |
---|
116 | SubString subLoads(loadString); |
---|
117 | if (subLoads.getCount() == 3) |
---|
118 | (*pt2Object.*function)(atof(subLoads.getString(0)), atof(subLoads.getString(1)), atof(subLoads.getString(2))); |
---|
119 | else |
---|
120 | PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", |
---|
121 | paramName, pt2Object->getClassName(), 3, subLoads.getCount()); |
---|
122 | } |
---|
123 | else |
---|
124 | PRINTF(2)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); |
---|
125 | }; |
---|
126 | |
---|
127 | // 4. FLOAT |
---|
128 | LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(float, float, float, float)) |
---|
129 | { |
---|
130 | const char* loadString = grabParameter(root, paramName); |
---|
131 | if (loadString != NULL) |
---|
132 | { |
---|
133 | SubString subLoads(loadString); |
---|
134 | if (subLoads.getCount() == 4) |
---|
135 | (*pt2Object.*function)(atof(subLoads.getString(0)), atof(subLoads.getString(1)), atof(subLoads.getString(2)), atof(subLoads.getString(3))); |
---|
136 | else |
---|
137 | PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", |
---|
138 | paramName, pt2Object->getClassName(), 4, subLoads.getCount()); |
---|
139 | |
---|
140 | } |
---|
141 | else |
---|
142 | PRINTF(2)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); |
---|
143 | }; |
---|
144 | |
---|
145 | // 1. INT |
---|
146 | LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(int)) |
---|
147 | { |
---|
148 | const char* loadString = grabParameter(root, paramName); |
---|
149 | if (loadString != NULL) |
---|
150 | (*pt2Object.*function)(atoi(loadString)); |
---|
151 | else |
---|
152 | PRINTF(2)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); |
---|
153 | }; |
---|
154 | |
---|
155 | // 2. INT |
---|
156 | LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(int, int)) |
---|
157 | { |
---|
158 | const char* loadString = grabParameter(root, paramName); |
---|
159 | if (loadString != NULL) |
---|
160 | { |
---|
161 | SubString subLoads(loadString); |
---|
162 | if (subLoads.getCount() == 2) |
---|
163 | (*pt2Object.*function)(atoi(subLoads.getString(0)), atoi(subLoads.getString(1))); |
---|
164 | else |
---|
165 | PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", |
---|
166 | paramName, pt2Object->getClassName(), 2, subLoads.getCount()); |
---|
167 | |
---|
168 | } |
---|
169 | else |
---|
170 | PRINTF(2)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); |
---|
171 | }; |
---|
172 | |
---|
173 | // 3. INT |
---|
174 | LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(int, int, int)) |
---|
175 | { |
---|
176 | const char* loadString = grabParameter(root, paramName); |
---|
177 | if (loadString != NULL) |
---|
178 | { |
---|
179 | SubString subLoads(loadString); |
---|
180 | if (subLoads.getCount() == 3) |
---|
181 | (*pt2Object.*function)(atoi(subLoads.getString(0)), atoi(subLoads.getString(1)), atoi(subLoads.getString(2))); |
---|
182 | else |
---|
183 | PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", |
---|
184 | paramName, pt2Object->getClassName(), 3, subLoads.getCount()); |
---|
185 | |
---|
186 | } |
---|
187 | else |
---|
188 | PRINTF(2)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); |
---|
189 | }; |
---|
190 | |
---|
191 | // 4. INT |
---|
192 | LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(int, int, int, int)) |
---|
193 | { |
---|
194 | const char* loadString = grabParameter(root, paramName); |
---|
195 | if (loadString != NULL) |
---|
196 | { |
---|
197 | SubString subLoads(loadString); |
---|
198 | if (subLoads.getCount() == 4) |
---|
199 | (*pt2Object.*function)(atoi(subLoads.getString(0)), atoi(subLoads.getString(1)), atoi(subLoads.getString(2)), atoi(subLoads.getString(3))); |
---|
200 | else |
---|
201 | PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", |
---|
202 | paramName, pt2Object->getClassName(), 4, subLoads.getCount()); |
---|
203 | } |
---|
204 | else |
---|
205 | PRINTF(2)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); |
---|
206 | }; |
---|
207 | |
---|
208 | }; |
---|
209 | |
---|
210 | |
---|
211 | #endif /* _LOAD_PARAM_H */ |
---|