MongoDB C++ Driver mongocxx-4.0.0
Loading...
Searching...
No Matches
value.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 <iostream>
18#include <memory>
19#include <string>
20#include <vector>
21
24
28
30
31namespace bsoncxx {
32namespace v_noabi {
33namespace types {
34namespace bson_value {
35
47class value {
48 public:
76
81
86
90 BSONCXX_ABI_EXPORT_CDECL() value(stdx::string_view v);
91
96
101
106
111
116
121
125 BSONCXX_ABI_EXPORT_CDECL() value(std::chrono::milliseconds v);
126
131
135 BSONCXX_ABI_EXPORT_CDECL() value(bsoncxx::v_noabi::document::view v);
136
141
151 value(std::vector<unsigned char> v, const binary_sub_type sub_type = {});
152
164 value(const uint8_t* data, size_t size, const binary_sub_type sub_type = {});
165
176 BSONCXX_ABI_EXPORT_CDECL() value(stdx::string_view collection, oid value);
177
187 value(stdx::string_view code, bsoncxx::v_noabi::document::view_or_value scope);
188
197 BSONCXX_ABI_EXPORT_CDECL() value(stdx::string_view regex, stdx::string_view options);
198
216 BSONCXX_ABI_EXPORT_CDECL() value(const type id, stdx::string_view v);
217
231
252 BSONCXX_ABI_EXPORT_CDECL() value(const type id, uint64_t a, uint64_t b);
253
255
257 BSONCXX_ABI_EXPORT_CDECL(value&) operator=(const value&);
258
260 BSONCXX_ABI_EXPORT_CDECL(value&) operator=(value&&) noexcept;
261
266
270 BSONCXX_ABI_EXPORT_CDECL(bson_value::view) view() const noexcept;
271
275 BSONCXX_ABI_EXPORT_CDECL() operator bson_value::view() const noexcept;
276
277 private:
278 friend ::bsoncxx::v_noabi::document::element;
279
280 value(const std::uint8_t* raw,
281 std::uint32_t length,
282 std::uint32_t offset,
283 std::uint32_t keylen);
284
285 // Makes a copy of 'internal_value' and owns the copy.
286 // Export is required by mongocxx via make_owning_bson.
287 BSONCXX_ABI_EXPORT_CDECL() value(void* internal_value);
288
289 friend value make_owning_bson(void* internal_value);
290
291 class impl;
292 std::unique_ptr<impl> _impl;
293};
294
299
301inline bool operator==(const value& lhs, const value& rhs) {
302 return (lhs.view() == rhs.view());
303}
304
306inline bool operator!=(const value& lhs, const value& rhs) {
307 return !(lhs == rhs);
308}
309
312
317
319inline bool operator==(const value& lhs, const view& rhs) {
320 return (lhs.view() == rhs);
321}
322
324inline bool operator==(const view& lhs, const value& rhs) {
325 return (rhs == lhs);
326}
327
329inline bool operator!=(const value& lhs, const view& rhs) {
330 return !(lhs == rhs);
331}
332
334inline bool operator!=(const view& lhs, const value& rhs) {
335 return !(lhs == rhs);
336}
337
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
358
363
364#if defined(BSONCXX_PRIVATE_DOXYGEN_PREPROCESSOR)
365
366namespace bsoncxx {
367namespace types {
368namespace bson_value {
369
373
377
381
385
389
393
394} // namespace bson_value
395} // namespace types
396} // namespace bsoncxx
397
398#endif // defined(BSONCXX_PRIVATE_DOXYGEN_PREPROCESSOR)
Provides bsoncxx::v_noabi::array::view_or_value.
The bsoncxx macro guard postlude header.
The bsoncxx macro guard prelude header.
Represents an IEEE 754-2008 BSON Decimal128 value in a platform-independent way.
Definition decimal128.hpp:32
Represents a MongoDB ObjectId. As this BSON type is used within the MongoDB server as a primary key f...
Definition oid.hpp:41
A variant owning type that represents any BSON type. Owns its underlying buffer. When a bson_value::v...
Definition value.hpp:47
bool operator==(const view &lhs, const value &rhs)
Compares a value with a view for (in)equality.
Definition value.hpp:324
bool operator!=(const view &lhs, const value &rhs)
Compares a value with a view for (in)equality.
Definition value.hpp:334
bool operator!=(const value &lhs, const value &rhs)
Compares values for (in)-equality.
Definition value.hpp:306
bson_value::view view() const noexcept
Get a view over the bson_value owned by this object.
bool operator==(const value &lhs, const view &rhs)
Compares a value with a view for (in)equality.
Definition value.hpp:319
bool operator!=(const value &lhs, const view &rhs)
Compares a value with a view for (in)equality.
Definition value.hpp:329
A view-only variant that can contain any BSON type.
Definition view.hpp:54
Declares bsoncxx::v_noabi::document::element.
Provides bsoncxx::v_noabi::document::view_or_value.
#define BSONCXX_ABI_EXPORT_CDECL(...)
Equivalent to BSONCXX_ABI_EXPORT with BSONCXX_ABI_CDECL.
Definition fwd.hpp:177
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,...
binary_sub_type
An enumeration of each BSON binary sub type.
Definition types.hpp:72
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:201
A BSON binary data value.
Definition types.hpp:226
A BSON boolean value.
Definition types.hpp:283
A BSON JavaScript code value.
Definition types.hpp:436
A BSON JavaScript code with scope value.
Definition types.hpp:506
A BSON date value.
Definition types.hpp:308
A BSON DBPointer (aka DBRef) value.
Definition types.hpp:417
A BSON Decimal128 value.
Definition types.hpp:609
A BSON document value.
Definition types.hpp:169
A BSON double value.
Definition types.hpp:110
A BSON signed 32-bit integer value.
Definition types.hpp:540
A BSON 64-bit signed integer value.
Definition types.hpp:584
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:365
A BSON ObjectId value.
Definition types.hpp:265
A BSON regex value.
Definition types.hpp:381
A BSON UTF-8 encoded string value.
Definition types.hpp:135
A BSON Symbol value.
Definition types.hpp:472
A BSON replication timestamp value.
Definition types.hpp:565
A BSON undefined value.
Definition types.hpp:249
Declares bsoncxx::v_noabi::types::bson_value::value.
Provides bsoncxx::v_noabi::types::bson_value::view.