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/string_builder_fwd.hpp>
17#include <userver/formats/parse/common.hpp>
19USERVER_NAMESPACE_BEGIN
27class InlineObjectBuilder;
28class InlineArrayBuilder;
29class MutableValueWrapper;
33impl::Value MakeJsonStringViewValue(std::string_view view);
65 using ContainerType =
Value;
74 using Builder = ValueBuilder;
79 Value(
const Value&) =
default;
80 Value(
Value&&)
noexcept;
86 Value& operator=(T&&) && {
89 "You're assigning to a temporary formats::json::Value! Use "
90 "formats::json::ValueBuilder for data modifications."
112 const_iterator
end()
const;
120 const_reverse_iterator
rend()
const;
134 bool operator!=(
const Value& other)
const;
184 template <
typename T>
190 template <
typename T,
typename First,
typename... Rest>
191 auto As(First&& default_arg, Rest&&... more_default_args)
const;
196 template <
typename T>
201 template <
typename T>
206 template <
typename T,
typename First,
typename... Rest>
207 T
ConvertTo(First&& default_arg, Rest&&... more_default_args)
const;
256 struct EmplaceEnabler {
257 explicit EmplaceEnabler() =
default;
260 class LazyDetachedPath;
266 const impl::VersionedValuePtr& root,
267 const impl::Value* root_ptr_for_path,
268 const impl::Value* value_ptr,
274 const impl::VersionedValuePtr& root,
275 impl::Value* root_ptr_for_path,
276 LazyDetachedPath&& lazy_detached_path
281 explicit Value(impl::VersionedValuePtr root)
noexcept;
283 bool IsUniqueReference()
const;
284 void EnsureNotMissing()
const;
285 const impl::Value& GetNative()
const;
286 impl::Value& GetNative();
287 void SetNative(impl::Value&);
288 int GetExtendedType()
const;
290 impl::VersionedValuePtr holder_{};
291 impl::Value* root_ptr_for_path_{
nullptr};
292 impl::Value* value_ptr_{
nullptr};
301 class LazyDetachedPath
final {
303 LazyDetachedPath()
noexcept;
304 LazyDetachedPath(impl::Value* parent_value_ptr,
int parent_depth, std::string_view key);
306 LazyDetachedPath(
const LazyDetachedPath&);
307 LazyDetachedPath(LazyDetachedPath&&)
noexcept;
308 LazyDetachedPath& operator=(
const LazyDetachedPath&);
309 LazyDetachedPath& operator=(LazyDetachedPath&&)
noexcept;
311 std::string Get(
const impl::Value* root)
const;
312 LazyDetachedPath Chain(std::string_view key)
const;
315 impl::Value* parent_value_ptr_{
nullptr};
316 int parent_depth_{0};
317 std::string virtual_path_{};
320 LazyDetachedPath lazy_detached_path_;
323 friend class Iterator;
324 friend class ValueBuilder;
325 friend class StringBuilder;
327 friend class impl::InlineObjectBuilder;
328 friend class impl::InlineArrayBuilder;
329 friend class impl::MutableValueWrapper;
330 friend class parser::JsonValueParser;
331 friend class impl::StringBuffer;
334 friend std::int64_t Parse(
const Value& value,
parse::
To<std::int64_t>);
335 friend std::uint64_t Parse(
const Value& value,
parse::
To<std::uint64_t>);
336 friend double Parse(
const Value& value,
parse::
To<
double>);
337 friend std::string Parse(
const Value& value,
parse::
To<std::string>);
353 "There is no `Parse(const Value&, formats::parse::To<T>)` "
354 "in namespace of `T` or `formats::parse`. "
355 "Probably you forgot to include the "
356 "<userver/formats/parse/common_containers.hpp> or you "
357 "have not provided a `Parse` function overload."
365std::int64_t Parse(
const Value& value,
parse::
To<std::int64_t>);
367std::uint64_t Parse(
const Value& value,
parse::
To<std::uint64_t>);
371std::string Parse(
const Value& value,
parse::
To<std::string>);
388template <
typename T,
typename First,
typename... Rest>
389auto Value::
As(First&& default_arg, Rest&&... more_default_args)
const {
393 return decltype(As<T>())(std::forward<First>(default_arg), std::forward<Rest>(more_default_args)...);
412 "There is no `Convert(const Value&, formats::parse::To<T>)` or"
413 "`Parse(const Value&, formats::parse::To<T>)`"
414 "in namespace of `T` or `formats::parse`. "
415 "Probably you have not provided a `Convert` function overload."
420template <
typename T,
typename First,
typename... Rest>
424 return T(std::forward<First>(default_arg), std::forward<Rest>(more_default_args)...);
426 return ConvertTo<T>();
431std::chrono::microseconds Parse(
const Value& value,
parse::
To<std::chrono::microseconds>);
433std::chrono::milliseconds Parse(
const Value& value,
parse::
To<std::chrono::milliseconds>);
435std::chrono::minutes Parse(
const Value& value,
parse::
To<std::chrono::minutes>);
437std::chrono::hours Parse(
const Value& value,
parse::
To<std::chrono::hours>);
455json::
Value operator
""_json(
const char* str, std::size_t len);