11#include <userver/formats/bson/exception.hpp>
12#include <userver/formats/bson/iterator.hpp>
13#include <userver/formats/bson/types.hpp>
14#include <userver/formats/common/items.hpp>
15#include <userver/formats/common/meta.hpp>
16#include <userver/formats/parse/common.hpp>
17#include <userver/formats/parse/common_containers.hpp>
19USERVER_NAMESPACE_BEGIN
21namespace formats::
bson {
58 Value(
const Value&) =
default;
59 Value(
Value&&)
noexcept =
default;
61 Value& operator=(
Value&&) &
noexcept =
default;
64 Value& operator=(T&&) && {
67 "You're assigning to a temporary formats::bson::Value! Use "
68 "formats::bson::ValueBuilder for data modifications."
75 explicit Value(impl::ValueImplPtr);
101 const_iterator
end()
const;
109 const_reverse_iterator
rend()
const;
125 bool operator==(
const Value&)
const;
126 bool operator!=(
const Value&)
const;
134 bool IsArray()
const;
135 bool IsDocument()
const;
138 bool IsInt32()
const;
139 bool IsInt64()
const;
140 bool IsDouble()
const;
141 bool IsString()
const;
142 bool IsDateTime()
const;
144 bool IsBinary()
const;
145 bool IsDecimal128()
const;
146 bool IsMinKey()
const;
147 bool IsMaxKey()
const;
148 bool IsTimestamp()
const;
150 bool IsObject()
const {
return IsDocument(); }
165 template <
typename T>
169 "There is no `Parse(const Value&, formats::parse::To<T>)` in namespace "
170 "of `T` or `formats::parse`. "
171 "Probably you have not provided a `Parse` function overload."
174 return Parse(*
this, formats::
parse::
To<T>{});
179 template <
typename T,
typename First,
typename... Rest>
180 auto As(First&& default_arg, Rest&&... more_default_args)
const {
184 return decltype(As<T>())(std::forward<First>(default_arg), std::forward<Rest>(more_default_args)...);
192 template <
typename T>
194 return (
IsMissing() || IsNull()) ?
decltype(As<T>())() : As<T>();
199 template <
typename T>
201 if constexpr (formats::
common::impl::kHasConvert<
Value, T>) {
202 return Convert(*
this, formats::
parse::
To<T>{});
203 }
else if constexpr (formats::
common::impl::kHasParse<
Value, T>) {
204 return Parse(*
this, formats::
parse::
To<T>{});
208 "There is no `Convert(const Value&, formats::parse::To<T>)` or"
209 "`Parse(const Value&, formats::parse::To<T>)`"
210 "in namespace of `T` or `formats::parse`. "
211 "Probably you have not provided a `Convert` function overload."
218 template <
typename T,
typename First,
typename... Rest>
219 T
ConvertTo(First&& default_arg, Rest&&... more_default_args)
const {
222 return T(std::forward<First>(default_arg), std::forward<Rest>(more_default_args)...);
224 return ConvertTo<T>();
253 Document GetInternalArrayDocument()
const;
257 const impl::BsonHolder& GetBson()
const;
261 friend class impl::BsonBuilder;
264 friend int64_t Parse(
const Value& value,
parse::
To<int64_t>);
265 friend uint64_t Parse(
const Value& value,
parse::
To<uint64_t>);
266 friend double Parse(
const Value& value,
parse::
To<
double>);
267 friend std::string Parse(
const Value& value,
parse::
To<std::string>);
268 friend std::chrono::system_clock::time_point
269 Parse(
const Value& value,
parse::
To<std::chrono::system_clock::time_point>);
276 impl::ValueImplPtr impl_;
288std::string Parse(
const Value& value,
parse::
To<std::string>);
290std::chrono::system_clock::time_point Parse(
const Value& value,
parse::
To<std::chrono::system_clock::time_point>);
303bool Value::ConvertTo<
bool>()
const;
306int64_t
Value::ConvertTo<int64_t>()
const;
309uint64_t
Value::ConvertTo<uint64_t>()
const;
312double Value::ConvertTo<
double>()
const;
315std::string
Value::ConvertTo<std::string>()
const;
323using formats::
common::Items;
331bson::
Value operator
"" _bson(
const char* str, std::size_t len);