Skip to content

Commit 98521ae

Browse files
committed
CXX-3232 add v1 interface declarations
1 parent b68fad3 commit 98521ae

File tree

25 files changed

+3321
-44
lines changed

25 files changed

+3321
-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+
///

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

Lines changed: 119 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,130 @@
2020

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

23+
#include <bsoncxx/v1/config/export.hpp>
24+
#include <bsoncxx/v1/document/view.hpp>
25+
#include <bsoncxx/v1/element/view.hpp>
26+
27+
#include <cstddef>
28+
#include <cstdint>
29+
#include <iterator>
30+
2331
namespace bsoncxx {
2432
namespace v1 {
2533
namespace array {
2634

2735
///
2836
/// A non-owning, read-only BSON array.
2937
///
38+
/// An "invalid" view, as indicated by @ref operator bool() const, does not satisfy the minimum requirements of a valid
39+
/// BSON document, which are that:
40+
///
41+
/// - @ref data() is not null, and
42+
/// - @ref size() is not less than `5` (the minimum size of a BSON document).
43+
///
44+
/// The BSON binary data being represented is only validated as minimally required to satisfy a requested operation.
45+
/// When an operation is not satisfiable due to invalid data, the operation will throw an @ref bsoncxx::v1::exception
46+
/// with @ref bsoncxx::v1::error::document::view::invalid_data.
47+
///
3048
/// @attention This feature is experimental! It is not ready for use!
3149
///
32-
class view {};
50+
class view {
51+
public:
52+
///
53+
/// Equivalent to @ref const_iterator.
54+
///
55+
using const_iterator = v1::document::view::const_iterator;
56+
57+
///
58+
/// Equivalent to @ref const_iterator.
59+
///
60+
using iterator = const_iterator;
61+
62+
private:
63+
v1::document::view _view;
64+
65+
public:
66+
/// @copydoc v1::document::view::view()
67+
view() = default;
68+
69+
/// @copydoc v1::document::view::view(std::uint8_t const* data, std::size_t length)
70+
view(std::uint8_t const* data, std::size_t length) : _view{data, length} {}
71+
72+
/// @copydoc v1::document::view::data() const
73+
std::uint8_t const* data() const {
74+
return _view.data();
75+
}
76+
77+
/// @copydoc v1::document::view::size() const
78+
std::size_t size() const {
79+
return _view.size();
80+
}
81+
82+
/// @copydoc v1::document::view::length() const
83+
std::size_t length() const {
84+
return _view.length();
85+
}
86+
87+
/// @copydoc v1::document::view::empty() const
88+
bool empty() const {
89+
return _view.empty();
90+
}
91+
92+
/// @copydoc v1::document::view::operator bool() const
93+
explicit operator bool() const {
94+
return _view.operator bool();
95+
}
96+
97+
/// @copydoc v1::document::view::cbegin() const
98+
BSONCXX_ABI_EXPORT_CDECL(const_iterator) cbegin() const;
99+
100+
/// @copydoc v1::document::view::cend() const
101+
const_iterator cend() const {
102+
return {};
103+
}
104+
105+
/// @copydoc v1::document::view::cbegin() const
106+
const_iterator begin() const {
107+
return this->cbegin();
108+
}
109+
110+
/// @copydoc v1::document::view::cend() const
111+
const_iterator end() const {
112+
return this->cend();
113+
}
114+
115+
///
116+
/// Return a const iterator to the element within the represented BSON array at index `i`.
117+
///
118+
/// If this view is invalid, returns an end iterator.
119+
///
120+
/// @exception bsoncxx::v1::exception with @ref bsoncxx::v1::error::document::view::invalid_data if this operation
121+
/// failed due to invalid BSON binary data.
122+
///
123+
BSONCXX_ABI_EXPORT_CDECL(const_iterator) find(std::uint32_t i) const;
124+
125+
/// @copydoc find(std::uint32_t i) const
126+
v1::element::view operator[](std::uint32_t i) const {
127+
return *(this->find(i));
128+
}
129+
130+
///
131+
/// Implicitly convert to a @ref bsoncxx::v1::document::view.
132+
///
133+
/* explicit(false) */ operator v1::document::view() const {
134+
return _view;
135+
}
136+
137+
/// @copydoc v1::document::view::operator==(v1::document::view const& lhs, v1::document::view const& rhs)
138+
friend bool operator==(view const& lhs, view const& rhs) {
139+
return lhs._view == rhs._view;
140+
}
141+
142+
/// @copydoc v1::document::view::operator!=(v1::document::view const& lhs, v1::document::view const& rhs)
143+
friend bool operator!=(view const& lhs, view const& rhs) {
144+
return !(lhs == rhs);
145+
}
146+
};
33147

34148
} // namespace array
35149
} // namespace v1
@@ -41,3 +155,7 @@ class view {};
41155
/// @file
42156
/// Provides @ref bsoncxx::v1::array::view.
43157
///
158+
/// @par Includes
159+
/// - @ref bsoncxx/v1/document/view.hpp
160+
/// - @ref bsoncxx/v1/element/view.hpp
161+
///

0 commit comments

Comments
 (0)