MongoDB C++ Driver mongocxx-3.0.3
Loading...
Searching...
No Matches
value.hpp
1// Copyright 2014 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/types.hpp>
22
23#include <bsoncxx/config/prelude.hpp>
24
25namespace bsoncxx {
26BSONCXX_INLINE_NAMESPACE_BEGIN
27
28namespace types {
29
37class BSONCXX_API value {
38 public:
42 explicit value(b_double) noexcept;
43
47 explicit value(b_utf8) noexcept;
48
52 explicit value(b_document) noexcept;
53
57 explicit value(b_array) noexcept;
58
62 explicit value(b_binary) noexcept;
63
67 explicit value(b_undefined) noexcept;
68
72 explicit value(b_oid) noexcept;
73
77 explicit value(b_bool) noexcept;
78
82 explicit value(b_date) noexcept;
83
87 explicit value(b_null) noexcept;
88
92 explicit value(b_regex) noexcept;
93
97 explicit value(b_dbpointer) noexcept;
98
102 explicit value(b_code) noexcept;
103
107 explicit value(b_symbol) noexcept;
108
112 explicit value(b_codewscope) noexcept;
113
117 explicit value(b_int32) noexcept;
118
122 explicit value(b_timestamp) noexcept;
123
127 explicit value(b_int64) noexcept;
128
132 explicit value(b_minkey) noexcept;
133
137 explicit value(b_maxkey) noexcept;
138
139 value(const value&) noexcept;
140 value& operator=(const value&) noexcept;
141
142 ~value();
143
151 friend BSONCXX_API bool BSONCXX_CALL operator==(const value&, const value&);
152 friend BSONCXX_API bool BSONCXX_CALL operator!=(const value&, const value&);
156
160 bsoncxx::type type() const;
161
169 const b_double& get_double() const;
170
178 const b_utf8& get_utf8() const;
179
187 const b_document& get_document() const;
188
196 const b_array& get_array() const;
197
205 const b_binary& get_binary() const;
206
215
223 const b_oid& get_oid() const;
224
232 const b_bool& get_bool() const;
233
241 const b_date& get_date() const;
242
250 const b_null& get_null() const;
251
259 const b_regex& get_regex() const;
260
269
277 const b_code& get_code() const;
278
286 const b_symbol& get_symbol() const;
287
296
304 const b_int32& get_int32() const;
305
314
322 const b_int64& get_int64() const;
323
331 const b_minkey& get_minkey() const;
332
340 const b_maxkey& get_maxkey() const;
341
342 private:
343 void BSONCXX_PRIVATE destroy() noexcept;
344
345 bsoncxx::type _type;
346 union {
347 struct b_double _b_double;
348 struct b_utf8 _b_utf8;
349 struct b_document _b_document;
350 struct b_array _b_array;
351 struct b_binary _b_binary;
352 struct b_undefined _b_undefined;
353 struct b_oid _b_oid;
354 struct b_bool _b_bool;
355 struct b_date _b_date;
356 struct b_null _b_null;
357 struct b_regex _b_regex;
358 struct b_dbpointer _b_dbpointer;
359 struct b_code _b_code;
360 struct b_symbol _b_symbol;
361 struct b_codewscope _b_codewscope;
362 struct b_int32 _b_int32;
363 struct b_timestamp _b_timestamp;
364 struct b_int64 _b_int64;
365 struct b_minkey _b_minkey;
366 struct b_maxkey _b_maxkey;
367 };
368};
369
370// sfinae in the bool return to avoid competing with the value == value
371// operators
372template <typename T>
373using not_value =
374 typename std::enable_if<!std::is_same<typename std::remove_reference<T>::type, value>::value,
375 bool>::type;
376
377// these all return bool
378template <typename T>
379BSONCXX_INLINE not_value<T> operator==(const value& lhs, T&& rhs) {
380 return lhs == value{std::forward<T>(rhs)};
381}
382
383template <typename T>
384BSONCXX_INLINE not_value<T> operator==(T&& lhs, const value& rhs) {
385 return value{std::forward<T>(lhs)} == rhs;
386}
387
388template <typename T>
389BSONCXX_INLINE not_value<T> operator!=(const value& lhs, T&& rhs) {
390 return lhs != value{std::forward<T>(rhs)};
391}
392
393template <typename T>
394BSONCXX_INLINE not_value<T> operator!=(T&& lhs, const value& rhs) {
395 return value{std::forward<T>(lhs)} != rhs;
396}
397
398} // namespace types
399
400BSONCXX_INLINE_NAMESPACE_END
401} // namespace bsoncxx
402
403#include <bsoncxx/config/postlude.hpp>
A variant that can contain any BSON type.
Definition value.hpp:37
friend bool operator==(const value &, const value &)
Compare two values for equality.
const b_minkey & get_minkey() const
value(b_symbol) noexcept
Construct a value from a BSON symbol.
const b_double & get_double() const
const b_timestamp & get_timestamp() const
bsoncxx::type type() const
value(b_timestamp) noexcept
Construct a value from a BSON replication timestamp.
const b_bool & get_bool() const
value(b_utf8) noexcept
Construct a value from a BSON UTF-8 string.
value(b_double) noexcept
Construct a value from a BSON double.
const b_oid & get_oid() const
const b_dbpointer & get_dbpointer() const
value(b_codewscope) noexcept
Construct a value from a BSON JavaScript code with scope.
const b_int32 & get_int32() const
value(b_oid) noexcept
Construct a value from a BSON ObjectId.
const b_null & get_null() const
const b_maxkey & get_maxkey() const
value(b_document) noexcept
Construct a value from a BSON document.
value(b_binary) noexcept
Construct a value from a BSON binary datum.
value(b_dbpointer) noexcept
Construct a value from a BSON DBPointer.
value(b_undefined) noexcept
Construct a value from a BSON undefined.
const b_int64 & get_int64() const
const b_binary & get_binary() const
const b_document & get_document() const
value(b_array) noexcept
Construct a value from a BSON array.
value(b_maxkey) noexcept
Construct a value from a BSON max-key.
value(b_int32) noexcept
Construct a value from a BSON 32-bit signed integer.
const b_symbol & get_symbol() const
const b_regex & get_regex() const
value(b_date) noexcept
Construct a value from a BSON date.
value(b_null) noexcept
Construct a value from a BSON null.
const b_code & get_code() const
value(b_regex) noexcept
Construct a value from a BSON regex.
const b_date & get_date() const
const b_utf8 & get_utf8() const
const b_codewscope & get_codewscope() const
const b_undefined & get_undefined() const
value(b_bool) noexcept
Construct a value from a BSON boolean.
const b_array & get_array() const
value(b_int64) noexcept
Construct a value from a BSON 64-bit signed integer.
value(b_code) noexcept
Construct a value from a BSON JavaScript code.
friend bool operator!=(const value &, const value &)
Compare two values for equality.
value(b_minkey) noexcept
Construct a value from a BSON min-key.
A BSON array value.
Definition types.hpp:179
A BSON binary data value.
Definition types.hpp:204
A BSON boolean value.
Definition types.hpp:262
A BSON JavaScript code value.
Definition types.hpp:419
A BSON JavaScript code with scope value.
Definition types.hpp:498
A BSON date value.
Definition types.hpp:287
A BSON DBPointer value.
Definition types.hpp:400
A BSON document value.
Definition types.hpp:147
A BSON double value.
Definition types.hpp:84
A BSON signed 32-bit integer value.
Definition types.hpp:531
A BSON 64-bit signed integer value.
Definition types.hpp:579
A BSON max-key value.
Definition types.hpp:620
A BSON min-key value.
Definition types.hpp:604
A BSON null value.
Definition types.hpp:348
A BSON ObjectId value.
Definition types.hpp:244
A BSON regex value.
Definition types.hpp:364
A BSON Symbol value.
Definition types.hpp:460
A BSON replication timestamp value.
Definition types.hpp:560
A BSON undefined value.
Definition types.hpp:228
A BSON UTF-8 encoded string value.
Definition types.hpp:109