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
39 using native_iter = YAML::const_iterator;
50 using Builder = ValueBuilder;
59 Value& operator=(Value&&);
60 Value& operator=(
const Value&);
63 Value& operator=(T&&) && {
66 "You're assigning to a temporary formats::yaml::Value! Use "
67 "formats::yaml::ValueBuilder for data modifications."
78 Value(Value&& other, std::string path_prefix);
96 const_iterator
end()
const;
109 bool operator!=(
const Value& other)
const;
157 template <
typename T>
163 template <
typename T,
typename First,
typename... Rest>
164 auto As(First&& default_arg, Rest&&... more_default_args)
const;
169 template <
typename T>
249 class EmplaceEnabler {};
253 Value(EmplaceEnabler,
const YAML::Node& value,
const formats::
yaml::
Path& path, std::string_view key);
255 Value(EmplaceEnabler,
const YAML::Node& value,
const formats::
yaml::
Path& path, size_t index);
257 Value CloneWithReplacedPath(std::string&& new_path)
const;
261 Value(
const YAML::Node& root)
noexcept;
263 static Value MakeNonRoot(
const YAML::Node& value,
const formats::
yaml::
Path& path, std::string_view key);
264 static Value MakeNonRoot(
const YAML::Node& val,
const formats::
yaml::
Path& path, size_t index);
266 const YAML::Node& GetNative()
const;
267 YAML::Node& GetNative();
268 int GetExtendedType()
const;
271 bool IsConvertibleToArithmetic()
const;
274 T ValueAsArithmetic()
const;
276 static constexpr std::size_t kNativeNodeSize = 64;
277 static constexpr std::size_t kNativeAlignment =
alignof(
void*);
279 utils::FastPimpl<YAML::Node, kNativeNodeSize, kNativeAlignment> value_pimpl_;
283 friend class ValueBuilder;
285 friend bool Parse(
const Value& value,
parse::
To<
bool>);
286 friend int64_t Parse(
const Value& value,
parse::
To<int64_t>);
287 friend uint64_t Parse(
const Value& value,
parse::
To<uint64_t>);
288 friend double Parse(
const Value& value,
parse::
To<
double>);
289 friend std::string Parse(
const Value& value,
parse::
To<std::string>);
297auto Value::
As()
const {
300 "There is no `Parse(const Value&, formats::parse::To<T>)` in "
301 "namespace of `T` or `formats::parse`. "
302 "Probably you forgot to include the "
303 "<userver/formats/parse/common_containers.hpp> or you "
304 "have not provided a `Parse` function overload."
310bool Parse(
const Value& value,
parse::
To<
bool>);
312int64_t Parse(
const Value& value,
parse::
To<int64_t>);
314uint64_t Parse(
const Value& value,
parse::
To<uint64_t>);
316double Parse(
const Value& value,
parse::
To<
double>);
318std::string Parse(
const Value& value,
parse::
To<std::string>);
320template <
typename T,
typename First,
typename... Rest>
321auto Value::
As(First&& default_arg, Rest&&... more_default_args)
const {
325 return decltype(As<T>())(std::forward<First>(default_arg), std::forward<Rest>(more_default_args)...);
348yaml::Value operator
"" _yaml(
const char* str, std::size_t len);