MongoDB C++ Driver  mongocxx-3.7.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 BSONCXX_INLINE_NAMESPACE_BEGIN
30 
31 namespace types {
32 namespace bson_value {
33 
44 class BSONCXX_API value {
45  public:
55 #define BSONCXX_ENUM(name, val) value(b_##name v);
56 #include <bsoncxx/enums/type.hpp>
57 #undef BSONCXX_ENUM
58 
62  value(const char* v);
63 
67  value(std::string v);
68 
72  value(stdx::string_view v);
73 
77  value(int32_t v);
78 
82  value(int64_t v);
83 
87  value(double v);
88 
92  value(bool v);
93 
97  value(oid v);
98 
102  value(decimal128 v);
103 
107  value(std::chrono::milliseconds v);
108 
112  value(std::nullptr_t);
113 
118 
123 
132  value(std::vector<unsigned char> v, const binary_sub_type sub_type = {});
133 
144  value(const uint8_t* data, size_t size, const binary_sub_type sub_type = {});
145 
157  value(stdx::string_view collection, oid value);
158 
167  value(stdx::string_view code, bsoncxx::document::view_or_value scope);
168 
177  value(stdx::string_view regex, stdx::string_view options);
178 
198  value(const type id, stdx::string_view v);
199 
211  value(const type id);
212 
233  value(const type id, uint64_t a, uint64_t b);
234 
235  ~value();
236 
237  value(const value&);
238  value& operator=(const value&);
239 
240  value(value&&) noexcept;
241  value& operator=(value&&) noexcept;
242 
246  explicit value(const view&);
247 
251  bson_value::view view() const noexcept;
252 
256  operator bson_value::view() const noexcept;
257 
258  private:
259  friend class bsoncxx::document::element;
260 
261  value(const std::uint8_t* raw,
262  std::uint32_t length,
263  std::uint32_t offset,
264  std::uint32_t keylen);
265 
266  // Makes a copy of 'internal_value' and owns the copy.
267  value(void* internal_value);
268 
269  friend value make_owning_bson(void* internal_value);
270 
271  class BSONCXX_PRIVATE impl;
272  std::unique_ptr<impl> _impl;
273 };
274 
282 BSONCXX_INLINE bool operator==(const value& lhs, const value& rhs) {
283  return (lhs.view() == rhs.view());
284 }
285 
286 BSONCXX_INLINE bool operator!=(const value& lhs, const value& rhs) {
287  return !(lhs == rhs);
288 }
289 
293 
301 BSONCXX_INLINE bool operator==(const value& lhs, const view& rhs) {
302  return (lhs.view() == rhs);
303 }
304 
305 BSONCXX_INLINE bool operator==(const view& lhs, const value& rhs) {
306  return (rhs == lhs);
307 }
308 
309 BSONCXX_INLINE bool operator!=(const value& lhs, const view& rhs) {
310  return !(lhs == rhs);
311 }
312 
313 BSONCXX_INLINE bool operator!=(const view& lhs, const value& rhs) {
314  return !(lhs == rhs);
315 }
316 
320 
321 } // namespace bson_value
322 } // namespace types
323 
324 BSONCXX_INLINE_NAMESPACE_END
325 } // namespace bsoncxx
326 
327 #include <bsoncxx/config/postlude.hpp>
bsoncxx::types::bson_value::value::operator==
bool operator==(const value &lhs, const view &rhs)
Compares a value with a view for (in)-equality.
Definition: value.hpp:301
bsoncxx
Top level namespace for MongoDB C++ BSON functionality.
Definition: element.hpp:24
bsoncxx::view_or_value< document::view, document::value >
bsoncxx::binary_sub_type
binary_sub_type
An enumeration of each BSON binary sub type.
Definition: types.hpp:66
bsoncxx::array::view
A read-only, non-owning view of a BSON document.
Definition: view.hpp:40
bsoncxx::document::element::length
std::uint32_t length() const
Getter for length of the raw bson bytes the element points to.
bsoncxx::types::bson_value::value::view
bson_value::view view() const noexcept
Get a view over the bson_value owned by this object.
bsoncxx::oid
Represents a MongoDB ObjectId.
Definition: oid.hpp:38
bsoncxx::decimal128
Represents an IEEE 754-2008 BSON Decimal128 value in a platform-independent way.
Definition: decimal128.hpp:30
bsoncxx::document::element::raw
const std::uint8_t * raw() const
Getter for the raw bson bytes the element points to.
bsoncxx::document::element
A variant view type that accesses values in serialized BSON documents.
Definition: element.hpp:76
bsoncxx::document::element::keylen
std::uint32_t keylen() const
Getter for the element's key length.
bsoncxx::type
type
An enumeration of each BSON type.
Definition: types.hpp:46
bsoncxx::types::bson_value::value::operator==
bool operator==(const value &lhs, const value &rhs)
Compares values for (in)-equality.
Definition: value.hpp:282
bsoncxx::types::bson_value::value
A variant owning type that represents any BSON type.
Definition: value.hpp:44
bsoncxx::document::view
A read-only, non-owning view of a BSON document.
Definition: view.hpp:33
bsoncxx::types::bson_value::view
A view-only variant that can contain any BSON type.
Definition: view.hpp:44
bsoncxx::document::element::offset
std::uint32_t offset() const
Getter for the offset into the raw bson bytes the element points to.