Action.hpp

A mechanism to abstract functions from their underlying type and provide run-time names.

Todo:

Create an ActionDefaults class that can take fewer args than expected and fill in rest.

Allow for named arguments to facilitate interpreted functions.

Note

Status: Beta

Functions

template<typename RETURN, typename ...ARGS>
auto make_action(const std::function<RETURN(ARGS...)> &in_fun, const std::string &name = "")

Build an action object using this function.

class ActionBase
#include <Action.hpp>

BaseActions abstract functions and allow for signals to be setup at runtime; they can be called with types specified in the call.

Actions can be a bit heavyweight, but can easily be converted to std::function objects.

Subclassed by ActionSize< ARG_COUNT >, ActionSize< sizeof…(ARGS)>

Public Functions

inline virtual ~ActionBase()
inline const std::string &GetName() const

Get the name of this action.

virtual size_t GetArgCount() const = 0

Get number of arguments this action takes.

virtual ActionBase *Clone() const = 0

Clone() will produce a pointer to a full copy of an Action, going through derived version.

Protected Functions

inline ActionBase(const std::string &in_name)
ActionBase(const ActionBase&) = default
ActionBase(ActionBase&&) = default
ActionBase &operator=(const ActionBase&) = default
ActionBase &operator=(ActionBase&&) = default

Protected Attributes

std::string name

A unique name for this action so it can be called at runtime.

template<size_t ARG_COUNT>
class ActionSize : public ActionBase
#include <Action.hpp>

ActionSize is a second layer of abstract actions that know the number of arguments used at compile time to facilitate easy type-checking.

Public Functions

inline virtual size_t GetArgCount() const

Get number of arguments this action takes.

Protected Functions

inline ActionSize(const std::string &in_name)
template<typename ...ARGS>
class Action
#include <Action.hpp>

The declaration for Action has any template types; the only defined specializations require a function type to be specified (with void and non-void return type variants.)

template<typename ...ARGS>
class Action<void(ARGS...)> : public ActionSize<sizeof...(ARGS)>
#include <Action.hpp>

This Action class specialization takes a function with a void return type and builds it off of the action base classes.

Public Types

using this_t = Action<void(ARGS...)>
using parent_t = ActionSize<sizeof...(ARGS)>

Public Functions

inline Action(const std::function<void(ARGS...)> &in_fun, const std::string &in_name = "")
template<typename RETURN>
inline Action(const std::function<RETURN(ARGS...)> &in_fun, const std::string &in_name = "")
Action(const this_t&) = default
Action(this_t&&) = default
this_t &operator=(const this_t&) = default
this_t &operator=(this_t&&) = default
inline const std::function<void(ARGS...)> &GetFun() const
inline void Call(ARGS&&... args)

Call the function associated with this action.

inline virtual this_t *Clone() const

Build a copy of this Action.

Protected Attributes

std::function<void(ARGS...)> fun

The specific function associated with this action.

template<typename RETURN, typename ...ARGS>
class Action<RETURN(ARGS...)> : public ActionSize<sizeof...(ARGS)>
#include <Action.hpp>

This Action class specialization takes a function with any non-void return type and builds it off of the action base classes.

Public Types

using fun_t = RETURN(ARGS...)
using this_t = Action<fun_t>
using parent_t = ActionSize<sizeof...(ARGS)>

Public Functions

inline Action(const std::function<RETURN(ARGS...)> &in_fun, const std::string &in_name = "")
Action(const this_t&) = default
Action(this_t&&) = default
this_t &operator=(const this_t&) = default
this_t &operator=(this_t&&) = default
inline const std::function<fun_t> &GetFun() const
inline RETURN Call(ARGS&&... args)

Call the function associated with this action.

inline virtual this_t *Clone() const

Build a copy of this Action.

Protected Attributes

std::function<RETURN(ARGS...)> fun

The specific function associated with this action.