void add(const std::string &k, void (L::*func)(A0))
{ add(k, new LoaderFunc1<L, A0>(func)); }
+#if __cplusplus>=201103L
+ template<typename L, typename... Args>
+ void add(const std::string &k, void (L::*func)(Args...))
+ { add(k, new LoaderFuncN<L, Args...>(func)); }
+
+#else
template<typename L, typename A0, typename A1>
void add(const std::string &k, void (L::*func)(A0, A1))
{ add(k, new LoaderFunc2<L, A0, A1>(func)); }
template<typename L, typename A0, typename A1, typename A2, typename A3, typename A4>
void add(const std::string &k, void (L::*func)(A0, A1, A2, A3, A4))
{ add(k, new LoaderFunc5<L, A0, A1, A2, A3, A4>(func)); }
+#endif
/** Adds a keyword that is loaded into a member of the loaded object. */
template<typename L, typename T0>
#ifndef MSP_DATAFILE_LOADERACTION_H_
#define MSP_DATAFILE_LOADERACTION_H_
+#include <msp/core/meta.h>
#include "argumentstore.h"
#include "statement.h"
namespace Msp {
namespace DataFile {
+#if __cplusplus>=201103L
+template<typename T>
+std::string create_signature(const std::string &prefix = std::string())
+{ return prefix+std::string(1, TypeInfo<T>::signature); }
+
+template<typename T0, typename T1, typename... Tail>
+std::string create_signature(const std::string &prefix = std::string())
+{ return create_signature<T1, Tail...>(prefix+std::string(1, TypeInfo<T0>::signature)); }
+#endif
+
class Loader;
/**
};
+#if __cplusplus>=201103L
+template<unsigned I, typename... Args>
+struct Apply;
+
+template<unsigned I>
+struct Apply<I>
+{
+ template<typename L, typename F, typename... Args>
+ static void apply(L &l, F func, const Statement &, Args... args)
+ {
+ (l.*func)(args...);
+ }
+
+ template<typename L, typename F, typename... Args>
+ static void apply(L &l, F func, const ArgumentStore &, Args... args)
+ {
+ (l.*func)(args...);
+ }
+};
+
+template<unsigned I, typename Head, typename... Tail>
+struct Apply<I, Head, Tail...>
+{
+ template<typename L, typename F, typename... Args>
+ static void apply(L &l, F func, const Statement &st, Args... args)
+ {
+ Apply<I+1, Tail...>::apply(l, func, st, args..., st.args[I].get<Head>());
+ }
+
+ template<typename L, typename F, typename... Args>
+ static void apply(L &l, F func, const ArgumentStore &as, Args... args)
+ {
+ Apply<I+1, Tail...>::apply(l, func, as, args..., as.get<Head>(I));
+ }
+};
+
+
+template<typename L, typename... Args>
+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 &>(l), func, st);
+ }
+
+ virtual void execute(Loader &l, const ArgumentStore &as) const
+ {
+ Apply<0, Args...>::apply(dynamic_cast<L &>(l), func, as);
+ }
+
+ virtual std::string get_signature() const
+ { return create_signature<Args...>(); }
+};
+
+#endif
+
+
template<typename L, typename T0>
class LoadValue1: public LoaderAction
{