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>
225 class EmplaceEnabler {};
229 Value(EmplaceEnabler,
const YAML::Node& value,
230 const formats::
yaml::
Path& path, std::string_view key);
232 Value(EmplaceEnabler,
const YAML::Node& value,
233 const formats::
yaml::
Path& path, size_t index);
237 Value(
const YAML::Node& root)
noexcept;
239 static Value MakeNonRoot(
const YAML::Node& value,
241 std::string_view key);
242 static Value MakeNonRoot(
const YAML::Node& val,
243 const formats::
yaml::
Path& path, size_t index);
245 const YAML::Node& GetNative()
const;
246 YAML::Node& GetNative();
247 int GetExtendedType()
const;
250 bool IsConvertible()
const;
255 static constexpr std::size_t kNativeNodeSize = 64;
256 static constexpr std::size_t kNativeAlignment =
alignof(
void*);
258 utils::FastPimpl<YAML::Node, kNativeNodeSize, kNativeAlignment> value_pimpl_;
262 friend class ValueBuilder;
264 friend bool Parse(
const Value& value,
parse::
To<
bool>);
265 friend int64_t Parse(
const Value& value,
parse::
To<int64_t>);
266 friend uint64_t Parse(
const Value& value,
parse::
To<uint64_t>);
267 friend double Parse(
const Value& value,
parse::
To<
double>);
268 friend std::string Parse(
const Value& value,
parse::
To<std::string>);
276auto Value::
As()
const {
277 static_assert(formats::
common::impl::kHasParse<Value, T>,
278 "There is no `Parse(const Value&, formats::parse::To<T>)` in "
279 "namespace of `T` or `formats::parse`. "
280 "Probably you forgot to include the "
281 "<userver/formats/parse/common_containers.hpp> or you "
282 "have not provided a `Parse` function overload.");
284 return Parse(*
this, formats::
parse::
To<T>{});
287bool Parse(
const Value& value,
parse::
To<
bool>);
289int64_t Parse(
const Value& value,
parse::
To<int64_t>);
291uint64_t Parse(
const Value& value,
parse::
To<uint64_t>);
293double Parse(
const Value& value,
parse::
To<
double>);
295std::string Parse(
const Value& value,
parse::
To<std::string>);
297template <
typename T,
typename First,
typename... Rest>
298auto Value::
As(First&& default_arg, Rest&&... more_default_args)
const {
302 return decltype(As<T>())(std::forward<First>(default_arg),
303 std::forward<Rest>(more_default_args)...);
318using formats::
common::Items;
326yaml::Value operator
"" _yaml(
const char* str, std::size_t len);