Skip to content

Commit 07f460e

Browse files
committed
CXX-3232 add v1 interface declarations
1 parent b68fad3 commit 07f460e

File tree

25 files changed

+3386
-44
lines changed

25 files changed

+3386
-44
lines changed

.evergreen/scripts/abidiff-test.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ echo "---" >>cxx-noabi/mongocxx.txt
5454

5555
# Allow task to upload the diff reports despite failed status.
5656
echo "Comparing stable ABI for bsoncxx..."
57-
if ! abidiff "${abi_flags[@]:?}" install/old/lib/libbsoncxx.so install/new/lib/libbsoncxx.so >>cxx-abi/bsoncxx.txt; then
57+
abidiff "${abi_flags[@]:?}" install/old/lib/libbsoncxx.so install/new/lib/libbsoncxx.so >>cxx-abi/bsoncxx.txt && ret="$?" || ret="$?"
58+
if (("$ret" & 0x03)); then # ABIDIFF_ERROR (1) | ABIDIFF_USAGE_ERROR (2)
59+
echo "abidiff error" >&2
60+
exit 1
61+
elif (("$ret" & 0x08)); then # ABIDIFF_ABI_INCOMPATIBLE_CHANGE (8).
5862
declare status
5963
status='{"status":"failed", "type":"test", "should_continue":true, "desc":"abidiff returned an error for bsoncxx (stable)"}'
6064
curl -sS -d "${status:?}" -H "Content-Type: application/json" -X POST localhost:2285/task_status || true
@@ -63,7 +67,11 @@ echo "Comparing stable ABI for bsoncxx... done."
6367

6468
# Allow task to upload the diff reports despite failed status.
6569
echo "Comparing stable ABI for mongocxx..."
66-
if ! abidiff "${abi_flags[@]:?}" install/old/lib/libmongocxx.so install/new/lib/libmongocxx.so >>cxx-abi/mongocxx.txt; then
70+
abidiff "${abi_flags[@]:?}" install/old/lib/libmongocxx.so install/new/lib/libmongocxx.so >>cxx-abi/mongocxx.txt && ret="$?" || ret="$?"
71+
if (("$ret" & 0x03)); then # ABIDIFF_ERROR (1) | ABIDIFF_USAGE_ERROR (2)
72+
echo "abidiff error" >&2
73+
exit 1
74+
elif (("$ret" & 0x08)); then # ABIDIFF_ABI_INCOMPATIBLE_CHANGE (8)
6775
declare status
6876
status='{"status":"failed", "type":"test", "should_continue":true, "desc":"abidiff returned an error for mongocxx (stable)"}'
6977
curl -sS -d "${status:?}" -H "Content-Type: application/json" -X POST localhost:2285/task_status || true

src/bsoncxx/include/bsoncxx/v1/array/value.hpp

Lines changed: 175 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@
2020

2121
#include <bsoncxx/v1/detail/prelude.hpp>
2222

23+
#include <bsoncxx/v1/array/view.hpp>
24+
#include <bsoncxx/v1/config/export.hpp>
25+
#include <bsoncxx/v1/document/value.hpp>
26+
27+
#include <cstdint>
28+
#include <cstring>
29+
#include <functional>
30+
#include <memory>
31+
#include <type_traits>
32+
#include <utility>
33+
2334
namespace bsoncxx {
2435
namespace v1 {
2536
namespace array {
@@ -29,7 +40,165 @@ namespace array {
2940
///
3041
/// @attention This feature is experimental! It is not ready for use!
3142
///
32-
class value {};
43+
class value {
44+
private:
45+
v1::document::value _value;
46+
47+
template <typename T>
48+
struct is_valid_deleter : std::is_constructible<v1::document::value, std::uint8_t*, std::size_t, T> {};
49+
50+
public:
51+
/// @copydoc v1::document::value::deleter_type
52+
using deleter_type = v1::document::value::deleter_type;
53+
54+
/// @copydoc v1::document::value::default_deleter_type
55+
using default_deleter_type = v1::document::value::default_deleter_type;
56+
57+
/// @copydoc v1::document::value::unique_ptr_type
58+
using unique_ptr_type = v1::document::value::unique_ptr_type;
59+
60+
/// @copydoc v1::document::view::const_iterator
61+
using const_iterator = v1::document::view::const_iterator;
62+
63+
/// @copydoc v1::document::view::iterator
64+
using iterator = const_iterator;
65+
66+
/// @copydoc v1::document::value::~value()
67+
~value() = default;
68+
69+
/// @copydoc v1::document::value::value(v1::document::value&& other) noexcept
70+
value(value&& other) noexcept : _value{std::move(other._value)} {}
71+
72+
/// @copydoc v1::document::value::operator=(v1::document::value&& other) noexcept
73+
value& operator=(value&& other) noexcept {
74+
_value = std::move(other._value);
75+
return *this;
76+
}
77+
78+
/// @copydoc v1::document::value::value(v1::document::value const& other)
79+
value(value const& other) : _value(other._value) {}
80+
81+
/// @copydoc v1::document::value::operator=(v1::document::value const& other)
82+
value& operator=(value const& other) {
83+
_value = other._value;
84+
return *this;
85+
}
86+
87+
/// @copydoc v1::document::value::value()
88+
value() = default;
89+
90+
/// @copydoc v1::document::value::value(std::uint8_t* data, std::size_t length, Deleter deleter)
91+
template <typename Deleter, detail::enable_if_t<is_valid_deleter<Deleter>::value>* = nullptr>
92+
value(std::uint8_t* data, std::size_t length, Deleter deleter) : _value{data, length, std::move(deleter)} {}
93+
94+
/// @copydoc v1::document::value::value(std::uint8_t* data, std::size_t length)
95+
value(std::uint8_t* data, std::size_t length) : _value{data, length} {}
96+
97+
/// @copydoc v1::document::value::value(v1::document::value::unique_ptr_type ptr, std::size_t length)
98+
value(unique_ptr_type ptr, std::size_t length) : _value{std::move(ptr), length} {}
99+
100+
/// @copydoc v1::document::value::value(v1::document::view const& view)
101+
explicit value(v1::array::view view) : _value{view} {}
102+
103+
/// @copydoc v1::document::value::get_deleter() const
104+
deleter_type const& get_deleter() const {
105+
return _value.get_deleter();
106+
}
107+
108+
/// @copydoc v1::document::value::release()
109+
unique_ptr_type release() {
110+
return _value.release();
111+
}
112+
113+
/// @copydoc v1::document::value::reset(v1::document::value v)
114+
void reset(value v) {
115+
_value = std::move(v._value);
116+
}
117+
118+
/// @copydoc v1::document::value::reset(v1::document::view const& v)
119+
void reset(v1::array::view v) {
120+
*this = value{v};
121+
}
122+
123+
///
124+
/// Return a view of the BSON binary data as an array.
125+
///
126+
v1::array::view view() const {
127+
return {_value.data(), _value.size()};
128+
}
129+
130+
///
131+
/// Implicitly convert to `this->view()`.
132+
///
133+
/* explicit(false) */ operator v1::array::view() const {
134+
return this->view();
135+
}
136+
137+
/// @copydoc v1::array::view::cbegin() const
138+
v1::array::view::const_iterator cbegin() const {
139+
return this->view().cbegin();
140+
}
141+
142+
/// @copydoc v1::array::view::cend() const
143+
v1::array::view::const_iterator cend() const {
144+
return this->view().cend();
145+
}
146+
147+
/// @copydoc v1::array::view::begin() const
148+
v1::array::view::const_iterator begin() const {
149+
return this->view().begin();
150+
}
151+
152+
/// @copydoc v1::array::view::end() const
153+
v1::array::view::const_iterator end() const {
154+
return this->view().end();
155+
}
156+
157+
/// @copydoc v1::array::view::find(std::uint32_t i) const
158+
v1::array::view::const_iterator find(std::uint32_t i) const {
159+
return this->view().find(i);
160+
}
161+
162+
/// @copydoc v1::array::view::operator[](std::uint32_t i) const
163+
v1::element::view operator[](std::uint32_t i) const {
164+
return this->view()[i];
165+
}
166+
167+
/// @copydoc v1::array::view::data() const
168+
std::uint8_t const* data() const {
169+
return this->view().data();
170+
}
171+
172+
/// @copydoc v1::array::view::size() const
173+
std::size_t size() const {
174+
return this->view().size();
175+
}
176+
177+
/// @copydoc v1::array::view::length() const
178+
std::size_t length() const {
179+
return this->view().length();
180+
}
181+
182+
/// @copydoc v1::array::view::empty() const
183+
bool empty() const {
184+
return this->view().empty();
185+
}
186+
187+
/// @copydoc v1::array::view::operator bool() const
188+
explicit operator bool() const {
189+
return this->view().operator bool();
190+
}
191+
192+
/// @copydoc v1::array::view::operator==(v1::array::view const& lhs, v1::array::view const& rhs)
193+
friend bool operator==(value const& lhs, value const& rhs) {
194+
return lhs.view() == rhs.view();
195+
}
196+
197+
/// @copydoc v1::array::view::operator!=(v1::array::view const& lhs, v1::array::view const& rhs)
198+
friend bool operator!=(value const& lhs, value const& rhs) {
199+
return !(lhs == rhs);
200+
}
201+
};
33202

34203
} // namespace array
35204
} // namespace v1
@@ -41,3 +210,8 @@ class value {};
41210
/// @file
42211
/// Provides @ref bsoncxx::v1::array::value.
43212
///
213+
/// @par Includes
214+
/// - @ref bsoncxx/v1/array/view.hpp
215+
/// - @ref bsoncxx/v1/document/value.hpp
216+
/// - @ref bsoncxx/v1/element/view.hpp
217+
///

0 commit comments

Comments
 (0)