14 #ifndef EMP_CONTROL_ACTION 15 #define EMP_CONTROL_ACTION 32 ActionBase(
const std::string & in_name) : name(in_name) { ; }
54 template <
size_t ARG_COUNT>
64 template <
typename... ARGS>
class Action;
68 template <
typename... ARGS>
71 std::function<void(ARGS...)>
fun;
76 Action(
const std::function<
void(ARGS...)> & in_fun,
const std::string & in_name=
"")
77 :
parent_t(in_name), fun(in_fun) { ; }
78 template <
typename RETURN>
79 Action(
const std::function<RETURN(ARGS...)> & in_fun,
const std::string & in_name=
"")
81 , fun([in_fun](ARGS &&... args){in_fun(std::forward<ARGS>(args)...);}) { ; }
88 const std::function<void(ARGS...)> &
GetFun()
const {
return fun; };
91 void Call(ARGS &&... args) {
return fun(std::forward<ARGS>(args)...); }
100 template <
typename RETURN,
typename... ARGS>
103 std::function<RETURN(ARGS...)>
fun;
109 Action(
const std::function<RETURN(ARGS...)> & in_fun,
const std::string & in_name=
"")
110 :
parent_t(in_name), fun(in_fun) { ; }
117 const std::function<fun_t> &
GetFun()
const {
return fun; };
120 RETURN
Call(ARGS &&... args) {
return fun(std::forward<ARGS>(args)...); }
127 template <
typename RETURN,
typename... ARGS>
128 auto make_action(
const std::function<RETURN(ARGS...)> & in_fun,
const std::string &
name=
"") {
ActionBase(const std::string &in_name)
Definition: Action.h:32
RETURN(ARGS...) fun_t
Definition: Action.h:105
size_t GetArgCount() const
Get number of arguments this action takes.
Definition: Action.h:59
virtual ~ActionBase()
Definition: Action.h:40
std::string name
A unique name for this action so it can be called at runtime.
Definition: Action.h:30
virtual size_t GetArgCount() const =0
Get number of arguments this action takes.
this_t * Clone() const
Build a copy of this Action.
Definition: Action.h:94
virtual ActionBase * Clone() const =0
Clone() will produce a pointer to a full copy of an Action, going through derived version...
this_t * Clone() const
Build a copy of this Action.
Definition: Action.h:123
auto make_action(const std::function< RETURN(ARGS...)> &in_fun, const std::string &name="")
Build an action object using this function.
Definition: Action.h:128
std::function< RETURN(ARGS...)> fun
The specific function associated with this action.
Definition: Action.h:103
Action(const std::function< RETURN(ARGS...)> &in_fun, const std::string &in_name="")
Definition: Action.h:79
Action(const std::function< void(ARGS...)> &in_fun, const std::string &in_name="")
Definition: Action.h:76
std::function< void(ARGS...)> fun
The specific function associated with this action.
Definition: Action.h:71
ActionSize(const std::string &in_name)
Definition: Action.h:57
const std::string & GetName() const
Get the name of this action.
Definition: Action.h:43
If we are in emscripten, make sure to include the header.
Definition: array.h:37
RETURN Call(ARGS &&...args)
Call the function associated with this action.
Definition: Action.h:120
const std::function< void(ARGS...)> & GetFun() const
Definition: Action.h:88
void Call(ARGS &&...args)
Call the function associated with this action.
Definition: Action.h:91
ActionBase & operator=(const ActionBase &)=default
Action(const std::function< RETURN(ARGS...)> &in_fun, const std::string &in_name="")
Definition: Action.h:109
const std::function< fun_t > & GetFun() const
Definition: Action.h:117