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>
58#define BSONCXX_ENUM(name, val) k_##name = val,
59#include <bsoncxx/enums/binary_sub_type.hpp>
89 static constexpr auto type_id = type::k_double;
96 BSONCXX_INLINE
operator double()
const {
107 return lhs.value == rhs.value;
114 static constexpr auto type_id = type::k_utf8;
122 template <
typename T,
123 typename std::enable_if<!std::is_same<b_utf8, typename std::decay<T>::type>::value,
125 BSONCXX_INLINE
explicit b_utf8(T&& t) :
value(std::forward<T>(t)) {}
127 stdx::string_view
value;
132 BSONCXX_INLINE
operator stdx::string_view()
const {
143 return lhs.value == rhs.value;
150 static constexpr auto type_id = type::k_document;
175 return lhs.value == rhs.value;
182 static constexpr auto type_id = type::k_array;
200 return lhs.value == rhs.value;
207 static constexpr auto type_id = type::k_binary;
211 const uint8_t* bytes;
220 return lhs.sub_type == rhs.sub_type && lhs.size == rhs.size &&
221 (std::memcmp(lhs.bytes, rhs.bytes, lhs.size) == 0);
231 static constexpr auto type_id = type::k_undefined;
247 static constexpr auto type_id = type::k_oid;
258 return lhs.value == rhs.value;
265 static constexpr auto type_id = type::k_bool;
272 BSONCXX_INLINE
operator bool()
const {
283 return lhs.value == rhs.value;
290 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())) {}
311 std::chrono::milliseconds
value;
316 BSONCXX_INLINE
operator int64_t()
const {
317 return value.count();
324 return value.count();
330 BSONCXX_INLINE
operator std::chrono::system_clock::time_point()
const {
331 return std::chrono::system_clock::time_point(
332 std::chrono::duration_cast<std::chrono::system_clock::duration>(
value));
342 return lhs.value == rhs.value;
349 static constexpr auto type_id = type::k_null;
365 static constexpr auto type_id = type::k_regex;
376 template <
typename T,
377 typename U = stdx::string_view,
378 typename std::enable_if<!std::is_same<b_regex, typename std::decay<T>::type>::value,
380 BSONCXX_INLINE
explicit b_regex(T&& regex, U&& options = U{})
381 : 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;
422 static constexpr auto type_id = type::k_code;
430 template <
typename T,
431 typename std::enable_if<!std::is_same<b_code, typename std::decay<T>::type>::value,
433 BSONCXX_INLINE
explicit b_code(T&& t) : code(std::forward<T>(t)) {}
435 stdx::string_view code;
440 BSONCXX_INLINE
operator stdx::string_view()
const {
451 return lhs.code == rhs.code;
461 static constexpr auto type_id = type::k_symbol;
469 template <
typename T,
470 typename std::enable_if<!std::is_same<b_symbol, typename std::decay<T>::type>::value,
472 BSONCXX_INLINE
explicit b_symbol(T&& t) : symbol(std::forward<T>(t)) {}
474 stdx::string_view symbol;
479 BSONCXX_INLINE
operator stdx::string_view()
const {
490 return lhs.symbol == rhs.symbol;
497 static constexpr auto type_id = type::k_codewscope;
511 typename std::enable_if<!std::is_same<b_codewscope, typename std::decay<T>::type>::value,
514 : 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()
const {
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()
const {
599 return lhs.value == rhs.value;
606 static constexpr auto type_id = type::k_decimal128;
618 typename std::enable_if<!std::is_same<b_decimal128, typename std::decay<T>::type>::value,
629 return lhs.value == rhs.value;
636 static constexpr auto type_id = type::k_minkey;
652 static constexpr auto type_id = type::k_maxkey;
664#define BSONCXX_ENUM(name, val) \
665 BSONCXX_INLINE bool operator!=(const b_##name& lhs, const b_##name& rhs) { \
666 return !(lhs == rhs); \
668#include <bsoncxx/enums/type.hpp>
672BSONCXX_INLINE_NAMESPACE_END
675#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 view-only variant that can contain any BSON type.
Definition view.hpp:44
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:57
A BSON array value.
Definition types.hpp:181
bool operator==(const b_array &lhs, const b_array &rhs)
free function comparator for b_array
Definition types.hpp:199
A BSON binary data value.
Definition types.hpp:206
bool operator==(const b_binary &lhs, const b_binary &rhs)
free function comparator for b_binary
Definition types.hpp:219
A BSON boolean value.
Definition types.hpp:264
bool operator==(const b_bool &lhs, const b_bool &rhs)
free function comparator for b_bool
Definition types.hpp:282
A BSON JavaScript code value.
Definition types.hpp:421
bool operator==(const b_code &lhs, const b_code &rhs)
free function comparator for b_code
Definition types.hpp:450
b_code(T &&t)
Constructor for b_code.
Definition types.hpp:433
A BSON JavaScript code with scope value.
Definition types.hpp:496
b_codewscope(T &&code, U &&scope)
Constructor for b_codewscope.
Definition types.hpp:513
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:289
int64_t to_int64() const
Manually convert this b_date to an int64_t.
Definition types.hpp:323
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:341
b_date(std::chrono::milliseconds value)
Constructor for b_date.
Definition types.hpp:299
A BSON DBPointer value.
Definition types.hpp:402
bool operator==(const b_dbpointer &lhs, const b_dbpointer &rhs)
free function comparator for b_dbpointer
Definition types.hpp:414
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:628
b_decimal128(T &&t)
Constructor for b_decimal128.
Definition types.hpp:620
A BSON document value.
Definition types.hpp:149
bool operator==(const b_document &lhs, const b_document &rhs)
free function comparator for b_document
Definition types.hpp:174
document::view view()
Returns an unwrapped document::view.
Definition types.hpp:164
A BSON double value.
Definition types.hpp:88
bool operator==(const b_double &lhs, const b_double &rhs)
free function comparator for b_double
Definition types.hpp:106
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:651
bool operator==(const b_maxkey &, const b_maxkey &)
free function comparator for b_maxkey
Definition types.hpp:660
A BSON min-key value.
Definition types.hpp:635
bool operator==(const b_minkey &, const b_minkey &)
free function comparator for b_minkey
Definition types.hpp:644
A BSON null value.
Definition types.hpp:348
bool operator==(const b_null &, const b_null &)
free function comparator for b_null
Definition types.hpp:357
A BSON ObjectId value.
Definition types.hpp:246
bool operator==(const b_oid &lhs, const b_oid &rhs)
free function comparator for b_oid
Definition types.hpp:257
A BSON regex value.
Definition types.hpp:364
bool operator==(const b_regex &lhs, const b_regex &rhs)
free function comparator for b_regex
Definition types.hpp:392
b_regex(T &®ex, U &&options=U{})
Constructor for b_regex.
Definition types.hpp:380
A BSON Symbol value.
Definition types.hpp:460
bool operator==(const b_symbol &lhs, const b_symbol &rhs)
free function comparator for b_symbol
Definition types.hpp:489
b_symbol(T &&t)
Constructor for b_symbol.
Definition types.hpp:472
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:230
bool operator==(const b_undefined &, const b_undefined &)
free function comparator for b_undefined
Definition types.hpp:239
A BSON UTF-8 encoded string value.
Definition types.hpp:113
b_utf8(T &&t)
Constructor for b_utf8.
Definition types.hpp:125
bool operator==(const b_utf8 &lhs, const b_utf8 &rhs)
free function comparator for b_utf8
Definition types.hpp:142