X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Floaderaction.h;h=82fd3b437902a3494167ae295c7f065184424a5b;hb=b39ce68f12c30eedb272b65fe78baec5864d89ca;hp=cfbe281f399c4071df30e12b17f53f6d99843d18;hpb=b34b46788d69853eabdbbd9e71ca82f2f5c09df8;p=libs%2Fdatafile.git diff --git a/source/loaderaction.h b/source/loaderaction.h index cfbe281..82fd3b4 100644 --- a/source/loaderaction.h +++ b/source/loaderaction.h @@ -1,14 +1,7 @@ -/* $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 "argumentstore.h" #include "statement.h" namespace Msp { @@ -29,6 +22,8 @@ public: /** Called to process a statement. */ virtual void execute(Loader &, const Statement &) const = 0; + virtual void execute(Loader &, const ArgumentStore &) const = 0; + virtual std::string get_signature() const = 0; }; @@ -47,9 +42,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 + { + (dynamic_cast(l).*func)(); + }; + + virtual void execute(Loader &l, const ArgumentStore &) const { - if(st.args.size()!=0) throw TypeError("Wrong number of arguments"); (dynamic_cast(l).*func)(); }; @@ -74,10 +73,14 @@ 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 void execute(Loader &l, const ArgumentStore &as) const + { + (dynamic_cast(l).*func)(as.get(0)); + } + virtual std::string get_signature() const { return std::string(1, TypeInfo::signature); } }; @@ -106,6 +109,16 @@ public: (dynamic_cast(l).*func)(values); } + virtual void execute(Loader &l, const ArgumentStore &as) const + { + std::vector values; + unsigned n_args = as.get_info().key.signature.size(); + values.reserve(n_args); + for(unsigned i=0; i(i)); + (dynamic_cast(l).*func)(values); + } + virtual std::string get_signature() const { std::string result; @@ -135,6 +148,11 @@ public: (dynamic_cast(l).*func)(st); } + virtual void execute(Loader &, const ArgumentStore &) const + { + throw std::logic_error("incompatible format"); + } + virtual std::string get_signature() const { return "*"; } }; @@ -153,10 +171,14 @@ 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 void execute(Loader &l, const ArgumentStore &as) const + { + (dynamic_cast(l).*func)(as.get(0), as.get(1)); + } + virtual std::string get_signature() const { std::string result; @@ -180,10 +202,14 @@ 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 void execute(Loader &l, const ArgumentStore &as) const + { + (dynamic_cast(l).*func)(as.get(0), as.get(1), as.get(2)); + } + virtual std::string get_signature() const { std::string result; @@ -208,10 +234,14 @@ 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 void execute(Loader &l, const ArgumentStore &as) const + { + (dynamic_cast(l).*func)(as.get(0), as.get(1), as.get(2), as.get(3)); + } + virtual std::string get_signature() const { std::string result; @@ -237,10 +267,14 @@ 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 void execute(Loader &l, const ArgumentStore &as) const + { + (dynamic_cast(l).*func)(as.get(0), as.get(1), as.get(2), as.get(3), as.get(4)); + } + virtual std::string get_signature() const { std::string result; @@ -267,8 +301,12 @@ 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 void execute(Loader &l, const ArgumentStore &as) const + { + dynamic_cast(l).get_object().*ptr0 = as.get(0); } virtual std::string get_signature() const @@ -289,9 +327,14 @@ 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 void execute(Loader &l, const ArgumentStore &as) const + { + typename L::Loader &ldr = dynamic_cast(l); + ldr.get_object().*ptr0 = &ldr.get_collection().template get(as.get(0)); } virtual std::string get_signature() const @@ -314,9 +357,14 @@ 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 void execute(Loader &l, const ArgumentStore &as) const + { + dynamic_cast(l).get_object().*ptr0 = as.get(0); + dynamic_cast(l).get_object().*ptr1 = as.get(1); } virtual std::string get_signature() const