37class ValueBuilder
final {
40 using ValueType = formats::json::ValueBuilder;
41 using Reference = formats::json::ValueBuilder&;
42 using Pointer = formats::json::ValueBuilder*;
43 using ContainerType = impl::MutableValueWrapper;
46 using iterator = Iterator<IterTraits>;
49 ValueBuilder() =
default;
56 ValueBuilder(
common::TransferTag, ValueBuilder&&)
noexcept;
58 ValueBuilder(
const ValueBuilder& other);
60 ValueBuilder(ValueBuilder&& other);
61 ValueBuilder& operator=(
const ValueBuilder& other);
63 ValueBuilder& operator=(ValueBuilder&& other);
65 ValueBuilder(
const formats::json::
Value& other);
66 ValueBuilder(formats::json::
Value&& other);
70 ValueBuilder(std::nullptr_t)
74 ValueBuilder(
const char* str);
75 ValueBuilder(
char* str);
76 ValueBuilder(
const std::string& str);
77 ValueBuilder(std::string_view str);
79 ValueBuilder(
unsigned int t);
80 ValueBuilder(uint64_t t);
81 ValueBuilder(int64_t t);
82 ValueBuilder(
float t);
83 ValueBuilder(
double t);
88 ValueBuilder(
const T& t)
89 : ValueBuilder(DoSerialize(t))
94 ValueBuilder operator[](std::string key);
98 ValueBuilder operator[](std::size_t index);
101 template <
typename Tag,
utils::StrongTypedefOps Ops>
102 requires(
utils::IsStrongTypedefLoggable(Ops))
103 ValueBuilder operator[](
utils::StrongTypedef<Tag, std::string, Ops> key) {
104 return (*
this)[std::move(key.GetUnderlying())];
110 void EmplaceNocheck(std::string_view key, ValueBuilder value);
114 void Remove(std::string_view key);
121 bool IsEmpty()
const;
124 bool IsNull()
const noexcept;
127 bool IsBool()
const noexcept;
130 bool IsInt()
const noexcept;
133 bool IsInt64()
const noexcept;
136 bool IsUInt64()
const noexcept;
139 bool IsDouble()
const noexcept;
142 bool IsString()
const noexcept;
145 bool IsArray()
const noexcept;
148 bool IsObject()
const noexcept;
152 std::size_t GetSize()
const;
156 bool HasMember(std::string_view key)
const;
159 std::string GetPath()
const;
164 void Resize(std::size_t size);
168 void PushBack(ValueBuilder&& bld);
174 formats::json::
Value ExtractValue();
177 class EmplaceEnabler {};
181 ValueBuilder(EmplaceEnabler, impl::MutableValueWrapper)
noexcept;
185 enum class CheckMemberExists { kYes, kNo };
187 explicit ValueBuilder(impl::MutableValueWrapper)
noexcept;
189 static void Copy(impl::Value& to,
const ValueBuilder& from);
190 static void Move(impl::Value& to, ValueBuilder&& from);
192 impl::Value& AddMember(std::string_view key, CheckMemberExists);
194 template <
typename T>
195 USERVER_IMPL_NODEBUG_INLINE_FUNC
static Value DoSerialize(
const T& t) {
198 "There is no `Serialize(const T&, formats::serialize::To<json::Value>)` "
199 "in namespace of `T` or `formats::serialize`. "
201 "Probably you forgot to include the <userver/formats/serialize/common_containers.hpp> header "
202 "or one of the <formats/json/serialize_*.hpp> headers or you have not provided a `Serialize` function "
209 impl::MutableValueWrapper value_;
237requires meta::IsUniqueMap<T> && std::is_convertible_v<
typename T::key_type, std::string>