X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Floaderaction.h;h=a3b04437d279e3e6835bd20538d2c99311721064;hb=b0186e8878204a29e25ca4063c1dac4dea908508;hp=82fd3b437902a3494167ae295c7f065184424a5b;hpb=3b78eeb8b92dc3524d6a0456b4daf0a0f3dbf813;p=libs%2Fdatafile.git diff --git a/source/loaderaction.h b/source/loaderaction.h index 82fd3b4..a3b0443 100644 --- a/source/loaderaction.h +++ b/source/loaderaction.h @@ -1,12 +1,23 @@ #ifndef MSP_DATAFILE_LOADERACTION_H_ #define MSP_DATAFILE_LOADERACTION_H_ +#include #include "argumentstore.h" #include "statement.h" namespace Msp { namespace DataFile { +#if __cplusplus>=201103L +template +std::string create_signature(const std::string &prefix = std::string()) +{ return prefix+std::string(1, TypeInfo::signature); } + +template +std::string create_signature(const std::string &prefix = std::string()) +{ return create_signature(prefix+std::string(1, TypeInfo::signature)); } +#endif + class Loader; /** @@ -288,6 +299,98 @@ public: }; +#if __cplusplus>=201103L +template +struct Apply; + +template +struct Apply +{ + template + static void apply(L &l, F func, const Statement &, Args... args) + { + (l.*func)(args...); + } + + template + static void apply(L &l, F func, const ArgumentStore &, Args... args) + { + (l.*func)(args...); + } +}; + +template +struct Apply +{ + template + static void apply(L &l, F func, const Statement &st, Args... args) + { + Apply::apply(l, func, st, args..., st.args[I].get()); + } + + template + static void apply(L &l, F func, const ArgumentStore &as, Args... args) + { + Apply::apply(l, func, as, args..., as.get(I)); + } +}; + + +template +class LoaderFuncN: public LoaderAction +{ +protected: + typedef void (L::*FuncType)(Args...); + + FuncType func; + +public: + LoaderFuncN(FuncType f): func(f) { } + + virtual void execute(Loader &l, const Statement &st) const + { + Apply<0, Args...>::apply(dynamic_cast(l), func, st); + } + + virtual void execute(Loader &l, const ArgumentStore &as) const + { + Apply<0, Args...>::apply(dynamic_cast(l), func, as); + } + + virtual std::string get_signature() const + { return create_signature(); } +}; + + +template +class LoaderFuncNBound1: public LoaderAction +{ +protected: + typedef void (L::*FuncType)(B0, Args...); + typedef typename RemoveReference::Type Bound0Type; + + FuncType func; + Bound0Type bound0; + +public: + LoaderFuncNBound1(FuncType f, const Bound0Type &b0): func(f), bound0(b0) { } + + virtual void execute(Loader &l, const Statement &st) const + { + Apply<0, Args...>::apply(dynamic_cast(l), func, st, bound0); + } + + virtual void execute(Loader &l, const ArgumentStore &as) const + { + Apply<0, Args...>::apply(dynamic_cast(l), func, as, bound0); + } + + virtual std::string get_signature() const + { return create_signature(); } +}; +#endif + + template class LoadValue1: public LoaderAction {