7#include <unordered_map>
62 virtual std::vector<std::type_index>
argTypes()
const = 0;
68 template<
typename R,
typename... Args>
69 static bool isValid(
const std::string& name)
77 template<
typename R,
typename... Args>
78 static R
call(
const std::string& name, Args... args)
82 return func.
call(args...);
91 template<
typename R,
typename... Args>
105 explicit Holder(std::function<R(Args...)> f);
109 std::vector<std::type_index>
argTypes()
const override;
119 std::function<R(Args...)> func;
137 operator
bool() const noexcept;
145 R call(Args... args) const;
150 R operator()(Args... args) const;
161 std::shared_ptr<
Base> _holder;
173 template<typename R, typename... Args, typename F>
174 static
void add(const std::
string& name, F&& f, const std::
string& desc = {});
183 template<
typename R,
typename... Args>
194 template<
class R,
class... Args>
195 static bool remove(
const std::string& name);
201 static void list(std::ostream& os);
211 template<
typename R,
typename... Args>
212 static std::string makeKey(
const std::string& name);
219 std::shared_ptr<Base> holder;
220 std::string description;
227 static std::unordered_map<std::string, Entry>& registry();
233 static unsigned& counter();
239#include <misc/gen/FunctionRegistry.hpp>
Base class for type-erased function storage.
Definition FunctionRegistry.h:48
virtual std::type_index returnType() const =0
Get the return type of the stored function.
virtual std::vector< std::type_index > argTypes() const =0
Get the argument types of the stored function.
Nested holder storing a function with a specific signature.
Definition FunctionRegistry.h:99
std::vector< std::type_index > argTypes() const override
Get the argument types of the stored function.
R invoke(Args... args) const
Invoke the stored function.
std::type_index returnType() const override
Get the return type of the stored function.
Holder(std::function< R(Args...)> f)
Constructor accepting a std::function.
Registration handle templated on function signature.
Definition FunctionRegistry.h:93
bool isValid() const noexcept
Check if the registration is valid.
Registration(const std::string &name)
Construct registration by function name.
R call(Args... args) const
Calls the registered function when it exists.
Registry managing function registration and lookup.
Definition FunctionRegistry.h:42
static void list(std::ostream &os)
List all registered functions to the provided stream.
static bool remove(const std::string &name)
Removes a registered function by name and signature. Existing Registration instances are still able t...
static bool isValid(const std::string &name)
Check validity of the function using the registration.
Definition FunctionRegistry.h:69
static bool contains(const std::string &name)
Check if a function is registered.
static R call(const std::string &name, Args... args)
Check validity of registration the function and makes the call.
Definition FunctionRegistry.h:78
#define _MISC_CLASS
Definition misc/global.h:40
Definition Application.h:10