MongoDB C++ Driver 4.5.0
Loading...
Searching...
No Matches
pool.hpp
Go to the documentation of this file.
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/pool-fwd.hpp> // IWYU pragma: export
18
19//
20
22
25
28
29#include <mongocxx/v1/client.hpp> // IWYU pragma: export
31
32#include <cstddef>
33#include <system_error>
34#include <type_traits>
35
36namespace mongocxx {
37namespace v1 {
38
49class pool {
50 private:
51 class impl;
52 void* _impl;
53
54 public:
55 class options;
56 class entry;
57
64
71 MONGOCXX_ABI_EXPORT_CDECL() pool(pool&& other) noexcept;
72
79 MONGOCXX_ABI_EXPORT_CDECL(pool&) operator=(pool&& other) noexcept;
80
84 pool(pool const& other) = delete;
85
89 pool& operator=(pool const& other) = delete;
90
100
101 /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() pool(v1::uri const& uri);
104
113
117 explicit MONGOCXX_ABI_EXPORT_CDECL() operator bool() const;
118
134
147
168 bsoncxx::v1::stdx::string_view name,
169 bsoncxx::v1::stdx::optional<bsoncxx::v1::stdx::string_view> version = {},
171
180
184 static MONGOCXX_ABI_EXPORT_CDECL(std::error_category const&) error_category();
185
189 friend std::error_code make_error_code(errc v) {
190 return {static_cast<int>(v), error_category()};
191 }
192
193 class internal;
194
195 private:
196 /* explicit(false) */ pool(void* impl);
197};
198
203 private:
204 class impl;
205 void* _impl;
206
207 public:
212
220
227 MONGOCXX_ABI_EXPORT_CDECL(options&) operator=(options&& other) noexcept;
228
233
237 MONGOCXX_ABI_EXPORT_CDECL(options&) operator=(options const& other);
238
242 /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() options(v1::client::options opts);
243
251
256
257 class internal;
258};
259
263class pool::entry {
264 private:
265 class impl;
266 void* _impl;
267
268 public:
273
281
288 MONGOCXX_ABI_EXPORT_CDECL(entry&) operator=(entry&& other) noexcept;
289
293 entry(entry const& other) = delete;
294
298 entry& operator=(entry const& other) = delete;
299
304
309
316 MONGOCXX_ABI_EXPORT_CDECL(entry&) operator=(std::nullptr_t);
317
321 explicit MONGOCXX_ABI_EXPORT_CDECL() operator bool() const;
322
328 MONGOCXX_ABI_EXPORT_CDECL(v1::database) operator[](bsoncxx::v1::stdx::string_view name);
331
332 class internal;
333
334 private:
335 /* explicit(false) */ entry(void* impl);
336};
337
338} // namespace v1
339} // namespace mongocxx
340
341namespace std {
342
343template <>
344struct is_error_code_enum<mongocxx::v1::pool::errc> : true_type {};
345
346} // namespace std
347
349
A polyfill for std::optional<T>.
Definition optional.hpp:799
A connection to a MongoDB deployment.
Definition client.hpp:60
A handle to a client object owned by an associated pool.
Definition pool.hpp:263
~entry()
Destroy this object, releasing the managed client object back to the associated pool.
v1::database database(bsoncxx::v1::stdx::string_view name)
Equivalent to (*this)->database(name).
entry(entry &&other) noexcept
Move constructor.
Options for mongocxx::v1::pool.
Definition pool.hpp:202
v1::client::options client_opts() const
Return the current client options.
~options()
Destroy this object.
options(options &&other) noexcept
Move constructor.
entry acquire()
Return a client object associated with this pool.
static std::error_category const & error_category()
The error category for mongocxx::v1::pool::errc.
~pool()
Destroy this object.
pool(pool &&other) noexcept
Move constructor.
friend std::error_code make_error_code(errc v)
Support implicit conversion to std::error_code.
Definition pool.hpp:189
pool()
Initialize this pool with default URI options.
void append_metadata(bsoncxx::v1::stdx::string_view name, bsoncxx::v1::stdx::optional< bsoncxx::v1::stdx::string_view > version={}, bsoncxx::v1::stdx::optional< bsoncxx::v1::stdx::string_view > platform={})
Append client metadata to the handshake command sent as part of the initial connection handshake.
bsoncxx::v1::stdx::optional< entry > try_acquire()
Return a client object associated with this pool.
errc
Errors codes which may be returned by mongocxx::v1::pool.
Definition pool.hpp:175
@ append_metadata_failure
Failed to append client metadata.
Definition pool.hpp:178
@ wait_queue_timeout
Failed to acquire a client object due to "waitQueueTimeoutMS".
Definition pool.hpp:177
@ zero
Zero.
Definition pool.hpp:176
A MongoDB connection string.
Definition uri.hpp:89
Provides macros to control the set of symbols exported in the ABI.
#define MONGOCXX_ABI_EXPORT_CDECL(...)
Equivalent to MONGOCXX_ABI_EXPORT with MONGOCXX_ABI_CDECL.
Definition export.hpp:52
The mongocxx v1 macro guard postlude header.
The mongocxx v1 macro guard prelude header.
The top-level namespace within which all bsoncxx library entities are declared.
Declares entities whose ABI stability is guaranteed for documented symbols.
The top-level namespace within which all mongocxx library entities are declared.
Provides mongocxx::v1::client.
Declares mongocxx::v1::database.
Declares mongocxx::v1::pool.
Provides std::optional-related polyfills for library API usage.
Provides std::string_view-related polyfills for library API usage.
Declares mongocxx::v1::uri.