MongoDB C++ Driver mongocxx-3.10.1
Loading...
Searching...
No Matches
view.hpp
1// Copyright 2020 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
21#include <bsoncxx/document/element-fwd.hpp>
22#include <bsoncxx/types/bson_value/value-fwd.hpp>
23#include <bsoncxx/types/bson_value/view-fwd.hpp>
24
25#include <bsoncxx/stdx/type_traits.hpp>
26#include <bsoncxx/types.hpp>
27
28#include <bsoncxx/config/prelude.hpp>
29
30namespace bsoncxx {
31namespace v_noabi {
32namespace types {
33namespace bson_value {
41class view {
42 public:
57#define BSONCXX_ENUM(type, val) explicit view(b_##type) noexcept;
58#include <bsoncxx/enums/type.hpp>
59#undef BSONCXX_ENUM
60
65 view() noexcept;
66
67 view(const view&) noexcept;
68 view& operator=(const view&) noexcept;
69
70 ~view();
71
79 friend BSONCXX_API bool BSONCXX_CALL operator==(const bson_value::view&,
80 const bson_value::view&);
81 friend BSONCXX_API bool BSONCXX_CALL operator!=(const bson_value::view&,
82 const bson_value::view&);
86
90 bsoncxx::v_noabi::type type() const;
91
98 const b_double& get_double() const;
99
108 BSONCXX_DEPRECATED const b_string& get_utf8() const;
109
116 const b_string& get_string() const;
117
124 const b_document& get_document() const;
125
132 const b_array& get_array() const;
133
140 const b_binary& get_binary() const;
141
149
156 const b_oid& get_oid() const;
157
164 const b_bool& get_bool() const;
165
172 const b_date& get_date() const;
173
180 const b_null& get_null() const;
181
188 const b_regex& get_regex() const;
189
197
204 const b_code& get_code() const;
205
212 const b_symbol& get_symbol() const;
213
221
228 const b_int32& get_int32() const;
229
237
244 const b_int64& get_int64() const;
245
253
260 const b_minkey& get_minkey() const;
261
268 const b_maxkey& get_maxkey() const;
269
270 private:
271 friend ::bsoncxx::v_noabi::types::bson_value::value;
272 friend ::bsoncxx::v_noabi::document::element;
273
274 view(const std::uint8_t* raw, std::uint32_t length, std::uint32_t offset, std::uint32_t keylen);
275 view(void* internal_value) noexcept;
276
277 void _init(void* internal_value) noexcept;
278
279 void BSONCXX_PRIVATE destroy() noexcept;
280
281 bsoncxx::v_noabi::type _type;
282
283 union {
284 struct b_double _b_double;
285 struct b_string _b_string;
286 struct b_document _b_document;
287 struct b_array _b_array;
288 struct b_binary _b_binary;
289 struct b_undefined _b_undefined;
290 struct b_oid _b_oid;
291 struct b_bool _b_bool;
292 struct b_date _b_date;
293 struct b_null _b_null;
294 struct b_regex _b_regex;
295 struct b_dbpointer _b_dbpointer;
296 struct b_code _b_code;
297 struct b_symbol _b_symbol;
298 struct b_codewscope _b_codewscope;
299 struct b_int32 _b_int32;
300 struct b_timestamp _b_timestamp;
301 struct b_int64 _b_int64;
302 struct b_decimal128 _b_decimal128;
303 struct b_minkey _b_minkey;
304 struct b_maxkey _b_maxkey;
305 };
306};
307
308template <typename T>
309using is_bson_view_compatible = detail::conjunction<
310 std::is_constructible<bson_value::view, T>,
311 detail::negation<detail::disjunction<detail::is_alike<T, bson_value::view>,
312 detail::is_alike<T, bson_value::value>>>>;
313
314template <typename T>
315using not_view = is_bson_view_compatible<T>;
316
317template <typename T>
318BSONCXX_INLINE detail::requires_t<bool, is_bson_view_compatible<T>> //
319operator==(const bson_value::view& lhs, T&& rhs) {
320 return lhs == bson_value::view{std::forward<T>(rhs)};
321}
322
323template <typename T>
324BSONCXX_INLINE detail::requires_t<bool, is_bson_view_compatible<T>> //
325operator==(T&& lhs, const bson_value::view& rhs) {
326 return bson_value::view{std::forward<T>(lhs)} == rhs;
327}
328
329template <typename T>
330BSONCXX_INLINE detail::requires_t<bool, is_bson_view_compatible<T>> //
331operator!=(const bson_value::view& lhs, T&& rhs) {
332 return lhs != bson_value::view{std::forward<T>(rhs)};
333}
334
335template <typename T>
336BSONCXX_INLINE detail::requires_t<bool, 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
341} // namespace bson_value
342} // namespace types
343} // namespace v_noabi
344} // namespace bsoncxx
345
346namespace bsoncxx {
347namespace types {
348namespace bson_value {
349
350using ::bsoncxx::v_noabi::types::bson_value::operator==;
351using ::bsoncxx::v_noabi::types::bson_value::operator!=;
352
353} // namespace bson_value
354} // namespace types
355} // namespace bsoncxx
356
357#include <bsoncxx/config/postlude.hpp>
A variant owning type that represents any BSON type.
Definition value.hpp:46
A view-only variant that can contain any BSON type.
Definition view.hpp:41
const b_dbpointer & get_dbpointer() const
const b_document & get_document() const
const b_decimal128 & get_decimal128() const
view() noexcept
Default constructs a bson_value::view.
const b_codewscope & get_codewscope() const
const b_undefined & get_undefined() const
const b_timestamp & get_timestamp() const
type
An enumeration of each BSON type.
Definition types.hpp:48
The top-level namespace for bsoncxx library entities.
Definition element-fwd.hpp:19
A BSON array value.
Definition types.hpp:197
A BSON binary data value.
Definition types.hpp:222
A BSON boolean value.
Definition types.hpp:280
A BSON JavaScript code value.
Definition types.hpp:436
A BSON JavaScript code with scope value.
Definition types.hpp:507
A BSON date value.
Definition types.hpp:305
A BSON DBPointer value.
Definition types.hpp:417
A BSON Decimal128 value.
Definition types.hpp:610
A BSON document value.
Definition types.hpp:165
A BSON double value.
Definition types.hpp:99
A BSON signed 32-bit integer value.
Definition types.hpp:541
A BSON 64-bit signed integer value.
Definition types.hpp:585
A BSON max-key value.
Definition types.hpp:653
A BSON min-key value.
Definition types.hpp:637
A BSON null value.
Definition types.hpp:364
A BSON ObjectId value.
Definition types.hpp:262
A BSON regex value.
Definition types.hpp:380
A BSON UTF-8 encoded string value.
Definition types.hpp:124
A BSON Symbol value.
Definition types.hpp:473
A BSON replication timestamp value.
Definition types.hpp:566
A BSON undefined value.
Definition types.hpp:246