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&&) && {
62 static_assert(!
sizeof(T),
63 "You're assigning to a temporary formats::yaml::Value! Use "
64 "formats::yaml::ValueBuilder for data modifications.");
74 Value(Value&& other, std::string path_prefix);
92 const_iterator
end()
const;
105 bool operator!=(
const Value& other)
const;
153 template <
typename T>
159 template <
typename T,
typename First,
typename... Rest>
160 auto As(First&& default_arg, Rest&&... more_default_args)
const;
165 template <
typename T>
245 class EmplaceEnabler {};
249 Value(EmplaceEnabler,
const YAML::Node& value,
250 const formats::
yaml::
Path& path, std::string_view key);
252 Value(EmplaceEnabler,
const YAML::Node& value,
253 const formats::
yaml::
Path& path, size_t index);
257 Value(
const YAML::Node& root)
noexcept;
259 static Value MakeNonRoot(
const YAML::Node& value,
261 std::string_view key);
262 static Value MakeNonRoot(
const YAML::Node& val,
263 const formats::
yaml::
Path& path, size_t index);
265 const YAML::Node& GetNative()
const;
266 YAML::Node& GetNative();
267 int GetExtendedType()
const;
270 bool IsConvertibleToArithmetic()
const;
273 T ValueAsArithmetic()
const;
275 static constexpr std::size_t kNativeNodeSize = 64;
276 static constexpr std::size_t kNativeAlignment =
alignof(
void*);
278 utils::FastPimpl<YAML::Node, kNativeNodeSize, kNativeAlignment> value_pimpl_;
282 friend class ValueBuilder;
284 friend bool Parse(
const Value& value,
parse::
To<
bool>);
285 friend int64_t Parse(
const Value& value,
parse::
To<int64_t>);
286 friend uint64_t Parse(
const Value& value,
parse::
To<uint64_t>);
287 friend double Parse(
const Value& value,
parse::
To<
double>);
288 friend std::string Parse(
const Value& value,
parse::
To<std::string>);
296auto Value::
As()
const {
297 static_assert(formats::
common::impl::kHasParse<Value, T>,
298 "There is no `Parse(const Value&, formats::parse::To<T>)` in "
299 "namespace of `T` or `formats::parse`. "
300 "Probably you forgot to include the "
301 "<userver/formats/parse/common_containers.hpp> or you "
302 "have not provided a `Parse` function overload.");
304 return Parse(*
this, formats::
parse::
To<T>{});
307bool Parse(
const Value& value,
parse::
To<
bool>);
309int64_t Parse(
const Value& value,
parse::
To<int64_t>);
311uint64_t Parse(
const Value& value,
parse::
To<uint64_t>);
313double Parse(
const Value& value,
parse::
To<
double>);
315std::string Parse(
const Value& value,
parse::
To<std::string>);
317template <
typename T,
typename First,
typename... Rest>
318auto Value::
As(First&& default_arg, Rest&&... more_default_args)
const {
322 return decltype(As<T>())(std::forward<First>(default_arg),
323 std::forward<Rest>(more_default_args)...);
338using formats::
common::Items;
346yaml::Value operator
"" _yaml(
const char* str, std::size_t len);