1 #ifndef MSP_DATAFILE_LOADERACTION_H_
2 #define MSP_DATAFILE_LOADERACTION_H_
12 Base class for loader actions.
19 virtual ~LoaderAction() { }
21 /** Called to process a statement. */
22 virtual void execute(Loader &, const Statement &) const = 0;
24 virtual std::string get_signature() const = 0;
29 Loads a statement by calling a function that takes no arguments.
32 class LoaderFunc0: public LoaderAction
35 typedef void (L::*FuncType)();
40 LoaderFunc0(FuncType f): func(f) { }
42 virtual void execute(Loader &l, const Statement &) const
44 (dynamic_cast<L &>(l).*func)();
47 virtual std::string get_signature() const
48 { return std::string(); }
53 Loads a statement by calling a function that takes one argument.
55 template<typename L, typename A0>
56 class LoaderFunc1: public LoaderAction
59 typedef void (L::*FuncType)(A0);
64 LoaderFunc1(FuncType f): func(f) { }
66 virtual void execute(Loader &l, const Statement &st) const
68 (dynamic_cast<L &>(l).*func)(st.args[0].get<A0>());
71 virtual std::string get_signature() const
72 { return std::string(1, TypeInfo<A0>::signature); }
77 Loads a statement by calling a function that takes an array of values.
79 template<typename L, typename A0>
80 class LoaderFunc1<L, const std::vector<A0> &>: public LoaderAction
83 typedef void (L::*FuncType)(const std::vector<A0> &);
88 LoaderFunc1(FuncType f): func(f) { }
90 virtual void execute(Loader &l, const Statement &st) const
92 std::vector<A0> values;
93 values.reserve(st.args.size());
94 for(Statement::Arguments::const_iterator i=st.args.begin(); i!=st.args.end(); ++i)
95 values.push_back(i->get<A0>());
96 (dynamic_cast<L &>(l).*func)(values);
99 virtual std::string get_signature() const
102 result += TypeInfo<A0>::signature;
110 Loads a statement by calling a function with the statement itself as argument.
113 class LoaderFunc1<L, const Statement &>: public LoaderAction
116 typedef void (L::*FuncType)(const Statement &);
121 LoaderFunc1(FuncType f): func(f) { }
123 virtual void execute(Loader &l, const Statement &st) const
125 (dynamic_cast<L &>(l).*func)(st);
128 virtual std::string get_signature() const
133 template<typename L, typename A0, typename A1>
134 class LoaderFunc2: public LoaderAction
137 typedef void (L::*FuncType)(A0, A1);
142 LoaderFunc2(FuncType f): func(f) { }
144 virtual void execute(Loader &l, const Statement &st) const
146 (dynamic_cast<L &>(l).*func)(st.args[0].get<A0>(), st.args[1].get<A1>());
149 virtual std::string get_signature() const
152 result += TypeInfo<A0>::signature;
153 result += TypeInfo<A1>::signature;
159 template<typename L, typename A0, typename A1, typename A2>
160 class LoaderFunc3: public LoaderAction
163 typedef void (L::*FuncType)(A0, A1, A2);
168 LoaderFunc3(FuncType f): func(f) { }
170 virtual void execute(Loader &l, const Statement &st) const
172 (dynamic_cast<L &>(l).*func)(st.args[0].get<A0>(), st.args[1].get<A1>(), st.args[2].get<A2>());
175 virtual std::string get_signature() const
178 result += TypeInfo<A0>::signature;
179 result += TypeInfo<A1>::signature;
180 result += TypeInfo<A2>::signature;
186 template<typename L, typename A0, typename A1, typename A2, typename A3>
187 class LoaderFunc4: public LoaderAction
190 typedef void (L::*FuncType)(A0, A1, A2, A3);
195 LoaderFunc4(FuncType f): func(f) { }
197 virtual void execute(Loader &l, const Statement &st) const
199 (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>());
202 virtual std::string get_signature() const
205 result += TypeInfo<A0>::signature;
206 result += TypeInfo<A1>::signature;
207 result += TypeInfo<A2>::signature;
208 result += TypeInfo<A3>::signature;
214 template<typename L, typename A0, typename A1, typename A2, typename A3, typename A4>
215 class LoaderFunc5: public LoaderAction
218 typedef void (L::*FuncType)(A0, A1, A2, A3, A4);
223 LoaderFunc5(FuncType f): func(f) { }
225 virtual void execute(Loader &l, const Statement &st) const
227 (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>());
230 virtual std::string get_signature() const
233 result += TypeInfo<A0>::signature;
234 result += TypeInfo<A1>::signature;
235 result += TypeInfo<A2>::signature;
236 result += TypeInfo<A3>::signature;
237 result += TypeInfo<A4>::signature;
243 template<typename L, typename T0>
244 class LoadValue1: public LoaderAction
247 typedef T0 L::*Pointer0Type;
252 LoadValue1(Pointer0Type p0): ptr0(p0) { }
254 virtual void execute(Loader &l, const Statement &st) const
256 dynamic_cast<typename L::Loader &>(l).get_object().*ptr0 = st.args[0].get<T0>();
259 virtual std::string get_signature() const
260 { return std::string(1, TypeInfo<T0>::signature); }
264 template<typename L, typename T0>
265 class LoadValue1<L, T0 *>: public LoaderAction
268 typedef T0 *L::*Pointer0Type;
273 LoadValue1(Pointer0Type p0): ptr0(p0) { }
275 virtual void execute(Loader &l, const Statement &st) const
277 typename L::Loader &ldr = dynamic_cast<typename L::Loader &>(l);
278 ldr.get_object().*ptr0 = &ldr.get_collection().template get<T0>(st.args[0].get<std::string>());
281 virtual std::string get_signature() const
282 { return std::string(1, TypeInfo<std::string>::signature); }
286 template<typename L, typename T0, typename T1>
287 class LoadValue2: public LoaderAction
290 typedef T0 L::*Pointer0Type;
291 typedef T1 L::*Pointer1Type;
297 LoadValue2(Pointer0Type p0, Pointer1Type p1): ptr0(p0), ptr1(p1) { }
299 virtual void execute(Loader &l, const Statement &st) const
301 dynamic_cast<typename L::Loader &>(l).get_object().*ptr0 = st.args[0].get<T0>();
302 dynamic_cast<typename L::Loader &>(l).get_object().*ptr1 = st.args[1].get<T1>();
305 virtual std::string get_signature() const
308 result += TypeInfo<T0>::signature;
309 result += TypeInfo<T1>::signature;
314 } // namespace DataFile