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*;
47 using Builder = ValueBuilder;
56 Value& operator=(Value&&);
57 Value& operator=(
const Value&);
60 Value& operator=(T&&) && {
61 static_assert(!
sizeof(T),
62 "You're assigning to a temporary formats::yaml::Value! Use "
63 "formats::yaml::ValueBuilder for data modifications.");
73 Value(Value&& other, std::string path_prefix);
91 const_iterator
end()
const;
104 bool operator!=(
const Value& other)
const;
151 template <
typename T>
157 template <
typename T,
typename First,
typename... Rest>
158 T
As(First&& default_arg, Rest&&... more_default_args)
const;
163 template <
typename T>
223 class EmplaceEnabler {};
227 Value(EmplaceEnabler,
const YAML::Node& value,
228 const formats::
yaml::
Path& path, std::string_view key);
230 Value(EmplaceEnabler,
const YAML::Node& value,
231 const formats::
yaml::
Path& path, size_t index);
235 Value(
const YAML::Node& root)
noexcept;
237 static Value MakeNonRoot(
const YAML::Node& value,
239 std::string_view key);
240 static Value MakeNonRoot(
const YAML::Node& val,
241 const formats::
yaml::
Path& path, size_t index);
243 const YAML::Node& GetNative()
const;
244 YAML::Node& GetNative();
245 int GetExtendedType()
const;
248 bool IsConvertible()
const;
253 static constexpr std::size_t kNativeNodeSize = 64;
254 static constexpr std::size_t kNativeAlignment =
alignof(
void*);
256 utils::FastPimpl<YAML::Node, kNativeNodeSize, kNativeAlignment> value_pimpl_;
260 friend class ValueBuilder;
269 static_assert(formats::
common::impl::kHasParse<Value, T>,
270 "There is no `Parse(const Value&, formats::parse::To<T>)` in "
271 "namespace of `T` or `formats::parse`. "
272 "Probably you forgot to include the "
273 "<userver/formats/parse/common_containers.hpp> or you "
274 "have not provided a `Parse` function overload.");
276 return Parse(*
this, formats::
parse::
To<T>{});
280bool Value::As<
bool>()
const;
283int64_t Value::As<int64_t>()
const;
286uint64_t Value::As<uint64_t>()
const;
289double Value::As<
double>()
const;
292std::string Value::As<std::string>()
const;
294template <
typename T,
typename First,
typename... Rest>
295T Value::
As(First&& default_arg, Rest&&... more_default_args)
const {
299 return T(std::forward<First>(default_arg),
300 std::forward<Rest>(more_default_args)...);
315using formats::
common::Items;
323yaml::Value operator
"" _yaml(
const char* str, std::size_t len);