20 #include <bsoncxx/array/view.hpp>
21 #include <bsoncxx/document/view.hpp>
22 #include <bsoncxx/oid.hpp>
23 #include <bsoncxx/stdx/string_view.hpp>
25 #include <bsoncxx/config/prelude.hpp>
28 BSONCXX_INLINE_NAMESPACE_BEGIN
38 enum class type : std::uint8_t {
39 #define BSONCXX_ENUM(name, val) k_##name = val,
40 #include <bsoncxx/enums/type.hpp>
53 enum class binary_sub_type : std::uint8_t {
54 #define BSONCXX_ENUM(name, val) k_##name = val,
55 #include <bsoncxx/enums/binary_sub_type.hpp>
67 BSONCXX_API std::string BSONCXX_CALL to_string(type rhs);
77 BSONCXX_API std::string BSONCXX_CALL to_string(binary_sub_type rhs);
85 static constexpr
auto type_id = type::k_double;
92 BSONCXX_INLINE
operator double() {
103 return lhs.value == rhs.value;
110 static constexpr
auto type_id = type::k_utf8;
118 template <
typename T>
123 stdx::string_view
value;
128 BSONCXX_INLINE
operator stdx::string_view() {
139 return lhs.value == rhs.value;
146 static constexpr
auto type_id = type::k_document;
171 return lhs.value == rhs.value;
178 static constexpr
auto type_id = type::k_array;
196 return lhs.value == rhs.value;
203 static constexpr
auto type_id = type::k_binary;
205 binary_sub_type sub_type;
207 const uint8_t* bytes;
216 return lhs.sub_type == rhs.sub_type && lhs.size == rhs.size &&
217 (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() {
280 return lhs.value == rhs.value;
287 static constexpr
auto type_id = type::k_date;
306 explicit b_date(
const std::chrono::system_clock::time_point& tp)
307 :
value(
std::chrono::duration_cast<
std::chrono::milliseconds>(tp.time_since_epoch())
316 BSONCXX_INLINE
operator int64_t() {
323 BSONCXX_INLINE
operator std::chrono::system_clock::time_point() {
324 return std::chrono::system_clock::time_point(
325 std::chrono::duration_cast<std::chrono::system_clock::duration>(
326 std::chrono::milliseconds{value}));
336 return lhs.value == rhs.value;
347 static constexpr
auto type_id = type::k_null;
367 static constexpr
auto type_id = type::k_regex;
378 template <
typename T,
typename U>
379 BSONCXX_INLINE
explicit b_regex(T&& regex, U&& options)
380 : regex(
std::forward<T>(regex)), options(
std::forward<U>(options)) {
383 stdx::string_view regex;
384 stdx::string_view options;
393 return lhs.regex == rhs.regex && lhs.options == rhs.options;
403 static constexpr
auto type_id = type::k_dbpointer;
405 stdx::string_view collection;
415 return lhs.collection == rhs.collection && lhs.value == rhs.value;
426 static constexpr
auto type_id = type::k_code;
434 template <
typename T>
436 : code(
std::forward<T>(code)) {
439 stdx::string_view code;
444 BSONCXX_INLINE
operator stdx::string_view() {
455 return lhs.code == rhs.code;
466 static constexpr
auto type_id = type::k_symbol;
474 template <
typename T>
476 : symbol(
std::forward<T>(symbol)) {
479 stdx::string_view symbol;
484 BSONCXX_INLINE
operator stdx::string_view() {
495 return lhs.symbol == rhs.symbol;
506 static constexpr
auto type_id = type::k_codewscope;
517 template <
typename T,
typename U>
519 : code(
std::forward<T>(code)), scope(
std::forward<U>(scope)) {
522 stdx::string_view code;
532 return lhs.code == rhs.code && lhs.scope == rhs.scope;
539 static constexpr
auto type_id = type::k_int32;
546 BSONCXX_INLINE
operator int32_t() {
557 return lhs.value == rhs.value;
568 static constexpr
auto type_id = type::k_timestamp;
580 return lhs.increment == rhs.increment && lhs.timestamp == rhs.timestamp;
587 static constexpr
auto type_id = type::k_int64;
594 BSONCXX_INLINE
operator int64_t() {
605 return lhs.value == rhs.value;
616 static constexpr
auto type_id = type::k_minkey;
636 static constexpr
auto type_id = type::k_maxkey;
648 #define BSONCXX_ENUM(name, val) \
649 BSONCXX_INLINE bool operator!=(const b_##name& lhs, const b_##name& rhs) { \
650 return !(lhs == rhs); \
652 #include <bsoncxx/enums/type.hpp>
656 BSONCXX_INLINE_NAMESPACE_END
659 #include <bsoncxx/config/postlude.hpp>
bool operator==(const b_document &lhs, const b_document &rhs)
free function comparator for b_document
Definition: types.hpp:170
bool operator==(const b_maxkey &, const b_maxkey &)
free function comparator for b_maxkey
Definition: types.hpp:644
A BSON signed 32-bit integer value.
Definition: types.hpp:538
A BSON double value.
Definition: types.hpp:84
A BSON JavaScript code value.
Definition: types.hpp:465
Represents a MongoDB ObjectId.
Definition: oid.hpp:38
A read-only, non-owning view of a BSON document.
Definition: view.hpp:33
bool operator==(const b_regex &lhs, const b_regex &rhs)
free function comparator for b_regex
Definition: types.hpp:392
Definition: error_code.hpp:67
b_date(int64_t value)
Constructor for b_date.
Definition: types.hpp:296
A BSON null value.
Definition: types.hpp:346
A BSON regex value.
Definition: types.hpp:366
A BSON binary data value.
Definition: types.hpp:202
bool operator==(const b_null &, const b_null &)
free function comparator for b_null
Definition: types.hpp:355
bool operator==(const b_code &lhs, const b_code &rhs)
free function comparator for b_code
Definition: types.hpp:454
A BSON DBPointer value.
Definition: types.hpp:402
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:635
b_utf8(T &&value)
Constructor for b_utf8.
Definition: types.hpp:119
A BSON UTF-8 encoded string value.
Definition: types.hpp:109
bool operator==(const b_symbol &lhs, const b_symbol &rhs)
free function comparator for b_symbol
Definition: types.hpp:494
A BSON date value.
Definition: types.hpp:286
A BSON min-key value.
Definition: types.hpp:615
bool operator==(const b_binary &lhs, const b_binary &rhs)
free function comparator for b_binary
Definition: types.hpp:215
A read-only, non-owning view of a BSON document.
Definition: view.hpp:33
A BSON JavaScript code value.
Definition: types.hpp:425
b_code(T &&code)
Constructor for b_code.
Definition: types.hpp:435
bool operator==(const b_double &lhs, const b_double &rhs)
free function comparator for b_double
Definition: types.hpp:102
b_codewscope(T &&code, U &&scope)
Constructor for b_codewscope.
Definition: types.hpp:518
bool operator==(const b_oid &lhs, const b_oid &rhs)
free function comparator for b_oid
Definition: types.hpp:254
bool operator==(const b_timestamp &lhs, const b_timestamp &rhs)
free function comparator for b_timestamp
Definition: types.hpp:579
bool operator==(const b_dbpointer &lhs, const b_dbpointer &rhs)
free function comparator for b_dbpointer
Definition: types.hpp:414
A BSON JavaScript code with scope value.
Definition: types.hpp:505
A BSON 64-bit signed integer value.
Definition: types.hpp:586
A BSON replication timestamp value.
Definition: types.hpp:567
bool operator==(const b_bool &lhs, const b_bool &rhs)
free function comparator for b_bool
Definition: types.hpp:279
bool operator==(const b_int64 &lhs, const b_int64 &rhs)
free function comparator for b_int64
Definition: types.hpp:604
A BSON document value.
Definition: types.hpp:145
bool operator==(const b_int32 &lhs, const b_int32 &rhs)
free function comparator for b_int32
Definition: types.hpp:556
bool operator==(const b_date &lhs, const b_date &rhs)
free function comparator for b_date
Definition: types.hpp:335
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:195
bool operator==(const b_minkey &, const b_minkey &)
free function comparator for b_minkey
Definition: types.hpp:624
b_symbol(T &&symbol)
Constructor for b_symbol.
Definition: types.hpp:475
b_date(const std::chrono::system_clock::time_point &tp)
Constructor for b_date.
Definition: types.hpp:306
bool operator==(const b_utf8 &lhs, const b_utf8 &rhs)
free function comparator for b_utf8
Definition: types.hpp:138
A BSON ObjectId value.
Definition: types.hpp:243
document::view view()
Returns an unwrapped document::view.
Definition: types.hpp:160
b_regex(T &®ex, U &&options)
Constructor for b_regex.
Definition: types.hpp:379
Definition: element.hpp:24
A BSON undefined value.
Definition: types.hpp:227
A BSON array value.
Definition: types.hpp:177
A variant that can contain any BSON type.
Definition: value.hpp:37
bool operator==(const b_codewscope &lhs, const b_codewscope &rhs)
free function comparator for b_codewscope
Definition: types.hpp:531