MongoDB C++ Driver  mongocxx-3.6.2
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 <memory>
18 
19 #include <bsoncxx/types/bson_value/view.hpp>
20 
21 #include <bsoncxx/config/prelude.hpp>
22 
23 namespace bsoncxx {
24 BSONCXX_INLINE_NAMESPACE_BEGIN
25 
26 namespace types {
27 namespace bson_value {
28 
39 class BSONCXX_API value {
40  public:
41  ~value();
42 
43  value(const value&);
44  value& operator=(const value&);
45 
46  value(value&&) noexcept;
47  value& operator=(value&&) noexcept;
48 
52  explicit value(const view&);
53 
57  bson_value::view view() const noexcept;
58 
62  operator bson_value::view() const noexcept;
63 
64  private:
65  friend class bsoncxx::document::element;
66 
67  value(const std::uint8_t* raw,
68  std::uint32_t length,
69  std::uint32_t offset,
70  std::uint32_t keylen);
71 
72  // Makes a copy of 'internal_value' and owns the copy.
73  value(void* internal_value);
74 
75  friend value make_owning_bson(void* internal_value);
76 
77  class BSONCXX_PRIVATE impl;
78  std::unique_ptr<impl> _impl;
79 };
80 
88 BSONCXX_INLINE bool operator==(const value& lhs, const value& rhs) {
89  return (lhs.view() == rhs.view());
90 }
91 
92 BSONCXX_INLINE bool operator!=(const value& lhs, const value& rhs) {
93  return !(lhs == rhs);
94 }
95 
99 
107 BSONCXX_INLINE bool operator==(const value& lhs, const view& rhs) {
108  return (lhs.view() == rhs);
109 }
110 
111 BSONCXX_INLINE bool operator==(const view& lhs, const value& rhs) {
112  return (rhs == lhs);
113 }
114 
115 BSONCXX_INLINE bool operator!=(const value& lhs, const view& rhs) {
116  return !(lhs == rhs);
117 }
118 
119 BSONCXX_INLINE bool operator!=(const view& lhs, const value& rhs) {
120  return !(lhs == rhs);
121 }
122 
126 
127 } // namespace bson_value
128 } // namespace types
129 
130 BSONCXX_INLINE_NAMESPACE_END
131 } // namespace bsoncxx
132 
133 #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:107
bsoncxx
Top level namespace for MongoDB C++ BSON functionality.
Definition: element.hpp:24
bsoncxx::types::bson_value::value::view
bson_value::view view() const noexcept
Get a view over the bson_value owned by this object.
bsoncxx::types::bson_value::value::value
value(const view &)
Create an owning copy of a bson_value::view.
bsoncxx::types::bson_value::value
A variant owning type that represents any BSON type.
Definition: value.hpp:39
bsoncxx::types::bson_value::view
A view-only variant that can contain any BSON type.
Definition: view.hpp:44