MongoDB C++ Driver mongocxx-4.0.0
Loading...
Searching...
No Matches
view.hpp
Go to the documentation of this file.
1// Copyright 2009-present MongoDB, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <cstddef>
18#include <cstdint>
19#include <type_traits>
20
24
26#include <bsoncxx/types.hpp>
27
29
30namespace bsoncxx {
31namespace detail {
32
33template <typename T>
34using is_bson_view_compatible =
35 detail::conjunction<std::is_constructible<bsoncxx::v_noabi::types::bson_value::view, T>,
36 detail::negation<detail::disjunction<
37 detail::is_alike<T, bsoncxx::v_noabi::types::bson_value::view>,
38 detail::is_alike<T, bsoncxx::v_noabi::types::bson_value::value>>>>;
39
40} // namespace detail
41} // namespace bsoncxx
42
43namespace bsoncxx {
44namespace v_noabi {
45namespace types {
46namespace bson_value {
54class view {
55 public:
60 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_double v) noexcept;
61 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_string v) noexcept;
63 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_array v) noexcept;
64 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_binary v) noexcept;
66 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_oid v) noexcept;
67 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_bool v) noexcept;
68 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_date v) noexcept;
69 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_null v) noexcept;
70 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_regex v) noexcept;
72 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_code v) noexcept;
73 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_symbol v) noexcept;
75 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_int32 v) noexcept;
77 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_int64 v) noexcept;
79 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_maxkey v) noexcept;
80 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_minkey v) noexcept;
83
89
90 BSONCXX_ABI_EXPORT_CDECL() view(const view&) noexcept;
91 BSONCXX_ABI_EXPORT_CDECL(view&) operator=(const view&) noexcept;
92
94
101 friend BSONCXX_ABI_EXPORT_CDECL(bool) operator==(const bson_value::view&,
102 const bson_value::view&);
103 friend BSONCXX_ABI_EXPORT_CDECL(bool) operator!=(const bson_value::view&,
104 const bson_value::view&);
107
112
120
128
136
144
152
160
168
176
184
192
200
208
216
224
232
240
248
256
264
272
280
281 private:
282 friend ::bsoncxx::v_noabi::types::bson_value::value;
283 friend ::bsoncxx::v_noabi::document::element;
284
285 view(const std::uint8_t* raw, std::uint32_t length, std::uint32_t offset, std::uint32_t keylen);
286 view(void* internal_value) noexcept;
287
288 void _init(void* internal_value) noexcept;
289
290 void destroy() noexcept;
291
292 bsoncxx::v_noabi::type _type;
293
294 union {
295 struct b_double _b_double;
296 struct b_string _b_string;
297 struct b_document _b_document;
298 struct b_array _b_array;
299 struct b_binary _b_binary;
300 struct b_undefined _b_undefined;
301 struct b_oid _b_oid;
302 struct b_bool _b_bool;
303 struct b_date _b_date;
304 struct b_null _b_null;
305 struct b_regex _b_regex;
306 struct b_dbpointer _b_dbpointer;
307 struct b_code _b_code;
308 struct b_symbol _b_symbol;
309 struct b_codewscope _b_codewscope;
310 struct b_int32 _b_int32;
311 struct b_timestamp _b_timestamp;
312 struct b_int64 _b_int64;
313 struct b_decimal128 _b_decimal128;
314 struct b_minkey _b_minkey;
315 struct b_maxkey _b_maxkey;
316 };
317};
318
326
328template <typename T>
329detail::requires_t<bool, detail::is_bson_view_compatible<T>> //
330operator==(const bson_value::view& lhs, T&& rhs) {
331 return lhs == bson_value::view{std::forward<T>(rhs)};
332}
333
335template <typename T>
336detail::requires_t<bool, detail::is_bson_view_compatible<T>> //
337operator==(T&& lhs, const bson_value::view& rhs) {
338 return bson_value::view{std::forward<T>(lhs)} == rhs;
339}
340
342template <typename T>
343detail::requires_t<bool, detail::is_bson_view_compatible<T>> //
344operator!=(const bson_value::view& lhs, T&& rhs) {
345 return lhs != bson_value::view{std::forward<T>(rhs)};
346}
347
349template <typename T>
350detail::requires_t<bool, detail::is_bson_view_compatible<T>> //
351operator!=(T&& lhs, const bson_value::view& rhs) {
352 return bson_value::view{std::forward<T>(lhs)} != rhs;
353}
354
357
358} // namespace bson_value
359} // namespace types
360} // namespace v_noabi
361} // namespace bsoncxx
362
363namespace bsoncxx {
364namespace types {
365namespace bson_value {
366
367using ::bsoncxx::v_noabi::types::bson_value::operator==;
368using ::bsoncxx::v_noabi::types::bson_value::operator!=;
369
370} // namespace bson_value
371} // namespace types
372} // namespace bsoncxx
373
375
380
381#if defined(BSONCXX_PRIVATE_DOXYGEN_PREPROCESSOR)
382
383namespace bsoncxx {
384namespace types {
385namespace bson_value {
386
388template <typename T>
390
392template <typename T>
394
396template <typename T>
398
400template <typename T>
402
403} // namespace bson_value
404} // namespace types
405} // namespace bsoncxx
406
407#endif // defined(BSONCXX_PRIVATE_DOXYGEN_PREPROCESSOR)
The bsoncxx macro guard postlude header.
The bsoncxx macro guard prelude header.
A variant owning type that represents any BSON type. Owns its underlying buffer. When a bson_value::v...
Definition value.hpp:47
A view-only variant that can contain any BSON type.
Definition view.hpp:54
detail::requires_t< bool, detail::is_bson_view_compatible< T > > operator!=(T &&lhs, const bson_value::view &rhs)
Compares a view with a type representable as a view.
Definition view.hpp:351
const b_dbpointer & get_dbpointer() const
Returns the underlying BSON DBPointer value.
detail::requires_t< bool, detail::is_bson_view_compatible< T > > operator==(T &&lhs, const bson_value::view &rhs)
Compares a view with a type representable as a view.
Definition view.hpp:337
const b_document & get_document() const
Returns the underlying BSON document value.
const b_null & get_null() const
Returns the underlying BSON null value.
const b_symbol & get_symbol() const
Returns the underlying BSON symbol value.
const b_decimal128 & get_decimal128() const
Returns the underlying BSON Decimal128 value.
const b_oid & get_oid() const
Returns the underlying BSON ObjectId value.
const b_binary & get_binary() const
Returns the underlying BSON binary data value.
const b_code & get_code() const
Returns the underlying BSON JavaScript code value.
const b_date & get_date() const
Returns the underlying BSON date value.
const b_bool & get_bool() const
Returns the underlying BSON boolean value.
const b_minkey & get_minkey() const
Returns the underlying BSON min-key value.
detail::requires_t< bool, detail::is_bson_view_compatible< T > > operator==(const bson_value::view &lhs, T &&rhs)
Compares a view with a type representable as a view.
Definition view.hpp:330
const b_double & get_double() const
Returns the underlying BSON double value.
const b_array & get_array() const
Returns the underlying BSON array value.
const b_int32 & get_int32() const
Returns the underlying BSON 32-bit signed integer value.
const b_codewscope & get_codewscope() const
Returns the underlying BSON JavaScript code with scope value.
detail::requires_t< bool, detail::is_bson_view_compatible< T > > operator!=(const bson_value::view &lhs, T &&rhs)
Compares a view with a type representable as a view.
Definition view.hpp:344
const b_maxkey & get_maxkey() const
Returns the underlying BSON max-key value.
const b_undefined & get_undefined() const
Returns the underlying BSON undefined value.
const b_timestamp & get_timestamp() const
Returns the underlying BSON replication timestamp value.
const b_regex & get_regex() const
Returns the underlying BSON regex value.
const b_int64 & get_int64() const
Returns the underlying BSON 64-bit signed integer value.
const b_string & get_string() const
Returns the underlying BSON UTF-8 string value.
Declares bsoncxx::v_noabi::document::element.
#define BSONCXX_ABI_EXPORT_CDECL(...)
Equivalent to BSONCXX_ABI_EXPORT with BSONCXX_ABI_CDECL.
Definition fwd.hpp:177
bool operator==(const v_noabi::types::bson_value::value &lhs, const v_noabi::types::bson_value::value &rhs)
bsoncxx::v_noabi::types::bson_value::operator==(const v_noabi::types::bson_value::value& lhs,...
bool operator!=(const v_noabi::types::bson_value::value &lhs, const v_noabi::types::bson_value::value &rhs)
bsoncxx::v_noabi::types::bson_value::operator!=(const v_noabi::types::bson_value::value& lhs,...
type
An enumeration of each BSON type.
Definition types.hpp:43
The top-level namespace within which all bsoncxx library entities are declared.
The top-level namespace reserved for the C++ standard library.
A BSON array value.
Definition types.hpp:201
A BSON binary data value.
Definition types.hpp:226
A BSON boolean value.
Definition types.hpp:283
A BSON JavaScript code value.
Definition types.hpp:436
A BSON JavaScript code with scope value.
Definition types.hpp:506
A BSON date value.
Definition types.hpp:308
A BSON DBPointer (aka DBRef) value.
Definition types.hpp:417
A BSON Decimal128 value.
Definition types.hpp:609
A BSON document value.
Definition types.hpp:169
A BSON double value.
Definition types.hpp:110
A BSON signed 32-bit integer value.
Definition types.hpp:540
A BSON 64-bit signed integer value.
Definition types.hpp:584
A BSON max-key value.
Definition types.hpp:652
A BSON min-key value.
Definition types.hpp:636
A BSON null value.
Definition types.hpp:365
A BSON ObjectId value.
Definition types.hpp:265
A BSON regex value.
Definition types.hpp:381
A BSON UTF-8 encoded string value.
Definition types.hpp:135
A BSON Symbol value.
Definition types.hpp:472
A BSON replication timestamp value.
Definition types.hpp:565
A BSON undefined value.
Definition types.hpp:249
Provides <type_traits>-related polyfills for internal use.
Declares bsoncxx::v_noabi::types::bson_value::value.
Declares bsoncxx::v_noabi::types::bson_value::view.
Provides entities used to represent BSON types.