MongoDB C++ Driver mongocxx-3.11.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 v_noabi {
32namespace types {
33namespace bson_value {
41class view {
42 public:
47 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_double v) noexcept;
48 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_string v) noexcept;
50 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_array v) noexcept;
51 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_binary v) noexcept;
53 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_oid v) noexcept;
54 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_bool v) noexcept;
55 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_date v) noexcept;
56 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_null v) noexcept;
57 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_regex v) noexcept;
59 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_code v) noexcept;
60 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_symbol v) noexcept;
62 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_int32 v) noexcept;
64 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_int64 v) noexcept;
66 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_maxkey v) noexcept;
67 explicit BSONCXX_ABI_EXPORT_CDECL() view(b_minkey v) noexcept;
70
76
77 BSONCXX_ABI_EXPORT_CDECL() view(const view&) noexcept;
78 BSONCXX_ABI_EXPORT_CDECL(view&) operator=(const view&) noexcept;
79
81
88 friend BSONCXX_ABI_EXPORT_CDECL(bool) operator==(const bson_value::view&,
89 const bson_value::view&);
90 friend BSONCXX_ABI_EXPORT_CDECL(bool) operator!=(const bson_value::view&,
91 const bson_value::view&);
94
99
107
117
125
133
141
149
157
165
173
181
189
197
205
213
221
229
237
245
253
261
269
277
278 private:
279 friend ::bsoncxx::v_noabi::types::bson_value::value;
280 friend ::bsoncxx::v_noabi::document::element;
281
282 view(const std::uint8_t* raw, std::uint32_t length, std::uint32_t offset, std::uint32_t keylen);
283 view(void* internal_value) noexcept;
284
285 void _init(void* internal_value) noexcept;
286
287 void destroy() noexcept;
288
289 bsoncxx::v_noabi::type _type;
290
291 union {
292 struct b_double _b_double;
293 struct b_string _b_string;
294 struct b_document _b_document;
295 struct b_array _b_array;
296 struct b_binary _b_binary;
297 struct b_undefined _b_undefined;
298 struct b_oid _b_oid;
299 struct b_bool _b_bool;
300 struct b_date _b_date;
301 struct b_null _b_null;
302 struct b_regex _b_regex;
303 struct b_dbpointer _b_dbpointer;
304 struct b_code _b_code;
305 struct b_symbol _b_symbol;
306 struct b_codewscope _b_codewscope;
307 struct b_int32 _b_int32;
308 struct b_timestamp _b_timestamp;
309 struct b_int64 _b_int64;
310 struct b_decimal128 _b_decimal128;
311 struct b_minkey _b_minkey;
312 struct b_maxkey _b_maxkey;
313 };
314};
315
316template <typename T>
317using is_bson_view_compatible = detail::conjunction<
318 std::is_constructible<bson_value::view, T>,
319 detail::negation<detail::disjunction<detail::is_alike<T, bson_value::view>,
320 detail::is_alike<T, bson_value::value>>>>;
321
322template <typename T>
323using not_view = is_bson_view_compatible<T>;
324
332
334template <typename T>
335detail::requires_t<bool, is_bson_view_compatible<T>> //
336operator==(const bson_value::view& lhs, T&& rhs) {
337 return lhs == bson_value::view{std::forward<T>(rhs)};
338}
339
341template <typename T>
342detail::requires_t<bool, is_bson_view_compatible<T>> //
343operator==(T&& lhs, const bson_value::view& rhs) {
344 return bson_value::view{std::forward<T>(lhs)} == rhs;
345}
346
348template <typename T>
349detail::requires_t<bool, is_bson_view_compatible<T>> //
350operator!=(const bson_value::view& lhs, T&& rhs) {
351 return lhs != bson_value::view{std::forward<T>(rhs)};
352}
353
355template <typename T>
356detail::requires_t<bool, is_bson_view_compatible<T>> //
357operator!=(T&& lhs, const bson_value::view& rhs) {
358 return bson_value::view{std::forward<T>(lhs)} != rhs;
359}
360
363
364} // namespace bson_value
365} // namespace types
366} // namespace v_noabi
367} // namespace bsoncxx
368
369namespace bsoncxx {
370namespace types {
371namespace bson_value {
372
373using ::bsoncxx::v_noabi::types::bson_value::operator==;
374using ::bsoncxx::v_noabi::types::bson_value::operator!=;
375
376} // namespace bson_value
377} // namespace types
378} // namespace bsoncxx
379
381
386
387#if defined(BSONCXX_PRIVATE_DOXYGEN_PREPROCESSOR)
388
389namespace bsoncxx {
390namespace types {
391namespace bson_value {
392
394template <typename T>
396
398template <typename T>
400
402template <typename T>
404
406template <typename T>
408
409} // namespace bson_value
410} // namespace types
411} // namespace bsoncxx
412
413#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:48
A view-only variant that can contain any BSON type.
Definition view.hpp:41
const b_dbpointer & get_dbpointer() const
Returns the underlying BSON DBPointer value.
const b_document & get_document() const
Returns the underlying BSON document value.
detail::requires_t< bool, 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:336
detail::requires_t< bool, 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:350
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.
BSONCXX_DEPRECATED const b_string & get_utf8() const
Returns the underlying BSON UTF-8 string 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.
const b_double & get_double() const
Returns the underlying BSON double value.
detail::requires_t< bool, 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:343
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.
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.
detail::requires_t< bool, 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:357
const b_string & get_string() const
Returns the underlying BSON UTF-8 string value.
Declares bsoncxx::v_noabi::document::element.
#define BSONCXX_DEPRECATED
Declares the associated entity as deprecated.
Definition fwd.hpp:261
#define BSONCXX_ABI_EXPORT_CDECL(...)
Equivalent to BSONCXX_ABI_EXPORT with BSONCXX_ABI_CDECL.
Definition fwd.hpp:225
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:209
A BSON binary data value.
Definition types.hpp:234
A BSON boolean value.
Definition types.hpp:291
A BSON JavaScript code value.
Definition types.hpp:444
A BSON JavaScript code with scope value.
Definition types.hpp:514
A BSON date value.
Definition types.hpp:316
A BSON DBPointer (aka DBRef) value.
Definition types.hpp:425
A BSON Decimal128 value.
Definition types.hpp:617
A BSON document value.
Definition types.hpp:177
A BSON double value.
Definition types.hpp:111
A BSON signed 32-bit integer value.
Definition types.hpp:548
A BSON 64-bit signed integer value.
Definition types.hpp:592
A BSON max-key value.
Definition types.hpp:660
A BSON min-key value.
Definition types.hpp:644
A BSON null value.
Definition types.hpp:373
A BSON ObjectId value.
Definition types.hpp:273
A BSON regex value.
Definition types.hpp:389
A BSON UTF-8 encoded string value.
Definition types.hpp:136
A BSON Symbol value.
Definition types.hpp:480
A BSON replication timestamp value.
Definition types.hpp:573
A BSON undefined value.
Definition types.hpp:257
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.