|
FastMM C++ API 0.6.0
Public headers, tier 1 and tier 2
|
Strategy modules (ADR-0012, section 5): one registration function per strategy library. More...
#include "fastmm/strategies/registry.hpp"#include "fastmm/strategies/strategy.hpp"#include <cstdint>#include <memory>#include <stdexcept>#include <string>Go to the source code of this file.
Classes | |
| class | fastmm::StrategyConflict |
| Thrown by register_strategy when a name is already registered with a different schema or factory. More... | |
Namespaces | |
| namespace | fastmm |
Macros | |
| #define | FASTMM_INSTANTIATE_STRATEGY(S, kind) |
| Explicit instantiation of one factory, for splitting a strategy's engines over several files: | |
Typedefs | |
| using | fastmm::StrategyModule = void(*)(StrategyRegistry &) |
| A strategy library's registration function. | |
Enumerations | |
| enum class | fastmm::Transports : std::uint8_t { fastmm::None = 0 , fastmm::Sim = 1 , fastmm::Replay = 2 , fastmm::Live = 4 , fastmm::All = 7 } |
| Internal: the factories register_strategy adds. More... | |
Functions | |
| template<class S > | |
| std::unique_ptr< IEngineRunner > | fastmm::sim_factory (TransportKind kind, RunnerDeps &deps) |
Declared template <class S>, not template <StrategyLike S>: GCC and Clang mangle constrained templates differently. | |
| template<class S > | |
| std::unique_ptr< IEngineRunner > | fastmm::replay_factory (TransportKind kind, RunnerDeps &deps) |
| template<class S > | |
| std::unique_ptr< IEngineRunner > | fastmm::live_factory (TransportKind kind, RunnerDeps &deps) |
| constexpr Transports | fastmm::operator| (Transports a, Transports b) noexcept |
| constexpr bool | fastmm::has (Transports set, Transports t) noexcept |
| template<class S , Transports Enabled = Transports::All> | |
| void | fastmm::register_strategy (StrategyRegistry &r) |
Adds the Sim, Replay and Live factories of S (or those in Enabled). | |
Strategy modules (ADR-0012, section 5): one registration function per strategy library.
// mm/strategies.hpp namespace mm { void register_strategies(fastmm::StrategyRegistry& r); }
// strategies.cpp: the only registration file a strategy library needs #include "fastmm/strategies/factories.hpp" // factory definitions: instantiates the engines #include "mm/microprice_mm.hpp" #include "mm/strategies.hpp" void mm::register_strategies(fastmm::StrategyRegistry& r) { fastmm::register_strategy<mm::MicropriceMM>(r); // Sim + Replay + Live }
// apps: int main(int argc, char** argv) { return fastmm::cli::live(argc, argv, {mm::register_strategies}); }
This header only declares the factories; it never instantiates Engine. Their definitions are in factory_sim.hpp, factory_replay.hpp and factory_live.hpp (factories.hpp includes all three). A file that calls register_strategy<S> without them only references the factories, so a missing instantiation is a link error naming the factory, not an "unknown strategy" at runtime. The app references the registration function, so the linker pulls it and the instantiations out of static archives: no static initialisers and no whole-archive linking.
Only a strategy's owner instantiates it (two libraries instantiating the same factory break the one-definition rule); to use someone else's strategy, call their registration function.
| #define FASTMM_INSTANTIATE_STRATEGY | ( | S, | |
| kind | |||
| ) |
Explicit instantiation of one factory, for splitting a strategy's engines over several files:
// microprice_mm_live.cpp #include "fastmm/strategies/factory_live.hpp" #include "mm/microprice_mm.hpp" FASTMM_INSTANTIATE_STRATEGY(mm::MicropriceMM, live);
kind is sim, replay or live; the matching factory_<kind>.hpp must be included. (The trailing return type keeps unique_ptr<...> fastmm::... from parsing as a nested name.)