MongoDB C++ Driver  mongocxx-3.7.0
value.hpp
1 // Copyright 2014 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 <cstdlib>
18 #include <memory>
19 
20 #include <bsoncxx/array/view.hpp>
21 #include <bsoncxx/document/value.hpp>
22 
23 #include <bsoncxx/config/prelude.hpp>
24 
25 namespace bsoncxx {
26 BSONCXX_INLINE_NAMESPACE_BEGIN
27 namespace array {
28 
34 class BSONCXX_API value {
35  public:
36  using deleter_type = void (*)(std::uint8_t*);
37  using unique_ptr_type = std::unique_ptr<uint8_t[], deleter_type>;
38 
51  value(std::uint8_t* data, std::size_t length, deleter_type dtor);
52 
62  value(unique_ptr_type ptr, std::size_t length);
63 
72  explicit value(array::view view);
73 
74  value(const value&);
75  value& operator=(const value&);
76 
77  value(value&&) noexcept = default;
78  value& operator=(value&&) noexcept = default;
79 
83  BSONCXX_INLINE array::view view() const noexcept;
84 
90  BSONCXX_INLINE operator array::view() const noexcept;
91 
101  unique_ptr_type release();
102 
103  private:
104  unique_ptr_type _data;
105  std::size_t _length{0};
106 };
107 
108 BSONCXX_INLINE array::view value::view() const noexcept {
109  return array::view{static_cast<uint8_t*>(_data.get()), _length};
110 }
111 
112 BSONCXX_INLINE value::operator array::view() const noexcept {
113  return view();
114 }
115 
116 } // namespace array
117 BSONCXX_INLINE_NAMESPACE_END
118 } // namespace bsoncxx
119 
120 #include <bsoncxx/config/postlude.hpp>
bsoncxx
Top level namespace for MongoDB C++ BSON functionality.
Definition: element.hpp:24
bsoncxx::array::view
A read-only, non-owning view of a BSON document.
Definition: view.hpp:40
bsoncxx::array::value
A read-only BSON array that owns its underlying buffer.
Definition: value.hpp:34
bsoncxx::array::value::view
array::view view() const noexcept
Get a view over the document owned by this value.
Definition: value.hpp:108