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> 29 BSONCXX_INLINE_NAMESPACE_BEGIN
39 enum 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()
const {
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,
124 stdx::string_view
value;
129 BSONCXX_INLINE
operator stdx::string_view()
const {
140 return lhs.value == rhs.value;
147 static constexpr
auto type_id = type::k_document;
172 return lhs.value == rhs.value;
179 static constexpr
auto type_id = type::k_array;
197 return lhs.value == rhs.value;
204 static constexpr
auto type_id = type::k_binary;
208 const uint8_t* bytes;
217 return lhs.sub_type == rhs.sub_type && lhs.size == rhs.size &&
218 (std::memcmp(lhs.bytes, rhs.bytes, lhs.size) == 0);
228 static constexpr
auto type_id = type::k_undefined;
244 static constexpr
auto type_id = type::k_oid;
255 return lhs.value == rhs.value;
262 static constexpr
auto type_id = type::k_bool;
269 BSONCXX_INLINE
operator bool()
const {
280 return lhs.value == rhs.value;
287 static constexpr
auto type_id = type::k_date;
296 explicit b_date(std::chrono::milliseconds
value) : value(value) {}
305 explicit b_date(
const std::chrono::system_clock::time_point& tp)
306 :
value(
std::chrono::duration_cast<
std::chrono::milliseconds>(tp.time_since_epoch())) {}
308 std::chrono::milliseconds
value;
313 BSONCXX_INLINE
operator int64_t()
const {
314 return value.count();
321 return value.count();
327 BSONCXX_INLINE
operator std::chrono::system_clock::time_point()
const {
328 return std::chrono::system_clock::time_point(
329 std::chrono::duration_cast<std::chrono::system_clock::duration>(value));
339 return lhs.value == rhs.value;
346 static constexpr
auto type_id = type::k_null;
362 static constexpr
auto type_id = type::k_regex;
373 template <
typename T,
374 typename U = stdx::string_view,
375 typename std::enable_if<!std::is_same<b_regex, typename std::decay<T>::type>
::value,
377 BSONCXX_INLINE
explicit b_regex(T&& regex, U&& options = U{})
378 : regex(std::forward<T>(regex)), options(std::forward<U>(options)) {}
380 stdx::string_view regex;
381 stdx::string_view options;
390 return lhs.regex == rhs.regex && lhs.options == rhs.options;
400 static constexpr
auto type_id = type::k_dbpointer;
402 stdx::string_view collection;
412 return lhs.collection == rhs.collection && lhs.value == rhs.value;
419 static constexpr
auto type_id = type::k_code;
427 template <
typename T,
428 typename std::enable_if<!std::is_same<b_code, typename std::decay<T>::type>::value,
430 BSONCXX_INLINE
explicit b_code(T&& t) : code(
std::forward<T>(t)) {}
432 stdx::string_view code;
437 BSONCXX_INLINE
operator stdx::string_view()
const {
448 return lhs.code == rhs.code;
458 static constexpr
auto type_id = type::k_symbol;
466 template <
typename T,
467 typename std::enable_if<!std::is_same<b_symbol, typename std::decay<T>::type>::value,
469 BSONCXX_INLINE
explicit b_symbol(T&& t) : symbol(
std::forward<T>(t)) {}
471 stdx::string_view symbol;
476 BSONCXX_INLINE
operator stdx::string_view()
const {
487 return lhs.symbol == rhs.symbol;
494 static constexpr
auto type_id = type::k_codewscope;
508 typename std::enable_if<!std::is_same<b_codewscope, typename std::decay<T>::type>::value,
511 : code(
std::forward<T>(code)), scope(
std::forward<U>(scope)) {}
513 stdx::string_view code;
523 return lhs.code == rhs.code && lhs.scope == rhs.scope;
530 static constexpr
auto type_id = type::k_int32;
537 BSONCXX_INLINE
operator int32_t()
const {
548 return lhs.value == rhs.value;
559 static constexpr
auto type_id = type::k_timestamp;
571 return lhs.increment == rhs.increment && lhs.timestamp == rhs.timestamp;
578 static constexpr
auto type_id = type::k_int64;
585 BSONCXX_INLINE
operator int64_t()
const {
596 return lhs.value == rhs.value;
603 static constexpr
auto type_id = type::k_decimal128;
615 typename std::enable_if<!std::is_same<b_decimal128, typename std::decay<T>::type>::value,
626 return lhs.value == rhs.value;
633 static constexpr
auto type_id = type::k_minkey;
649 static constexpr
auto type_id = type::k_maxkey;
661 #define BSONCXX_ENUM(name, val) \ 662 BSONCXX_INLINE bool operator!=(const b_##name& lhs, const b_##name& rhs) { \ 663 return !(lhs == rhs); \ 665 #include <bsoncxx/enums/type.hpp> 669 BSONCXX_INLINE_NAMESPACE_END
672 #include <bsoncxx/config/postlude.hpp> bool operator==(const b_document &lhs, const b_document &rhs)
free function comparator for b_document
Definition: types.hpp:171
bool operator==(const b_maxkey &, const b_maxkey &)
free function comparator for b_maxkey
Definition: types.hpp:657
A BSON signed 32-bit integer value.
Definition: types.hpp:529
A BSON double value.
Definition: types.hpp:85
A BSON Symbol value.
Definition: types.hpp:457
Represents a MongoDB ObjectId.
Definition: oid.hpp:38
b_regex(T &®ex, U &&options=U{})
Constructor for b_regex.
Definition: types.hpp:377
A read-only, non-owning view of a BSON document.
Definition: view.hpp:33
b_utf8(T &&t)
Constructor for b_utf8.
Definition: types.hpp:122
bool operator==(const b_regex &lhs, const b_regex &rhs)
free function comparator for b_regex
Definition: types.hpp:389
binary_sub_type
An enumeration of each BSON binary sub type.
Definition: types.hpp:54
Definition: error_code.hpp:117
A BSON null value.
Definition: types.hpp:345
b_code(T &&t)
Constructor for b_code.
Definition: types.hpp:430
A BSON regex value.
Definition: types.hpp:361
A BSON binary data value.
Definition: types.hpp:203
bool operator==(const b_null &, const b_null &)
free function comparator for b_null
Definition: types.hpp:354
bool operator==(const b_decimal128 &lhs, const b_decimal128 &rhs)
free function comparator for b_decimal128
Definition: types.hpp:625
bool operator==(const b_code &lhs, const b_code &rhs)
free function comparator for b_code
Definition: types.hpp:447
A BSON DBPointer value.
Definition: types.hpp:399
bool operator==(const b_undefined &, const b_undefined &)
free function comparator for b_undefined
Definition: types.hpp:236
A BSON max-key value.
Definition: types.hpp:648
A BSON UTF-8 encoded string value.
Definition: types.hpp:110
Represents an IEEE 754-2008 BSON Decimal128 value in a platform-independent way.
Definition: decimal128.hpp:30
bool operator==(const b_symbol &lhs, const b_symbol &rhs)
free function comparator for b_symbol
Definition: types.hpp:486
A BSON date value.
Definition: types.hpp:286
A BSON min-key value.
Definition: types.hpp:632
bool operator==(const b_binary &lhs, const b_binary &rhs)
free function comparator for b_binary
Definition: types.hpp:216
A read-only, non-owning view of a BSON document.
Definition: view.hpp:33
b_decimal128(T &&t)
Constructor for b_decimal128.
Definition: types.hpp:617
A BSON JavaScript code value.
Definition: types.hpp:418
bool operator==(const b_double &lhs, const b_double &rhs)
free function comparator for b_double
Definition: types.hpp:103
bool operator==(const b_oid &lhs, const b_oid &rhs)
free function comparator for b_oid
Definition: types.hpp:254
b_symbol(T &&t)
Constructor for b_symbol.
Definition: types.hpp:469
int64_t to_int64() const
Manually convert this b_date to an int64_t.
Definition: types.hpp:320
bool operator==(const b_timestamp &lhs, const b_timestamp &rhs)
free function comparator for b_timestamp
Definition: types.hpp:570
bool operator==(const b_dbpointer &lhs, const b_dbpointer &rhs)
free function comparator for b_dbpointer
Definition: types.hpp:411
A BSON JavaScript code with scope value.
Definition: types.hpp:493
A BSON 64-bit signed integer value.
Definition: types.hpp:577
A BSON replication timestamp value.
Definition: types.hpp:558
bool operator==(const b_bool &lhs, const b_bool &rhs)
free function comparator for b_bool
Definition: types.hpp:279
b_codewscope(T &&code, U &&scope)
Constructor for b_codewscope.
Definition: types.hpp:510
bool operator==(const b_int64 &lhs, const b_int64 &rhs)
free function comparator for b_int64
Definition: types.hpp:595
A BSON document value.
Definition: types.hpp:146
bool operator==(const b_int32 &lhs, const b_int32 &rhs)
free function comparator for b_int32
Definition: types.hpp:547
type
An enumeration of each BSON type.
Definition: types.hpp:39
bool operator==(const b_date &lhs, const b_date &rhs)
free function comparator for b_date
Definition: types.hpp:338
b_date(std::chrono::milliseconds value)
Constructor for b_date.
Definition: types.hpp:296
A BSON boolean value.
Definition: types.hpp:261
bool operator==(const b_array &lhs, const b_array &rhs)
free function comparator for b_array
Definition: types.hpp:196
std::string to_string(type rhs)
Returns a stringification of the given type.
bool operator==(const b_minkey &, const b_minkey &)
free function comparator for b_minkey
Definition: types.hpp:641
b_date(const std::chrono::system_clock::time_point &tp)
Constructor for b_date.
Definition: types.hpp:305
bool operator==(const b_utf8 &lhs, const b_utf8 &rhs)
free function comparator for b_utf8
Definition: types.hpp:139
A BSON ObjectId value.
Definition: types.hpp:243
document::view view()
Returns an unwrapped document::view.
Definition: types.hpp:161
Top level namespace for MongoDB C++ BSON functionality.
Definition: element.hpp:24
A BSON undefined value.
Definition: types.hpp:227
A BSON array value.
Definition: types.hpp:178
A variant that can contain any BSON type.
Definition: value.hpp:37
A BSON Decimal128 value.
Definition: types.hpp:602
bool operator==(const b_codewscope &lhs, const b_codewscope &rhs)
free function comparator for b_codewscope
Definition: types.hpp:522