![]() |
Shamrock 2025.10.0
Astrophysical Code
|
Name-keyed registry of the implementation selectors (IImplVariant) of every algorithm. More...
#include "shambase/call_lambda.hpp"#include "shambase/unique_name_macro.hpp"#include "shamalgs/ImplVariant.hpp"#include "shambackends/DeviceScheduler.hpp"#include <string_view>#include <string>#include <vector>Go to the source code of this file.
Namespaces | |
| namespace | shamalgs |
| namespace to contain everything implemented by shamalgs | |
Macros | |
| #define | SHAMALGS_REGISTER_IMPL(name, impl) |
| Register the implementation selector impl under name at static initialization. | |
Functions | |
| void | shamalgs::impl_registry::register_impl (std::string name, IImplVariant &impl) |
| Register an implementation selector under name. | |
| std::vector< std::string > | shamalgs::impl_registry::get_registered_algs () |
| Get the names of every registered algorithm, sorted. | |
| std::vector< std::string > | shamalgs::impl_registry::get_default_impl_list (std::string_view alg) |
| Get the list of available implementations of alg, as config json strings. | |
| std::string | shamalgs::impl_registry::get_current_impl (std::string_view alg) |
| Get the current implementation of alg as a config json string, "null" if unset. | |
| bool | shamalgs::impl_registry::is_impl_set (std::string_view alg) |
| Whether an implementation of alg has been selected yet. | |
| void | shamalgs::impl_registry::set_impl (std::string_view alg, std::string_view impl) |
| Select the implementation of alg from a config json string. | |
| void | shamalgs::impl_registry::autoselect_impl (std::string_view alg, const sham::DeviceScheduler_ptr &sched) |
| Select the default implementation of alg for the device behind sched. | |
Name-keyed registry of the implementation selectors (IImplVariant) of every algorithm.
Each algorithm registers its selector once, at static initialization, right after defining it:
The selection of any registered algorithm can then be read or changed by name. Every function taking an algorithm name throws std::invalid_argument if no algorithm is registered under it.
Definition in file impl_registry.hpp.
| #define SHAMALGS_REGISTER_IMPL | ( | name, | |
| impl ) |
Register the implementation selector impl under name at static initialization.
Meant for namespace scope in a .cpp file, right after the definition of impl: objects of one translation unit are initialized in definition order, so impl is constructed by then. See shamalgs::impl_registry::register_impl for the requirements and errors.
Usage :
| name | the registry name (string literal or std::string_view constant) |
| impl | the namespace-scope IImplVariant to register |
Definition at line 94 of file impl_registry.hpp.
| void shamalgs::impl_registry::autoselect_impl | ( | std::string_view | alg, |
| const sham::DeviceScheduler_ptr & | sched ) |
Select the default implementation of alg for the device behind sched.
| std::runtime_error | if sched is null |
Definition at line 99 of file impl_registry.cpp.
| std::string shamalgs::impl_registry::get_current_impl | ( | std::string_view | alg | ) |
Get the current implementation of alg as a config json string, "null" if unset.
Definition at line 86 of file impl_registry.cpp.
| std::vector< std::string > shamalgs::impl_registry::get_default_impl_list | ( | std::string_view | alg | ) |
Get the list of available implementations of alg, as config json strings.
Definition at line 82 of file impl_registry.cpp.
| std::vector< std::string > shamalgs::impl_registry::get_registered_algs | ( | ) |
Get the names of every registered algorithm, sorted.
Definition at line 73 of file impl_registry.cpp.
| bool shamalgs::impl_registry::is_impl_set | ( | std::string_view | alg | ) |
Whether an implementation of alg has been selected yet.
Definition at line 90 of file impl_registry.cpp.
| void shamalgs::impl_registry::register_impl | ( | std::string | name, |
| IImplVariant & | impl ) |
Register an implementation selector under name.
The registry stores the address of impl, which must therefore outlive every later use of the registry (in practice, a namespace-scope global). There is no unregister.
| std::invalid_argument | if name is already registered (nothing is stored then) |
Definition at line 64 of file impl_registry.cpp.
| void shamalgs::impl_registry::set_impl | ( | std::string_view | alg, |
| std::string_view | impl ) |
Select the implementation of alg from a config json string.
Definition at line 92 of file impl_registry.cpp.