Signal.hpp

Allow functions to be bundled (as Actions) and triggered enmasse.

Todo:

Setup easier mechanism to control the order in which actions are triggered.

Signals should have default parameters so not all need be supplied when triggered.

Note

Status: Beta

class SignalKey
#include <Signal.hpp>

SignalKey tracks a specific function triggered by a signal. For now, its just a value pair.

Public Functions

inline SignalKey(uint32_t _kid = 0, uint32_t _sid = 0)
SignalKey(const SignalKey&) = default
SignalKey &operator=(const SignalKey&) = default
inline ~SignalKey()
inline bool operator==(const SignalKey &in) const

Are two signal keys identical?

inline bool operator!=(const SignalKey &in) const

Are two signal keys different?

inline bool operator<(const SignalKey &in) const
inline bool operator>(const SignalKey &in) const
inline bool operator<=(const SignalKey &in) const
inline bool operator>=(const SignalKey &in) const
inline uint32_t GetID() const

What is the KeyID associated with this signal key.

inline uint32_t GetSignalID() const

What is the ID of the signal that this key is associated with.

inline bool IsActive() const

Is this key currently pointing to a signal action?

inline void Set(uint32_t _kid = 0, uint32_t _sid = 0)

Set this key to specified values.

inline void Clear()

Clear this key.

inline operator bool()

Private Functions

inline int Compare(const SignalKey &in) const

Private Members

uint32_t signal_id

Which signal is this key associated with?

uint32_t key_id

Which key id is this.

class SignalBase
#include <Signal.hpp>

Base class for all signals.

Subclassed by Signal< RETURN(ARGS…)>, Signal< void(ARGS…)>

Public Functions

SignalBase() = delete
SignalBase(const SignalBase&) = delete
SignalBase(SignalBase&&) = delete
SignalBase &operator=(const SignalBase&) = delete
SignalBase &operator=(SignalBase&&) = delete
inline virtual ~SignalBase()
virtual SignalBase *Clone() const = 0
inline const std::string &GetName() const
virtual size_t GetNumArgs() const = 0
virtual size_t GetNumActions() const = 0
template<typename ...ARGS>
void BaseTrigger(ARGS... args)
template<typename ...ARGS>
SignalKey AddAction(const std::function<void(ARGS...)> &in_fun)

Actions without arguments or a return type can be associated with any signal.

virtual SignalKey AddAction(ActionBase&) = 0

Add an action using an Action object.

virtual bool TestMatch(ActionBase&) = 0

Test if an action is compatible with a signal.

virtual void Remove(SignalKey key) = 0

Remove an action specified by its key.

inline void Clear()

Remove all actions from this signal.

inline bool Has(SignalKey key) const

Protected Types

using man_t = internal::SignalManager_Base

Protected Functions

inline SignalKey NextSignalKey()
inline SignalBase(const std::string &n, internal::SignalManager_Base *manager = nullptr)

Protected Attributes

std::string name

What is the unique name of this signal?

uint32_t signal_id

What is the unique ID of this signal?

What ID should the next link have?

Map unique link keys to link index for actions.

vector<man_t*> managers

What manager is handling this signal?

man_t *prime_manager

Which manager leads deletion? (nullptr for self)

Friends

friend class SignalManager
template<typename ...ARGS>
class Signal<void(ARGS...)> : public SignalBase
#include <Signal.hpp>

Signals with void return.

Public Types

using fun_t = void(ARGS...)
using this_t = Signal<fun_t>

Public Functions

inline Signal(const std::string &name = "", internal::SignalManager_Base *manager = nullptr)
inline Signal(const std::string &name, internal::SignalControl_Base &control)
inline virtual this_t *Clone() const
inline virtual size_t GetNumArgs() const
inline virtual size_t GetNumActions() const
inline void Trigger(ARGS... args)

Trigger this signal, providing all needed arguments.

inline SignalKey AddAction(const std::function<void(ARGS...)> &in_fun)

Add an action that takes the proper arguments.

inline virtual SignalKey AddAction(ActionBase &in_action)

Add a specified action to this signal.

inline virtual bool TestMatch(ActionBase &in_action)

Test if an action is compatible with a signal.

template<typename ...FUN_ARGS, typename ...EXTRA_ARGS>
inline SignalKey AddAction(const std::function<void(FUN_ARGS...)> &in_fun, TypePack<EXTRA_ARGS...>)

Add an action that takes too few arguments… but provide specific padding info.

template<typename ...FUN_ARGS>
inline SignalKey AddAction(const std::function<void(FUN_ARGS...)> &in_fun)

Add an std::function that takes the wrong number of arguments. For now, we will assume that there are too few and we need to figure out how to pad it out.

template<typename ...FUN_ARGS>
inline SignalKey AddAction(void in_fun(FUN_ARGS...))

Add a regular function that takes the wrong number of arguments. For now, we will assume that there are too few and we need to figure out how to pad it out.

inline virtual void Remove(SignalKey key)

Remove an action from this signal by providing its key.

inline size_t GetPriority(SignalKey key)

Retrieve the relative priority associated with a specific.

Protected Attributes

FunctionSet<void(ARGS...)> actions

Set of functions (actions) to be triggered with this signal.

template<typename RETURN, typename ...ARGS>
class Signal<RETURN(ARGS...)> : public SignalBase
#include <Signal.hpp>

Public Types

using fun_t = RETURN(ARGS...)
using this_t = Signal<fun_t>

Public Functions

inline Signal(const std::string &name = "", internal::SignalManager_Base *manager = nullptr)
inline Signal(const std::string &name, internal::SignalControl_Base &control)
inline virtual this_t *Clone() const
inline virtual size_t GetNumArgs() const
inline virtual size_t GetNumActions() const
inline const vector<RETURN> &Trigger(ARGS... args)
inline SignalKey AddAction(const std::function<fun_t> &in_fun)
inline virtual SignalKey AddAction(ActionBase &in_action)

Add an action using an Action object.

inline virtual bool TestMatch(ActionBase &in_action)

Test if an action is compatible with a signal.

template<typename ...FUN_ARGS, typename ...EXTRA_ARGS>
inline SignalKey AddAction(const std::function<RETURN(FUN_ARGS...)> &in_fun, TypePack<EXTRA_ARGS...>)
template<typename ...FUN_ARGS>
inline SignalKey AddAction(const std::function<RETURN(FUN_ARGS...)> &in_fun)
template<typename ...FUN_ARGS>
inline SignalKey AddAction(RETURN in_fun(FUN_ARGS...))
inline virtual void Remove(SignalKey key)

Remove an action specified by its key.

inline size_t GetPriority(SignalKey key)

Protected Attributes

FunctionSet<RETURN(ARGS...)> actions