1616
1717#include < mongocxx/options/replace-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/replace_one_options.hpp> // IWYU pragma: export
25+
26+ #include < utility>
27+
1928#include < bsoncxx/array/view_or_value.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
29+ #include < bsoncxx/document/view.hpp>
2030#include < bsoncxx/document/view_or_value.hpp>
2131#include < bsoncxx/stdx/optional.hpp>
32+ #include < bsoncxx/types/bson_value/view.hpp>
2233#include < bsoncxx/types/bson_value/view_or_value.hpp>
2334
2435#include < mongocxx/hint.hpp>
@@ -35,6 +46,60 @@ namespace options {
3546// /
3647class replace {
3748 public:
49+ // /
50+ // / Default initialization.
51+ // /
52+ replace () = default ;
53+
54+ // /
55+ // / Construct with the @ref mongocxx::v1 equivalent.
56+ // /
57+ /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() replace(v1::replace_one_options opts);
58+
59+ // /
60+ // / Convert to the @ref mongocxx::v1 equivalent.
61+ // /
62+ explicit operator v1::replace_one_options () const {
63+ using bsoncxx::v_noabi::to_v1;
64+ using mongocxx::v_noabi::to_v1;
65+
66+ v1::replace_one_options ret;
67+
68+ if (_bypass_document_validation) {
69+ ret.bypass_document_validation (*_bypass_document_validation);
70+ }
71+
72+ if (_collation) {
73+ ret.collation (bsoncxx::v1::document::value{to_v1 (_collation->view ())});
74+ }
75+
76+ if (_upsert) {
77+ ret.upsert (*_upsert);
78+ }
79+
80+ if (_write_concern) {
81+ ret.write_concern (to_v1 (*_write_concern));
82+ }
83+
84+ if (_hint) {
85+ ret.hint (to_v1 (*_hint));
86+ }
87+
88+ if (_let) {
89+ ret.let (bsoncxx::v1::document::value{to_v1 (_let->view ())});
90+ }
91+
92+ if (_sort) {
93+ ret.sort (bsoncxx::v1::document::value{to_v1 (_sort->view ())});
94+ }
95+
96+ if (_comment) {
97+ ret.comment (bsoncxx::v1::types::value{to_v1 (_comment->view ())});
98+ }
99+
100+ return ret;
101+ }
102+
38103 // /
39104 // / Sets the bypass_document_validation option.
40105 // / If true, allows the write to opt-out of document level validation.
@@ -50,15 +115,19 @@ class replace {
50115 // / A reference to the object on which this member function is being called. This facilitates
51116 // / method chaining.
52117 // /
53- MONGOCXX_ABI_EXPORT_CDECL (replace&) bypass_document_validation(bool bypass_document_validation);
118+ replace& bypass_document_validation (bool bypass_document_validation) {
119+ _bypass_document_validation = bypass_document_validation;
120+ return *this ;
121+ }
54122
55123 // /
56124 // / Gets the current value of the bypass_document_validation option.
57125 // /
58126 // / @return The optional value of the bypass_document_validation option.
59127 // /
60- MONGOCXX_ABI_EXPORT_CDECL (bsoncxx::v_noabi::stdx::optional<bool > const &)
61- bypass_document_validation () const ;
128+ bsoncxx::v_noabi::stdx::optional<bool > const & bypass_document_validation () const {
129+ return _bypass_document_validation;
130+ }
62131
63132 // /
64133 // / Sets the collation for this operation.
@@ -73,8 +142,10 @@ class replace {
73142 // / @see
74143 // / - https://www.mongodb.com/docs/manual/reference/collation/
75144 // /
76- MONGOCXX_ABI_EXPORT_CDECL (replace&)
77- collation (bsoncxx::v_noabi::document::view_or_value collation);
145+ replace& collation (bsoncxx::v_noabi::document::view_or_value collation) {
146+ _collation = std::move (collation);
147+ return *this ;
148+ }
78149
79150 // /
80151 // / Retrieves the current collation for this operation.
@@ -85,8 +156,9 @@ class replace {
85156 // / @see
86157 // / - https://www.mongodb.com/docs/manual/reference/collation/
87158 // /
88- MONGOCXX_ABI_EXPORT_CDECL (bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> const &)
89- collation () const ;
159+ bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> const & collation () const {
160+ return _collation;
161+ }
90162
91163 // /
92164 // / Sets the upsert option.
@@ -104,14 +176,19 @@ class replace {
104176 // / A reference to the object on which this member function is being called. This facilitates
105177 // / method chaining.
106178 // /
107- MONGOCXX_ABI_EXPORT_CDECL (replace&) upsert(bool upsert);
179+ replace& upsert (bool upsert) {
180+ _upsert = upsert;
181+ return *this ;
182+ }
108183
109184 // /
110185 // / Gets the current value of the upsert option.
111186 // /
112187 // / @return The optional value of the upsert option.
113188 // /
114- MONGOCXX_ABI_EXPORT_CDECL (bsoncxx::v_noabi::stdx::optional<bool > const &) upsert() const ;
189+ bsoncxx::v_noabi::stdx::optional<bool > const & upsert () const {
190+ return _upsert;
191+ }
115192
116193 // /
117194 // / Sets the write_concern for this operation.
@@ -126,7 +203,10 @@ class replace {
126203 // / @see
127204 // / - https://www.mongodb.com/docs/manual/core/write-concern/
128205 // /
129- MONGOCXX_ABI_EXPORT_CDECL (replace&) write_concern(mongocxx::v_noabi::write_concern wc);
206+ replace& write_concern (v_noabi::write_concern wc) {
207+ _write_concern = std::move (wc);
208+ return *this ;
209+ }
130210
131211 // /
132212 // / The current write_concern for this operation.
@@ -137,8 +217,9 @@ class replace {
137217 // / @see
138218 // / - https://www.mongodb.com/docs/manual/core/write-concern/
139219 // /
140- MONGOCXX_ABI_EXPORT_CDECL (bsoncxx::v_noabi::stdx::optional<mongocxx::v_noabi::write_concern> const &)
141- write_concern () const ;
220+ bsoncxx::v_noabi::stdx::optional<v_noabi::write_concern> const & write_concern () const {
221+ return _write_concern;
222+ }
142223
143224 // /
144225 // / Sets the index to use for this operation.
@@ -153,15 +234,19 @@ class replace {
153234 // / A reference to the object on which this member function is being called. This facilitates
154235 // / method chaining.
155236 // /
156- MONGOCXX_ABI_EXPORT_CDECL (replace&) hint(mongocxx::v_noabi::hint index_hint);
237+ replace& hint (v_noabi::hint index_hint) {
238+ _hint = std::move (index_hint);
239+ return *this ;
240+ }
157241
158242 // /
159243 // / Gets the current hint.
160244 // /
161245 // / @return The current hint, if one is set.
162246 // /
163- MONGOCXX_ABI_EXPORT_CDECL (bsoncxx::v_noabi::stdx::optional<mongocxx::v_noabi::hint> const &)
164- hint () const ;
247+ bsoncxx::v_noabi::stdx::optional<v_noabi::hint> const & hint () const {
248+ return _hint;
249+ }
165250
166251 // /
167252 // / Set the value of the let option.
@@ -173,27 +258,35 @@ class replace {
173258 // / A reference to the object on which this member function is being called. This facilitates
174259 // / method chaining.
175260 // /
176- MONGOCXX_ABI_EXPORT_CDECL (replace&) let(bsoncxx::v_noabi::document::view_or_value let);
261+ replace& let (bsoncxx::v_noabi::document::view_or_value let) {
262+ _let = std::move (let);
263+ return *this ;
264+ }
177265
178266 // /
179267 // / Gets the current value of the let option.
180268 // /
181269 // / @return
182270 // / The current let option.
183271 // /
184- MONGOCXX_ABI_EXPORT_CDECL (bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> const )
185- let () const ;
272+ bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> const let () const {
273+ return _let;
274+ }
186275
187276 // /
188277 // / Set the sort option.
189278 // /
190- MONGOCXX_ABI_EXPORT_CDECL (replace&) sort(bsoncxx::v_noabi::document::view_or_value sort);
279+ replace& sort (bsoncxx::v_noabi::document::view_or_value sort) {
280+ _sort = std::move (sort);
281+ return *this ;
282+ }
191283
192284 // /
193285 // / Get the current value of the sort option.
194286 // /
195- MONGOCXX_ABI_EXPORT_CDECL (bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> const &)
196- sort () const ;
287+ bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> const & sort () const {
288+ return _sort;
289+ }
197290
198291 // /
199292 // / Set the value of the comment option.
@@ -205,24 +298,27 @@ class replace {
205298 // / A reference to the object on which this member function is being called. This facilitates
206299 // / method chaining.
207300 // /
208- MONGOCXX_ABI_EXPORT_CDECL (replace&)
209- comment (bsoncxx::v_noabi::types::bson_value::view_or_value comment);
301+ replace& comment (bsoncxx::v_noabi::types::bson_value::view_or_value comment) {
302+ _comment = std::move (comment);
303+ return *this ;
304+ }
210305
211306 // /
212307 // / Gets the current value of the comment option.
213308 // /
214309 // / @return
215310 // / The current comment option.
216311 // /
217- MONGOCXX_ABI_EXPORT_CDECL (bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::types::bson_value::view_or_value> const )
218- comment () const ;
312+ bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::types::bson_value::view_or_value> const comment () const {
313+ return _comment;
314+ }
219315
220316 private:
221317 bsoncxx::v_noabi::stdx::optional<bool > _bypass_document_validation;
222318 bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> _collation;
223319 bsoncxx::v_noabi::stdx::optional<bool > _upsert;
224- bsoncxx::v_noabi::stdx::optional<mongocxx:: v_noabi::write_concern> _write_concern;
225- bsoncxx::v_noabi::stdx::optional<mongocxx:: v_noabi::hint> _hint;
320+ bsoncxx::v_noabi::stdx::optional<v_noabi::write_concern> _write_concern;
321+ bsoncxx::v_noabi::stdx::optional<v_noabi::hint> _hint;
226322 bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> _let;
227323 bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> _sort;
228324 bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::types::bson_value::view_or_value> _comment;
@@ -232,9 +328,32 @@ class replace {
232328} // namespace v_noabi
233329} // namespace mongocxx
234330
331+ namespace mongocxx {
332+ namespace v_noabi {
333+
334+ // /
335+ // / Convert to the @ref mongocxx::v_noabi equivalent of `v`.
336+ // /
337+ inline v_noabi::options::replace from_v1 (v1::replace_one_options v) {
338+ return {std::move (v)};
339+ }
340+
341+ // /
342+ // / Convert to the @ref mongocxx::v1 equivalent of `v`.
343+ // /
344+ inline v1::replace_one_options to_v1 (v_noabi::options::replace const & v) {
345+ return v1::replace_one_options{v};
346+ }
347+
348+ } // namespace v_noabi
349+ } // namespace mongocxx
350+
235351#include < mongocxx/config/postlude.hpp>
236352
237353// /
238354// / @file
239355// / Provides @ref mongocxx::v_noabi::options::replace.
240356// /
357+ // / @par Includes
358+ // / - @ref mongocxx/v1/replace_one_options.hpp
359+ // /
0 commit comments