10std::string to_lower(std::string_view s) {
12 std::transform(out.begin(), out.end(), out.begin(),
13 [](
unsigned char c) { return static_cast<char>(std::tolower(c)); });
20 static BrokerRegistry registry;
27 auto lowered = to_lower(key);
28 if (factory ==
nullptr ||
find(lowered) !=
nullptr) {
31 entries_.push_back(Entry{std::move(lowered), factory});
36 for (
const auto& entry : entries_) {
37 if (entry.key.size() == key.size() &&
38 std::equal(entry.key.begin(), entry.key.end(), key.begin(), [](
char a,
unsigned char b) {
39 return a == static_cast<char>(std::tolower(b));
48 slick::stream_buffer_multiplexer& event_mux,
49 slick::queue<uint8_t>& control_queue,
50 slick::queue<uint8_t>& md_request_queue,
51 slick::queue<uint8_t>& order_request_queue,
52 std::string& error)
const {
54 if (factory ==
nullptr) {
55 error =
"no adapter for '" + std::string(key) +
"' is built into this binary";
59 auto broker = factory(config, event_mux, control_queue, md_request_queue, order_request_queue);
61 error =
"its factory returned nothing";
64 }
catch (
const std::exception& e) {
67 error =
"its constructor threw something that is not a std::exception";
73 std::vector<std::string> result;
74 result.reserve(entries_.size());
75 for (
const auto& entry : entries_) {
76 result.push_back(entry.key);
static BrokerRegistry & instance()
std::shared_ptr< IBroker >(*)( const json &config, slick::stream_buffer_multiplexer &event_mux, slick::queue< uint8_t > &control_queue, slick::queue< uint8_t > &md_request_queue, slick::queue< uint8_t > &order_request_queue) Factory
A plain function pointer, not std::function - no allocation, no <functional>.
Factory find(std::string_view key) const noexcept
nullptr when no adapter for this key was built into the binary.
bool add(std::string_view key, Factory factory)
key is matched case-insensitively.
std::vector< std::string > keys() const
Registered keys, lowercased, in registration order - for the startup log and for the error on an unkn...
std::shared_ptr< IBroker > create(std::string_view key, const json &config, slick::stream_buffer_multiplexer &event_mux, slick::queue< uint8_t > &control_queue, slick::queue< uint8_t > &md_request_queue, slick::queue< uint8_t > &order_request_queue, std::string &error) const
Builds the broker registered under key.