10#include <userver/formats/common/items.hpp>
11#include <userver/formats/common/meta.hpp>
12#include <userver/formats/json/exception.hpp>
13#include <userver/formats/json/impl/types.hpp>
14#include <userver/formats/json/iterator.hpp>
15#include <userver/formats/json/schema.hpp>
16#include <userver/formats/json/serialize.hpp>
17#include <userver/formats/json/string_builder_fwd.hpp>
18#include <userver/formats/parse/common.hpp>
20USERVER_NAMESPACE_BEGIN
28class InlineObjectBuilder;
29class InlineArrayBuilder;
30class MutableValueWrapper;
34impl::Value MakeJsonStringViewValue(std::string_view view);
64 using ContainerType = Value;
73 using Builder = ValueBuilder;
78 Value(
const Value&) =
default;
79 Value(Value&&)
noexcept;
81 Value& operator=(
const Value&) & =
default;
82 Value& operator=(Value&&)
noexcept;
85 Value& operator=(T&&) && {
88 "You're assigning to a temporary formats::json::Value! Use "
89 "formats::json::ValueBuilder for data modifications."
109 const_iterator
end()
const;
117 const_reverse_iterator
rend()
const;
131 bool operator!=(
const Value& other)
const;
178 template <
typename T>
184 template <
typename T,
typename First,
typename... Rest>
185 auto As(First&& default_arg, Rest&&... more_default_args)
const;
190 template <
typename T>
195 template <
typename T>
200 template <
typename T,
typename First,
typename... Rest>
201 T
ConvertTo(First&& default_arg, Rest&&... more_default_args)
const;
247 struct EmplaceEnabler {
248 explicit EmplaceEnabler() =
default;
251 class LazyDetachedPath;
257 const impl::VersionedValuePtr& root,
258 const impl::Value* root_ptr_for_path,
259 const impl::Value* value_ptr,
265 const impl::VersionedValuePtr& root,
266 impl::Value* root_ptr_for_path,
267 LazyDetachedPath&& lazy_detached_path
272 explicit Value(impl::VersionedValuePtr root)
noexcept;
274 bool IsUniqueReference()
const;
275 void EnsureNotMissing()
const;
276 const impl::Value& GetNative()
const;
277 impl::Value& GetNative();
278 void SetNative(impl::Value&);
279 int GetExtendedType()
const;
281 impl::VersionedValuePtr holder_{};
282 impl::Value* root_ptr_for_path_{
nullptr};
283 impl::Value* value_ptr_{
nullptr};
292 class LazyDetachedPath
final {
294 LazyDetachedPath()
noexcept;
295 LazyDetachedPath(impl::Value* parent_value_ptr,
int parent_depth, std::string_view key);
297 LazyDetachedPath(
const LazyDetachedPath&);
298 LazyDetachedPath(LazyDetachedPath&&)
noexcept;
299 LazyDetachedPath& operator=(
const LazyDetachedPath&);
300 LazyDetachedPath& operator=(LazyDetachedPath&&)
noexcept;
302 std::string Get(
const impl::Value* root)
const;
303 LazyDetachedPath Chain(std::string_view key)
const;
306 impl::Value* parent_value_ptr_{
nullptr};
307 int parent_depth_{0};
308 std::string virtual_path_{};
311 LazyDetachedPath lazy_detached_path_;
314 friend class Iterator;
315 friend class ValueBuilder;
316 friend class StringBuilder;
318 friend class impl::InlineObjectBuilder;
319 friend class impl::InlineArrayBuilder;
320 friend class impl::MutableValueWrapper;
321 friend class parser::JsonValueParser;
322 friend class impl::StringBuffer;
324 friend bool Parse(
const Value& value,
parse::
To<
bool>);
325 friend std::int64_t Parse(
const Value& value,
parse::
To<std::int64_t>);
326 friend std::uint64_t Parse(
const Value& value,
parse::
To<std::uint64_t>);
327 friend double Parse(
const Value& value,
parse::
To<
double>);
328 friend std::string Parse(
const Value& value,
parse::
To<std::string>);
341auto Value::
As()
const {
344 "There is no `Parse(const Value&, formats::parse::To<T>)` "
345 "in namespace of `T` or `formats::parse`. "
346 "Probably you forgot to include the "
347 "<userver/formats/parse/common_containers.hpp> or you "
348 "have not provided a `Parse` function overload."
354bool Parse(
const Value& value,
parse::
To<
bool>);
356std::int64_t Parse(
const Value& value,
parse::
To<std::int64_t>);
358std::uint64_t Parse(
const Value& value,
parse::
To<std::uint64_t>);
360double Parse(
const Value& value,
parse::
To<
double>);
362std::string Parse(
const Value& value,
parse::
To<std::string>);
365bool Value::ConvertTo<
bool>()
const;
368int64_t Value::ConvertTo<int64_t>()
const;
371uint64_t Value::ConvertTo<uint64_t>()
const;
374double Value::ConvertTo<
double>()
const;
377std::string Value::ConvertTo<std::string>()
const;
379template <
typename T,
typename First,
typename... Rest>
380auto Value::
As(First&& default_arg, Rest&&... more_default_args)
const {
384 return decltype(As<T>())(std::forward<First>(default_arg), std::forward<Rest>(more_default_args)...);
396 if constexpr (
formats::
common::impl::kHasConvert<Value, T>) {
398 }
else if constexpr (
formats::
common::impl::kHasParse<Value, T>) {
403 "There is no `Convert(const Value&, formats::parse::To<T>)` or"
404 "`Parse(const Value&, formats::parse::To<T>)`"
405 "in namespace of `T` or `formats::parse`. "
406 "Probably you have not provided a `Convert` function overload."
411template <
typename T,
typename First,
typename... Rest>
412T Value::
ConvertTo(First&& default_arg, Rest&&... more_default_args)
const {
415 return T(std::forward<First>(default_arg), std::forward<Rest>(more_default_args)...);
417 return ConvertTo<T>();
420inline Value Parse(
const Value& value,
parse::
To<Value>) {
return value; }
422std::chrono::microseconds Parse(
const Value& value,
parse::
To<std::chrono::microseconds>);
424std::chrono::milliseconds Parse(
const Value& value,
parse::
To<std::chrono::milliseconds>);
426std::chrono::minutes Parse(
const Value& value, parse::To<std::chrono::minutes>);
428std::chrono::hours Parse(
const Value& value, parse::To<std::chrono::hours>);
443json::Value operator
"" _json(
const char* str, std::size_t len);