8#include <userver/formats/common/items.hpp>
9#include <userver/formats/common/meta.hpp>
10#include <userver/formats/parse/common.hpp>
11#include <userver/formats/yaml/exception.hpp>
12#include <userver/formats/yaml/iterator.hpp>
13#include <userver/formats/yaml/types.hpp>
14#include <userver/utils/fast_pimpl.hpp>
16USERVER_NAMESPACE_BEGIN
18namespace formats::
yaml {
37 using native_iter = YAML::const_iterator;
38 using value_type = formats::
yaml::Value;
39 using reference =
const formats::
yaml::Value&;
40 using pointer =
const formats::
yaml::Value*;
48 using Builder = ValueBuilder;
57 Value& operator=(Value&&);
58 Value& operator=(
const Value&);
61 Value& operator=(T&&) && {
64 "You're assigning to a temporary formats::yaml::Value! Use "
65 "formats::yaml::ValueBuilder for data modifications."
76 Value(Value&& other, std::string path_prefix);
94 const_iterator
end()
const;
107 bool operator!=(
const Value& other)
const;
155 template <
typename T>
161 template <
typename T,
typename First,
typename... Rest>
162 auto As(First&& default_arg, Rest&&... more_default_args)
const;
167 template <
typename T>
247 class EmplaceEnabler {};
251 Value(EmplaceEnabler,
const YAML::Node& value,
const formats::
yaml::
Path& path, std::string_view key);
253 Value(EmplaceEnabler,
const YAML::Node& value,
const formats::
yaml::
Path& path, size_t index);
257 Value(
const YAML::Node& root)
noexcept;
259 static Value MakeNonRoot(
const YAML::Node& value,
const formats::
yaml::
Path& path, std::string_view key);
260 static Value MakeNonRoot(
const YAML::Node& val,
const formats::
yaml::
Path& path, size_t index);
262 const YAML::Node& GetNative()
const;
263 YAML::Node& GetNative();
264 int GetExtendedType()
const;
267 bool IsConvertibleToArithmetic()
const;
270 T ValueAsArithmetic()
const;
272 static constexpr std::size_t kNativeNodeSize = 64;
273 static constexpr std::size_t kNativeAlignment =
alignof(
void*);
275 utils::FastPimpl<YAML::Node, kNativeNodeSize, kNativeAlignment> value_pimpl_;
279 friend class ValueBuilder;
281 friend bool Parse(
const Value& value,
parse::
To<
bool>);
282 friend int64_t Parse(
const Value& value,
parse::
To<int64_t>);
283 friend uint64_t Parse(
const Value& value,
parse::
To<uint64_t>);
284 friend double Parse(
const Value& value,
parse::
To<
double>);
285 friend std::string Parse(
const Value& value,
parse::
To<std::string>);
293auto Value::
As()
const {
295 formats::
common::impl::kHasParse<Value, T>,
296 "There is no `Parse(const Value&, formats::parse::To<T>)` in "
297 "namespace of `T` or `formats::parse`. "
298 "Probably you forgot to include the "
299 "<userver/formats/parse/common_containers.hpp> or you "
300 "have not provided a `Parse` function overload."
303 return Parse(*
this, formats::
parse::
To<T>{});
306bool Parse(
const Value& value,
parse::
To<
bool>);
308int64_t Parse(
const Value& value,
parse::
To<int64_t>);
310uint64_t Parse(
const Value& value,
parse::
To<uint64_t>);
312double Parse(
const Value& value,
parse::
To<
double>);
314std::string Parse(
const Value& value,
parse::
To<std::string>);
316template <
typename T,
typename First,
typename... Rest>
317auto Value::
As(First&& default_arg, Rest&&... more_default_args)
const {
321 return decltype(As<T>())(std::forward<First>(default_arg), std::forward<Rest>(more_default_args)...);
336using formats::
common::Items;
344yaml::Value operator
"" _yaml(
const char* str, std::size_t len);