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;
187 template <
typename T>
193 template <
typename T,
typename First,
typename... Rest>
194 auto As(First&& default_arg, Rest&&... more_default_args)
const;
199 template <
typename T>
204 template <
typename T>
209 template <
typename T,
typename First,
typename... Rest>
210 T
ConvertTo(First&& default_arg, Rest&&... more_default_args)
const;
259 struct EmplaceEnabler {
260 explicit EmplaceEnabler() =
default;
263 class LazyDetachedPath;
269 const impl::VersionedValuePtr& root,
270 const impl::Value* root_ptr_for_path,
271 const impl::Value* value_ptr,
277 const impl::VersionedValuePtr& root,
278 impl::Value* root_ptr_for_path,
279 LazyDetachedPath&& lazy_detached_path
284 explicit Value(impl::VersionedValuePtr root)
noexcept;
286 bool IsUniqueReference()
const;
287 void EnsureNotMissing()
const;
288 const impl::Value& GetNative()
const;
289 impl::Value& GetNative();
290 void SetNative(impl::Value&);
291 int GetExtendedType()
const;
293 impl::VersionedValuePtr holder_{};
294 impl::Value* root_ptr_for_path_{
nullptr};
295 impl::Value* value_ptr_{
nullptr};
304 class LazyDetachedPath
final {
306 LazyDetachedPath()
noexcept;
307 LazyDetachedPath(impl::Value* parent_value_ptr,
int parent_depth, std::string_view key);
309 LazyDetachedPath(
const LazyDetachedPath&);
310 LazyDetachedPath(LazyDetachedPath&&)
noexcept;
311 LazyDetachedPath& operator=(
const LazyDetachedPath&);
312 LazyDetachedPath& operator=(LazyDetachedPath&&)
noexcept;
314 std::string Get(
const impl::Value* root)
const;
315 LazyDetachedPath Chain(std::string_view key)
const;
318 impl::Value* parent_value_ptr_{
nullptr};
319 int parent_depth_{0};
320 std::string virtual_path_{};
323 LazyDetachedPath lazy_detached_path_;
326 friend class Iterator;
327 friend class ValueBuilder;
328 friend class StringBuilder;
330 friend class impl::InlineObjectBuilder;
331 friend class impl::InlineArrayBuilder;
332 friend class impl::MutableValueWrapper;
333 friend class parser::JsonValueParser;
334 friend class impl::StringBuffer;
337 friend std::int64_t Parse(
const Value& value,
parse::
To<std::int64_t>);
338 friend std::uint64_t Parse(
const Value& value,
parse::
To<std::uint64_t>);
339 friend double Parse(
const Value& value,
parse::
To<
double>);
340 friend std::string Parse(
const Value& value,
parse::
To<std::string>);
356 "There is no `Parse(const Value&, formats::parse::To<T>)` "
357 "in namespace of `T` or `formats::parse`. "
358 "Probably you forgot to include the "
359 "<userver/formats/parse/common_containers.hpp> or you "
360 "have not provided a `Parse` function overload."
368std::int64_t Parse(
const Value& value,
parse::
To<std::int64_t>);
370std::uint64_t Parse(
const Value& value,
parse::
To<std::uint64_t>);
374std::string Parse(
const Value& value,
parse::
To<std::string>);
391template <
typename T,
typename First,
typename... Rest>
392auto Value::
As(First&& default_arg, Rest&&... more_default_args)
const {
396 return decltype(As<T>())(std::forward<First>(default_arg), std::forward<Rest>(more_default_args)...);
415 "There is no `Convert(const Value&, formats::parse::To<T>)` or"
416 "`Parse(const Value&, formats::parse::To<T>)`"
417 "in namespace of `T` or `formats::parse`. "
418 "Probably you have not provided a `Convert` function overload."
423template <
typename T,
typename First,
typename... Rest>
427 return T(std::forward<First>(default_arg), std::forward<Rest>(more_default_args)...);
429 return ConvertTo<T>();
434std::chrono::microseconds Parse(
const Value& value,
parse::
To<std::chrono::microseconds>);
436std::chrono::milliseconds Parse(
const Value& value,
parse::
To<std::chrono::milliseconds>);
438std::chrono::minutes Parse(
const Value& value,
parse::
To<std::chrono::minutes>);
440std::chrono::hours Parse(
const Value& value,
parse::
To<std::chrono::hours>);
458json::
Value operator
""_json(
const char* str, std::size_t len);