FunctionSet.hpp

Setup a collection of functions, all with the same signature, that can be run as a group.

Note

Status: BETA

template<typename T>
class FunctionSet
#include <FunctionSet.hpp>
template<typename RETURN_T, typename ...ARGS>
class FunctionSet<RETURN_T(ARGS...)> : public vector<std::function<RETURN_T(ARGS...)>>
#include <FunctionSet.hpp>

A vector of functions that can all be triggered at onece; results can either be returned in a vector or post-processed in a function (such as max, min, etc.) Derived from vector, hence with all of the same methods as vector.

Public Types

using base_t = vector<std::function<RETURN_T(ARGS...)>>
using value_type = typename base_t::value_type
using return_t = RETURN_T

Public Functions

inline FunctionSet()
inline ~FunctionSet()
inline size_t GetSize() const

How many functions are in this FunctionSet?

inline void Add(const value_type &in_fun)

Add a new funtion to this FunctionSet.

inline void Remove(size_t pos)

Remove the function at a specified position.

inline const vector<RETURN_T> &Run(ARGS... args) const

Run all functions and return a vector of all results.

inline RETURN_T Run(ARGS... args, std::function<RETURN_T(RETURN_T, RETURN_T)> comp_fun, RETURN_T default_val = 0) const

If you want to provide a filter function, you can retrieve a specific return value. The filter should take in two return values and indicate which is “better”.

inline RETURN_T FindMax(ARGS... args, RETURN_T default_val = 0) const

Run all functions and return the highest value.

inline RETURN_T FindMin(ARGS... args, RETURN_T default_val = 0) const

Run all functions and return the lowest value.

inline RETURN_T FindSum(ARGS... args, RETURN_T default_val = 0) const

Run all functions and return the total value.

inline RETURN_T FindProduct(ARGS... args, RETURN_T default_val = 1) const

Run all functions and return a product of all values.

Protected Attributes

mutable vector<RETURN_T> return_vals
template<typename ...ARGS>
class FunctionSet<void(ARGS...)> : public vector<std::function<void(ARGS...)>>
#include <FunctionSet.hpp>

A specialized version of FunctionSet for void functions.

Public Types

using base_t = vector<std::function<void(ARGS...)>>
using value_type = typename base_t::value_type
using return_t = void

Public Functions

inline FunctionSet()
inline ~FunctionSet()
inline size_t GetSize() const

How many functions are in this FunctionSet?

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

Add a new function to this FunctionSet.

inline void Remove(size_t pos)

Remove the function at the designated position from this FunctionSet.

inline void Run(ARGS... args) const

Run all functions in the FunctionSet.