Strategy hooks (ADR-0012): the hook table, the compile-time checker and the Fill view.
More...
|
| #define | FASTMM_STRATEGY_HOOKS(X) |
| | The hook table.
|
| |
| #define | FASTMM_STRATEGY_HOOK_NEAR_MISSES(Y) |
| | Y(misspelling, hook): names that produce a "did you mean" warning.
|
| |
| #define | FASTMM_HOOK_ENUM(E, name, word, params, args, sig) E, |
| |
| #define | FASTMM_HOOK_INFO(E, name, word, params, args, sig) {Hook::E, #name, word, sig}, |
| |
| #define | FASTMM_HOOK_UNPAREN(...) __VA_ARGS__ |
| |
| #define | FASTMM_HOOK_PROBE(name) |
| |
| #define | FASTMM_HOOK_CALL(E, name, word, params, args, sig) |
| |
| #define | FASTMM_HOOK_NEAR_MISS(name, hook) |
| |
| #define | FASTMM_HOOK_STATUS(E, name, word, params, args, sig) |
| |
| #define | FASTMM_HOOK_ASSERT(E, name, word, params, args, sig) |
| |
| #define | FASTMM_HOOK_WARN(name, hook) |
| |
|
| template<class S > |
| constexpr std::uint32_t | fastmm::state_version_of (S &s) noexcept |
| | The layout of the bytes state() returns: static constexpr std::uint32_t state_version, or a state_version() member function; 0 when the strategy declares none.
|
| |
| template<class S , class Ctx , class Book > |
| constexpr HookStatus | fastmm::hook_status (Hook h) noexcept |
| |
| template<class S , class Ctx , class Book > |
| constexpr bool | fastmm::implements_hook (Hook h) noexcept |
| | True when the engine calls S's hook h (the engine dispatches on this at compile time).
|
| |
| template<class S , class Ctx = detail::hooks::StandInContext, class Book = detail::hooks::StandInBook> |
| constexpr bool | fastmm::verify_strategy () noexcept |
| | Compile-time check of every hook of S; always returns true (failures are static_asserts), so it can be written as static_assert(fastmm::verify_strategy<MyMM>());.
|
| |
| template<class S , class Ctx , class Book > |
| constexpr std::string_view | fastmm::implemented_hooks () noexcept |
| | The implemented hooks as words in table order ("start book fill timer connection quoting").
|
| |
Strategy hooks (ADR-0012): the hook table, the compile-time checker and the Fill view.
A strategy is a plain class. Its hooks are ordinary public member functions, all optional:
on_start(ctx) on_stop(ctx) on_book(ctx, id, book) on_book_ticker(ctx, id, m) on_trade(ctx, id, m) on_option_ticker(ctx, id, m) on_fill(ctx, fill) on_order_update(ctx, u) on_timer(ctx, timer_id, tag) on_connection(ctx, m) on_quoting(ctx, enabled) on_params(ctx) on_balance(ctx, m) on_perp_state(ctx, id, m) on_risk_reject(ctx, r) on_batch_end(ctx) on_instrument_rules(ctx, id, m)
The engine checks every hook name when it is instantiated. If the strategy has a member with a hook's name (function, template, data member, static, inherited or private) and the engine's call does not compile, the build stops with one error per hook:
fastmm: on_trade has the wrong signature or is not public; expected void on_trade(auto& ctx, InstrumentId id, const TradeMsg& m)
A few likely misspellings (on_fills, on_tick, onBook, ...) produce a deprecation warning instead, because a private helper may use such a name; static constexpr bool fastmm_allow_near_miss_names = true; in the strategy silences it. Strategy headers can run the same check early with stand-in context and book types:
static_assert(fastmm::verify_strategy<MyMM>());
Limits:
- a
final class loses the name probe; only the call check remains, so a wrong signature is silently not called;
- a hook that is ambiguous across two bases is reported as a wrong signature;
- a hook with a deduced (
auto) return type must not be checked with verify_strategy: the stand-in types instantiate its body;
- private hooks are rejected, also when the class befriends the engine;
- implicit argument conversions are accepted (on_timer(auto&, TimerId, int) compiles);
- near-miss warnings are emitted inside this header, so a build that includes FastMM as a system header does not show them.