MongoDB C++ Driver mongocxx-3.10.1
Loading...
Searching...
No Matches
value.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 <iostream>
18#include <memory>
19#include <vector>
20
21#include <bsoncxx/document/element-fwd.hpp>
22#include <bsoncxx/types/bson_value/value-fwd.hpp>
23
24#include <bsoncxx/array/view_or_value.hpp>
25#include <bsoncxx/document/view_or_value.hpp>
26#include <bsoncxx/stdx/make_unique.hpp>
27#include <bsoncxx/types/bson_value/view.hpp>
28
29#include <bsoncxx/config/prelude.hpp>
30
31namespace bsoncxx {
32namespace v_noabi {
33namespace types {
34namespace bson_value {
35
46class value {
47 public:
57#define BSONCXX_ENUM(name, val) value(b_##name v);
58#include <bsoncxx/enums/type.hpp>
59#undef BSONCXX_ENUM
60
64 value(const char* v);
65
69 value(std::string v);
70
74 value(stdx::string_view v);
75
79 value(int32_t v);
80
84 value(int64_t v);
85
89 value(double v);
90
94 value(bool v);
95
100
105
109 value(std::chrono::milliseconds v);
110
114 value(std::nullptr_t);
115
120
125
134 value(std::vector<unsigned char> v, const binary_sub_type sub_type = {});
135
146 value(const uint8_t* data, size_t size, const binary_sub_type sub_type = {});
147
159 value(stdx::string_view collection, oid value);
160
169 value(stdx::string_view code, bsoncxx::v_noabi::document::view_or_value scope);
170
179 value(stdx::string_view regex, stdx::string_view options);
180
200 value(const type id, stdx::string_view v);
201
214 value(const type id);
215
236 value(const type id, uint64_t a, uint64_t b);
237
238 ~value();
239
240 value(const value&);
241 value& operator=(const value&);
242
243 value(value&&) noexcept;
244 value& operator=(value&&) noexcept;
245
249 explicit value(const view&);
250
254 bson_value::view view() const noexcept;
255
259 operator bson_value::view() const noexcept;
260
261 private:
262 friend ::bsoncxx::v_noabi::document::element;
263
264 value(const std::uint8_t* raw,
265 std::uint32_t length,
266 std::uint32_t offset,
267 std::uint32_t keylen);
268
269 // Makes a copy of 'internal_value' and owns the copy.
270 value(void* internal_value);
271
272 friend value make_owning_bson(void* internal_value);
273
274 class BSONCXX_PRIVATE impl;
275 std::unique_ptr<impl> _impl;
276};
277
285BSONCXX_INLINE bool operator==(const value& lhs, const value& rhs) {
286 return (lhs.view() == rhs.view());
287}
288
289BSONCXX_INLINE bool operator!=(const value& lhs, const value& rhs) {
290 return !(lhs == rhs);
291}
292
296
304BSONCXX_INLINE bool operator==(const value& lhs, const view& rhs) {
305 return (lhs.view() == rhs);
306}
307
308BSONCXX_INLINE bool operator==(const view& lhs, const value& rhs) {
309 return (rhs == lhs);
310}
311
312BSONCXX_INLINE bool operator!=(const value& lhs, const view& rhs) {
313 return !(lhs == rhs);
314}
315
316BSONCXX_INLINE bool operator!=(const view& lhs, const value& rhs) {
317 return !(lhs == rhs);
318}
319
323
324} // namespace bson_value
325} // namespace types
326} // namespace v_noabi
327} // namespace bsoncxx
328
329namespace bsoncxx {
330namespace types {
331namespace bson_value {
332
333using ::bsoncxx::v_noabi::types::bson_value::operator==;
334using ::bsoncxx::v_noabi::types::bson_value::operator!=;
335
336} // namespace bson_value
337} // namespace types
338} // namespace bsoncxx
339
340#include <bsoncxx/config/postlude.hpp>
A read-only, non-owning view of a BSON document.
Definition view.hpp:36
Represents an IEEE 754-2008 BSON Decimal128 value in a platform-independent way.
Definition decimal128.hpp:32
A read-only, non-owning view of a BSON document.
Definition view.hpp:35
Represents a MongoDB ObjectId.
Definition oid.hpp:40
A variant owning type that represents any BSON type.
Definition value.hpp:46
value(decimal128 v)
Constructs a BSON Decimal128 value.
value(bsoncxx::v_noabi::array::view v)
Constructs a BSON array value.
value(stdx::string_view collection, oid value)
Constructs a BSON DBPointer value.
bson_value::view view() const noexcept
Get a view over the bson_value owned by this object.
value(std::vector< unsigned char > v, const binary_sub_type sub_type={})
Constructs a BSON binary data value.
value(int64_t v)
Constructs a BSON 64-bit signed integer value.
value(double v)
Constructs a BSON double value.
value(std::string v)
Constructs a BSON UTF-8 string value.
value(const uint8_t *data, size_t size, const binary_sub_type sub_type={})
Constructs a BSON binary data value.
value(stdx::string_view v)
Constructs a BSON UTF-8 string value.
bool operator==(const value &lhs, const value &rhs)
Compares values for (in)-equality.
Definition value.hpp:285
value(const type id, uint64_t a, uint64_t b)
Constructs one of the following BSON values (each specified by the parenthesized type):
bool operator==(const value &lhs, const view &rhs)
Compares a value with a view for (in)-equality.
Definition value.hpp:304
value(oid v)
Constructs a BSON ObjectId value.
value(bsoncxx::v_noabi::document::view v)
Constructs a BSON document value.
value(stdx::string_view regex, stdx::string_view options)
Constructs a BSON regex value with options.
value(std::chrono::milliseconds v)
Constructs a BSON date value.
value(bool v)
Constructs a BSON boolean value.
value(const type id, stdx::string_view v)
Constructs one of the following BSON values (each specified by the parenthesized type):
value(const type id)
Constructs one of the following BSON values (each specified by the parenthesized type):
value(stdx::string_view code, bsoncxx::v_noabi::document::view_or_value scope)
Constructs a BSON JavaScript code with scope value.
value(const char *v)
Constructs a BSON UTF-8 string value.
value(int32_t v)
Constructs a BSON 32-bit signed integer value.
value(std::nullptr_t)
Constructs a BSON null value.
A view-only variant that can contain any BSON type.
Definition view.hpp:41
binary_sub_type
An enumeration of each BSON binary sub type.
Definition types.hpp:68
type
An enumeration of each BSON type.
Definition types.hpp:48
The top-level namespace for bsoncxx library entities.
Definition element-fwd.hpp:19