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>
28BSONCXX_INLINE_NAMESPACE_BEGIN
38enum class type : std::uint8_t {
39#define BSONCXX_ENUM(name, val) k_##name = val,
40#include <bsoncxx/enums/type.hpp>
53enum class binary_sub_type : std::uint8_t {
54#define BSONCXX_ENUM(name, val) k_##name = val,
55#include <bsoncxx/enums/binary_sub_type.hpp>
67BSONCXX_API std::string BSONCXX_CALL to_string(type rhs);
77BSONCXX_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,
119 typename std::enable_if<!std::is_same<b_utf8, typename std::decay<T>::type>::value,
122 :
value(std::forward<T>(t)) {
125 stdx::string_view
value;
130 BSONCXX_INLINE
operator stdx::string_view() {
141 return lhs.value == rhs.value;
148 static constexpr auto type_id = type::k_document;
173 return lhs.value == rhs.value;
180 static constexpr auto type_id = type::k_array;
198 return lhs.value == rhs.value;
205 static constexpr auto type_id = type::k_binary;
207 binary_sub_type sub_type;
209 const uint8_t* bytes;
218 return lhs.sub_type == rhs.sub_type && lhs.size == rhs.size &&
219 (std::memcmp(lhs.bytes, rhs.bytes, lhs.size) == 0);
229 static constexpr auto type_id = type::k_undefined;
245 static constexpr auto type_id = type::k_oid;
256 return lhs.value == rhs.value;
263 static constexpr auto type_id = type::k_bool;
270 BSONCXX_INLINE
operator bool() {
281 return lhs.value == rhs.value;
288 static constexpr auto type_id = type::k_date;
307 explicit b_date(
const std::chrono::system_clock::time_point& tp)
308 :
value(std::chrono::duration_cast<std::chrono::milliseconds>(tp.time_since_epoch())) {
311 std::chrono::milliseconds
value;
316 BSONCXX_INLINE
operator int64_t() {
317 return value.count();
324 return value.count();
330 BSONCXX_INLINE
operator std::chrono::system_clock::time_point() {
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,
typename U>
377 BSONCXX_INLINE
explicit b_regex(T&& regex, U&& options)
378 : regex(std::forward<T>(regex)), options(std::forward<U>(options)) {
381 stdx::string_view regex;
382 stdx::string_view options;
391 return lhs.regex == rhs.regex && lhs.options == rhs.options;
401 static constexpr auto type_id = type::k_dbpointer;
403 stdx::string_view collection;
413 return lhs.collection == rhs.collection && lhs.value == rhs.value;
420 static constexpr auto type_id = type::k_code;
428 template <
typename T,
429 typename std::enable_if<!std::is_same<b_code, typename std::decay<T>::type>::value,
432 : code(std::forward<T>(t)) {
435 stdx::string_view code;
440 BSONCXX_INLINE
operator stdx::string_view() {
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,
473 : symbol(std::forward<T>(t)) {
476 stdx::string_view symbol;
481 BSONCXX_INLINE
operator stdx::string_view() {
492 return lhs.symbol == rhs.symbol;
499 static constexpr auto type_id = type::k_codewscope;
510 template <
typename T,
typename U>
512 : code(std::forward<T>(code)), scope(std::forward<U>(scope)) {
515 stdx::string_view code;
525 return lhs.code == rhs.code && lhs.scope == rhs.scope;
532 static constexpr auto type_id = type::k_int32;
539 BSONCXX_INLINE
operator int32_t() {
550 return lhs.value == rhs.value;
561 static constexpr auto type_id = type::k_timestamp;
573 return lhs.increment == rhs.increment && lhs.timestamp == rhs.timestamp;
580 static constexpr auto type_id = type::k_int64;
587 BSONCXX_INLINE
operator int64_t() {
598 return lhs.value == rhs.value;
605 static constexpr auto type_id = type::k_minkey;
621 static constexpr auto type_id = type::k_maxkey;
633#define BSONCXX_ENUM(name, val) \
634 BSONCXX_INLINE bool operator!=(const b_##name& lhs, const b_##name& rhs) { \
635 return !(lhs == rhs); \
637#include <bsoncxx/enums/type.hpp>
641BSONCXX_INLINE_NAMESPACE_END
644#include <bsoncxx/config/postlude.hpp>
A read-only, non-owning view of a BSON document.
Definition view.hpp:33
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
A BSON array value.
Definition types.hpp:179
bool operator==(const b_array &lhs, const b_array &rhs)
free function comparator for b_array
Definition types.hpp:197
A BSON binary data value.
Definition types.hpp:204
bool operator==(const b_binary &lhs, const b_binary &rhs)
free function comparator for b_binary
Definition types.hpp:217
A BSON boolean value.
Definition types.hpp:262
bool operator==(const b_bool &lhs, const b_bool &rhs)
free function comparator for b_bool
Definition types.hpp:280
A BSON JavaScript code value.
Definition types.hpp:419
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:431
A BSON JavaScript code with scope value.
Definition types.hpp:498
b_codewscope(T &&code, U &&scope)
Constructor for b_codewscope.
Definition types.hpp:511
bool operator==(const b_codewscope &lhs, const b_codewscope &rhs)
free function comparator for b_codewscope
Definition types.hpp:524
A BSON date value.
Definition types.hpp:287
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:307
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:297
A BSON DBPointer value.
Definition types.hpp:400
bool operator==(const b_dbpointer &lhs, const b_dbpointer &rhs)
free function comparator for b_dbpointer
Definition types.hpp:412
A BSON document value.
Definition types.hpp:147
bool operator==(const b_document &lhs, const b_document &rhs)
free function comparator for b_document
Definition types.hpp:172
document::view view()
Returns an unwrapped document::view.
Definition types.hpp:162
A BSON double value.
Definition types.hpp:84
bool operator==(const b_double &lhs, const b_double &rhs)
free function comparator for b_double
Definition types.hpp:102
A BSON signed 32-bit integer value.
Definition types.hpp:531
bool operator==(const b_int32 &lhs, const b_int32 &rhs)
free function comparator for b_int32
Definition types.hpp:549
A BSON 64-bit signed integer value.
Definition types.hpp:579
bool operator==(const b_int64 &lhs, const b_int64 &rhs)
free function comparator for b_int64
Definition types.hpp:597
A BSON max-key value.
Definition types.hpp:620
bool operator==(const b_maxkey &, const b_maxkey &)
free function comparator for b_maxkey
Definition types.hpp:629
A BSON min-key value.
Definition types.hpp:604
bool operator==(const b_minkey &, const b_minkey &)
free function comparator for b_minkey
Definition types.hpp:613
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:244
bool operator==(const b_oid &lhs, const b_oid &rhs)
free function comparator for b_oid
Definition types.hpp:255
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:390
b_regex(T &®ex, U &&options)
Constructor for b_regex.
Definition types.hpp:377
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:491
b_symbol(T &&t)
Constructor for b_symbol.
Definition types.hpp:472
A BSON replication timestamp value.
Definition types.hpp:560
bool operator==(const b_timestamp &lhs, const b_timestamp &rhs)
free function comparator for b_timestamp
Definition types.hpp:572
A BSON undefined value.
Definition types.hpp:228
bool operator==(const b_undefined &, const b_undefined &)
free function comparator for b_undefined
Definition types.hpp:237
A BSON UTF-8 encoded string value.
Definition types.hpp:109
b_utf8(T &&t)
Constructor for b_utf8.
Definition types.hpp:121
bool operator==(const b_utf8 &lhs, const b_utf8 &rhs)
free function comparator for b_utf8
Definition types.hpp:140