Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
sf::FunctionRegistry Class Reference

Registry managing function registration and lookup. More...

#include <FunctionRegistry.h>

Classes

class  Base
 Base class for type-erased function storage. More...
 
class  Registration
 Registration handle templated on function signature. More...
 

Static Public Member Functions

template<typename R , typename... Args>
static bool isValid (const std::string &name)
 Check validity of the function using the registration.
 
template<typename R , typename... Args>
static R call (const std::string &name, Args... args)
 Check validity of registration the function and makes the call.
 
template<typename R , typename... Args, typename F >
static void add (const std::string &name, F &&f, const std::string &desc={})
 Add a function by name and signature, with optional description.
 
template<typename R , typename... Args>
static bool contains (const std::string &name)
 Check if a function is registered.
 
template<class R , class... Args>
static bool remove (const std::string &name)
 Removes a registered function by name and signature. Existing Registration instances are still able to call the function since the Holder does not change.
 
static void list (std::ostream &os)
 List all registered functions to the provided stream.
 

Detailed Description

Registry managing function registration and lookup.

Example usage:

// Register overloads:
FunctionRegistry::add<int, int, int>("add",
[](int a, int b){ return a + b; },
"Adds two ints");
FunctionRegistry::add<double, double, double>("add",
[](double x, double y){ return x + y; },
"Adds two doubles");
// Retrieve and call:
auto func = FunctionRegistry::Registration<int, int, int>("add");
if (func.isValid())
{
int sum = regInt.call(3, 4);
}
// Instant call:
FunctionRegistry::call<int, int, int>("add", 1, 2);
// List all overloads with descriptions:
static void list(std::ostream &os)
List all registered functions to the provided stream.

Member Function Documentation

◆ add()

template<typename R , typename... Args, typename F >
static void sf::FunctionRegistry::add ( const std::string &  name,
F &&  f,
const std::string &  desc = {} 
)
static

Add a function by name and signature, with optional description.

Template Parameters
RReturn type
ArgsArgument types
FCallable type
Parameters
nameName to register under
fFunction or lambda to register
descOptional description

◆ call()

template<typename R , typename... Args>
static R sf::FunctionRegistry::call ( const std::string &  name,
Args...  args 
)
inlinestatic

Check validity of registration the function and makes the call.

◆ contains()

template<typename R , typename... Args>
static bool sf::FunctionRegistry::contains ( const std::string &  name)
static

Check if a function is registered.

Template Parameters
RReturn type
ArgsArgument types
Parameters
nameFunction name
Returns
true if found, false otherwise

◆ isValid()

template<typename R , typename... Args>
static bool sf::FunctionRegistry::isValid ( const std::string &  name)
inlinestatic

Check validity of the function using the registration.

◆ list()

static void sf::FunctionRegistry::list ( std::ostream &  os)
static

List all registered functions to the provided stream.

Parameters
osOutput stream

◆ remove()

template<class R , class... Args>
static bool sf::FunctionRegistry::remove ( const std::string &  name)
static

Removes a registered function by name and signature. Existing Registration instances are still able to call the function since the Holder does not change.

Template Parameters
RReturn type
ArgsArgument types
Parameters
nameFunction name
Returns
true if found and removed, false otherwise

The documentation for this class was generated from the following file: