MongoDB C++ Driver  mongocxx-3.9.0
All Classes Namespaces Functions Typedefs Enumerations Enumerator Friends Pages
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/array/view_or_value.hpp>
22 #include <bsoncxx/document/view_or_value.hpp>
23 #include <bsoncxx/stdx/make_unique.hpp>
24 #include <bsoncxx/types/bson_value/view.hpp>
25 
26 #include <bsoncxx/config/prelude.hpp>
27 
28 namespace bsoncxx {
29 inline namespace v_noabi {
30 namespace types {
31 namespace bson_value {
32 
43 class BSONCXX_API value {
44  public:
54 #define BSONCXX_ENUM(name, val) value(b_##name v);
55 #include <bsoncxx/enums/type.hpp>
56 #undef BSONCXX_ENUM
57 
61  value(const char* v);
62 
66  value(std::string v);
67 
71  value(stdx::string_view v);
72 
76  value(int32_t v);
77 
81  value(int64_t v);
82 
86  value(double v);
87 
91  value(bool v);
92 
96  value(oid v);
97 
102 
106  value(std::chrono::milliseconds v);
107 
111  value(std::nullptr_t);
112 
116  value(bsoncxx::document::view v);
117 
121  value(bsoncxx::array::view v);
122 
131  value(std::vector<unsigned char> v, const binary_sub_type sub_type = {});
132 
143  value(const uint8_t* data, size_t size, const binary_sub_type sub_type = {});
144 
156  value(stdx::string_view collection, oid value);
157 
166  value(stdx::string_view code, bsoncxx::document::view_or_value scope);
167 
176  value(stdx::string_view regex, stdx::string_view options);
177 
197  value(const type id, stdx::string_view v);
198 
210  value(const type id);
211 
232  value(const type id, uint64_t a, uint64_t b);
233 
234  ~value();
235 
236  value(const value&);
237  value& operator=(const value&);
238 
239  value(value&&) noexcept;
240  value& operator=(value&&) noexcept;
241 
245  explicit value(const view&);
246 
250  bson_value::view view() const noexcept;
251 
255  operator bson_value::view() const noexcept;
256 
257  private:
258  friend class bsoncxx::document::element;
259 
260  value(const std::uint8_t* raw,
261  std::uint32_t length,
262  std::uint32_t offset,
263  std::uint32_t keylen);
264 
265  // Makes a copy of 'internal_value' and owns the copy.
266  value(void* internal_value);
267 
268  friend value make_owning_bson(void* internal_value);
269 
270  class BSONCXX_PRIVATE impl;
271  std::unique_ptr<impl> _impl;
272 };
273 
281 BSONCXX_INLINE bool operator==(const value& lhs, const value& rhs) {
282  return (lhs.view() == rhs.view());
283 }
284 
285 BSONCXX_INLINE bool operator!=(const value& lhs, const value& rhs) {
286  return !(lhs == rhs);
287 }
288 
292 
300 BSONCXX_INLINE bool operator==(const value& lhs, const view& rhs) {
301  return (lhs.view() == rhs);
302 }
303 
304 BSONCXX_INLINE bool operator==(const view& lhs, const value& rhs) {
305  return (rhs == lhs);
306 }
307 
308 BSONCXX_INLINE bool operator!=(const value& lhs, const view& rhs) {
309  return !(lhs == rhs);
310 }
311 
312 BSONCXX_INLINE bool operator!=(const view& lhs, const value& rhs) {
313  return !(lhs == rhs);
314 }
315 
319 
320 } // namespace bson_value
321 } // namespace types
322 
323 } // namespace v_noabi
324 } // namespace bsoncxx
325 
326 #include <bsoncxx/config/postlude.hpp>
Represents an IEEE 754-2008 BSON Decimal128 value in a platform-independent way.
Definition: decimal128.hpp:29
Represents a MongoDB ObjectId.
Definition: oid.hpp:37
A variant owning type that represents any BSON type.
Definition: value.hpp:43
value(decimal128 v)
Constructs a BSON Decimal128 value.
value(bsoncxx::document::view v)
Constructs a BSON document value.
value(bsoncxx::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(stdx::string_view code, bsoncxx::document::view_or_value scope)
Constructs a BSON JavaScript code with scope 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.
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:300
value(oid v)
Constructs a BSON ObjectId 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(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:44
binary_sub_type
An enumeration of each BSON binary sub type.
Definition: types.hpp:70
type
An enumeration of each BSON type.
Definition: types.hpp:50
The top-level namespace for bsoncxx library entities.
Definition: element.hpp:24