Template Class CallbackRegistry#

Class Documentation#

template<typename Return, typename ...Args>
class CallbackRegistry#

This class stores functions to be called with tempalted Return type and Args, and it can call them in order (or reverse order).

The template parameters define the type of function that will be stored on the CallbackRegistry. Functions are identified by a unique name and are stored in the order they were added. They can be added or modified the same way you would modify a map entry. They can be retrieved by name or by index. The functions registered can be called in forward or reverse order using the execute or executeReverse methods.

Public Types

using f = std::function<Return(Args...)>#

Alias to the function type.

Public Functions

inline const f &operator[](const std::string &name) const#

Set the callback function associated with name.

Parameters:

name – The associated with the callback function.

Returns:

f A placeholder for the callback function.

inline f &operator[](const std::string &name)#

Get the callback function associated with name.

Parameters:

name – The associated with the callback function.

Returns:

f The callback function.

inline f &operator[](const uint index)#

Set the callback function at the given index.

Parameters:

index – The index to insert the callback function at.

Returns:

f A placeholder for the callback function.

inline const f &operator[](const uint index) const#

Get the callback function at the given index.

Parameters:

index – The index of the callback function to get.

Returns:

f The callback function at index.

inline void execute(Args... args)#

Execute the callbacks in order.

Parameters:

args – The arguments passed to the callbacks.

inline std::vector<Return> execute(Args... args)

Execute the callbacks in order.

Parameters:

args – The arguments passed to the callbacks.

Returns:

A vector of the return types from each function.

inline void executeReverse(Args... args)#

Execute the callbacks in reverse order.

Parameters:

args – The arguments passed to the callbacks.

inline std::vector<Return> executeReverse(Args... args)

Execute the callbacks in reverse order.

Parameters:

args – The arguments passed to the callbacks.

Returns:

A vector of the return types from each function.

inline size_t size() const#

Returns the number of registered functions.

Returns:

The number of registered functions

inline std::string dumpString(const std::string &prefix = "") const#

Create a string that lists all the functions by name.

Parameters:

prefix – A string to use as prefix for each output line

Returns:

A dump string of the CallbackRegistry.

inline void dump(const std::string &prefix = "") const#

Print out the string from dumpString. See dumpString for more details.

Parameters:

prefix – A string to use as prefix for each output line

inline void erase(const std::string &name)#

Erase the callback with the associated name from the registry.

Parameters:

name – The name of the callback to erase.

inline void erase(size_t index)#

Erase the callback at the provided index.

Parameters:

index – The index of the callback.

inline f pop(const std::string &name)#

Pop the callback with the associated name from the registry.

Parameters:

name – The name of the callback to pop.

Returns:

The function associated with name.

inline f pop(size_t index)#

Pop the callback at the provided index.

Parameters:

index – The index of the callback.

Returns:

The function at the given index.

inline void clear()#

Clear out the entire CallbackRegistry. All callbacks will be removed.

inline bool contains(const std::string &name)#

Determine whether the CallbackRegistry contains a function with the provided name.

Parameters:

name – The name of the callback to check for.

Returns:

true if a callback with the given name is in the registry, false otherwise.