From: Mikko Rasa Date: Sun, 19 Apr 2020 14:24:55 +0000 (+0300) Subject: Support loader functions with bound first argument X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=b0186e8878204a29e25ca4063c1dac4dea908508;p=libs%2Fdatafile.git Support loader functions with bound first argument This allows more flexibility in defining dynamic keywords. Only available with C++11. --- diff --git a/source/loader.h b/source/loader.h index 02caaaf..7799a7e 100644 --- a/source/loader.h +++ b/source/loader.h @@ -120,6 +120,14 @@ protected: { add(k, new LoaderFunc5(func)); } #endif +#if __cplusplus>=201103L + /** Adds a keyword that is loaded by calling a function with a bound + first argument. */ + template + void add(const std::string &k, void (L::*func)(B0, Args...), const typename RemoveReference::Type &b0) + { add(k, new LoaderFuncNBound1(func, b0)); } +#endif + /** Adds a keyword that is loaded into a member of the loaded object. */ template void add(const std::string &k, T0 L::*p0) diff --git a/source/loaderaction.h b/source/loaderaction.h index 7e4feac..a3b0443 100644 --- a/source/loaderaction.h +++ b/source/loaderaction.h @@ -361,6 +361,33 @@ public: { 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