11#include <userver/formats/common/items.hpp>
12#include <userver/formats/common/meta.hpp>
13#include <userver/formats/json/exception.hpp>
14#include <userver/formats/json/impl/types.hpp>
15#include <userver/formats/json/iterator.hpp>
16#include <userver/formats/json/schema.hpp>
17#include <userver/formats/json/serialize.hpp>
18#include <userver/formats/json/string_builder_fwd.hpp>
19#include <userver/formats/parse/common.hpp>
21USERVER_NAMESPACE_BEGIN
29class InlineObjectBuilder;
30class InlineArrayBuilder;
31class MutableValueWrapper;
35impl::Value MakeJsonStringViewValue(std::string_view view);
67 using ContainerType = Value;
76 using Builder = ValueBuilder;
81 Value(
const Value&) =
default;
82 Value(Value&&)
noexcept;
84 Value& operator=(
const Value&) & =
default;
85 Value& operator=(Value&&)
noexcept;
88 Value& operator=(T&&) && {
91 "You're assigning to a temporary formats::json::Value! Use "
92 "formats::json::ValueBuilder for data modifications."
114 const_iterator
end()
const;
122 const_reverse_iterator
rend()
const;
136 bool operator!=(
const Value& other)
const;
183 template <
typename T>
189 template <
typename T,
typename First,
typename... Rest>
190 auto As(First&& default_arg, Rest&&... more_default_args)
const;
195 template <
typename T>
200 template <
typename T>
205 template <
typename T,
typename First,
typename... Rest>
206 T
ConvertTo(First&& default_arg, Rest&&... more_default_args)
const;
252 struct EmplaceEnabler {
253 explicit EmplaceEnabler() =
default;
256 class LazyDetachedPath;
262 const impl::VersionedValuePtr& root,
263 const impl::Value* root_ptr_for_path,
264 const impl::Value* value_ptr,
270 const impl::VersionedValuePtr& root,
271 impl::Value* root_ptr_for_path,
272 LazyDetachedPath&& lazy_detached_path
277 explicit Value(impl::VersionedValuePtr root)
noexcept;
279 bool IsUniqueReference()
const;
280 void EnsureNotMissing()
const;
281 const impl::Value& GetNative()
const;
282 impl::Value& GetNative();
283 void SetNative(impl::Value&);
284 int GetExtendedType()
const;
286 impl::VersionedValuePtr holder_{};
287 impl::Value* root_ptr_for_path_{
nullptr};
288 impl::Value* value_ptr_{
nullptr};
297 class LazyDetachedPath
final {
299 LazyDetachedPath()
noexcept;
300 LazyDetachedPath(impl::Value* parent_value_ptr,
int parent_depth, std::string_view key);
302 LazyDetachedPath(
const LazyDetachedPath&);
303 LazyDetachedPath(LazyDetachedPath&&)
noexcept;
304 LazyDetachedPath& operator=(
const LazyDetachedPath&);
305 LazyDetachedPath& operator=(LazyDetachedPath&&)
noexcept;
307 std::string Get(
const impl::Value* root)
const;
308 LazyDetachedPath Chain(std::string_view key)
const;
311 impl::Value* parent_value_ptr_{
nullptr};
312 int parent_depth_{0};
313 std::string virtual_path_{};
316 LazyDetachedPath lazy_detached_path_;
319 friend class Iterator;
320 friend class ValueBuilder;
321 friend class StringBuilder;
323 friend class impl::InlineObjectBuilder;
324 friend class impl::InlineArrayBuilder;
325 friend class impl::MutableValueWrapper;
326 friend class parser::JsonValueParser;
327 friend class impl::StringBuffer;
329 friend bool Parse(
const Value& value,
parse::
To<
bool>);
330 friend std::int64_t Parse(
const Value& value,
parse::
To<std::int64_t>);
331 friend std::uint64_t Parse(
const Value& value,
parse::
To<std::uint64_t>);
332 friend double Parse(
const Value& value,
parse::
To<
double>);
333 friend std::string Parse(
const Value& value,
parse::
To<std::string>);
346auto Value::
As()
const {
349 "There is no `Parse(const Value&, formats::parse::To<T>)` "
350 "in namespace of `T` or `formats::parse`. "
351 "Probably you forgot to include the "
352 "<userver/formats/parse/common_containers.hpp> or you "
353 "have not provided a `Parse` function overload."
359bool Parse(
const Value& value,
parse::
To<
bool>);
361std::int64_t Parse(
const Value& value,
parse::
To<std::int64_t>);
363std::uint64_t Parse(
const Value& value,
parse::
To<std::uint64_t>);
365double Parse(
const Value& value,
parse::
To<
double>);
367std::string Parse(
const Value& value,
parse::
To<std::string>);
370bool Value::ConvertTo<
bool>()
const;
373int64_t Value::ConvertTo<int64_t>()
const;
376uint64_t Value::ConvertTo<uint64_t>()
const;
379double Value::ConvertTo<
double>()
const;
382std::string Value::ConvertTo<std::string>()
const;
384template <
typename T,
typename First,
typename... Rest>
385auto Value::
As(First&& default_arg, Rest&&... more_default_args)
const {
389 return decltype(As<T>())(std::forward<First>(default_arg), std::forward<Rest>(more_default_args)...);
401 if constexpr (
formats::
common::impl::kHasConvert<Value, T>) {
403 }
else if constexpr (
formats::
common::impl::kHasParse<Value, T>) {
408 "There is no `Convert(const Value&, formats::parse::To<T>)` or"
409 "`Parse(const Value&, formats::parse::To<T>)`"
410 "in namespace of `T` or `formats::parse`. "
411 "Probably you have not provided a `Convert` function overload."
416template <
typename T,
typename First,
typename... Rest>
417T Value::
ConvertTo(First&& default_arg, Rest&&... more_default_args)
const {
420 return T(std::forward<First>(default_arg), std::forward<Rest>(more_default_args)...);
422 return ConvertTo<T>();
425inline Value Parse(
const Value& value,
parse::
To<Value>) {
return value; }
427std::chrono::microseconds Parse(
const Value& value,
parse::
To<std::chrono::microseconds>);
429std::chrono::milliseconds Parse(
const Value& value,
parse::
To<std::chrono::milliseconds>);
431std::chrono::minutes Parse(
const Value& value, parse::To<std::chrono::minutes>);
433std::chrono::hours Parse(
const Value& value, parse::To<std::chrono::hours>);
451json::Value operator
"" _json(
const char* str, std::size_t len);