20#include <bsoncxx/array/view.hpp>
21#include <bsoncxx/decimal128.hpp>
22#include <bsoncxx/document/view.hpp>
23#include <bsoncxx/oid.hpp>
24#include <bsoncxx/stdx/string_view.hpp>
26#include <bsoncxx/config/prelude.hpp>
29BSONCXX_INLINE_NAMESPACE_BEGIN
39enum class type : std::uint8_t {
40#define BSONCXX_ENUM(name, val) k_##name = val,
41#include <bsoncxx/enums/type.hpp>
55#define BSONCXX_ENUM(name, val) k_##name = val,
56#include <bsoncxx/enums/binary_sub_type.hpp>
86 static constexpr auto type_id = type::k_double;
93 BSONCXX_INLINE
operator double() {
104 return lhs.value == rhs.value;
111 static constexpr auto type_id = type::k_utf8;
119 template <
typename T,
120 typename std::enable_if<!std::is_same<b_utf8, typename std::decay<T>::type>::value,
123 :
value(std::forward<T>(t)) {
126 stdx::string_view
value;
131 BSONCXX_INLINE
operator stdx::string_view() {
142 return lhs.value == rhs.value;
149 static constexpr auto type_id = type::k_document;
174 return lhs.value == rhs.value;
181 static constexpr auto type_id = type::k_array;
199 return lhs.value == rhs.value;
206 static constexpr auto type_id = type::k_binary;
210 const uint8_t* bytes;
219 return lhs.sub_type == rhs.sub_type && lhs.size == rhs.size &&
220 (std::memcmp(lhs.bytes, rhs.bytes, lhs.size) == 0);
230 static constexpr auto type_id = type::k_undefined;
246 static constexpr auto type_id = type::k_oid;
257 return lhs.value == rhs.value;
264 static constexpr auto type_id = type::k_bool;
271 BSONCXX_INLINE
operator bool() {
282 return lhs.value == rhs.value;
289 static constexpr auto type_id = type::k_date;
308 explicit b_date(
const std::chrono::system_clock::time_point& tp)
309 :
value(std::chrono::duration_cast<std::chrono::milliseconds>(tp.time_since_epoch())) {
312 std::chrono::milliseconds
value;
317 BSONCXX_INLINE
operator int64_t() {
318 return value.count();
325 return value.count();
331 BSONCXX_INLINE
operator std::chrono::system_clock::time_point() {
332 return std::chrono::system_clock::time_point(
333 std::chrono::duration_cast<std::chrono::system_clock::duration>(
value));
343 return lhs.value == rhs.value;
350 static constexpr auto type_id = type::k_null;
366 static constexpr auto type_id = type::k_regex;
377 template <
typename T,
typename U>
378 BSONCXX_INLINE
explicit b_regex(T&& regex, U&& options)
379 : regex(std::forward<T>(regex)), options(std::forward<U>(options)) {
382 stdx::string_view regex;
383 stdx::string_view options;
392 return lhs.regex == rhs.regex && lhs.options == rhs.options;
402 static constexpr auto type_id = type::k_dbpointer;
404 stdx::string_view collection;
414 return lhs.collection == rhs.collection && lhs.value == rhs.value;
421 static constexpr auto type_id = type::k_code;
429 template <
typename T,
430 typename std::enable_if<!std::is_same<b_code, typename std::decay<T>::type>::value,
433 : code(std::forward<T>(t)) {
436 stdx::string_view code;
441 BSONCXX_INLINE
operator stdx::string_view() {
452 return lhs.code == rhs.code;
462 static constexpr auto type_id = type::k_symbol;
470 template <
typename T,
471 typename std::enable_if<!std::is_same<b_symbol, typename std::decay<T>::type>::value,
474 : symbol(std::forward<T>(t)) {
477 stdx::string_view symbol;
482 BSONCXX_INLINE
operator stdx::string_view() {
493 return lhs.symbol == rhs.symbol;
500 static constexpr auto type_id = type::k_codewscope;
511 template <
typename T,
typename U>
513 : code(std::forward<T>(code)), scope(std::forward<U>(scope)) {
516 stdx::string_view code;
526 return lhs.code == rhs.code && lhs.scope == rhs.scope;
533 static constexpr auto type_id = type::k_int32;
540 BSONCXX_INLINE
operator int32_t() {
551 return lhs.value == rhs.value;
562 static constexpr auto type_id = type::k_timestamp;
574 return lhs.increment == rhs.increment && lhs.timestamp == rhs.timestamp;
581 static constexpr auto type_id = type::k_int64;
588 BSONCXX_INLINE
operator int64_t() {
599 return lhs.value == rhs.value;
606 static constexpr auto type_id = type::k_decimal128;
616 template <
typename T,
617 typename std::enable_if<
618 !std::is_same<b_decimal128, typename std::decay<T>::type>::value,
int>::type = 0>
620 :
value(std::forward<T>(t)) {
630 return lhs.value == rhs.value;
637 static constexpr auto type_id = type::k_minkey;
653 static constexpr auto type_id = type::k_maxkey;
665#define BSONCXX_ENUM(name, val) \
666 BSONCXX_INLINE bool operator!=(const b_##name& lhs, const b_##name& rhs) { \
667 return !(lhs == rhs); \
669#include <bsoncxx/enums/type.hpp>
673BSONCXX_INLINE_NAMESPACE_END
676#include <bsoncxx/config/postlude.hpp>
A read-only, non-owning view of a BSON document.
Definition view.hpp:33
Represents an IEEE 754-2008 BSON Decimal128 value in a platform-independent way.
Definition decimal128.hpp:30
A read-only, non-owning view of a BSON document.
Definition view.hpp:33
Represents a MongoDB ObjectId.
Definition oid.hpp:38
A variant that can contain any BSON type.
Definition value.hpp:37
Top level namespace for MongoDB C++ BSON functionality.
Definition element.hpp:24
type
An enumeration of each BSON type.
Definition types.hpp:39
std::string to_string(type rhs)
Returns a stringification of the given type.
binary_sub_type
An enumeration of each BSON binary sub type.
Definition types.hpp:54
A BSON array value.
Definition types.hpp:180
bool operator==(const b_array &lhs, const b_array &rhs)
free function comparator for b_array
Definition types.hpp:198
A BSON binary data value.
Definition types.hpp:205
bool operator==(const b_binary &lhs, const b_binary &rhs)
free function comparator for b_binary
Definition types.hpp:218
A BSON boolean value.
Definition types.hpp:263
bool operator==(const b_bool &lhs, const b_bool &rhs)
free function comparator for b_bool
Definition types.hpp:281
A BSON JavaScript code value.
Definition types.hpp:420
bool operator==(const b_code &lhs, const b_code &rhs)
free function comparator for b_code
Definition types.hpp:451
b_code(T &&t)
Constructor for b_code.
Definition types.hpp:432
A BSON JavaScript code with scope value.
Definition types.hpp:499
b_codewscope(T &&code, U &&scope)
Constructor for b_codewscope.
Definition types.hpp:512
bool operator==(const b_codewscope &lhs, const b_codewscope &rhs)
free function comparator for b_codewscope
Definition types.hpp:525
A BSON date value.
Definition types.hpp:288
int64_t to_int64() const
Manually convert this b_date to an int64_t.
Definition types.hpp:324
b_date(const std::chrono::system_clock::time_point &tp)
Constructor for b_date.
Definition types.hpp:308
bool operator==(const b_date &lhs, const b_date &rhs)
free function comparator for b_date
Definition types.hpp:342
b_date(std::chrono::milliseconds value)
Constructor for b_date.
Definition types.hpp:298
A BSON DBPointer value.
Definition types.hpp:401
bool operator==(const b_dbpointer &lhs, const b_dbpointer &rhs)
free function comparator for b_dbpointer
Definition types.hpp:413
A BSON Decimal128 value.
Definition types.hpp:605
bool operator==(const b_decimal128 &lhs, const b_decimal128 &rhs)
free function comparator for b_decimal128
Definition types.hpp:629
b_decimal128(T &&t)
Constructor for b_decimal128.
Definition types.hpp:619
A BSON document value.
Definition types.hpp:148
bool operator==(const b_document &lhs, const b_document &rhs)
free function comparator for b_document
Definition types.hpp:173
document::view view()
Returns an unwrapped document::view.
Definition types.hpp:163
A BSON double value.
Definition types.hpp:85
bool operator==(const b_double &lhs, const b_double &rhs)
free function comparator for b_double
Definition types.hpp:103
A BSON signed 32-bit integer value.
Definition types.hpp:532
bool operator==(const b_int32 &lhs, const b_int32 &rhs)
free function comparator for b_int32
Definition types.hpp:550
A BSON 64-bit signed integer value.
Definition types.hpp:580
bool operator==(const b_int64 &lhs, const b_int64 &rhs)
free function comparator for b_int64
Definition types.hpp:598
A BSON max-key value.
Definition types.hpp:652
bool operator==(const b_maxkey &, const b_maxkey &)
free function comparator for b_maxkey
Definition types.hpp:661
A BSON min-key value.
Definition types.hpp:636
bool operator==(const b_minkey &, const b_minkey &)
free function comparator for b_minkey
Definition types.hpp:645
A BSON null value.
Definition types.hpp:349
bool operator==(const b_null &, const b_null &)
free function comparator for b_null
Definition types.hpp:358
A BSON ObjectId value.
Definition types.hpp:245
bool operator==(const b_oid &lhs, const b_oid &rhs)
free function comparator for b_oid
Definition types.hpp:256
A BSON regex value.
Definition types.hpp:365
bool operator==(const b_regex &lhs, const b_regex &rhs)
free function comparator for b_regex
Definition types.hpp:391
b_regex(T &®ex, U &&options)
Constructor for b_regex.
Definition types.hpp:378
A BSON Symbol value.
Definition types.hpp:461
bool operator==(const b_symbol &lhs, const b_symbol &rhs)
free function comparator for b_symbol
Definition types.hpp:492
b_symbol(T &&t)
Constructor for b_symbol.
Definition types.hpp:473
A BSON replication timestamp value.
Definition types.hpp:561
bool operator==(const b_timestamp &lhs, const b_timestamp &rhs)
free function comparator for b_timestamp
Definition types.hpp:573
A BSON undefined value.
Definition types.hpp:229
bool operator==(const b_undefined &, const b_undefined &)
free function comparator for b_undefined
Definition types.hpp:238
A BSON UTF-8 encoded string value.
Definition types.hpp:110
b_utf8(T &&t)
Constructor for b_utf8.
Definition types.hpp:122
bool operator==(const b_utf8 &lhs, const b_utf8 &rhs)
free function comparator for b_utf8
Definition types.hpp:141