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 {
46 using const_iterator = Iterator<
const Value, common::IteratorDirection::kForward>;
47 using const_reverse_iterator = Iterator<
const Value, common::IteratorDirection::kReverse>;
60 Value(
const Value&) =
default;
61 Value(
Value&&)
noexcept =
default;
63 Value& operator=(
Value&&) &
noexcept =
default;
66 Value& operator=(T&&) && {
69 "You're assigning to a temporary formats::bson::Value! Use "
70 "formats::bson::ValueBuilder for data modifications."
77 explicit Value(impl::ValueImplPtr);
105 const_iterator
end()
const;
113 const_reverse_iterator
rend()
const;
129 bool operator==(
const Value&)
const;
130 bool operator!=(
const Value&)
const;
138 bool IsArray()
const;
139 bool IsDocument()
const;
142 bool IsInt32()
const;
143 bool IsInt64()
const;
144 bool IsDouble()
const;
145 bool IsString()
const;
146 bool IsDateTime()
const;
148 bool IsBinary()
const;
149 bool IsDecimal128()
const;
150 bool IsMinKey()
const;
151 bool IsMaxKey()
const;
152 bool IsTimestamp()
const;
154 bool IsObject()
const {
return IsDocument(); }
169 template <
typename T>
172 formats::common::impl::kHasParse<
Value, T>,
173 "There is no `Parse(const Value&, formats::parse::To<T>)` in namespace "
174 "of `T` or `formats::parse`. "
175 "Probably you have not provided a `Parse` function overload."
178 return Parse(*
this, formats::parse::To<T>{});
183 template <
typename T,
typename First,
typename... Rest>
184 auto As(First&& default_arg, Rest&&... more_default_args)
const {
188 return decltype(As<T>())(std::forward<First>(default_arg), std::forward<Rest>(more_default_args)...);
196 template <
typename T>
198 return (
IsMissing() || IsNull()) ?
decltype(As<T>())() : As<T>();
203 template <
typename T>
205 if constexpr (formats::common::impl::kHasConvert<
Value, T>) {
206 return Convert(*
this, formats::parse::To<T>{});
207 }
else if constexpr (formats::common::impl::kHasParse<
Value, T>) {
208 return Parse(*
this, formats::parse::To<T>{});
212 "There is no `Convert(const Value&, formats::parse::To<T>)` or"
213 "`Parse(const Value&, formats::parse::To<T>)`"
214 "in namespace of `T` or `formats::parse`. "
215 "Probably you have not provided a `Convert` function overload."
222 template <
typename T,
typename First,
typename... Rest>
223 T
ConvertTo(First&& default_arg, Rest&&... more_default_args)
const {
226 return T(std::forward<First>(default_arg), std::forward<Rest>(more_default_args)...);
228 return ConvertTo<T>();
257 Document GetInternalArrayDocument()
const;
261 const impl::BsonHolder& GetBson()
const;
265 friend class impl::BsonBuilder;
267 friend bool Parse(
const Value& value, parse::To<
bool>);
268 friend int64_t Parse(
const Value& value, parse::To<int64_t>);
269 friend uint64_t Parse(
const Value& value, parse::To<uint64_t>);
270 friend double Parse(
const Value& value, parse::To<
double>);
271 friend std::string Parse(
const Value& value, parse::To<std::string>);
272 friend std::chrono::system_clock::time_point
273 Parse(
const Value& value, parse::To<std::chrono::system_clock::time_point>);
274 friend Oid Parse(
const Value& value, parse::To<
Oid>);
280 impl::ValueImplPtr impl_;
284bool Parse(
const Value& value, parse::To<
bool>);
286int64_t Parse(
const Value& value, parse::To<int64_t>);
288uint64_t Parse(
const Value& value, parse::To<uint64_t>);
290double Parse(
const Value& value, parse::To<
double>);
292std::string Parse(
const Value& value, parse::To<std::string>);
294std::chrono::system_clock::time_point Parse(
const Value& value, parse::To<std::chrono::system_clock::time_point>);
327using formats::common::Items;
333namespace formats::literals {
335bson::
Value operator
"" _bson(
const char* str, std::size_t len);