12 #ifndef DOCWIRE_STRINGIFICATION_H
13 #define DOCWIRE_STRINGIFICATION_H
15 #include "concepts_misc.h"
16 #include "concepts_stream.h"
17 #include "concepts_string.h"
18 #include "diagnostic_message.h"
20 #include "serialization_base.h"
23 #include <type_traits>
36 std::string stringify(
const T& value)
44 template <streamable T>
48 std::string operator()(
const T& value)
const
59 template <
string_method_equipped T>
62 std::string operator()(
const T& value)
const {
return std::string(value.string()); }
77 requires (!string_method_equipped<T> && !streamable<T> && !strong_type_alias<T>)
80 std::string operator()(
const T& value)
const
89 std::string operator()(
const char* value)
const {
return value; }
102 template <
typename T1,
typename T2>
105 std::string operator()(
const std::pair<T1, T2>& pair)
const
107 return stringify(pair.first) +
": " + stringify(pair.second);
114 template <
typename T>
119 return stringify(nv.
name) +
": " + stringify(nv.
value);
123 template <strong_type_alias T>
125 !std::is_same_v<T, serialization::object> &&
126 !std::is_same_v<T, serialization::array>)
129 std::string operator()(
const T& value)
const {
return stringify(value.v); }
135 std::string operator()(
const std::string& value)
const {
return value; }
153 [](
auto&& arg) -> std::string {
154 using T = std::decay_t<decltype(arg)>;
155 if constexpr (std::is_same_v<T, serialization::object>)
157 std::string result =
"{";
159 for (
const auto& [key, val] : arg.v)
161 if (!first) result +=
", ";
162 result += key +
": " + stringify(val);
168 else if constexpr (std::is_same_v<T, serialization::array>)
170 std::string result =
"[";
172 for (
const auto& val : arg.v)
174 if (!first) result +=
", ";
175 result += stringify(val);
181 else if constexpr (std::is_same_v<T, std::nullptr_t>)
185 else if constexpr (std::is_same_v<T, bool>)
187 return arg ?
"true" :
"false";
191 return stringify(arg);
DOCWIRE_CORE_EXPORT std::string diagnostic_message(const std::exception &e)
Generates a diagnostic message for the given nested exceptions chain.
std::variant< std::nullptr_t, bool, std::int64_t, std::uint64_t, double, std::string, array, object > value
A variant type representing any serialized value.
value full(const T &value)
Serializes a value of type T into a docwire::serialization::value.
The main namespace for the DocWire SDK.
requires(!string_method_equipped< T >) struct stringifier< T >
Specialization for types that are streamable to std::ostream.
T value
The value of the parameter.
std::string_view name
The name of the parameter.
Represents a serialized object (map of string keys to values).
Specialization for types with a string() method.
Primary template for the stringifier.