X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Floaderaction.h;h=afca01e9ba3b478d95bd320e550f0cf7fbf08fff;hb=bbb5a5b00b4008684d5c32b3ea2fd21f7a5fad54;hp=6eebeccc76f47c8144fac9f5ceeb93a35dff0a93;hpb=215e719d0ef85f748898660d15d01e77ac551de9;p=libs%2Fdatafile.git diff --git a/source/loaderaction.h b/source/loaderaction.h index 6eebecc..afca01e 100644 --- a/source/loaderaction.h +++ b/source/loaderaction.h @@ -1,14 +1,6 @@ -/* $Id$ - -This file is part of libmspdatafile -Copyright © 2008, 2010 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - #ifndef MSP_DATAFILE_LOADERACTION_H_ #define MSP_DATAFILE_LOADERACTION_H_ -#include "except.h" #include "statement.h" namespace Msp { @@ -28,6 +20,8 @@ public: /** Called to process a statement. */ virtual void execute(Loader &, const Statement &) const = 0; + + virtual std::string get_signature() const = 0; }; @@ -45,11 +39,13 @@ private: public: LoaderFunc0(FuncType f): func(f) { } - virtual void execute(Loader &l, const Statement &st) const + virtual void execute(Loader &l, const Statement &) const { - if(st.args.size()!=0) throw TypeError("Wrong number of arguments"); (dynamic_cast(l).*func)(); }; + + virtual std::string get_signature() const + { return std::string(); } }; @@ -69,9 +65,11 @@ public: 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()); } + + virtual std::string get_signature() const + { return std::string(1, TypeInfo::signature); } }; @@ -97,6 +95,14 @@ public: values.push_back(i->get()); (dynamic_cast(l).*func)(values); } + + virtual std::string get_signature() const + { + std::string result; + result += TypeInfo::signature; + result += '*'; + return result; + } }; @@ -118,6 +124,9 @@ public: { (dynamic_cast(l).*func)(st); } + + virtual std::string get_signature() const + { return "*"; } }; @@ -134,9 +143,16 @@ public: 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()); } + + virtual std::string get_signature() const + { + std::string result; + result += TypeInfo::signature; + result += TypeInfo::signature; + return result; + } }; @@ -153,9 +169,17 @@ public: 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()); } + + virtual std::string get_signature() const + { + std::string result; + result += TypeInfo::signature; + result += TypeInfo::signature; + result += TypeInfo::signature; + return result; + } }; @@ -172,9 +196,18 @@ public: 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()); } + + virtual std::string get_signature() const + { + std::string result; + result += TypeInfo::signature; + result += TypeInfo::signature; + result += TypeInfo::signature; + result += TypeInfo::signature; + return result; + } }; @@ -191,9 +224,19 @@ public: 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()); } + + virtual std::string get_signature() const + { + std::string result; + result += TypeInfo::signature; + result += TypeInfo::signature; + result += TypeInfo::signature; + result += TypeInfo::signature; + result += TypeInfo::signature; + return result; + } }; @@ -210,9 +253,11 @@ public: 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(); + dynamic_cast(l).get_object().*ptr0 = st.args[0].get(); } + + virtual std::string get_signature() const + { return std::string(1, TypeInfo::signature); } }; @@ -229,10 +274,12 @@ public: 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()); + typename L::Loader &ldr = dynamic_cast(l); + ldr.get_object().*ptr0 = &ldr.get_collection().template get(st.args[0].get()); } + + virtual std::string get_signature() const + { return std::string(1, TypeInfo::signature); } }; @@ -251,9 +298,16 @@ public: 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(); + dynamic_cast(l).get_object().*ptr0 = st.args[0].get(); + dynamic_cast(l).get_object().*ptr1 = st.args[1].get(); + } + + virtual std::string get_signature() const + { + std::string result; + result += TypeInfo::signature; + result += TypeInfo::signature; + return result; } };