11#include <nlohmann/json_fwd.hpp>
25class ExchangeRegistry {
32 using Factory = std::vector<std::unique_ptr<Exchange>> (*)(
const nlohmann::json &config);
46 std::vector<std::string>
keys()
const;
49 ExchangeRegistry() =
default;
56 std::vector<Entry> entries_;
61concept MultiInstanceVenue =
requires(
const nlohmann::json &config) { T::create_instances(config); };
73template <
typename T,
typename Base = Exchange>
74std::vector<std::unique_ptr<Base>>
make_exchanges(
const nlohmann::json &config) {
76 return T::create_instances(config);
78 std::vector<std::unique_ptr<Base>> one;
79 one.push_back(std::make_unique<T>(config));
100#define SLICK_SIM_REGISTER_VENUE(key, venue_enum, ExchangeType) \
102 ::std::vector<::std::unique_ptr<::slick::sim::exch::Exchange>> \
103 slick_sim_make_##ExchangeType(const ::nlohmann::json &config) { \
104 return ::slick::sim::exch::make_exchanges<ExchangeType>(config); \
106 [[maybe_unused]] const bool slick_sim_registered_##ExchangeType = \
107 ::slick::sim::exch::ExchangeRegistry::instance().add( \
108 key, venue_enum, &slick_sim_make_##ExchangeType); \
110 static_assert(true, "require a trailing semicolon")
Factory find(std::string_view key) const noexcept
nullptr when no adapter for this key was built into the binary.
std::vector< std::unique_ptr< Exchange > >(*)(const nlohmann::json &config) Factory
A plain function pointer, not std::function - no allocation, no <functional>.
std::vector< std::string > keys() const
Registered keys, in registration order - for the startup banner and for the error message on an unkno...
static ExchangeRegistry & instance()
bool add(std::string_view key, Venue venue, Factory factory)
key is matched case-insensitively, the same way to_venue matches a venue name.
A venue whose one config entry can describe several exchanges.
Helpers for a venue whose one config entry describes several independent exchange instances,...
std::vector< std::unique_ptr< Base > > make_exchanges(const nlohmann::json &config)
The factory body SLICK_SIM_REGISTER_VENUE registers.