2#include <ossia/detail/config.hpp>
3#if defined(OSSIA_HAS_FMT)
4#include <ossia/detail/flat_set.hpp>
5#include <ossia/detail/fmt.hpp>
6#include <ossia/detail/optional.hpp>
7#include <ossia/network/value/value.hpp>
9#include <boost/algorithm/string/replace.hpp>
11#include <fmt/ranges.h>
13#if FMT_VERSION >= 120200
16template <
typename T>
struct is_container_adaptor<boost::container::flat_set<T>>
20#elif FMT_VERSION >= 100000
22template <
typename T>
class is_container_adaptor_like<boost::container::flat_set<T>>
23 :
public std::false_type {
31template <
typename FmtCtx>
32struct value_prettyprint_visitor
35 using iterator =
typename FmtCtx::iterator;
36 iterator operator()(impulse)
const;
37 iterator operator()(int32_t i)
const;
38 iterator operator()(
float f)
const;
39 iterator operator()(
bool b)
const;
40 iterator operator()(
char c)
const;
41 iterator operator()(std::string str)
const;
42 iterator operator()(vec2f vec)
const;
43 iterator operator()(vec3f vec)
const;
44 iterator operator()(vec4f vec)
const;
45 iterator operator()(
const std::vector<ossia::value>& t)
const;
46 iterator operator()(
const value_map_type& t)
const;
47 iterator operator()()
const;
54struct formatter<std::optional<T>>
56 template <
typename ParseContext>
57 constexpr auto parse(ParseContext& ctx)
62 template <
typename FormatContext>
63 auto format(
const std::optional<T>& n, FormatContext& ctx)
const
67 return fmt::format_to(ctx.out(),
"{}", *n);
71 return fmt::format_to(ctx.out(),
"none");
77struct formatter<
ossia::value>
79 template <
typename ParseContext>
80 constexpr auto parse(ParseContext& ctx)
85 template <
typename FormatContext>
86 auto format(
const ossia::value& v, FormatContext& ctx)
const
88 return v.apply(ossia::value_prettyprint_visitor<FormatContext>{ctx});
97template <
typename FmtCtx>
98inline typename FmtCtx::iterator
99value_prettyprint_visitor<FmtCtx>::operator()(impulse)
const
101 return fmt::format_to(ctx.out(),
"impulse");
104template <
typename FmtCtx>
105inline typename FmtCtx::iterator
106value_prettyprint_visitor<FmtCtx>::operator()(int32_t i)
const
108 return fmt::format_to(ctx.out(),
"int: {}", i);
111template <
typename FmtCtx>
112inline typename FmtCtx::iterator
113value_prettyprint_visitor<FmtCtx>::operator()(
float f)
const
115 return fmt::format_to(ctx.out(),
"float: {:.2f}", f);
118template <
typename FmtCtx>
119inline typename FmtCtx::iterator
120value_prettyprint_visitor<FmtCtx>::operator()(
bool b)
const
122 return fmt::format_to(ctx.out(),
"bool: {}", b ?
"true" :
"false");
125template <
typename FmtCtx>
126inline typename FmtCtx::iterator
127value_prettyprint_visitor<FmtCtx>::operator()(
char c)
const
129 return fmt::format_to(ctx.out(),
"char: '{}'", c);
132template <
typename FmtCtx>
133inline typename FmtCtx::iterator
134value_prettyprint_visitor<FmtCtx>::operator()(std::string str)
const
136 boost::algorithm::replace_all(str,
"\"",
"\\\"");
137 return fmt::format_to(ctx.out(),
"string: \"{}\"", str);
140template <
typename FmtCtx>
141inline typename FmtCtx::iterator
142value_prettyprint_visitor<FmtCtx>::operator()(vec2f vec)
const
144 return fmt::format_to(ctx.out(),
"vec2f: [{:.2f}, {:.2f}]", vec[0], vec[1]);
147template <
typename FmtCtx>
148inline typename FmtCtx::iterator
149value_prettyprint_visitor<FmtCtx>::operator()(vec3f vec)
const
151 return fmt::format_to(
152 ctx.out(),
"vec3f: [{:.2f}, {:.2f}, {:.2f}]", vec[0], vec[1], vec[2]);
155template <
typename FmtCtx>
156inline typename FmtCtx::iterator
157value_prettyprint_visitor<FmtCtx>::operator()(vec4f vec)
const
159 return fmt::format_to(
160 ctx.out(),
"vec4f: [{:.2f}, {:.2f}, {:.2f}, {:.2f}]", vec[0], vec[1], vec[2],
163template <
typename FmtCtx>
164inline typename FmtCtx::iterator
165value_prettyprint_visitor<FmtCtx>::operator()(
const std::vector<value>& t)
const
167 fmt::format_to(ctx.out(),
"list: [");
172 if(++i < std::ssize(t))
173 fmt::format_to(ctx.out(),
", ");
175 return fmt::format_to(ctx.out(),
"]");
178template <
typename FmtCtx>
179inline typename FmtCtx::iterator
180value_prettyprint_visitor<FmtCtx>::operator()(
const value_map_type& t)
const
182 fmt::format_to(ctx.out(),
"map: {{");
186 fmt::format_to(ctx.out(),
"\"{}\": ", v.first);
187 v.second.apply(*
this);
188 if(++i < std::ssize(t))
189 fmt::format_to(ctx.out(),
", ");
191 return fmt::format_to(ctx.out(),
"}}");
194template <
typename FmtCtx>
195inline typename FmtCtx::iterator value_prettyprint_visitor<FmtCtx>::operator()()
const
197 return fmt::format_to(ctx.out(),
"invalid");
The value class.
Definition value.hpp:173