44 using std::logic_error::logic_error;
61 return static_cast<Transports>(
static_cast<std::uint8_t
>(a) |
static_cast<std::uint8_t
>(b));
64 return (
static_cast<std::uint8_t
>(set) &
static_cast<std::uint8_t
>(t)) != 0;
72 if constexpr (
requires {
typename S::params_type; }) {
73 return [](ParamSink sink,
const ParamMap& params, std::size_t instruments) {
74 typename S::params_type p{};
75 if (
auto err = p.apply(params))
throw std::invalid_argument(*err);
76 if (
auto err = validate_params(p))
throw std::invalid_argument(*err);
77 bool per_instrument =
false;
78 if constexpr (
requires { S::param_scope; })
80 return std::make_unique<ParamPublisher>(sink, p, per_instrument ? instruments : 0);
90template <
class S, Transports Enabled = Transports::All>
92 static_assert(StrategyLike<S>,
93 "fastmm: register_strategy<S> needs a strategy: static name(), static schema() "
94 "and a default constructor");
96 switch (r.try_add(S::name(), &S::schema(), kind, factory, detail::publisher_factory<S>())) {
103 ") is already registered by different code; strategy names must be "
104 "unique across every registered library");
108 throw std::invalid_argument(
"strategy '" + std::string(S::name()) +
109 "' cannot be registered: empty name or no parameter schema");
128#define FASTMM_INSTANTIATE_STRATEGY(S, kind) \
129 template auto ::fastmm::kind##_factory<S>(::fastmm::TransportKind, ::fastmm::RunnerDeps&) \
130 ->std::unique_ptr<::fastmm::IEngineRunner>
Thrown by register_strategy when a name is already registered with a different schema or factory.
Definition module.hpp:44
Definition strategy.hpp:23
void(*)(StrategyRegistry &) StrategyModule
A strategy library's registration function.
Definition module.hpp:41
std::unique_ptr< IEngineRunner > replay_factory(TransportKind kind, RunnerDeps &deps)
Definition factory_replay.hpp:15
constexpr bool has(Transports set, Transports t) noexcept
Definition module.hpp:65
constexpr Transports operator|(Transports a, Transports b) noexcept
Definition module.hpp:62
Transports
Internal: the factories register_strategy adds.
Definition module.hpp:61
TransportKind
Definition registry.hpp:33
std::unique_ptr< IEngineRunner > sim_factory(TransportKind kind, RunnerDeps &deps)
Declared template <class S>, not template <StrategyLike S>: GCC and Clang mangle constrained template...
Definition factory_sim.hpp:15
constexpr std::string_view to_string(ParamType t) noexcept
Definition params.hpp:63
@ Invalid
empty name, null schema or factory, or an invalid kind
@ AlreadyPresent
the same schema and factory were registered before: nothing changed
@ Conflict
name is registered with a different schema, or (name, kind) with another factory
@ Added
the factory is now registered for (name, kind)
void register_strategy(StrategyRegistry &r)
Adds the Sim, Replay and Live factories of S (or those in Enabled).
Definition module.hpp:93
std::unique_ptr< IEngineRunner > live_factory(TransportKind kind, RunnerDeps &deps)
Definition factory_live.hpp:15
std::map< std::string, std::string > ParamMap
Definition params.hpp:119
Strategy registry (8.6, ADR-0012): name -> parameter schema + one factory per transport kind,...
Strategy concept and the StrategyBase helper (8.6).
Everything a factory needs that is backend-independent.
Definition registry.hpp:51
std::unique_ptr< ParamPublisher >(*)(ParamSink, const ParamMap &, std::size_t instruments) PublisherFactory
Builds a publisher for this strategy's parameters over sink, its copy seeded with the values the sess...
Definition registry.hpp:74
std::unique_ptr< IEngineRunner >(*)(TransportKind, RunnerDeps &) Factory
Definition registry.hpp:65