Skip to content

Commit 39c2bdc

Browse files
authored
CXX-3234 refactor bsoncxx::v_noabi to use bsoncxx::v1 (#1447)
* Add warnings to ctors accepting not-validated lengths * Use more copydoc in v_noabi documentation * Apply empty() warning docs to v_noabi view types * Remove all remaining instances of BSONCXX_ENUM
1 parent 031b33b commit 39c2bdc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+2862
-2358
lines changed

src/bsoncxx/include/bsoncxx/v1/oid.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@ class oid {
189189
friend std::error_code make_error_code(errc v) {
190190
return {static_cast<int>(v), error_category()};
191191
}
192+
193+
class internal;
194+
195+
private:
196+
struct for_overwrite_tag {};
197+
198+
/* explicit(false) */ oid(for_overwrite_tag) : _bytes{} {}
192199
};
193200

194201
} // namespace v1

src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/array/element-fwd.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
#pragma once
1616

17+
#include <bsoncxx/v1/element/view-fwd.hpp>
18+
1719
#include <bsoncxx/config/prelude.hpp>
1820

1921
namespace bsoncxx {
@@ -29,7 +31,7 @@ class element;
2931
namespace bsoncxx {
3032
namespace array {
3133

32-
using ::bsoncxx::v_noabi::array::element;
34+
using v_noabi::array::element;
3335

3436
} // namespace array
3537
} // namespace bsoncxx
@@ -40,3 +42,6 @@ using ::bsoncxx::v_noabi::array::element;
4042
/// @file
4143
/// Declares @ref bsoncxx::v_noabi::array::element.
4244
///
45+
/// @par Includes
46+
/// - @ref bsoncxx/v1/element/view-fwd.hpp
47+
///

src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/array/element.hpp

Lines changed: 76 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,15 @@
1414

1515
#pragma once
1616

17+
#include <bsoncxx/array/element-fwd.hpp>
18+
19+
//
20+
21+
#include <bsoncxx/v1/element/view.hpp>
22+
1723
#include <cstddef>
1824
#include <cstdint>
1925

20-
#include <bsoncxx/array/element-fwd.hpp>
2126
#include <bsoncxx/array/view-fwd.hpp>
2227
#include <bsoncxx/types/bson_value/view-fwd.hpp>
2328

@@ -36,50 +41,41 @@ namespace array {
3641
/// interrogated by calling type() and a specific value can be extracted through
3742
/// get_X() accessors.
3843
///
39-
class element : private document::element {
44+
class element : private v_noabi::document::element {
4045
public:
41-
BSONCXX_ABI_EXPORT_CDECL() element();
42-
43-
using document::element::operator bool;
44-
45-
using document::element::type;
46-
47-
using document::element::get_array;
48-
using document::element::get_binary;
49-
using document::element::get_bool;
50-
using document::element::get_code;
51-
using document::element::get_codewscope;
52-
using document::element::get_date;
53-
using document::element::get_dbpointer;
54-
using document::element::get_decimal128;
55-
using document::element::get_document;
56-
using document::element::get_double;
57-
using document::element::get_int32;
58-
using document::element::get_int64;
59-
using document::element::get_maxkey;
60-
using document::element::get_minkey;
61-
using document::element::get_null;
62-
using document::element::get_oid;
63-
using document::element::get_regex;
64-
using document::element::get_string;
65-
using document::element::get_symbol;
66-
using document::element::get_timestamp;
67-
using document::element::get_undefined;
68-
69-
using document::element::get_value;
70-
71-
using document::element::operator[];
72-
73-
using document::element::key;
74-
using document::element::keylen;
75-
using document::element::length;
76-
using document::element::offset;
77-
using document::element::raw;
78-
79-
private:
80-
friend ::bsoncxx::v_noabi::array::view;
81-
82-
explicit element(std::uint8_t const* raw, std::uint32_t length, std::uint32_t offset, std::uint32_t keylen);
46+
element() : v_noabi::document::element() {}
47+
48+
/* explicit(false) */ element(v1::element::view const& v) : v_noabi::document::element{v} {}
49+
50+
using v_noabi::document::element::operator v1::element::view;
51+
52+
using v_noabi::document::element::operator bool;
53+
54+
using v_noabi::document::element::raw;
55+
56+
using v_noabi::document::element::length;
57+
58+
using v_noabi::document::element::offset;
59+
60+
using v_noabi::document::element::keylen;
61+
62+
using v_noabi::document::element::type;
63+
64+
using v_noabi::document::element::key;
65+
66+
#pragma push_macro("X")
67+
#undef X
68+
#define X(_name, _value) using v_noabi::document::element::get_##_name;
69+
BSONCXX_V1_TYPES_XMACRO(X)
70+
#pragma pop_macro("X")
71+
72+
using v_noabi::document::element::get_value;
73+
74+
using v_noabi::document::element::get_owning_value;
75+
76+
using v_noabi::document::element::operator[];
77+
78+
friend bool operator==(element const& lhs, v_noabi::types::bson_value::view const& rhs);
8379
};
8480

8581
///
@@ -90,16 +86,24 @@ class element : private document::element {
9086
/// @{
9187

9288
/// @relatesalso bsoncxx::v_noabi::array::element
93-
BSONCXX_ABI_EXPORT_CDECL(bool) operator==(element const& elem, types::bson_value::view const& v);
89+
inline bool operator==(element const& lhs, v_noabi::types::bson_value::view const& rhs) {
90+
return static_cast<v_noabi::document::element const&>(lhs) == rhs;
91+
}
9492

9593
/// @relatesalso bsoncxx::v_noabi::array::element
96-
BSONCXX_ABI_EXPORT_CDECL(bool) operator==(types::bson_value::view const& v, element const& elem);
94+
inline bool operator==(v_noabi::types::bson_value::view const& lhs, element const& rhs) {
95+
return rhs == lhs;
96+
}
9797

9898
/// @relatesalso bsoncxx::v_noabi::array::element
99-
BSONCXX_ABI_EXPORT_CDECL(bool) operator!=(element const& elem, types::bson_value::view const& v);
99+
inline bool operator!=(element const& lhs, v_noabi::types::bson_value::view const& rhs) {
100+
return !(lhs == rhs);
101+
}
100102

101103
/// @relatesalso bsoncxx::v_noabi::array::element
102-
BSONCXX_ABI_EXPORT_CDECL(bool) operator!=(types::bson_value::view const& v, element const& elem);
104+
inline bool operator!=(v_noabi::types::bson_value::view const& lhs, element const& rhs) {
105+
return !(lhs == rhs);
106+
}
103107

104108
/// @}
105109
///
@@ -108,11 +112,29 @@ BSONCXX_ABI_EXPORT_CDECL(bool) operator!=(types::bson_value::view const& v, elem
108112
} // namespace v_noabi
109113
} // namespace bsoncxx
110114

115+
namespace bsoncxx {
116+
namespace v_noabi {
117+
118+
// Ambiguous whether `v1::element::view` should be converted to `v_noabi::array::element` or
119+
// `v_noabi::document::element.` Require users to explicitly cast to the expected type instead.
120+
//
121+
// v_noabi::array::element from_v1(v1::element::view const& v);
122+
123+
///
124+
/// Convert to the @ref bsoncxx::v1 equivalent of `v`.
125+
///
126+
inline v1::element::view to_v1(v_noabi::array::element const& v) {
127+
return v1::element::view{v};
128+
}
129+
130+
} // namespace v_noabi
131+
} // namespace bsoncxx
132+
111133
namespace bsoncxx {
112134
namespace array {
113135

114-
using ::bsoncxx::v_noabi::array::operator==;
115-
using ::bsoncxx::v_noabi::array::operator!=;
136+
using v_noabi::array::operator==;
137+
using v_noabi::array::operator!=;
116138

117139
} // namespace array
118140
} // namespace bsoncxx
@@ -123,3 +145,7 @@ using ::bsoncxx::v_noabi::array::operator!=;
123145
/// @file
124146
/// Provides @ref bsoncxx::v_noabi::array::element.
125147
///
148+
/// @par Includes
149+
/// - @ref bsoncxx/document/element.hpp
150+
/// - @ref bsoncxx/v1/element/view.hpp
151+
///

src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/array/value-fwd.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
#pragma once
1616

17+
#include <bsoncxx/v1/array/value-fwd.hpp>
18+
1719
#include <bsoncxx/config/prelude.hpp>
1820

1921
namespace bsoncxx {
@@ -29,7 +31,7 @@ class value;
2931
namespace bsoncxx {
3032
namespace array {
3133

32-
using ::bsoncxx::v_noabi::array::value;
34+
using v_noabi::array::value;
3335

3436
} // namespace array
3537
} // namespace bsoncxx
@@ -40,3 +42,6 @@ using ::bsoncxx::v_noabi::array::value;
4042
/// @file
4143
/// Declares @ref bsoncxx::v_noabi::array::value.
4244
///
45+
/// @par Includes
46+
/// - @ref bsoncxx/v1/array/value-fwd.hpp
47+
///

0 commit comments

Comments
 (0)