Skip to content

Command

Base class for all commands. More...

#include "Commands/Command.h"

Inherits from ICommand

Public Types

Name
typedef std::function< void(Args &...)>Callback

Public Functions

Name
Command() =default
virtual~Command() =default
virtual voidexecute() override<br>Call all callbacks.
voidaddListener(Callback function)<br>Add a listener for a command.
voiddispatch(Args... args)<br>Tell application that command was issued.
voiddispatchImmediate(Args... args)

Protected Functions

Name
Command(const std::tuple< Args... > & args)<br>Copy a command and its arguments.

Additional inherited members

Public Functions inherited from ICommand

Name
virtual~ICommand() =default

Detailed Description

cpp
template <typename Type ,
typename... Args>
class Command;
template <typename Type ,
typename... Args>
class Command;

Base class for all commands.

Template Parameters:

  • Type command derived class (CloseCommand for example)-
  • Args command argument for callback call.

Any derived command can be accessed by calling DerivedCommandName::addListener(fptr); For more information see Curiously recurring template pattern (static m_listeners).

Public Types Documentation

typedef Callback

cpp
typedef std::function<void(Args&...)> Command< Type, Args >::Callback;
typedef std::function<void(Args&...)> Command< Type, Args >::Callback;

Public Functions Documentation

function Command

cpp
Command() =default
Command() =default

function ~Command

cpp
virtual ~Command() =default
virtual ~Command() =default

function execute

cpp
inline virtual void execute() override
inline virtual void execute() override

Call all callbacks.

Reimplements: ICommand::execute

Expand m_params tuple as function arguments, link.

function addListener

cpp
static inline void addListener(
    Callback function
)
static inline void addListener(
    Callback function
)

Add a listener for a command.

Parameters:

  • function callback to call when the command is issued. Use std::bind for member function of instantiated class or raw function pointer for static member function or plain function.

Todo: Check how std::bind handle this reference.

NEVER use the function from constructor of statically instantiated object.

function dispatch

cpp
static inline void dispatch(
    Args... args
)
static inline void dispatch(
    Args... args
)

Tell application that command was issued.

Pass a copy of command and its arguments to the Application.

function dispatchImmediate

cpp
static inline void dispatchImmediate(
    Args... args
)
static inline void dispatchImmediate(
    Args... args
)

Protected Functions Documentation

function Command

cpp
inline explicit Command(
    const std::tuple< Args... > & args
)
inline explicit Command(
    const std::tuple< Args... > & args
)

Copy a command and its arguments.

Parameters:

  • args command arguments.

Updated on 2024-03-16 at 19:15:01 +0000