X-Git-Url: http://git.tdb.fi/?p=libs%2Fdatafile.git;a=blobdiff_plain;f=source%2Floaderaction.h;h=6eebeccc76f47c8144fac9f5ceeb93a35dff0a93;hp=972757bd399fbc953cd65100567eca343cf99d7b;hb=215e719d0ef85f748898660d15d01e77ac551de9;hpb=a582163d380833b1370ba067a1fd0ad5c2984723 diff --git a/source/loaderaction.h b/source/loaderaction.h index 972757b..6eebecc 100644 --- a/source/loaderaction.h +++ b/source/loaderaction.h @@ -21,14 +21,13 @@ Base class for loader actions. */ class LoaderAction { -public: - /** - Called when a statement is to be loaded. - */ - virtual void execute(Loader &, const Statement &) const=0; - virtual ~LoaderAction() { } protected: LoaderAction() { } +public: + virtual ~LoaderAction() { } + + /** Called to process a statement. */ + virtual void execute(Loader &, const Statement &) const = 0; }; @@ -38,17 +37,19 @@ Loads a statement by calling a function that takes no arguments. template class LoaderFunc0: public LoaderAction { -public: +private: typedef void (L::*FuncType)(); + FuncType func; + +public: LoaderFunc0(FuncType f): func(f) { } - void execute(Loader &l, const Statement &st) const + + virtual void execute(Loader &l, const Statement &st) const { if(st.args.size()!=0) throw TypeError("Wrong number of arguments"); (dynamic_cast(l).*func)(); }; -private: - FuncType func; }; @@ -58,17 +59,19 @@ Loads a statement by calling a function that takes one argument. template class LoaderFunc1: public LoaderAction { -public: +private: typedef void (L::*FuncType)(A0); + FuncType func; + +public: LoaderFunc1(FuncType f): func(f) { } - void execute(Loader &l, const Statement &st) const + + virtual void execute(Loader &l, const Statement &st) const { if(st.args.size()!=1) throw TypeError("Wrong number of arguments"); (dynamic_cast(l).*func)(st.args[0].get()); } -private: - FuncType func; }; @@ -78,11 +81,15 @@ Loads a statement by calling a function that takes an array of values. template class LoaderFunc1 &>: public LoaderAction { -public: +private: typedef void (L::*FuncType)(const std::vector &); + FuncType func; + +public: LoaderFunc1(FuncType f): func(f) { } - void execute(Loader &l, const Statement &st) const + + virtual void execute(Loader &l, const Statement &st) const { std::vector values; values.reserve(st.args.size()); @@ -90,8 +97,6 @@ public: values.push_back(i->get()); (dynamic_cast(l).*func)(values); } -private: - FuncType func; }; @@ -101,139 +106,155 @@ Loads a statement by calling a function with the statement itself as argument. template class LoaderFunc1: public LoaderAction { -public: +private: typedef void (L::*FuncType)(const Statement &); + FuncType func; + +public: LoaderFunc1(FuncType f): func(f) { } - void execute(Loader &l, const Statement &st) const + + virtual void execute(Loader &l, const Statement &st) const { (dynamic_cast(l).*func)(st); } -private: - FuncType func; }; template class LoaderFunc2: public LoaderAction { -public: +private: typedef void (L::*FuncType)(A0, A1); + FuncType func; + +public: LoaderFunc2(FuncType f): func(f) { } - void execute(Loader &l, const Statement &st) const + + virtual void execute(Loader &l, const Statement &st) const { if(st.args.size()!=2) throw TypeError("Wrong number of arguments"); (dynamic_cast(l).*func)(st.args[0].get(), st.args[1].get()); } -private: - FuncType func; }; template class LoaderFunc3: public LoaderAction { -public: +private: typedef void (L::*FuncType)(A0, A1, A2); + FuncType func; + +public: LoaderFunc3(FuncType f): func(f) { } - void execute(Loader &l, const Statement &st) const + + virtual void execute(Loader &l, const Statement &st) const { if(st.args.size()!=3) throw TypeError("Wrong number of arguments"); (dynamic_cast(l).*func)(st.args[0].get(), st.args[1].get(), st.args[2].get()); } -private: - FuncType func; }; template class LoaderFunc4: public LoaderAction { -public: +private: typedef void (L::*FuncType)(A0, A1, A2, A3); + FuncType func; + +public: LoaderFunc4(FuncType f): func(f) { } - void execute(Loader &l, const Statement &st) const + + virtual void execute(Loader &l, const Statement &st) const { if(st.args.size()!=4) throw TypeError("Wrong number of arguments"); (dynamic_cast(l).*func)(st.args[0].get(), st.args[1].get(), st.args[2].get(), st.args[3].get()); } -private: - FuncType func; }; template class LoaderFunc5: public LoaderAction { -public: +private: typedef void (L::*FuncType)(A0, A1, A2, A3, A4); + FuncType func; + +public: LoaderFunc5(FuncType f): func(f) { } - void execute(Loader &l, const Statement &st) const + + virtual void execute(Loader &l, const Statement &st) const { if(st.args.size()!=5) throw TypeError("Wrong number of arguments"); (dynamic_cast(l).*func)(st.args[0].get(), st.args[1].get(), st.args[2].get(), st.args[3].get(), st.args[4].get()); } -private: - FuncType func; }; template class LoadValue1: public LoaderAction { -public: +private: typedef T0 L::*Pointer0Type; + Pointer0Type ptr0; + +public: LoadValue1(Pointer0Type p0): ptr0(p0) { } - void execute(Loader &l, const Statement &st) const + + virtual void execute(Loader &l, const Statement &st) const { if(st.args.size()!=1) throw TypeError("Wrong number of arguments"); dynamic_cast(l).get_object().*ptr0=st.args[0].get(); } -private: - Pointer0Type ptr0; }; template class LoadValue1: public LoaderAction { -public: +private: typedef T0 *L::*Pointer0Type; + Pointer0Type ptr0; + +public: LoadValue1(Pointer0Type p0): ptr0(p0) { } - void execute(Loader &l, const Statement &st) const + + virtual void execute(Loader &l, const Statement &st) const { if(st.args.size()!=1) throw TypeError("Wrong number of arguments"); typename L::Loader &ldr=dynamic_cast(l); ldr.get_object().*ptr0=ldr.get_collection().template get(st.args[0].get()); } -private: - Pointer0Type ptr0; }; template class LoadValue2: public LoaderAction { -public: +private: typedef T0 L::*Pointer0Type; typedef T1 L::*Pointer1Type; + Pointer0Type ptr0; + Pointer1Type ptr1; + +public: LoadValue2(Pointer0Type p0, Pointer1Type p1): ptr0(p0), ptr1(p1) { } - void execute(Loader &l, const Statement &st) const + + virtual void execute(Loader &l, const Statement &st) const { if(st.args.size()!=2) throw TypeError("Wrong number of arguments"); dynamic_cast(l).get_object().*ptr0=st.args[0].get(); dynamic_cast(l).get_object().*ptr1=st.args[1].get(); } -private: - Pointer0Type ptr0; - Pointer1Type ptr1; }; } // namespace DataFile