Skip to content

Commit 7e9e1a1

Browse files
authored
v1: estimated_document_count_options (CXX-3237, CXX-3238) (#1521)
1 parent 2369919 commit 7e9e1a1

File tree

8 files changed

+381
-45
lines changed

8 files changed

+381
-45
lines changed

src/mongocxx/include/mongocxx/v1/estimated_document_count_options.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ class estimated_document_count_options {
124124
/// Return the current "readPreference" field.
125125
///
126126
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<v1::read_preference>) read_preference() const;
127+
128+
class internal;
127129
};
128130

129131
} // namespace v1

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

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

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

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

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

Lines changed: 88 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,20 @@
1414

1515
#pragma once
1616

17-
#include <chrono>
18-
1917
#include <mongocxx/options/estimated_document_count-fwd.hpp> // IWYU pragma: export
2018

19+
//
20+
21+
#include <bsoncxx/v1/types/value.hpp>
22+
23+
#include <mongocxx/v1/estimated_document_count_options.hpp> // IWYU pragma: export
24+
25+
#include <chrono>
26+
#include <utility>
27+
2128
#include <bsoncxx/stdx/optional.hpp>
2229
#include <bsoncxx/types/bson_value/view_or_value.hpp>
30+
#include <bsoncxx/types/view.hpp>
2331

2432
#include <mongocxx/read_preference.hpp>
2533

@@ -34,6 +42,40 @@ namespace options {
3442
///
3543
class estimated_document_count {
3644
public:
45+
///
46+
/// Default initialization.
47+
///
48+
estimated_document_count() = default;
49+
50+
///
51+
/// Construct with the @ref mongocxx::v1 equivalent.
52+
///
53+
/* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() estimated_document_count(
54+
v1::estimated_document_count_options opts);
55+
56+
///
57+
/// Convert to the @ref mongocxx::v1 equivalent.
58+
///
59+
explicit operator v1::estimated_document_count_options() const {
60+
using bsoncxx::v_noabi::to_v1;
61+
62+
v1::estimated_document_count_options ret;
63+
64+
if (_max_time) {
65+
ret.max_time(*_max_time);
66+
}
67+
68+
if (_comment) {
69+
ret.comment(bsoncxx::v1::types::value{to_v1(_comment->view())});
70+
}
71+
72+
if (_read_preference) {
73+
ret.read_preference(to_v1(*_read_preference));
74+
}
75+
76+
return ret;
77+
}
78+
3779
///
3880
/// Sets the maximum amount of time for this operation to run (server-side) in milliseconds.
3981
///
@@ -47,8 +89,10 @@ class estimated_document_count {
4789
/// @see
4890
/// - https://www.mongodb.com/docs/manual/reference/command/count/
4991
///
50-
MONGOCXX_ABI_EXPORT_CDECL(estimated_document_count&)
51-
max_time(std::chrono::milliseconds max_time);
92+
estimated_document_count& max_time(std::chrono::milliseconds max_time) {
93+
_max_time = max_time;
94+
return *this;
95+
}
5296

5397
///
5498
/// The current max_time setting.
@@ -58,8 +102,9 @@ class estimated_document_count {
58102
/// @see
59103
/// - https://www.mongodb.com/docs/manual/reference/command/count/
60104
///
61-
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::stdx::optional<std::chrono::milliseconds> const&)
62-
max_time() const;
105+
bsoncxx::v_noabi::stdx::optional<std::chrono::milliseconds> const& max_time() const {
106+
return _max_time;
107+
}
63108

64109
///
65110
/// Sets the comment for this operation.
@@ -74,8 +119,10 @@ class estimated_document_count {
74119
/// @see
75120
/// - https://www.mongodb.com/docs/manual/reference/command/count/
76121
///
77-
MONGOCXX_ABI_EXPORT_CDECL(estimated_document_count&)
78-
comment(bsoncxx::v_noabi::types::bson_value::view_or_value comment);
122+
estimated_document_count& comment(bsoncxx::v_noabi::types::bson_value::view_or_value comment) {
123+
_comment = std::move(comment);
124+
return *this;
125+
}
79126

80127
///
81128
/// The current comment for this operation.
@@ -85,8 +132,9 @@ class estimated_document_count {
85132
/// @see
86133
/// - https://www.mongodb.com/docs/manual/reference/command/count/
87134
///
88-
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::types::bson_value::view_or_value> const&)
89-
comment() const;
135+
bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::types::bson_value::view_or_value> const& comment() const {
136+
return _comment;
137+
}
90138

91139
///
92140
/// Sets the read_preference for this operation.
@@ -101,8 +149,10 @@ class estimated_document_count {
101149
/// @see
102150
/// - https://www.mongodb.com/docs/manual/reference/command/count/
103151
///
104-
MONGOCXX_ABI_EXPORT_CDECL(estimated_document_count&)
105-
read_preference(mongocxx::v_noabi::read_preference rp);
152+
estimated_document_count& read_preference(mongocxx::v_noabi::read_preference rp) {
153+
_read_preference = std::move(rp);
154+
return *this;
155+
}
106156

107157
///
108158
/// The current read_preference for this operation.
@@ -112,8 +162,9 @@ class estimated_document_count {
112162
/// @see
113163
/// - https://www.mongodb.com/docs/manual/reference/command/count/
114164
///
115-
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::stdx::optional<mongocxx::v_noabi::read_preference> const&)
116-
read_preference() const;
165+
bsoncxx::v_noabi::stdx::optional<mongocxx::v_noabi::read_preference> const& read_preference() const {
166+
return _read_preference;
167+
}
117168

118169
private:
119170
bsoncxx::v_noabi::stdx::optional<std::chrono::milliseconds> _max_time;
@@ -125,9 +176,32 @@ class estimated_document_count {
125176
} // namespace v_noabi
126177
} // namespace mongocxx
127178

179+
namespace mongocxx {
180+
namespace v_noabi {
181+
182+
///
183+
/// Convert to the @ref mongocxx::v_noabi equivalent of `v`.
184+
///
185+
inline v_noabi::options::estimated_document_count from_v1(v1::estimated_document_count_options v) {
186+
return {std::move(v)};
187+
}
188+
189+
///
190+
/// Convert to the @ref mongocxx::v1 equivalent of `v`.
191+
///
192+
inline v1::estimated_document_count_options to_v1(v_noabi::options::estimated_document_count const& v) {
193+
return v1::estimated_document_count_options{v};
194+
}
195+
196+
} // namespace v_noabi
197+
} // namespace mongocxx
198+
128199
#include <mongocxx/config/postlude.hpp>
129200

130201
///
131202
/// @file
132203
/// Provides @ref mongocxx::v_noabi::options::estimated_document_count.
133204
///
205+
/// @par Includes
206+
/// - @ref mongocxx/v1/estimated_document_count_options.hpp
207+
///

src/mongocxx/lib/mongocxx/v1/estimated_document_count_options.cpp

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,115 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include <mongocxx/v1/estimated_document_count_options.hpp>
15+
#include <mongocxx/v1/estimated_document_count_options.hh>
16+
17+
//
18+
19+
#include <bsoncxx/v1/stdx/optional.hpp>
20+
#include <bsoncxx/v1/types/value.hpp>
21+
22+
#include <mongocxx/v1/read_preference.hpp>
23+
24+
#include <chrono>
25+
26+
#include <mongocxx/private/utility.hh>
27+
28+
namespace mongocxx {
29+
namespace v1 {
30+
31+
class estimated_document_count_options::impl {
32+
public:
33+
bsoncxx::v1::stdx::optional<std::chrono::milliseconds> _max_time;
34+
bsoncxx::v1::stdx::optional<bsoncxx::v1::types::value> _comment;
35+
bsoncxx::v1::stdx::optional<mongocxx::v1::read_preference> _read_preference;
36+
37+
static impl const& with(estimated_document_count_options const& self) {
38+
return *static_cast<impl const*>(self._impl);
39+
}
40+
41+
static impl const* with(estimated_document_count_options const* self) {
42+
return static_cast<impl const*>(self->_impl);
43+
}
44+
45+
static impl& with(estimated_document_count_options& self) {
46+
return *static_cast<impl*>(self._impl);
47+
}
48+
49+
static impl* with(estimated_document_count_options* self) {
50+
return static_cast<impl*>(self->_impl);
51+
}
52+
53+
static impl* with(void* ptr) {
54+
return static_cast<impl*>(ptr);
55+
}
56+
};
57+
58+
estimated_document_count_options::~estimated_document_count_options() {
59+
delete impl::with(this);
60+
}
61+
62+
estimated_document_count_options::estimated_document_count_options(estimated_document_count_options&& other) noexcept
63+
: _impl{exchange(other._impl, nullptr)} {}
64+
65+
estimated_document_count_options& estimated_document_count_options::operator=(
66+
estimated_document_count_options&& other) noexcept {
67+
if (this != &other) {
68+
delete impl::with(exchange(_impl, exchange(other._impl, nullptr)));
69+
}
70+
71+
return *this;
72+
}
73+
74+
estimated_document_count_options::estimated_document_count_options(estimated_document_count_options const& other)
75+
: _impl{new impl{impl::with(other)}} {}
76+
77+
estimated_document_count_options& estimated_document_count_options::operator=(
78+
estimated_document_count_options const& other) {
79+
if (this != &other) {
80+
delete impl::with(exchange(_impl, new impl{impl::with(other)}));
81+
}
82+
83+
return *this;
84+
}
85+
86+
estimated_document_count_options::estimated_document_count_options() : _impl{new impl{}} {}
87+
88+
estimated_document_count_options& estimated_document_count_options::max_time(std::chrono::milliseconds max_time) {
89+
impl::with(this)->_max_time = max_time;
90+
return *this;
91+
}
92+
93+
bsoncxx::v1::stdx::optional<std::chrono::milliseconds> estimated_document_count_options::max_time() const {
94+
return impl::with(this)->_max_time;
95+
}
96+
97+
estimated_document_count_options& estimated_document_count_options::comment(bsoncxx::v1::types::value comment) {
98+
impl::with(this)->_comment = std::move(comment);
99+
return *this;
100+
}
101+
102+
bsoncxx::v1::stdx::optional<bsoncxx::v1::types::view> estimated_document_count_options::comment() const {
103+
return impl::with(this)->_comment;
104+
}
105+
106+
estimated_document_count_options& estimated_document_count_options::read_preference(v1::read_preference rp) {
107+
impl::with(this)->_read_preference = std::move(rp);
108+
return *this;
109+
}
110+
111+
bsoncxx::v1::stdx::optional<v1::read_preference> estimated_document_count_options::read_preference() const {
112+
return impl::with(this)->_read_preference;
113+
}
114+
115+
bsoncxx::v1::stdx::optional<bsoncxx::v1::types::value>& estimated_document_count_options::internal::comment(
116+
estimated_document_count_options& self) {
117+
return impl::with(self)._comment;
118+
}
119+
120+
bsoncxx::v1::stdx::optional<mongocxx::v1::read_preference>& estimated_document_count_options::internal::read_preference(
121+
estimated_document_count_options& self) {
122+
return impl::with(self)._read_preference;
123+
}
124+
125+
} // namespace v1
126+
} // namespace mongocxx
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2009-present MongoDB, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#pragma once
16+
17+
#include <mongocxx/v1/estimated_document_count_options.hpp> // IWYU pragma: export
18+
19+
//
20+
21+
#include <bsoncxx/v1/types/value-fwd.hpp>
22+
23+
#include <mongocxx/v1/read_preference-fwd.hpp>
24+
25+
#include <bsoncxx/v1/stdx/optional.hpp>
26+
27+
namespace mongocxx {
28+
namespace v1 {
29+
30+
class estimated_document_count_options::internal {
31+
public:
32+
static bsoncxx::v1::stdx::optional<bsoncxx::v1::types::value>& comment(estimated_document_count_options& self);
33+
static bsoncxx::v1::stdx::optional<mongocxx::v1::read_preference>& read_preference(
34+
estimated_document_count_options& self);
35+
};
36+
37+
} // namespace v1
38+
} // namespace mongocxx

0 commit comments

Comments
 (0)