Skip to content

Commit a86102c

Browse files
authored
v1: find_one_and_delete_options (CXX-3237, CXX-3238) (#1526)
1 parent 86ac281 commit a86102c

File tree

8 files changed

+599
-109
lines changed

8 files changed

+599
-109
lines changed

src/mongocxx/include/mongocxx/v1/find_one_and_delete_options.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ class find_one_and_delete_options {
182182
/// Return the current "comment" field.
183183
///
184184
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::types::view> const) comment() const;
185+
186+
class internal;
185187
};
186188

187189
} // namespace v1

src/mongocxx/include/mongocxx/v_noabi/mongocxx/options/find_one_and_delete-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 <mongocxx/v1/find_one_and_delete_options-fwd.hpp> // IWYU pragma: export
18+
1719
#include <mongocxx/config/prelude.hpp>
1820

1921
namespace mongocxx {
@@ -29,7 +31,7 @@ class find_one_and_delete;
2931
namespace mongocxx {
3032
namespace options {
3133

32-
using ::mongocxx::v_noabi::options::find_one_and_delete;
34+
using v_noabi::options::find_one_and_delete;
3335

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

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

Lines changed: 147 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,23 @@
1414

1515
#pragma once
1616

17+
#include <mongocxx/options/find_one_and_delete-fwd.hpp> // IWYU pragma: export
18+
19+
//
20+
21+
#include <bsoncxx/v1/document/value.hpp>
22+
#include <bsoncxx/v1/types/value.hpp>
23+
24+
#include <mongocxx/v1/find_one_and_delete_options.hpp> // IWYU pragma: export
25+
1726
#include <chrono>
1827
#include <cstdint> // IWYU pragma: keep: backward compatibility, to be removed.
28+
#include <utility>
1929

20-
#include <mongocxx/options/find_one_and_delete-fwd.hpp> // IWYU pragma: export
21-
30+
#include <bsoncxx/document/view.hpp>
2231
#include <bsoncxx/document/view_or_value.hpp>
2332
#include <bsoncxx/stdx/optional.hpp>
33+
#include <bsoncxx/types/bson_value/view.hpp>
2434
#include <bsoncxx/types/bson_value/view_or_value.hpp>
2535

2636
#include <mongocxx/hint.hpp>
@@ -37,6 +47,60 @@ namespace options {
3747
///
3848
class find_one_and_delete {
3949
public:
50+
///
51+
/// Default initialization.
52+
///
53+
find_one_and_delete() = default;
54+
55+
///
56+
/// Construct with the @ref mongocxx::v1 equivalent.
57+
///
58+
/* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() find_one_and_delete(v1::find_one_and_delete_options opts);
59+
60+
///
61+
/// Convert to the @ref mongocxx::v1 equivalent.
62+
///
63+
explicit operator v1::find_one_and_delete_options() const {
64+
using bsoncxx::v_noabi::to_v1;
65+
using mongocxx::v_noabi::to_v1;
66+
67+
v1::find_one_and_delete_options ret;
68+
69+
if (_collation) {
70+
ret.collation(bsoncxx::v1::document::value{to_v1(_collation->view())});
71+
}
72+
73+
if (_max_time) {
74+
ret.max_time(*_max_time);
75+
}
76+
77+
if (_projection) {
78+
ret.projection(bsoncxx::v1::document::value{to_v1(_projection->view())});
79+
}
80+
81+
if (_ordering) {
82+
ret.sort(bsoncxx::v1::document::value{to_v1(_ordering->view())});
83+
}
84+
85+
if (_write_concern) {
86+
ret.write_concern(to_v1(*_write_concern));
87+
}
88+
89+
if (_hint) {
90+
ret.hint(to_v1(*_hint));
91+
}
92+
93+
if (_let) {
94+
ret.let(bsoncxx::v1::document::value{to_v1(_let->view())});
95+
}
96+
97+
if (_comment) {
98+
ret.comment(bsoncxx::v1::types::value{to_v1(_comment->view())});
99+
}
100+
101+
return ret;
102+
}
103+
40104
/// Sets the collation for this operation.
41105
///
42106
/// @param collation
@@ -49,8 +113,10 @@ class find_one_and_delete {
49113
/// @see
50114
/// - https://www.mongodb.com/docs/manual/reference/command/findAndModify/
51115
///
52-
MONGOCXX_ABI_EXPORT_CDECL(find_one_and_delete&)
53-
collation(bsoncxx::v_noabi::document::view_or_value collation);
116+
find_one_and_delete& collation(bsoncxx::v_noabi::document::view_or_value collation) {
117+
_collation = std::move(collation);
118+
return *this;
119+
}
54120

55121
///
56122
/// Retrieves the current collation for this operation.
@@ -61,8 +127,9 @@ class find_one_and_delete {
61127
/// @see
62128
/// - https://www.mongodb.com/docs/manual/reference/command/findAndModify/
63129
///
64-
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> const&)
65-
collation() const;
130+
bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> const& collation() const {
131+
return _collation;
132+
}
66133

67134
///
68135
/// Sets the maximum amount of time for this operation to run (server-side) in milliseconds.
@@ -77,7 +144,10 @@ class find_one_and_delete {
77144
/// @see
78145
/// - https://www.mongodb.com/docs/manual/reference/command/findAndModify/
79146
///
80-
MONGOCXX_ABI_EXPORT_CDECL(find_one_and_delete&) max_time(std::chrono::milliseconds max_time);
147+
find_one_and_delete& max_time(std::chrono::milliseconds max_time) {
148+
_max_time = max_time;
149+
return *this;
150+
}
81151

82152
///
83153
/// The current max_time setting.
@@ -87,8 +157,9 @@ class find_one_and_delete {
87157
/// @see
88158
/// - https://www.mongodb.com/docs/manual/reference/command/findAndModify/
89159
///
90-
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::stdx::optional<std::chrono::milliseconds> const&)
91-
max_time() const;
160+
bsoncxx::v_noabi::stdx::optional<std::chrono::milliseconds> const& max_time() const {
161+
return _max_time;
162+
}
92163

93164
///
94165
/// Sets a projection that limits the fields to return.
@@ -103,8 +174,10 @@ class find_one_and_delete {
103174
/// @see
104175
/// - https://www.mongodb.com/docs/manual/reference/command/findAndModify/
105176
///
106-
MONGOCXX_ABI_EXPORT_CDECL(find_one_and_delete&)
107-
projection(bsoncxx::v_noabi::document::view_or_value projection);
177+
find_one_and_delete& projection(bsoncxx::v_noabi::document::view_or_value projection) {
178+
_projection = std::move(projection);
179+
return *this;
180+
}
108181

109182
///
110183
/// Gets the current projection set on this operation.
@@ -114,8 +187,9 @@ class find_one_and_delete {
114187
/// @see
115188
/// - https://www.mongodb.com/docs/manual/reference/command/findAndModify/
116189
///
117-
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> const&)
118-
projection() const;
190+
bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> const& projection() const {
191+
return _projection;
192+
}
119193

120194
///
121195
/// Sets the order to search for a matching document.
@@ -133,8 +207,10 @@ class find_one_and_delete {
133207
/// @see
134208
/// - https://www.mongodb.com/docs/manual/reference/command/findAndModify/
135209
///
136-
MONGOCXX_ABI_EXPORT_CDECL(find_one_and_delete&)
137-
sort(bsoncxx::v_noabi::document::view_or_value ordering);
210+
find_one_and_delete& sort(bsoncxx::v_noabi::document::view_or_value ordering) {
211+
_ordering = std::move(ordering);
212+
return *this;
213+
}
138214

139215
///
140216
/// Gets the current sort ordering.
@@ -144,8 +220,9 @@ class find_one_and_delete {
144220
/// @see
145221
/// - https://www.mongodb.com/docs/manual/reference/command/findAndModify/
146222
///
147-
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> const&)
148-
sort() const;
223+
bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> const& sort() const {
224+
return _ordering;
225+
}
149226

150227
///
151228
/// Sets the write concern for this operation.
@@ -160,8 +237,10 @@ class find_one_and_delete {
160237
/// @see
161238
/// - https://www.mongodb.com/docs/manual/reference/command/findAndModify/
162239
///
163-
MONGOCXX_ABI_EXPORT_CDECL(find_one_and_delete&)
164-
write_concern(mongocxx::v_noabi::write_concern write_concern);
240+
find_one_and_delete& write_concern(v_noabi::write_concern write_concern) {
241+
_write_concern = std::move(write_concern);
242+
return *this;
243+
}
165244

166245
///
167246
/// Gets the current write concern.
@@ -172,8 +251,9 @@ class find_one_and_delete {
172251
/// @see
173252
/// - https://www.mongodb.com/docs/manual/reference/command/findAndModify/
174253
///
175-
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::stdx::optional<mongocxx::v_noabi::write_concern> const&)
176-
write_concern() const;
254+
bsoncxx::v_noabi::stdx::optional<v_noabi::write_concern> const& write_concern() const {
255+
return _write_concern;
256+
}
177257

178258
///
179259
/// Sets the index to use for this operation.
@@ -188,15 +268,19 @@ class find_one_and_delete {
188268
/// A reference to the object on which this member function is being called. This facilitates
189269
/// method chaining.
190270
///
191-
MONGOCXX_ABI_EXPORT_CDECL(find_one_and_delete&) hint(mongocxx::v_noabi::hint index_hint);
271+
find_one_and_delete& hint(v_noabi::hint index_hint) {
272+
_hint = std::move(index_hint);
273+
return *this;
274+
}
192275

193276
///
194277
/// Gets the current hint.
195278
///
196279
/// @return The current hint, if one is set.
197280
///
198-
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::stdx::optional<mongocxx::v_noabi::hint> const&)
199-
hint() const;
281+
bsoncxx::v_noabi::stdx::optional<v_noabi::hint> const& hint() const {
282+
return _hint;
283+
}
200284

201285
///
202286
/// Set the value of the let option.
@@ -208,17 +292,20 @@ class find_one_and_delete {
208292
/// A reference to the object on which this member function is being called. This facilitates
209293
/// method chaining.
210294
///
211-
MONGOCXX_ABI_EXPORT_CDECL(find_one_and_delete&)
212-
let(bsoncxx::v_noabi::document::view_or_value let);
295+
find_one_and_delete& let(bsoncxx::v_noabi::document::view_or_value let) {
296+
_let = std::move(let);
297+
return *this;
298+
}
213299

214300
///
215301
/// Gets the current value of the let option.
216302
///
217303
/// @return
218304
/// The current let option.
219305
///
220-
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> const)
221-
let() const;
306+
bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> const let() const {
307+
return _let;
308+
}
222309

223310
///
224311
/// Set the value of the comment option.
@@ -230,25 +317,28 @@ class find_one_and_delete {
230317
/// A reference to the object on which this member function is being called. This facilitates
231318
/// method chaining.
232319
///
233-
MONGOCXX_ABI_EXPORT_CDECL(find_one_and_delete&)
234-
comment(bsoncxx::v_noabi::types::bson_value::view_or_value comment);
320+
find_one_and_delete& comment(bsoncxx::v_noabi::types::bson_value::view_or_value comment) {
321+
_comment = std::move(comment);
322+
return *this;
323+
}
235324

236325
///
237326
/// Gets the current value of the comment option.
238327
///
239328
/// @return
240329
/// The current comment option.
241330
///
242-
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::types::bson_value::view_or_value> const)
243-
comment() const;
331+
bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::types::bson_value::view_or_value> const comment() const {
332+
return _comment;
333+
}
244334

245335
private:
246336
bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> _collation;
247337
bsoncxx::v_noabi::stdx::optional<std::chrono::milliseconds> _max_time;
248338
bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> _projection;
249339
bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> _ordering;
250-
bsoncxx::v_noabi::stdx::optional<mongocxx::v_noabi::write_concern> _write_concern;
251-
bsoncxx::v_noabi::stdx::optional<mongocxx::v_noabi::hint> _hint;
340+
bsoncxx::v_noabi::stdx::optional<v_noabi::write_concern> _write_concern;
341+
bsoncxx::v_noabi::stdx::optional<v_noabi::hint> _hint;
252342
bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> _let;
253343
bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::types::bson_value::view_or_value> _comment;
254344
};
@@ -257,9 +347,32 @@ class find_one_and_delete {
257347
} // namespace v_noabi
258348
} // namespace mongocxx
259349

350+
namespace mongocxx {
351+
namespace v_noabi {
352+
353+
///
354+
/// Convert to the @ref mongocxx::v_noabi equivalent of `v`.
355+
///
356+
inline v_noabi::options::find_one_and_delete from_v1(v1::find_one_and_delete_options v) {
357+
return {std::move(v)};
358+
}
359+
360+
///
361+
/// Convert to the @ref mongocxx::v1 equivalent of `v`.
362+
///
363+
inline v1::find_one_and_delete_options to_v1(v_noabi::options::find_one_and_delete const& v) {
364+
return v1::find_one_and_delete_options{v};
365+
}
366+
367+
} // namespace v_noabi
368+
} // namespace mongocxx
369+
260370
#include <mongocxx/config/postlude.hpp>
261371

262372
///
263373
/// @file
264374
/// Provides @ref mongocxx::v_noabi::options::find_one_and_delete.
265375
///
376+
/// @par Includes
377+
/// - @ref mongocxx/v1/find_one_and_delete_options.hpp
378+
///

0 commit comments

Comments
 (0)