MongoDB C++ Driver mongocxx-3.1.1
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_decimal128) noexcept;
133
137 explicit value(b_minkey) noexcept;
138
142 explicit value(b_maxkey) noexcept;
143
144 value(const value&) noexcept;
145 value& operator=(const value&) noexcept;
146
147 ~value();
148
156 friend BSONCXX_API bool BSONCXX_CALL operator==(const value&, const value&);
157 friend BSONCXX_API bool BSONCXX_CALL operator!=(const value&, const value&);
161
166
174 const b_double& get_double() const;
175
183 const b_utf8& get_utf8() const;
184
192 const b_document& get_document() const;
193
201 const b_array& get_array() const;
202
210 const b_binary& get_binary() const;
211
220
228 const b_oid& get_oid() const;
229
237 const b_bool& get_bool() const;
238
246 const b_date& get_date() const;
247
255 const b_null& get_null() const;
256
264 const b_regex& get_regex() const;
265
274
282 const b_code& get_code() const;
283
291 const b_symbol& get_symbol() const;
292
301
309 const b_int32& get_int32() const;
310
319
327 const b_int64& get_int64() const;
328
337
345 const b_minkey& get_minkey() const;
346
354 const b_maxkey& get_maxkey() const;
355
356 private:
357 void BSONCXX_PRIVATE destroy() noexcept;
358
359 bsoncxx::type _type;
360 union {
361 struct b_double _b_double;
362 struct b_utf8 _b_utf8;
363 struct b_document _b_document;
364 struct b_array _b_array;
365 struct b_binary _b_binary;
366 struct b_undefined _b_undefined;
367 struct b_oid _b_oid;
368 struct b_bool _b_bool;
369 struct b_date _b_date;
370 struct b_null _b_null;
371 struct b_regex _b_regex;
372 struct b_dbpointer _b_dbpointer;
373 struct b_code _b_code;
374 struct b_symbol _b_symbol;
375 struct b_codewscope _b_codewscope;
376 struct b_int32 _b_int32;
377 struct b_timestamp _b_timestamp;
378 struct b_int64 _b_int64;
379 struct b_decimal128 _b_decimal128;
380 struct b_minkey _b_minkey;
381 struct b_maxkey _b_maxkey;
382 };
383};
384
385// sfinae in the bool return to avoid competing with the value == value
386// operators
387template <typename T>
388using not_value =
389 typename std::enable_if<!std::is_same<typename std::remove_reference<T>::type, value>::value,
390 bool>::type;
391
392// these all return bool
393template <typename T>
394BSONCXX_INLINE not_value<T> operator==(const value& lhs, T&& rhs) {
395 return lhs == value{std::forward<T>(rhs)};
396}
397
398template <typename T>
399BSONCXX_INLINE not_value<T> operator==(T&& lhs, const value& rhs) {
400 return value{std::forward<T>(lhs)} == rhs;
401}
402
403template <typename T>
404BSONCXX_INLINE not_value<T> operator!=(const value& lhs, T&& rhs) {
405 return lhs != value{std::forward<T>(rhs)};
406}
407
408template <typename T>
409BSONCXX_INLINE not_value<T> operator!=(T&& lhs, const value& rhs) {
410 return value{std::forward<T>(lhs)} != rhs;
411}
412
413} // namespace types
414
415BSONCXX_INLINE_NAMESPACE_END
416} // namespace bsoncxx
417
418#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.
const b_decimal128 & get_decimal128() const
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_decimal128) noexcept
Construct a value from a BSON Decimal128.
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.
Top level namespace for MongoDB C++ BSON functionality.
Definition element.hpp:24
type
An enumeration of each BSON type.
Definition types.hpp:39
A BSON array value.
Definition types.hpp:180
A BSON binary data value.
Definition types.hpp:205
A BSON boolean value.
Definition types.hpp:263
A BSON JavaScript code value.
Definition types.hpp:420
A BSON JavaScript code with scope value.
Definition types.hpp:499
A BSON date value.
Definition types.hpp:288
A BSON DBPointer value.
Definition types.hpp:401
A BSON Decimal128 value.
Definition types.hpp:605
A BSON document value.
Definition types.hpp:148
A BSON double value.
Definition types.hpp:85
A BSON signed 32-bit integer value.
Definition types.hpp:532
A BSON 64-bit signed integer value.
Definition types.hpp:580
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:349
A BSON ObjectId value.
Definition types.hpp:245
A BSON regex value.
Definition types.hpp:365
A BSON Symbol value.
Definition types.hpp:461
A BSON replication timestamp value.
Definition types.hpp:561
A BSON undefined value.
Definition types.hpp:229
A BSON UTF-8 encoded string value.
Definition types.hpp:110