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 {
44 using const_iterator =
46 using const_reverse_iterator =
59 Value(
const Value&) =
default;
60 Value(
Value&&)
noexcept =
default;
62 Value& operator=(
Value&&) &
noexcept =
default;
65 Value& operator=(T&&) && {
66 static_assert(!
sizeof(T),
67 "You're assigning to a temporary formats::bson::Value! Use "
68 "formats::bson::ValueBuilder for data modifications.");
74 explicit Value(impl::ValueImplPtr);
100 const_iterator
end()
const;
108 const_reverse_iterator
rend()
const;
124 bool operator==(
const Value&)
const;
125 bool operator!=(
const Value&)
const;
133 bool IsArray()
const;
134 bool IsDocument()
const;
137 bool IsInt32()
const;
138 bool IsInt64()
const;
139 bool IsDouble()
const;
140 bool IsString()
const;
141 bool IsDateTime()
const;
143 bool IsBinary()
const;
144 bool IsDecimal128()
const;
145 bool IsMinKey()
const;
146 bool IsMaxKey()
const;
147 bool IsTimestamp()
const;
149 bool IsObject()
const {
return IsDocument(); }
164 template <
typename T>
168 "There is no `Parse(const Value&, formats::parse::To<T>)` in namespace "
169 "of `T` or `formats::parse`. "
170 "Probably you have not provided a `Parse` function overload.");
172 return Parse(*
this, formats::
parse::
To<T>{});
177 template <
typename T,
typename First,
typename... Rest>
178 T
As(First&& default_arg, Rest&&... more_default_args)
const {
182 return T(std::forward<First>(default_arg),
183 std::forward<Rest>(more_default_args)...);
191 template <
typename T>
198 template <
typename T>
200 if constexpr (formats::
common::impl::kHasConvert<
Value, T>) {
201 return Convert(*
this, formats::
parse::
To<T>{});
202 }
else if constexpr (formats::
common::impl::kHasParse<
Value, T>) {
203 return Parse(*
this, formats::
parse::
To<T>{});
207 "There is no `Convert(const Value&, formats::parse::To<T>)` or"
208 "`Parse(const Value&, formats::parse::To<T>)`"
209 "in namespace of `T` or `formats::parse`. "
210 "Probably you have not provided a `Convert` function overload.");
216 template <
typename T,
typename First,
typename... Rest>
217 T
ConvertTo(First&& default_arg, Rest&&... more_default_args)
const {
220 return T(std::forward<First>(default_arg),
221 std::forward<Rest>(more_default_args)...);
223 return ConvertTo<T>();
252 Document GetInternalArrayDocument()
const;
256 const impl::BsonHolder& GetBson()
const;
260 friend class impl::BsonBuilder;
262 impl::ValueImplPtr impl_;
267bool Value::As<
bool>()
const;
270int64_t
Value::As<int64_t>()
const;
273uint64_t
Value::As<uint64_t>()
const;
276double Value::As<
double>()
const;
279std::string
Value::As<std::string>()
const;
282std::chrono::system_clock::time_point
283Value::As<std::chrono::system_clock::time_point>()
const;
301bool Value::ConvertTo<
bool>()
const;
304int64_t
Value::ConvertTo<int64_t>()
const;
307uint64_t
Value::ConvertTo<uint64_t>()
const;
310double Value::ConvertTo<
double>()
const;
313std::string
Value::ConvertTo<std::string>()
const;
321using formats::
common::Items;
329bson::
Value operator
"" _bson(
const char* str, std::size_t len);