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>
25 #include <bsoncxx/stdx/type_traits.hpp>
27 #include <bsoncxx/config/prelude.hpp>
29 #pragma push_macro("BSONCXX_ENUM")
32 #if defined(__clang__)
33 #pragma clang diagnostic push
34 #pragma clang diagnostic ignored "-Wfloat-equal"
35 #elif defined(__GNUC__)
36 #pragma GCC diagnostic push
37 #pragma GCC diagnostic ignored "-Wfloat-equal"
41 inline namespace v_noabi {
50 enum class type : std::uint8_t {
51 #define BSONCXX_ENUM(name, val) k_##name = val,
52 #include <bsoncxx/enums/type.hpp>
71 #define BSONCXX_ENUM(name, val) k_##name = val,
72 #include <bsoncxx/enums/binary_sub_type.hpp>
102 static constexpr
auto type_id = type::k_double;
109 BSONCXX_INLINE
operator double()
const {
120 return lhs.value == rhs.value;
127 static constexpr
auto type_id = type::k_string;
135 template <
typename T, detail::requires_not_t<
int, detail::is_alike<b_
string, T>> = 0>
138 stdx::string_view
value;
143 BSONCXX_INLINE
operator stdx::string_view()
const {
154 return lhs.value == rhs.value;
168 static constexpr
auto type_id = type::k_document;
193 return lhs.value == rhs.value;
200 static constexpr
auto type_id = type::k_array;
218 return lhs.value == rhs.value;
225 static constexpr
auto type_id = type::k_binary;
229 const uint8_t* bytes;
238 return lhs.sub_type == rhs.sub_type && lhs.size == rhs.size &&
239 (!lhs.size || (std::memcmp(lhs.bytes, rhs.bytes, lhs.size) == 0));
249 static constexpr
auto type_id = type::k_undefined;
265 static constexpr
auto type_id = type::k_oid;
276 return lhs.value == rhs.value;
283 static constexpr
auto type_id = type::k_bool;
290 BSONCXX_INLINE
operator bool()
const {
301 return lhs.value == rhs.value;
308 static constexpr
auto type_id = type::k_date;
326 explicit b_date(
const std::chrono::system_clock::time_point& tp)
327 :
value(std::chrono::duration_cast<std::chrono::milliseconds>(tp.time_since_epoch())) {}
329 std::chrono::milliseconds
value;
334 BSONCXX_INLINE
operator int64_t()
const {
335 return value.count();
342 return value.count();
348 BSONCXX_INLINE
operator std::chrono::system_clock::time_point()
const {
349 return std::chrono::system_clock::time_point(
350 std::chrono::duration_cast<std::chrono::system_clock::duration>(
value));
360 return lhs.value == rhs.value;
367 static constexpr
auto type_id = type::k_null;
383 static constexpr
auto type_id = type::k_regex;
394 template <
typename T,
395 typename U = stdx::string_view,
396 detail::requires_not_t<int, detail::is_alike<b_regex, T>> = 0>
397 BSONCXX_INLINE
explicit b_regex(T&& regex, U&& options = U{})
398 : regex(std::forward<T>(regex)), options(std::forward<U>(options)) {}
400 stdx::string_view regex;
401 stdx::string_view options;
410 return lhs.regex == rhs.regex && lhs.options == rhs.options;
420 static constexpr
auto type_id = type::k_dbpointer;
422 stdx::string_view collection;
432 return lhs.collection == rhs.collection && lhs.value == rhs.value;
439 static constexpr
auto type_id = type::k_code;
447 template <
typename T, detail::requires_not_t<
int, detail::is_alike<b_code, T>> = 0>
448 BSONCXX_INLINE
explicit b_code(T&& t) : code(std::forward<T>(t)) {}
450 stdx::string_view code;
455 BSONCXX_INLINE
operator stdx::string_view()
const {
466 return lhs.code == rhs.code;
476 static constexpr
auto type_id = type::k_symbol;
484 template <
typename T, detail::requires_not_t<
int, detail::is_alike<b_symbol, T>> = 0>
485 BSONCXX_INLINE
explicit b_symbol(T&& t) : symbol(std::forward<T>(t)) {}
487 stdx::string_view symbol;
492 BSONCXX_INLINE
operator stdx::string_view()
const {
503 return lhs.symbol == rhs.symbol;
510 static constexpr
auto type_id = type::k_codewscope;
521 template <
typename T,
523 detail::requires_not_t<int, detail::is_alike<b_codewscope, T>> = 0>
525 : code(std::forward<T>(code)), scope(std::forward<U>(scope)) {}
527 stdx::string_view code;
537 return lhs.code == rhs.code && lhs.scope == rhs.scope;
544 static constexpr
auto type_id = type::k_int32;
551 BSONCXX_INLINE
operator int32_t()
const {
562 return lhs.value == rhs.value;
569 static constexpr
auto type_id = type::k_timestamp;
581 return lhs.increment == rhs.increment && lhs.timestamp == rhs.timestamp;
588 static constexpr
auto type_id = type::k_int64;
595 BSONCXX_INLINE
operator int64_t()
const {
606 return lhs.value == rhs.value;
613 static constexpr
auto type_id = type::k_decimal128;
623 template <
typename T, detail::requires_not_t<
int, detail::is_alike<b_decimal128, T>> = 0>
633 return lhs.value == rhs.value;
640 static constexpr
auto type_id = type::k_minkey;
656 static constexpr
auto type_id = type::k_maxkey;
668 #define BSONCXX_ENUM(name, val) \
669 BSONCXX_INLINE bool operator!=(const b_##name& lhs, const b_##name& rhs) { \
670 return !(lhs == rhs); \
672 #include <bsoncxx/enums/type.hpp>
679 #if defined(__clang__)
680 #pragma clang diagnostic pop
681 #elif defined(__GNUC__)
682 #pragma GCC diagnostic pop
686 static_assert(
false,
"BSONCXX_ENUM must be undef'ed");
688 #pragma pop_macro("BSONCXX_ENUM")
690 #include <bsoncxx/config/postlude.hpp>
A read-only, non-owning view of a BSON document.
Definition: view.hpp:39
Represents an IEEE 754-2008 BSON Decimal128 value in a platform-independent way.
Definition: decimal128.hpp:29
A read-only, non-owning view of a BSON document.
Definition: view.hpp:33
Represents a MongoDB ObjectId.
Definition: oid.hpp:37
A view-only variant that can contain any BSON type.
Definition: view.hpp:44
binary_sub_type
An enumeration of each BSON binary sub type.
Definition: types.hpp:70
std::string to_string(type rhs)
Returns a stringification of the given type.
type
An enumeration of each BSON type.
Definition: types.hpp:50
The top-level namespace for bsoncxx library entities.
Definition: element.hpp:24
A BSON array value.
Definition: types.hpp:199
bool operator==(const b_array &lhs, const b_array &rhs)
free function comparator for b_array
Definition: types.hpp:217
A BSON binary data value.
Definition: types.hpp:224
bool operator==(const b_binary &lhs, const b_binary &rhs)
free function comparator for b_binary
Definition: types.hpp:237
A BSON boolean value.
Definition: types.hpp:282
bool operator==(const b_bool &lhs, const b_bool &rhs)
free function comparator for b_bool
Definition: types.hpp:300
A BSON JavaScript code value.
Definition: types.hpp:438
bool operator==(const b_code &lhs, const b_code &rhs)
free function comparator for b_code
Definition: types.hpp:465
b_code(T &&t)
Constructor for b_code.
Definition: types.hpp:448
A BSON JavaScript code with scope value.
Definition: types.hpp:509
bool operator==(const b_codewscope &lhs, const b_codewscope &rhs)
free function comparator for b_codewscope
Definition: types.hpp:536
b_codewscope(T &&code, U &&scope)
Constructor for b_codewscope.
Definition: types.hpp:524
A BSON date value.
Definition: types.hpp:307
bool operator==(const b_date &lhs, const b_date &rhs)
free function comparator for b_date
Definition: types.hpp:359
b_date(const std::chrono::system_clock::time_point &tp)
Constructor for b_date.
Definition: types.hpp:326
int64_t to_int64() const
Manually convert this b_date to an int64_t.
Definition: types.hpp:341
b_date(std::chrono::milliseconds value)
Constructor for b_date.
Definition: types.hpp:317
A BSON DBPointer value.
Definition: types.hpp:419
bool operator==(const b_dbpointer &lhs, const b_dbpointer &rhs)
free function comparator for b_dbpointer
Definition: types.hpp:431
A BSON Decimal128 value.
Definition: types.hpp:612
bool operator==(const b_decimal128 &lhs, const b_decimal128 &rhs)
free function comparator for b_decimal128
Definition: types.hpp:632
b_decimal128(T &&t)
Constructor for b_decimal128.
Definition: types.hpp:624
A BSON document value.
Definition: types.hpp:167
document::view view()
Returns an unwrapped document::view.
Definition: types.hpp:182
bool operator==(const b_document &lhs, const b_document &rhs)
free function comparator for b_document
Definition: types.hpp:192
A BSON double value.
Definition: types.hpp:101
bool operator==(const b_double &lhs, const b_double &rhs)
free function comparator for b_double
Definition: types.hpp:119
A BSON signed 32-bit integer value.
Definition: types.hpp:543
bool operator==(const b_int32 &lhs, const b_int32 &rhs)
free function comparator for b_int32
Definition: types.hpp:561
A BSON 64-bit signed integer value.
Definition: types.hpp:587
bool operator==(const b_int64 &lhs, const b_int64 &rhs)
free function comparator for b_int64
Definition: types.hpp:605
A BSON max-key value.
Definition: types.hpp:655
bool operator==(const b_maxkey &, const b_maxkey &)
free function comparator for b_maxkey
Definition: types.hpp:664
A BSON min-key value.
Definition: types.hpp:639
bool operator==(const b_minkey &, const b_minkey &)
free function comparator for b_minkey
Definition: types.hpp:648
A BSON null value.
Definition: types.hpp:366
bool operator==(const b_null &, const b_null &)
free function comparator for b_null
Definition: types.hpp:375
A BSON ObjectId value.
Definition: types.hpp:264
bool operator==(const b_oid &lhs, const b_oid &rhs)
free function comparator for b_oid
Definition: types.hpp:275
A BSON regex value.
Definition: types.hpp:382
bool operator==(const b_regex &lhs, const b_regex &rhs)
free function comparator for b_regex
Definition: types.hpp:409
b_regex(T &®ex, U &&options=U{})
Constructor for b_regex.
Definition: types.hpp:397
A BSON UTF-8 encoded string value.
Definition: types.hpp:126
b_string(T &&t)
Constructor for b_string.
Definition: types.hpp:136
bool operator==(const b_string &lhs, const b_string &rhs)
free function comparator for b_string
Definition: types.hpp:153
A BSON Symbol value.
Definition: types.hpp:475
b_symbol(T &&t)
Constructor for b_symbol.
Definition: types.hpp:485
bool operator==(const b_symbol &lhs, const b_symbol &rhs)
free function comparator for b_symbol
Definition: types.hpp:502
A BSON replication timestamp value.
Definition: types.hpp:568
bool operator==(const b_timestamp &lhs, const b_timestamp &rhs)
free function comparator for b_timestamp
Definition: types.hpp:580
A BSON undefined value.
Definition: types.hpp:248
bool operator==(const b_undefined &, const b_undefined &)
free function comparator for b_undefined
Definition: types.hpp:257