MongoDB C++ Driver 4.1.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 <cstdlib>
18#include <memory>
19
21
24
26
27namespace bsoncxx {
28namespace v_noabi {
29namespace array {
30
37class value {
38 public:
39 using deleter_type = void(BSONCXX_ABI_CDECL*)(std::uint8_t*);
40 using unique_ptr_type = std::unique_ptr<uint8_t[], deleter_type>;
41
54 BSONCXX_ABI_EXPORT_CDECL() value(std::uint8_t* data, std::size_t length, deleter_type dtor);
55
65 BSONCXX_ABI_EXPORT_CDECL() value(unique_ptr_type ptr, std::size_t length);
66
76
78 BSONCXX_ABI_EXPORT_CDECL(value&) operator=(value const&);
79
80 value(value&&) = default;
81 value& operator=(value&&) = default;
82
86 array::view view() const noexcept {
87 return array::view{static_cast<uint8_t*>(_data.get()), _length};
88 }
89
95 operator array::view() const noexcept {
96 return view();
97 }
98
109
110 private:
111 unique_ptr_type _data;
112 std::size_t _length{0};
113};
114
115} // namespace array
116} // namespace v_noabi
117} // namespace bsoncxx
118
120
Declares bsoncxx::v_noabi::array::value.
Provides bsoncxx::v_noabi::array::view.
#define BSONCXX_ABI_CDECL
Expands to __cdecl when built with MSVC on Windows.
Definition export.hpp:49
#define BSONCXX_ABI_EXPORT_CDECL(...)
Equivalent to BSONCXX_ABI_EXPORT with BSONCXX_ABI_CDECL.
Definition export.hpp:52
The bsoncxx v_noabi macro guard postlude header.
The bsoncxx v_noabi macro guard prelude header.
value(std::uint8_t *data, std::size_t length, deleter_type dtor)
Constructs a value from a buffer. This constructor transfers ownership of the buffer to the resulting...
unique_ptr_type release()
Transfer ownership of the underlying buffer to the caller.
array::view view() const noexcept
Get a view over the document owned by this value.
Definition value.hpp:86
value(std::uint8_t *data, std::size_t length, deleter_type dtor)
Constructs a value from a buffer. This constructor transfers ownership of the buffer to the resulting...
A read-only, non-owning view of a BSON document.
Definition view.hpp:36
Provides bsoncxx::v_noabi::document::value.
Declares entities representing a BSON array.
Declares entities whose ABI stability is NOT guaranteed.
The top-level namespace within which all bsoncxx library entities are declared.