Skip to content

Commit 91b9c64

Browse files
authored
CXX-2745 add aliases and deprecations for v1 renames (#1463)
1 parent 6e20fbc commit 91b9c64

File tree

21 files changed

+311
-7
lines changed

21 files changed

+311
-7
lines changed

CHANGELOG.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ Changes prior to 3.9.0 are documented as [release notes on GitHub](https://githu
99

1010
## 4.2.0 [Unreleased]
1111

12+
### Added
13+
14+
* To support incremental migration, the following entities are defined as equivalent to their renamed counterparts.
15+
- `bsoncxx::types::id`: equivalent to `bsoncxx::type`.
16+
- `bsoncxx::types::binary_subtype`: equivalent to `bsoncxx::binary_sub_type`.
17+
- `bsoncxx::types::view`: equivalent to `bsoncxx::types::bson_value::view`.
18+
- `bsoncxx::types::value`: equivalent to `bsoncxx::types::bson_value::value`.
19+
- `type_view()` in `bsoncxx::document::element` and `bsoncxx::array::element`: equivalent to `get_value()`.
20+
- `type_value()` in `bsoncxx::document::element` and `bsoncxx::array::element`: equivalent to `get_owning_value()`.
21+
1222
### Fixed
1323

1424
- CMake option `ENABLE_TESTS` (`OFF` by default) is no longer overwritten by the auto-downloaded C Driver (`ON` by default) during CMake configuration.
@@ -46,6 +56,13 @@ Changes prior to 3.9.0 are documented as [release notes on GitHub](https://githu
4656
return instance;
4757
}
4858
```
59+
- These following entities will be renamed (and removed) in an upcoming major release. To support incremental migration, both old and new names are still provided.
60+
- `bsoncxx::type` -> `bsoncxx::types::id`.
61+
- `bsoncxx::binary_sub_type` -> `bsoncxx::types::binary_subtype`.
62+
- `bsoncxx::types::bson_value::view` -> `bsoncxx::types::view`
63+
- `bsoncxx::types::bson_value::value` -> `bsoncxx::types::value`
64+
- `get_value()` -> `type_view()` in `bsoncxx::document::element` and `bsoncxx::array::element`.
65+
- `get_owning_value()` -> `type_value()` in `bsoncxx::document::element` and `bsoncxx::array::element`.
4966

5067
### Removed
5168

@@ -69,7 +86,6 @@ Changes prior to 3.9.0 are documented as [release notes on GitHub](https://githu
6986
- Static pkg-config files are updated to depend on the static (not shared) libbson / libmongoc packages.
7087
- Fix build if macros `GCC`/`GNU`/`Clang`/`MSVC` are already defined.
7188

72-
7389
## 4.1.0
7490

7591
### Fixed

src/bsoncxx/include/bsoncxx/docs/top.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@
8888
/// @namespace bsoncxx::types::bson_value
8989
/// Declares entities representing any BSON value type.
9090
///
91+
/// @deprecated Use @ref bsoncxx::types instead (renamed).
92+
///
9193

9294
///
9395
/// @namespace bsoncxx::vector

src/bsoncxx/include/bsoncxx/docs/v_noabi.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@
9595
/// @dir bsoncxx/v_noabi/bsoncxx/types/bson_value
9696
/// Provides headers declaring entities in @ref bsoncxx::v_noabi::types::bson_value.
9797
///
98+
/// @deprecated Use @ref bsoncxx/types/view.hpp or @ref bsoncxx/types/value.hpp instead.
99+
///
98100

99101
///
100102
/// @dir bsoncxx/v_noabi/bsoncxx/vector
@@ -153,6 +155,8 @@
153155
/// @namespace bsoncxx::v_noabi::types::bson_value
154156
/// Declares entities representing any BSON value type.
155157
///
158+
/// @deprecated Use @ref bsoncxx::v_noabi::types instead (renamed).
159+
///
156160

157161
///
158162
/// @namespace bsoncxx::v_noabi::vector

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ class element : private v_noabi::document::element {
7373

7474
using v_noabi::document::element::get_owning_value;
7575

76+
using v_noabi::document::element::type_view;
77+
78+
using v_noabi::document::element::type_value;
79+
7680
using v_noabi::document::element::operator[];
7781

7882
friend bool operator==(element const& lhs, v_noabi::types::bson_value::view const& rhs);

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ class element {
155155
/// Getter for a types::bson_value::view variant wrapper of the value portion of the
156156
/// element.
157157
///
158+
/// @deprecated Use @ref type_view() const instead (renamed).
159+
///
158160
/// @return the element's value.
159161
///
160162
BSONCXX_ABI_EXPORT_CDECL(v_noabi::types::bson_value::view) get_value() const;
@@ -163,10 +165,26 @@ class element {
163165
/// Getter for a types::bson_value::value variant wrapper of the value portion of
164166
/// the element. The returned object will make a copy of the buffer from this object.
165167
///
168+
/// @deprecated Use @ref type_value() const instead (renamed).
169+
///
166170
/// @return an owning version of the element's value.
167171
///
168172
BSONCXX_ABI_EXPORT_CDECL(v_noabi::types::bson_value::value) get_owning_value() const;
169173

174+
///
175+
/// Equivalent to @ref get_value() const.
176+
///
177+
/// To support incremental migration to @ref bsoncxx::v1::element::view::type_view() const.
178+
///
179+
BSONCXX_ABI_EXPORT_CDECL(v_noabi::types::bson_value::view) type_view() const;
180+
181+
///
182+
/// Equivalent to @ref get_owning_value() const.
183+
///
184+
/// To support incremental migration to @ref bsoncxx::v1::element::view::type_value() const.
185+
///
186+
BSONCXX_ABI_EXPORT_CDECL(v_noabi::types::bson_value::value) type_value() const;
187+
170188
///
171189
/// If this element is a document, finds the first element of the document
172190
/// with the provided key. If there is no such element, an invalid

src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/oid.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ class oid {
122122
return reinterpret_cast<char const*>(_oid.bytes());
123123
}
124124

125+
///
126+
/// Equivalent to [`bson_oid_compare`](https://mongoc.org/libbson/current/bson_oid_compare.html).
127+
///
128+
int compare(oid const& other) const {
129+
return _oid.compare(other._oid);
130+
}
131+
125132
///
126133
/// @relates bsoncxx::v_noabi::oid
127134
///

src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/types-fwd.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@ namespace bsoncxx {
3333
namespace v_noabi {
3434
namespace types {
3535

36+
///
37+
/// Equivalent to @ref bsoncxx::v_noabi::type.
38+
///
39+
/// To support incremental migration to @ref bsoncxx::v1::types::id.
40+
///
41+
using id = v_noabi::type;
42+
43+
///
44+
/// Equivalent to @ref bsoncxx::v_noabi::binary_sub_type.
45+
///
46+
/// To support incremental migration to @ref bsoncxx::v1::types::binary_subtype.
47+
///
48+
using binary_subtype = v_noabi::binary_sub_type;
49+
3650
struct b_double;
3751
struct b_string;
3852
struct b_document;
@@ -69,6 +83,9 @@ using v_noabi::type;
6983
namespace bsoncxx {
7084
namespace types {
7185

86+
using v_noabi::types::binary_subtype;
87+
using v_noabi::types::id;
88+
7289
using v_noabi::types::b_array;
7390
using v_noabi::types::b_binary;
7491
using v_noabi::types::b_bool;
@@ -100,6 +117,8 @@ using v_noabi::types::b_undefined;
100117
/// @file
101118
/// Declares entities used to represent BSON types.
102119
///
120+
/// @deprecated Use @ref bsoncxx/types/id-fwd.hpp or @ref bsoncxx/types/view-fwd.hpp instead.
121+
///
103122
/// @par Includes
104123
/// - @ref bsoncxx/v1/types/view-fwd.hpp
105124
///

src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/types.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ namespace v_noabi {
4242
///
4343
/// @showenumvalues
4444
///
45+
/// @deprecated Use @ref bsoncxx::v_noabi::types::id instead (renamed).
46+
///
4547
enum class type : std::uint8_t {
4648
k_double = 0x01, ///< 64-bit binary floating point.
4749
k_string = 0x02, ///< UTF-8 string.
@@ -71,6 +73,8 @@ enum class type : std::uint8_t {
7173
///
7274
/// @showenumvalues
7375
///
76+
/// @deprecated Use @ref bsoncxx::v_noabi::types::binary_subtype instead (renamed).
77+
///
7478
enum class binary_sub_type : std::uint8_t {
7579
k_binary = 0x00, ///< Generic binary subtype.
7680
k_function = 0x01, ///< Function.
@@ -1105,6 +1109,8 @@ using v_noabi::types::operator!=;
11051109
/// @file
11061110
/// Provides entities used to represent BSON types.
11071111
///
1112+
/// @deprecated Use @ref bsoncxx/types/id.hpp or @ref bsoncxx/types/view.hpp instead.
1113+
///
11081114
/// @par Includes
11091115
/// - @ref bsoncxx/v1/types/view.hpp
11101116
///

src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/types/bson_value/value-fwd.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ class value;
2727

2828
} // namespace bson_value
2929

30-
using bson_value::value;
30+
///
31+
/// Equivalent to @ref bsoncxx::v_noabi::types::bson_value::value.
32+
///
33+
/// To support incremental migration to @ref bsoncxx::v1::types::value.
34+
///
35+
using value = bson_value::value;
3136

3237
} // namespace types
3338
} // namespace v_noabi
@@ -41,7 +46,7 @@ using v_noabi::types::bson_value::value;
4146

4247
} // namespace bson_value
4348

44-
using bson_value::value;
49+
using v_noabi::types::value;
4550

4651
} // namespace types
4752
} // namespace bsoncxx
@@ -52,6 +57,8 @@ using bson_value::value;
5257
/// @file
5358
/// Declares @ref bsoncxx::v_noabi::types::bson_value::value.
5459
///
60+
/// @deprecated Use @ref bsoncxx/types/value-fwd.hpp instead (renamed).
61+
///
5562
/// @par Includes
5663
/// - @ref bsoncxx/v1/types/value-fwd.hpp
5764
///

src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/types/bson_value/value.hpp

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ namespace bson_value {
4949
/// For accessors into this type and to extract the various BSON types out,
5050
/// please use bson_value::view.
5151
///
52+
/// @deprecated Use @ref bsoncxx::v_noabi::types::value instead (renamed).
53+
///
5254
/// @see
5355
/// - @ref bsoncxx::v_noabi::types::bson_value::view
5456
///
@@ -254,7 +256,7 @@ class value {
254256
/// @throws bsoncxx::v_noabi::exception if the type's value is not k_maxkey, k_minkey, or
255257
/// k_undefined.
256258
///
257-
/* explicit(false) */ BSONCXX_ABI_EXPORT_CDECL() value(type const id);
259+
/* explicit(false) */ BSONCXX_ABI_EXPORT_CDECL() value(v_noabi::type const id);
258260

259261
///
260262
/// Constructs one of the following BSON values (each specified by the parenthesized type):
@@ -297,6 +299,24 @@ class value {
297299
return _value;
298300
}
299301

302+
///
303+
/// Returns the type of the underlying BSON value stored in this object.
304+
///
305+
/// @deprecated Use @ref type_id() const instead (renamed).
306+
///
307+
v_noabi::type type() const {
308+
return this->view().type();
309+
}
310+
311+
///
312+
/// Equivalent to @ref type() const.
313+
///
314+
/// To support incremental migration to @ref bsoncxx::v1::types::value.
315+
///
316+
v_noabi::type type_id() const {
317+
return this->view().type_id();
318+
}
319+
300320
///
301321
/// Get a view over the bson_value owned by this object.
302322
///
@@ -310,6 +330,25 @@ class value {
310330
/* explicit(false) */ operator v_noabi::types::bson_value::view() const noexcept {
311331
return _value.view();
312332
}
333+
334+
#pragma push_macro("X")
335+
#undef X
336+
#define X(_name, _value) \
337+
v_noabi::types::b_##_name const& get_##_name() const { \
338+
return this->view().get_##_name(); \
339+
}
340+
341+
///
342+
/// Return the underlying BSON type value.
343+
///
344+
/// @warning
345+
/// Calling the wrong get_<type> method will cause an exception to be thrown.
346+
///
347+
/// @{
348+
BSONCXX_V1_TYPES_XMACRO(X)
349+
/// @}
350+
///
351+
#pragma pop_macro("X")
313352
};
314353

315354
///
@@ -400,6 +439,8 @@ using v_noabi::types::bson_value::operator!=;
400439
/// @file
401440
/// Provides @ref bsoncxx::v_noabi::types::bson_value::value.
402441
///
442+
/// @deprecated Use @ref bsoncxx/types/value.hpp instead (renamed).
443+
///
403444
/// @par Includes
404445
/// - @ref bsoncxx/v1/types/value.hpp
405446
///

0 commit comments

Comments
 (0)