MongoDB C++ Driver 4.1.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 = detail::conjunction<
35 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 {
47
55class view {
56 public:
61 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_double v) noexcept;
62 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_string v) noexcept;
64 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_array v) noexcept;
65 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_binary v) noexcept;
67 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_oid v) noexcept;
68 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_bool v) noexcept;
69 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_date v) noexcept;
70 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_null v) noexcept;
71 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_regex v) noexcept;
73 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_code v) noexcept;
74 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_symbol v) noexcept;
76 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_int32 v) noexcept;
78 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_int64 v) noexcept;
80 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_maxkey v) noexcept;
81 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_minkey v) noexcept;
84
90
91 BSONCXX_ABI_EXPORT_CDECL() view(view const&) noexcept;
92 BSONCXX_ABI_EXPORT_CDECL(view&) operator=(view const&) noexcept;
93
95
102 friend BSONCXX_ABI_EXPORT_CDECL(bool) operator==(bson_value::view const&, bson_value::view const&);
103 friend BSONCXX_ABI_EXPORT_CDECL(bool) operator!=(bson_value::view const&, bson_value::view const&);
106
111
119
127
135
143
151
159
167
175
183
191
199
207
215
223
231
239
247
255
263
271
279
280 private:
281 friend ::bsoncxx::v_noabi::types::bson_value::value;
282 friend ::bsoncxx::v_noabi::document::element;
283
284 view(std::uint8_t const* raw, std::uint32_t length, std::uint32_t offset, std::uint32_t keylen);
285 view(void* internal_value) noexcept;
286
287 void _init(void* internal_value) noexcept;
288
289 void destroy() noexcept;
290
291 bsoncxx::v_noabi::type _type;
292
293 union {
294 struct b_double _b_double;
295 struct b_string _b_string;
296 struct b_document _b_document;
297 struct b_array _b_array;
298 struct b_binary _b_binary;
299 struct b_undefined _b_undefined;
300 struct b_oid _b_oid;
301 struct b_bool _b_bool;
302 struct b_date _b_date;
303 struct b_null _b_null;
304 struct b_regex _b_regex;
305 struct b_dbpointer _b_dbpointer;
306 struct b_code _b_code;
307 struct b_symbol _b_symbol;
308 struct b_codewscope _b_codewscope;
309 struct b_int32 _b_int32;
310 struct b_timestamp _b_timestamp;
311 struct b_int64 _b_int64;
312 struct b_decimal128 _b_decimal128;
313 struct b_minkey _b_minkey;
314 struct b_maxkey _b_maxkey;
315 };
316};
317
325
327template <typename T>
328detail::requires_t<bool, detail::is_bson_view_compatible<T>> operator==(bson_value::view const& lhs, T&& rhs) {
329 return lhs == bson_value::view{std::forward<T>(rhs)};
330}
331
333template <typename T>
334detail::requires_t<bool, detail::is_bson_view_compatible<T>> operator==(T&& lhs, bson_value::view const& rhs) {
335 return bson_value::view{std::forward<T>(lhs)} == rhs;
336}
337
339template <typename T>
340detail::requires_t<bool, detail::is_bson_view_compatible<T>> operator!=(bson_value::view const& lhs, T&& rhs) {
341 return lhs != bson_value::view{std::forward<T>(rhs)};
342}
343
345template <typename T>
346detail::requires_t<bool, detail::is_bson_view_compatible<T>> operator!=(T&& lhs, bson_value::view const& rhs) {
347 return bson_value::view{std::forward<T>(lhs)} != rhs;
348}
349
352
353} // namespace bson_value
354} // namespace types
355} // namespace v_noabi
356} // namespace bsoncxx
357
358namespace bsoncxx {
359namespace types {
360namespace bson_value {
361
362using ::bsoncxx::v_noabi::types::bson_value::operator==;
363using ::bsoncxx::v_noabi::types::bson_value::operator!=;
364
365} // namespace bson_value
366} // namespace types
367} // namespace bsoncxx
368
370
#define BSONCXX_ABI_EXPORT_CDECL(...)
Equivalent to BSONCXX_ABI_EXPORT with BSONCXX_ABI_CDECL.
Definition export.hpp:52
The bsoncxx v_noabi macro guard postlude header.
The bsoncxx v_noabi macro guard prelude header.
view(b_double v) noexcept
Construct a bson_value::view from the provided BSON type.
An owning variant type that represents any BSON type.
Definition value.hpp:48
A non-owning variant that can contain any BSON type.
Definition view.hpp:55
b_dbpointer const & get_dbpointer() const
Returns the underlying BSON DBPointer value.
b_null const & get_null() const
Returns the underlying BSON null value.
b_date const & get_date() const
Returns the underlying BSON date value.
b_maxkey const & get_maxkey() const
Returns the underlying BSON max-key value.
detail::requires_t< bool, detail::is_bson_view_compatible< T > > operator==(bson_value::view const &lhs, T &&rhs)
Compares a view with a type representable as a view.
Definition view.hpp:328
b_double const & get_double() const
Returns the underlying BSON double value.
b_string const & get_string() const
Returns the underlying BSON UTF-8 string value.
b_int32 const & get_int32() const
Returns the underlying BSON 32-bit signed integer value.
b_code const & get_code() const
Returns the underlying BSON JavaScript code value.
b_array const & get_array() const
Returns the underlying BSON array value.
b_int64 const & get_int64() const
Returns the underlying BSON 64-bit signed integer value.
detail::requires_t< bool, detail::is_bson_view_compatible< T > > operator!=(T &&lhs, bson_value::view const &rhs)
Compares a view with a type representable as a view.
Definition view.hpp:346
b_codewscope const & get_codewscope() const
Returns the underlying BSON JavaScript code with scope value.
bsoncxx::v_noabi::type type() const
Returns the type of the underlying BSON value stored in this object.
b_symbol const & get_symbol() const
Returns the underlying BSON symbol value.
b_document const & get_document() const
Returns the underlying BSON document value.
b_bool const & get_bool() const
Returns the underlying BSON boolean value.
view(b_double v) noexcept
Construct a bson_value::view from the provided BSON type.
detail::requires_t< bool, detail::is_bson_view_compatible< T > > operator==(T &&lhs, bson_value::view const &rhs)
Compares a view with a type representable as a view.
Definition view.hpp:334
b_decimal128 const & get_decimal128() const
Returns the underlying BSON Decimal128 value.
b_undefined const & get_undefined() const
Returns the underlying BSON undefined value.
b_oid const & get_oid() const
Returns the underlying BSON ObjectId value.
b_minkey const & get_minkey() const
Returns the underlying BSON min-key value.
b_timestamp const & get_timestamp() const
Returns the underlying BSON replication timestamp value.
detail::requires_t< bool, detail::is_bson_view_compatible< T > > operator!=(bson_value::view const &lhs, T &&rhs)
Compares a view with a type representable as a view.
Definition view.hpp:340
b_regex const & get_regex() const
Returns the underlying BSON regex value.
b_binary const & get_binary() const
Returns the underlying BSON binary data value.
Declares bsoncxx::v_noabi::document::element.
Declares entities representing a BSON document.
Declares entities representing any BSON value type.
Declares entities representing BSON value types.
Declares entities whose ABI stability is NOT guaranteed.
The top-level namespace within which all bsoncxx library entities are declared.
A BSON array value.
Definition types.hpp:202
A BSON binary data value.
Definition types.hpp:227
A BSON boolean value.
Definition types.hpp:284
A BSON JavaScript code value.
Definition types.hpp:434
A BSON JavaScript code with scope value.
Definition types.hpp:504
A BSON date value.
Definition types.hpp:309
A BSON DBPointer (aka DBRef) value.
Definition types.hpp:415
A BSON Decimal128 value.
Definition types.hpp:604
A BSON document value.
Definition types.hpp:170
A BSON double value.
Definition types.hpp:111
A BSON signed 32-bit integer value.
Definition types.hpp:535
A BSON 64-bit signed integer value.
Definition types.hpp:579
A BSON max-key value.
Definition types.hpp:647
A BSON min-key value.
Definition types.hpp:631
A BSON null value.
Definition types.hpp:366
A BSON ObjectId value.
Definition types.hpp:266
A BSON regex value.
Definition types.hpp:382
A BSON UTF-8 encoded string value.
Definition types.hpp:136
A BSON Symbol value.
Definition types.hpp:470
A BSON replication timestamp value.
Definition types.hpp:560
A BSON undefined value.
Definition types.hpp:250
Declares bsoncxx::v_noabi::types::bson_value::value.
Declares bsoncxx::v_noabi::types::bson_value::view.
Provides entities used to represent BSON types.
For internal use only!