61 lines
2.0 KiB
C++
61 lines
2.0 KiB
C++
#pragma once
|
|
|
|
#include "lib/domain_model/Security.pb.h"
|
|
#include "lib/orderman/CancelOrderMsg.h"
|
|
#include "lib/orderman/CancelReplaceOrderMsg.h"
|
|
#include "lib/orderman/CreateOrderMsg.h"
|
|
#include "lib/orderman/RFQMsg.h"
|
|
#include "lib/utils/overloaded.h"
|
|
|
|
#include <variant>
|
|
|
|
namespace bts::orderman {
|
|
|
|
using OrderMsg =
|
|
std::variant<CreateOrderMsg, CancelReplaceOrderMsg, CancelOrderMsg, RFQMsg>;
|
|
|
|
inline std::ostream &operator<<(std::ostream &out, OrderMsg const &msg) {
|
|
if (std::holds_alternative<CreateOrderMsg>(msg)) {
|
|
const CreateOrderMsg &cr_msg = std::get<CreateOrderMsg>(msg);
|
|
out << "Create: " << cr_msg;
|
|
} else if (std::holds_alternative<CancelReplaceOrderMsg>(msg)) {
|
|
const CancelReplaceOrderMsg &cxlr_msg =
|
|
std::get<CancelReplaceOrderMsg>(msg);
|
|
out << "CancelReplace : " << cxlr_msg;
|
|
} else if (std::holds_alternative<CancelOrderMsg>(msg)) {
|
|
const CancelOrderMsg &cxl_msg = std::get<CancelOrderMsg>(msg);
|
|
out << "Cancel: : " << cxl_msg;
|
|
}
|
|
return out;
|
|
}
|
|
} // namespace bts::orderman
|
|
|
|
template <>
|
|
struct fmt ::formatter<bts ::orderman ::OrderMsg> {
|
|
constexpr auto parse(fmt ::format_parse_context &ctx)
|
|
-> decltype(ctx.end()) {
|
|
return ctx.end();
|
|
}
|
|
template <typename FormatContext>
|
|
auto format(const bts ::orderman ::OrderMsg &m, FormatContext &ctx) const
|
|
-> decltype(ctx.out()) {
|
|
std::visit(
|
|
bts::overloaded{
|
|
[&ctx](const bts::orderman::CreateOrderMsg &m) {
|
|
fmt::format_to(ctx.out(), "{}", m);
|
|
},
|
|
[&ctx](const bts::orderman::CancelReplaceOrderMsg &m) {
|
|
fmt::format_to(ctx.out(), "{}", m);
|
|
},
|
|
[&ctx](const bts::orderman::CancelOrderMsg &m) {
|
|
fmt::format_to(ctx.out(), "{}", m);
|
|
},
|
|
[&ctx](const bts::orderman::RFQMsg &r) {
|
|
fmt::format_to(ctx.out(), "{}", r);
|
|
},
|
|
[]() {}},
|
|
m);
|
|
return fmt::format_to(ctx.out(), "{}", m);
|
|
}
|
|
};
|