1 #ifndef MSP_DATAFILE_LOADERACTION_H_
2 #define MSP_DATAFILE_LOADERACTION_H_
13 Base class for loader actions.
20 virtual ~LoaderAction() { }
22 /** Called to process a statement. */
23 virtual void execute(Loader &, const Statement &) const = 0;
25 virtual std::string get_signature() const = 0;
30 Loads a statement by calling a function that takes no arguments.
33 class LoaderFunc0: public LoaderAction
36 typedef void (L::*FuncType)();
41 LoaderFunc0(FuncType f): func(f) { }
43 virtual void execute(Loader &l, const Statement &) const
45 (dynamic_cast<L &>(l).*func)();
48 virtual std::string get_signature() const
49 { return std::string(); }
54 Loads a statement by calling a function that takes one argument.
56 template<typename L, typename A0>
57 class LoaderFunc1: public LoaderAction
60 typedef void (L::*FuncType)(A0);
65 LoaderFunc1(FuncType f): func(f) { }
67 virtual void execute(Loader &l, const Statement &st) const
69 (dynamic_cast<L &>(l).*func)(st.args[0].get<A0>());
72 virtual std::string get_signature() const
73 { return std::string(1, TypeInfo<A0>::signature); }
78 Loads a statement by calling a function that takes an array of values.
80 template<typename L, typename A0>
81 class LoaderFunc1<L, const std::vector<A0> &>: public LoaderAction
84 typedef void (L::*FuncType)(const std::vector<A0> &);
89 LoaderFunc1(FuncType f): func(f) { }
91 virtual void execute(Loader &l, const Statement &st) const
93 std::vector<A0> values;
94 values.reserve(st.args.size());
95 for(Statement::Arguments::const_iterator i=st.args.begin(); i!=st.args.end(); ++i)
96 values.push_back(i->get<A0>());
97 (dynamic_cast<L &>(l).*func)(values);
100 virtual std::string get_signature() const
103 result += TypeInfo<A0>::signature;
111 Loads a statement by calling a function with the statement itself as argument.
114 class LoaderFunc1<L, const Statement &>: public LoaderAction
117 typedef void (L::*FuncType)(const Statement &);
122 LoaderFunc1(FuncType f): func(f) { }
124 virtual void execute(Loader &l, const Statement &st) const
126 (dynamic_cast<L &>(l).*func)(st);
129 virtual std::string get_signature() const
134 template<typename L, typename A0, typename A1>
135 class LoaderFunc2: public LoaderAction
138 typedef void (L::*FuncType)(A0, A1);
143 LoaderFunc2(FuncType f): func(f) { }
145 virtual void execute(Loader &l, const Statement &st) const
147 (dynamic_cast<L &>(l).*func)(st.args[0].get<A0>(), st.args[1].get<A1>());
150 virtual std::string get_signature() const
153 result += TypeInfo<A0>::signature;
154 result += TypeInfo<A1>::signature;
160 template<typename L, typename A0, typename A1, typename A2>
161 class LoaderFunc3: public LoaderAction
164 typedef void (L::*FuncType)(A0, A1, A2);
169 LoaderFunc3(FuncType f): func(f) { }
171 virtual void execute(Loader &l, const Statement &st) const
173 (dynamic_cast<L &>(l).*func)(st.args[0].get<A0>(), st.args[1].get<A1>(), st.args[2].get<A2>());
176 virtual std::string get_signature() const
179 result += TypeInfo<A0>::signature;
180 result += TypeInfo<A1>::signature;
181 result += TypeInfo<A2>::signature;
187 template<typename L, typename A0, typename A1, typename A2, typename A3>
188 class LoaderFunc4: public LoaderAction
191 typedef void (L::*FuncType)(A0, A1, A2, A3);
196 LoaderFunc4(FuncType f): func(f) { }
198 virtual void execute(Loader &l, const Statement &st) const
200 (dynamic_cast<L &>(l).*func)(st.args[0].get<A0>(), st.args[1].get<A1>(), st.args[2].get<A2>(), st.args[3].get<A3>());
203 virtual std::string get_signature() const
206 result += TypeInfo<A0>::signature;
207 result += TypeInfo<A1>::signature;
208 result += TypeInfo<A2>::signature;
209 result += TypeInfo<A3>::signature;
215 template<typename L, typename A0, typename A1, typename A2, typename A3, typename A4>
216 class LoaderFunc5: public LoaderAction
219 typedef void (L::*FuncType)(A0, A1, A2, A3, A4);
224 LoaderFunc5(FuncType f): func(f) { }
226 virtual void execute(Loader &l, const Statement &st) const
228 (dynamic_cast<L &>(l).*func)(st.args[0].get<A0>(), st.args[1].get<A1>(), st.args[2].get<A2>(), st.args[3].get<A3>(), st.args[4].get<A4>());
231 virtual std::string get_signature() const
234 result += TypeInfo<A0>::signature;
235 result += TypeInfo<A1>::signature;
236 result += TypeInfo<A2>::signature;
237 result += TypeInfo<A3>::signature;
238 result += TypeInfo<A4>::signature;
244 template<typename L, typename T0>
245 class LoadValue1: public LoaderAction
248 typedef T0 L::*Pointer0Type;
253 LoadValue1(Pointer0Type p0): ptr0(p0) { }
255 virtual void execute(Loader &l, const Statement &st) const
257 dynamic_cast<typename L::Loader &>(l).get_object().*ptr0 = st.args[0].get<T0>();
260 virtual std::string get_signature() const
261 { return std::string(1, TypeInfo<T0>::signature); }
265 template<typename L, typename T0>
266 class LoadValue1<L, T0 *>: public LoaderAction
269 typedef T0 *L::*Pointer0Type;
274 LoadValue1(Pointer0Type p0): ptr0(p0) { }
276 virtual void execute(Loader &l, const Statement &st) const
278 typename L::Loader &ldr = dynamic_cast<typename L::Loader &>(l);
279 ldr.get_object().*ptr0 = ldr.get_collection().template get<T0>(st.args[0].get<std::string>());
282 virtual std::string get_signature() const
283 { return std::string(1, TypeInfo<std::string>::signature); }
287 template<typename L, typename T0, typename T1>
288 class LoadValue2: public LoaderAction
291 typedef T0 L::*Pointer0Type;
292 typedef T1 L::*Pointer1Type;
298 LoadValue2(Pointer0Type p0, Pointer1Type p1): ptr0(p0), ptr1(p1) { }
300 virtual void execute(Loader &l, const Statement &st) const
302 dynamic_cast<typename L::Loader &>(l).get_object().*ptr0 = st.args[0].get<T0>();
303 dynamic_cast<typename L::Loader &>(l).get_object().*ptr1 = st.args[1].get<T1>();
306 virtual std::string get_signature() const
309 result += TypeInfo<T0>::signature;
310 result += TypeInfo<T1>::signature;
315 } // namespace DataFile