9#ifndef CAMCOM_COMMON_VALUE_HPP
10#define CAMCOM_COMMON_VALUE_HPP
14#include <fmt/format.h>
17 using Value = std::variant<int, float, double, std::string, bool>;
20 return std::visit([](
const auto &x) -> std::string_view {
21 using T = std::decay_t<
decltype(x)>;
22 if constexpr (std::is_same_v<T, int>) {
return "int"; }
23 else if constexpr (std::is_same_v<T, float>) {
return "float"; }
24 else if constexpr (std::is_same_v<T, double>) {
return "double"; }
25 else if constexpr (std::is_same_v<T, std::string>) {
return "string"; }
26 else if constexpr (std::is_same_v<T, bool>) {
return "bool"; }
27 else {
return "unknown"; }
37 struct formatter<
camcom::common::Value> {
42 constexpr auto parse(format_parse_context& ctx) {
43 auto it = ctx.begin();
44 const auto end = ctx.end();
45 if (it != end && *it !=
'}') {
46 const auto start = it;
47 do { ++it; }
while (it != end && *it !=
'}');
48 specs.assign(start, it);
53 template <
typename FormatContext>
55 ->
typename FormatContext::iterator
57 return std::visit([&](
const auto& x) ->
typename FormatContext::iterator {
60 return fmt::format_to(ctx.out(),
"{}", x);
64 f.reserve(
specs.size() + 3);
68 return fmt::format_to(ctx.out(), fmt::runtime(f), x);
Definition adapterBase.cpp:18
std::variant< int, float, double, std::string, bool > Value
Definition value.hpp:17
std::string_view ValueTypeString(const Value &v) noexcept
Definition value.hpp:19
Definition adapterBase.cpp:18