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 =
60 Value(
const Value&) =
default;
61 Value(
Value&&)
noexcept =
default;
63 Value& operator=(
Value&&) &
noexcept =
default;
66 Value& operator=(T&&) && {
67 static_assert(!
sizeof(T),
68 "You're assigning to a temporary formats::bson::Value! Use "
69 "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.");
173 return Parse(*
this, formats::
parse::
To<T>{});
178 template <
typename T,
typename First,
typename... Rest>
179 auto As(First&& default_arg, Rest&&... more_default_args)
const {
183 return decltype(As<T>())(std::forward<First>(default_arg),
184 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.");
217 template <
typename T,
typename First,
typename... Rest>
218 T
ConvertTo(First&& default_arg, Rest&&... more_default_args)
const {
221 return T(std::forward<First>(default_arg),
222 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 Parse(
269 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(
291 const Value& value,
parse::
To<std::chrono::system_clock::time_point>);
304bool Value::ConvertTo<
bool>()
const;
307int64_t
Value::ConvertTo<int64_t>()
const;
310uint64_t
Value::ConvertTo<uint64_t>()
const;
313double Value::ConvertTo<
double>()
const;
316std::string
Value::ConvertTo<std::string>()
const;
324using formats::
common::Items;
332bson::
Value operator
"" _bson(
const char* str, std::size_t len);