Skip to content

Commit 4e8f2ca

Browse files
authored
v1: delete_many_options and delete_one_options (CXX-3237, CXX-3238) (#1527)
1 parent 1c31e7c commit 4e8f2ca

File tree

12 files changed

+859
-67
lines changed

12 files changed

+859
-67
lines changed

src/mongocxx/include/mongocxx/v1/delete_many_options.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ class delete_many_options {
146146
/// Return the current "comment" field.
147147
///
148148
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::types::view> const) comment() const;
149+
150+
class internal;
149151
};
150152

151153
} // namespace v1

src/mongocxx/include/mongocxx/v1/delete_one_options.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class delete_one_options {
110110
///
111111
/// Set the "writeConcern" field.
112112
///
113-
MONGOCXX_ABI_EXPORT_CDECL(delete_one_options&) write_concern(write_concern wc);
113+
MONGOCXX_ABI_EXPORT_CDECL(delete_one_options&) write_concern(v1::write_concern wc);
114114

115115
///
116116
/// Return the current "writeConcern" field.
@@ -146,6 +146,8 @@ class delete_one_options {
146146
/// Return the current "comment" field.
147147
///
148148
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::types::view> const) comment() const;
149+
150+
class internal;
149151
};
150152

151153
} // namespace v1

src/mongocxx/include/mongocxx/v_noabi/mongocxx/options/delete-fwd.hpp

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

1515
#pragma once
1616

17+
#include <mongocxx/v1/delete_many_options-fwd.hpp> // IWYU pragma: export
18+
#include <mongocxx/v1/delete_one_options-fwd.hpp> // IWYU pragma: export
19+
1720
#include <mongocxx/config/prelude.hpp>
1821

1922
namespace mongocxx {
@@ -29,7 +32,7 @@ class delete_options;
2932
namespace mongocxx {
3033
namespace options {
3134

32-
using ::mongocxx::v_noabi::options::delete_options;
35+
using v_noabi::options::delete_options;
3336

3437
} // namespace options
3538
} // namespace mongocxx
@@ -40,3 +43,7 @@ using ::mongocxx::v_noabi::options::delete_options;
4043
/// @file
4144
/// Declares @ref mongocxx::v_noabi::options::delete_options.
4245
///
46+
/// @par Includes
47+
/// - @ref mongocxx/v1/delete_many_options-fwd.hpp
48+
/// - @ref mongocxx/v1/delete_one_options-fwd.hpp
49+
///

src/mongocxx/include/mongocxx/v_noabi/mongocxx/options/delete.hpp

Lines changed: 158 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,20 @@
1616

1717
#include <mongocxx/options/delete-fwd.hpp> // IWYU pragma: export
1818

19+
//
20+
21+
#include <bsoncxx/v1/document/value.hpp>
22+
#include <bsoncxx/v1/types/value.hpp>
23+
24+
#include <mongocxx/v1/delete_many_options.hpp> // IWYU pragma: export
25+
#include <mongocxx/v1/delete_one_options.hpp> // IWYU pragma: export
26+
27+
#include <utility>
28+
29+
#include <bsoncxx/document/view.hpp>
1930
#include <bsoncxx/document/view_or_value.hpp>
2031
#include <bsoncxx/stdx/optional.hpp>
32+
#include <bsoncxx/types/bson_value/view.hpp>
2133
#include <bsoncxx/types/bson_value/view_or_value.hpp>
2234

2335
#include <mongocxx/hint.hpp>
@@ -34,6 +46,85 @@ namespace options {
3446
///
3547
class delete_options {
3648
public:
49+
///
50+
/// Default initialization.
51+
///
52+
delete_options() = default;
53+
54+
///
55+
/// Construct with the @ref mongocxx::v1 equivalent.
56+
///
57+
/* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() delete_options(v1::delete_many_options opts);
58+
59+
///
60+
/// Construct with the @ref mongocxx::v1 equivalent.
61+
///
62+
/* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() delete_options(v1::delete_one_options opts);
63+
64+
///
65+
/// Convert to the @ref mongocxx::v1 equivalent.
66+
///
67+
explicit operator v1::delete_many_options() const {
68+
using bsoncxx::v_noabi::to_v1;
69+
using mongocxx::v_noabi::to_v1;
70+
71+
v1::delete_many_options ret;
72+
73+
if (_collation) {
74+
ret.collation(bsoncxx::v1::document::value{to_v1(_collation->view())});
75+
}
76+
77+
if (_write_concern) {
78+
ret.write_concern(to_v1(*_write_concern));
79+
}
80+
81+
if (_hint) {
82+
ret.hint(to_v1(*_hint));
83+
}
84+
85+
if (_let) {
86+
ret.let(bsoncxx::v1::document::value{to_v1(_let->view())});
87+
}
88+
89+
if (_comment) {
90+
ret.comment(bsoncxx::v1::types::value{to_v1(_comment->view())});
91+
}
92+
93+
return ret;
94+
}
95+
96+
///
97+
/// Convert to the @ref mongocxx::v1 equivalent.
98+
///
99+
explicit operator v1::delete_one_options() const {
100+
using bsoncxx::v_noabi::to_v1;
101+
using mongocxx::v_noabi::to_v1;
102+
103+
v1::delete_one_options ret;
104+
105+
if (_collation) {
106+
ret.collation(bsoncxx::v1::document::value{to_v1(_collation->view())});
107+
}
108+
109+
if (_write_concern) {
110+
ret.write_concern(to_v1(*_write_concern));
111+
}
112+
113+
if (_hint) {
114+
ret.hint(to_v1(*_hint));
115+
}
116+
117+
if (_let) {
118+
ret.let(bsoncxx::v1::document::value{to_v1(_let->view())});
119+
}
120+
121+
if (_comment) {
122+
ret.comment(bsoncxx::v1::types::value{to_v1(_comment->view())});
123+
}
124+
125+
return ret;
126+
}
127+
37128
///
38129
/// Sets the collation for this operation.
39130
///
@@ -47,8 +138,10 @@ class delete_options {
47138
/// @see
48139
/// - https://www.mongodb.com/docs/manual/reference/collation/
49140
///
50-
MONGOCXX_ABI_EXPORT_CDECL(delete_options&)
51-
collation(bsoncxx::v_noabi::document::view_or_value collation);
141+
delete_options& collation(bsoncxx::v_noabi::document::view_or_value collation) {
142+
_collation = std::move(collation);
143+
return *this;
144+
}
52145

53146
///
54147
/// Retrieves the current collation for this operation.
@@ -59,8 +152,9 @@ class delete_options {
59152
/// @see
60153
/// - https://www.mongodb.com/docs/manual/reference/collation/
61154
///
62-
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> const&)
63-
collation() const;
155+
bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> const& collation() const {
156+
return _collation;
157+
}
64158

65159
///
66160
/// Sets the write_concern for this operation.
@@ -75,7 +169,10 @@ class delete_options {
75169
/// @see
76170
/// - https://www.mongodb.com/docs/manual/core/write-concern/
77171
///
78-
MONGOCXX_ABI_EXPORT_CDECL(delete_options&) write_concern(write_concern wc);
172+
delete_options& write_concern(write_concern wc) {
173+
_write_concern = std::move(wc);
174+
return *this;
175+
}
79176

80177
///
81178
/// The current write_concern for this operation.
@@ -86,8 +183,9 @@ class delete_options {
86183
/// @see
87184
/// - https://www.mongodb.com/docs/manual/core/write-concern/
88185
///
89-
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::stdx::optional<mongocxx::v_noabi::write_concern> const&)
90-
write_concern() const;
186+
bsoncxx::v_noabi::stdx::optional<v_noabi::write_concern> const& write_concern() const {
187+
return _write_concern;
188+
}
91189

92190
///
93191
/// Sets the index to use for this operation.
@@ -102,15 +200,19 @@ class delete_options {
102200
/// A reference to the object on which this member function is being called. This facilitates
103201
/// method chaining.
104202
///
105-
MONGOCXX_ABI_EXPORT_CDECL(delete_options&) hint(mongocxx::v_noabi::hint index_hint);
203+
delete_options& hint(v_noabi::hint index_hint) {
204+
_hint = std::move(index_hint);
205+
return *this;
206+
}
106207

107208
///
108209
/// Gets the current hint.
109210
///
110211
/// @return The current hint, if one is set.
111212
///
112-
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::stdx::optional<mongocxx::v_noabi::hint> const&)
113-
hint() const;
213+
bsoncxx::v_noabi::stdx::optional<v_noabi::hint> const& hint() const {
214+
return _hint;
215+
}
114216

115217
///
116218
/// Set the value of the let option.
@@ -122,16 +224,20 @@ class delete_options {
122224
/// A reference to the object on which this member function is being called. This facilitates
123225
/// method chaining.
124226
///
125-
MONGOCXX_ABI_EXPORT_CDECL(delete_options&) let(bsoncxx::v_noabi::document::view_or_value let);
227+
delete_options& let(bsoncxx::v_noabi::document::view_or_value let) {
228+
_let = std::move(let);
229+
return *this;
230+
}
126231

127232
///
128233
/// Gets the current value of the let option.
129234
///
130235
/// @return
131236
/// The current let option.
132237
///
133-
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> const)
134-
let() const;
238+
bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> const let() const {
239+
return _let;
240+
}
135241

136242
///
137243
/// Set the value of the comment option.
@@ -143,22 +249,25 @@ class delete_options {
143249
/// A reference to the object on which this member function is being called. This facilitates
144250
/// method chaining.
145251
///
146-
MONGOCXX_ABI_EXPORT_CDECL(delete_options&)
147-
comment(bsoncxx::v_noabi::types::bson_value::view_or_value comment);
252+
delete_options& comment(bsoncxx::v_noabi::types::bson_value::view_or_value comment) {
253+
_comment = std::move(comment);
254+
return *this;
255+
}
148256

149257
///
150258
/// Gets the current value of the comment option.
151259
///
152260
/// @return
153261
/// The current comment option.
154262
///
155-
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::types::bson_value::view_or_value> const)
156-
comment() const;
263+
bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::types::bson_value::view_or_value> const comment() const {
264+
return _comment;
265+
}
157266

158267
private:
159268
bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> _collation;
160-
bsoncxx::v_noabi::stdx::optional<mongocxx::v_noabi::write_concern> _write_concern;
161-
bsoncxx::v_noabi::stdx::optional<mongocxx::v_noabi::hint> _hint;
269+
bsoncxx::v_noabi::stdx::optional<v_noabi::write_concern> _write_concern;
270+
bsoncxx::v_noabi::stdx::optional<v_noabi::hint> _hint;
162271
bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> _let;
163272
bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::types::bson_value::view_or_value> _comment;
164273
};
@@ -167,9 +276,39 @@ class delete_options {
167276
} // namespace v_noabi
168277
} // namespace mongocxx
169278

279+
namespace mongocxx {
280+
namespace v_noabi {
281+
282+
///
283+
/// Convert to the @ref mongocxx::v_noabi equivalent of `v`.
284+
///
285+
inline v_noabi::options::delete_options from_v1(v1::delete_many_options v) {
286+
return {std::move(v)};
287+
}
288+
289+
///
290+
/// Convert to the @ref mongocxx::v_noabi equivalent of `v`.
291+
///
292+
inline v_noabi::options::delete_options from_v1(v1::delete_one_options v) {
293+
return {std::move(v)};
294+
}
295+
296+
// Ambiguous whether `v_noabi::options::delete_options` should be converted to `v1::delete_many_options` or
297+
// `v1::delete_one_options`. Require users to explicitly cast to the expected type instead.
298+
//
299+
// v1::delete_many_options to_v1(v_noabi::options::delete_options const& v);
300+
// v1::delete_one_options to_v1(v_noabi::options::delete_options const& v);
301+
302+
} // namespace v_noabi
303+
} // namespace mongocxx
304+
170305
#include <mongocxx/config/postlude.hpp>
171306

172307
///
173308
/// @file
174309
/// Provides @ref mongocxx::v_noabi::options::delete_options.
175310
///
311+
/// @par Includes
312+
/// - @ref mongocxx/v1/delete_many_options.hpp
313+
/// - @ref mongocxx/v1/delete_one_options.hpp
314+
///

0 commit comments

Comments
 (0)