1#ifndef AMPGEN_ARGUMENTPACK_H
2#define AMPGEN_ARGUMENTPACK_H
12 #define DECLARE_ARGUMENT(X, Y) \
13 struct X : public AmpGen::Argument<Y> { \
15 explicit X(Z val = Z()) : AmpGen::Argument<Y>(val){} \
16 X() : AmpGen::Argument<Y>(){} \
54 template <
typename TYPE>
60 operator TYPE()
const {
return val; }
61 TYPE
val = { TYPE() };
73 template <
typename... ARGS>
76 std::tuple<ARGS...> argTuple( args... );
77 for_each(argTuple, [
this](
const auto& f){ this->addArgument(f) ; } );
79 template <
typename arg_type> arg_type*
get()
const
81 for(
const auto& param : m_parameters )
83 auto ptr =
dynamic_cast<arg_type*
>(param.get());
84 if( ptr !=
nullptr )
return ptr;
88 template <
typename arg_type,
typename default_arg_type=arg_type>
89 arg_type
getArg(
const default_arg_type& default_argument = default_arg_type() )
const
92 return p ==
nullptr ? arg_type(default_argument) : *p;
95 std::vector<std::shared_ptr<IArgument>> m_parameters;
96 template <
typename T>
void addArgument(
const T& f ){ m_parameters.emplace_back( std::make_shared<T>(f) ) ; }
arg_type getArg(const default_arg_type &default_argument=default_arg_type()) const
ArgumentPack(const ARGS &... args)
std::enable_if_t< I==sizeof...(Tp), void > for_each(std::tuple< Tp... > &, FuncT)
Virtual base class for arguments Named arguments to functions (python-style) are given a virtual base...
virtual ~IArgument()=default