1414
1515#pragma once
1616
17+ #include < mongocxx/options/count-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/count_options.hpp> // IWYU pragma: export
25+
1726#include < chrono>
1827#include < cstdint>
1928#include < string> // IWYU pragma: keep: backward compatibility, to be removed.
29+ #include < utility>
2030
21- #include < mongocxx/options/count-fwd.hpp> // IWYU pragma: export
22-
31+ #include < bsoncxx/document/view.hpp>
2332#include < bsoncxx/document/view_or_value.hpp>
2433#include < bsoncxx/stdx/optional.hpp>
34+ #include < bsoncxx/types/bson_value/view.hpp>
2535#include < bsoncxx/types/bson_value/view_or_value.hpp>
2636
2737#include < mongocxx/hint.hpp>
@@ -38,6 +48,56 @@ namespace options {
3848// /
3949class count {
4050 public:
51+ // /
52+ // / Default initialization.
53+ // /
54+ count () = default ;
55+
56+ // /
57+ // / Construct with the @ref mongocxx::v1 equivalent.
58+ // /
59+ /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() count(v1::count_options opts);
60+
61+ // /
62+ // / Convert to the @ref mongocxx::v1 equivalent.
63+ // /
64+ explicit operator v1::count_options () const {
65+ using bsoncxx::v_noabi::to_v1;
66+ using mongocxx::v_noabi::to_v1;
67+
68+ v1::count_options ret;
69+
70+ if (_collation) {
71+ ret.collation (bsoncxx::v1::document::value{to_v1 (_collation->view ())});
72+ }
73+
74+ if (_hint) {
75+ ret.hint (to_v1 (*_hint));
76+ }
77+
78+ if (_comment) {
79+ ret.comment (bsoncxx::v1::types::value{to_v1 (_comment->view ())});
80+ }
81+
82+ if (_limit) {
83+ ret.limit (*_limit);
84+ }
85+
86+ if (_max_time) {
87+ ret.max_time (*_max_time);
88+ }
89+
90+ if (_skip) {
91+ ret.skip (*_skip);
92+ }
93+
94+ if (_read_preference) {
95+ ret.read_preference (to_v1 (*_read_preference));
96+ }
97+
98+ return ret;
99+ }
100+
41101 // /
42102 // / Sets the collation for this operation.
43103 // /
@@ -51,8 +111,10 @@ class count {
51111 // / @see
52112 // / - https://www.mongodb.com/docs/manual/reference/command/aggregate/
53113 // /
54- MONGOCXX_ABI_EXPORT_CDECL (count&)
55- collation (bsoncxx::v_noabi::document::view_or_value collation);
114+ count& collation (bsoncxx::v_noabi::document::view_or_value collation) {
115+ _collation = std::move (collation);
116+ return *this ;
117+ }
56118
57119 // /
58120 // / Retrieves the current collation for this operation.
@@ -63,8 +125,9 @@ class count {
63125 // / @see
64126 // / - https://www.mongodb.com/docs/manual/reference/command/aggregate/
65127 // /
66- MONGOCXX_ABI_EXPORT_CDECL (bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> const &)
67- collation () const ;
128+ bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> const & collation () const {
129+ return _collation;
130+ }
68131
69132 // /
70133 // / Sets the index to use for this operation.
@@ -79,7 +142,10 @@ class count {
79142 // / @see
80143 // / - https://www.mongodb.com/docs/manual/reference/command/aggregate/
81144 // /
82- MONGOCXX_ABI_EXPORT_CDECL (count&) hint(mongocxx::v_noabi::hint index_hint);
145+ count& hint (mongocxx::v_noabi::hint index_hint) {
146+ _hint = std::move (index_hint);
147+ return *this ;
148+ }
83149
84150 // /
85151 // / Gets the current hint.
@@ -89,8 +155,9 @@ class count {
89155 // / @see
90156 // / - https://www.mongodb.com/docs/manual/reference/command/aggregate/
91157 // /
92- MONGOCXX_ABI_EXPORT_CDECL (bsoncxx::v_noabi::stdx::optional<mongocxx::v_noabi::hint> const &)
93- hint () const ;
158+ bsoncxx::v_noabi::stdx::optional<mongocxx::v_noabi::hint> const & hint () const {
159+ return _hint;
160+ }
94161
95162 // /
96163 // / Set the value of the comment option.
@@ -105,8 +172,10 @@ class count {
105172 // / @see
106173 // / - https://www.mongodb.com/docs/manual/reference/command/aggregate/
107174 // /
108- MONGOCXX_ABI_EXPORT_CDECL (count&)
109- comment (bsoncxx::v_noabi::types::bson_value::view_or_value comment);
175+ count& comment (bsoncxx::v_noabi::types::bson_value::view_or_value comment) {
176+ _comment = std::move (comment);
177+ return *this ;
178+ }
110179
111180 // /
112181 // / Gets the current value of the comment option.
@@ -116,8 +185,9 @@ class count {
116185 // / @see
117186 // / - https://www.mongodb.com/docs/manual/reference/command/aggregate/
118187 // /
119- MONGOCXX_ABI_EXPORT_CDECL (bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::types::bson_value::view_or_value> const &)
120- comment () const ;
188+ bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::types::bson_value::view_or_value> const & comment () const {
189+ return _comment;
190+ }
121191
122192 // /
123193 // / Sets the maximum number of documents to count.
@@ -132,7 +202,10 @@ class count {
132202 // / @see
133203 // / - https://www.mongodb.com/docs/manual/reference/command/aggregate/
134204 // /
135- MONGOCXX_ABI_EXPORT_CDECL (count&) limit(std::int64_t limit);
205+ count& limit (std::int64_t limit) {
206+ _limit = limit;
207+ return *this ;
208+ }
136209
137210 // /
138211 // / Gets the current limit.
@@ -142,7 +215,9 @@ class count {
142215 // / @see
143216 // / - https://www.mongodb.com/docs/manual/reference/command/aggregate/
144217 // /
145- MONGOCXX_ABI_EXPORT_CDECL (bsoncxx::v_noabi::stdx::optional<std::int64_t > const &) limit() const ;
218+ bsoncxx::v_noabi::stdx::optional<std::int64_t > const & limit () const {
219+ return _limit;
220+ }
146221
147222 // /
148223 // / Sets the maximum amount of time for this operation to run (server-side) in milliseconds.
@@ -157,7 +232,10 @@ class count {
157232 // / @see
158233 // / - https://www.mongodb.com/docs/manual/reference/command/aggregate/
159234 // /
160- MONGOCXX_ABI_EXPORT_CDECL (count&) max_time(std::chrono::milliseconds max_time);
235+ count& max_time (std::chrono::milliseconds max_time) {
236+ _max_time = max_time;
237+ return *this ;
238+ }
161239
162240 // /
163241 // / The current max_time setting.
@@ -167,8 +245,9 @@ class count {
167245 // / @see
168246 // / - https://www.mongodb.com/docs/manual/reference/command/aggregate/
169247 // /
170- MONGOCXX_ABI_EXPORT_CDECL (bsoncxx::v_noabi::stdx::optional<std::chrono::milliseconds> const &)
171- max_time () const ;
248+ bsoncxx::v_noabi::stdx::optional<std::chrono::milliseconds> const & max_time () const {
249+ return _max_time;
250+ }
172251
173252 // /
174253 // / Sets the number of documents to skip before counting documents.
@@ -183,7 +262,10 @@ class count {
183262 // / @see
184263 // / - https://www.mongodb.com/docs/manual/reference/command/aggregate/
185264 // /
186- MONGOCXX_ABI_EXPORT_CDECL (count&) skip(std::int64_t skip);
265+ count& skip (std::int64_t skip) {
266+ _skip = skip;
267+ return *this ;
268+ }
187269
188270 // /
189271 // / Gets the current number of documents to skip.
@@ -193,7 +275,9 @@ class count {
193275 // / @see
194276 // / - https://www.mongodb.com/docs/manual/reference/command/aggregate/
195277 // /
196- MONGOCXX_ABI_EXPORT_CDECL (bsoncxx::v_noabi::stdx::optional<std::int64_t > const &) skip() const ;
278+ bsoncxx::v_noabi::stdx::optional<std::int64_t > const & skip () const {
279+ return _skip;
280+ }
197281
198282 // /
199283 // / Sets the read_preference for this operation.
@@ -208,7 +292,10 @@ class count {
208292 // / @see
209293 // / - https://www.mongodb.com/docs/manual/reference/command/aggregate/
210294 // /
211- MONGOCXX_ABI_EXPORT_CDECL (count&) read_preference(mongocxx::v_noabi::read_preference rp);
295+ count& read_preference (mongocxx::v_noabi::read_preference rp) {
296+ _read_preference = std::move (rp);
297+ return *this ;
298+ }
212299
213300 // /
214301 // / The current read_preference for this operation.
@@ -218,8 +305,9 @@ class count {
218305 // / @see
219306 // / - https://www.mongodb.com/docs/manual/reference/command/aggregate/
220307 // /
221- MONGOCXX_ABI_EXPORT_CDECL (bsoncxx::v_noabi::stdx::optional<mongocxx::v_noabi::read_preference> const &)
222- read_preference () const ;
308+ bsoncxx::v_noabi::stdx::optional<mongocxx::v_noabi::read_preference> const & read_preference () const {
309+ return _read_preference;
310+ }
223311
224312 private:
225313 bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> _collation;
@@ -235,9 +323,32 @@ class count {
235323} // namespace v_noabi
236324} // namespace mongocxx
237325
326+ namespace mongocxx {
327+ namespace v_noabi {
328+
329+ // /
330+ // / Convert to the @ref mongocxx::v_noabi equivalent of `v`.
331+ // /
332+ inline v_noabi::options::count from_v1 (v1::count_options v) {
333+ return {std::move (v)};
334+ }
335+
336+ // /
337+ // / Convert to the @ref mongocxx::v1 equivalent of `v`.
338+ // /
339+ inline v1::count_options to_v1 (v_noabi::options::count const & v) {
340+ return v1::count_options{v};
341+ }
342+
343+ } // namespace v_noabi
344+ } // namespace mongocxx
345+
238346#include < mongocxx/config/postlude.hpp>
239347
240348// /
241349// / @file
242350// / Provides @ref mongocxx::v_noabi::options::count.
243351// /
352+ // / @par Includes
353+ // / - @ref mongocxx/v1/count_options.hpp
354+ // /
0 commit comments