AmpGen
2.1
Toggle main menu visibility
Loading...
Searching...
No Matches
ArgumentPack.h
Go to the documentation of this file.
1
#ifndef AMPGEN_ARGUMENTPACK_H
2
#define AMPGEN_ARGUMENTPACK_H
3
4
#include "
AmpGen/MetaUtils.h
"
5
#include <iostream>
6
#include <memory>
7
#include <string>
8
#include <vector>
9
10
namespace
AmpGen
{
11
#define DECLARE_ARGUMENT(X, Y) \
12
struct X : public AmpGen::Argument<Y> { \
13
template <class Z> explicit X(Z val = Z()) : AmpGen::Argument<Y>(val) {} \
14
X() : AmpGen::Argument<Y>() {} \
15
}
16
22
struct
IArgument
{
23
virtual
~IArgument
() =
default
;
24
};
25
52
template
<
typename
TYPE>
struct
Argument
:
public
IArgument
{
53
template
<
typename
T>
explicit
Argument
(T x) :
val
(x) {}
54
Argument
() =
default
;
55
operator
TYPE()
const
{
return
val
; }
56
TYPE
val
= {TYPE()};
57
};
58
65
class
ArgumentPack
{
66
public
:
67
template
<
typename
... ARGS>
explicit
ArgumentPack
(
const
ARGS &...args) {
68
std::tuple<ARGS...> argTuple(args...);
69
for_each
(argTuple, [
this
](
const
auto
&f) { this->addArgument(f); });
70
}
71
template
<
typename
arg_type> arg_type *
get
()
const
{
72
for
(
const
auto
¶m : m_parameters) {
73
auto
ptr =
dynamic_cast<
arg_type *
>
(param.get());
74
if
(ptr !=
nullptr
)
return
ptr;
75
}
76
return
nullptr
;
77
}
78
template
<
typename
arg_type,
typename
default_arg_type = arg_type> arg_type
getArg
(
const
default_arg_type &default_argument = default_arg_type())
const
{
79
auto
p =
get<arg_type>
();
80
return
p ==
nullptr
? arg_type(default_argument) : *p;
81
}
82
83
private
:
84
std::vector<std::shared_ptr<IArgument>> m_parameters;
85
template
<
typename
T>
void
addArgument(
const
T &f) { m_parameters.emplace_back(std::make_shared<T>(f)); }
86
};
87
}
// namespace AmpGen
88
89
#endif
MetaUtils.h
AmpGen::ArgumentPack::getArg
arg_type getArg(const default_arg_type &default_argument=default_arg_type()) const
Definition
ArgumentPack.h:78
AmpGen::ArgumentPack::ArgumentPack
ArgumentPack(const ARGS &...args)
Definition
ArgumentPack.h:67
AmpGen::ArgumentPack::get
arg_type * get() const
Definition
ArgumentPack.h:71
AmpGen
Definition
AddCPConjugate.h:2
AmpGen::for_each
std::enable_if_t< I==sizeof...(Tp), void > for_each(std::tuple< Tp... > &, FuncT)
Definition
MetaUtils.h:36
AmpGen::Argument::val
TYPE val
Definition
ArgumentPack.h:56
AmpGen::Argument::Argument
Argument()=default
AmpGen::Argument::Argument
Argument(T x)
Definition
ArgumentPack.h:53
AmpGen::IArgument
Virtual base class for arguments Named arguments to functions (python-style) are given a virtual base...
Definition
ArgumentPack.h:22
AmpGen::IArgument::~IArgument
virtual ~IArgument()=default
AmpGen
ArgumentPack.h
Generated on
for AmpGen by
1.17.0