MongoDB C++ Driver 4.2.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/pool-fwd.hpp> // IWYU pragma: export
18
19//
20
21#include <mongocxx/v1/pool.hpp> // IWYU pragma: export
22
23#include <cstddef>
24#include <functional>
25#include <memory>
26#include <utility>
27
28#include <mongocxx/options/auto_encryption-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
29
32
33#include <mongocxx/client.hpp>
34#include <mongocxx/database.hpp>
36#include <mongocxx/uri.hpp>
37
39
40namespace mongocxx {
41namespace v_noabi {
42
62class pool {
63 private:
64 v1::pool _pool;
65
66 public:
79 v_noabi::uri const& mongodb_uri = {},
81
85 ~pool() = default;
86
87 pool(pool&&) = delete;
88 pool& operator=(pool&&) = delete;
89
90 pool(pool const&) = delete;
91 pool& operator=(pool const&) = delete;
92
101 class entry {
102 public:
104 v_noabi::client* operator->() const& noexcept {
105 return _client.get();
106 }
107 v_noabi::client* operator->() && = delete;
108
110 v_noabi::client& operator*() const& noexcept {
111 return *_client;
112 }
113 v_noabi::client& operator*() && = delete;
114
116 entry& operator=(std::nullptr_t) noexcept {
117 _client.reset();
118 return *this;
119 }
120
122 explicit operator bool() const noexcept {
123 return _client != nullptr;
124 }
125
126 // Allows the pool_entry["db_name"] syntax to be used to access a database within the
127 // entry's underlying client.
129 return (*_client)[name];
130 }
132
133 class internal;
134
135 private:
136 using ptr_type = std::unique_ptr<v_noabi::client, std::function<void MONGOCXX_ABI_CDECL(v_noabi::client*)>>;
137
138 ptr_type _client;
139
140 /* explicit(false) */ entry(ptr_type client) : _client{std::move(client)} {}
141 };
142
148
154
155 class internal;
156};
157
158} // namespace v_noabi
159} // namespace mongocxx
160
162
Declares mongocxx::v_noabi::options::auto_encryption.
A polyfill for std::optional<T>.
Definition optional.hpp:799
A view-or-value variant type for strings.
Definition view_or_value.hpp:41
pool(v_noabi::uri const &mongodb_uri={}, v_noabi::options::pool const &options={})
Creates a pool associated with a connection string.
A thread-safe pool of client objects.
Definition pool.hpp:51
A client connection to a MongoDB server.
Definition client.hpp:76
A MongoDB database.
Definition database.hpp:63
Used by mongocxx::v_noabi::pool.
Definition pool.hpp:36
An owning handle to a client obtained from a pool.
Definition pool.hpp:101
v_noabi::client * operator->() const &noexcept
Access a member of the client instance.
Definition pool.hpp:104
entry & operator=(std::nullptr_t) noexcept
Assign nullptr to this entry to release its client to the pool.
Definition pool.hpp:116
v_noabi::client & operator*() const &noexcept
Retrieve a reference to the client.
Definition pool.hpp:110
~pool()=default
Destroys a pool.
pool(v_noabi::uri const &mongodb_uri={}, v_noabi::options::pool const &options={})
Creates a pool associated with a connection string.
entry acquire()
Acquires a client from the pool. The calling thread will block until a connection is available.
A MongoDB connection string URI.
Definition uri.hpp:55
#define MONGOCXX_ABI_CDECL
Expands to __cdecl when built with MSVC on Windows.
Definition export.hpp:49
#define MONGOCXX_ABI_EXPORT_CDECL(...)
Equivalent to MONGOCXX_ABI_EXPORT with MONGOCXX_ABI_CDECL.
Definition export.hpp:52
The mongocxx v_noabi macro guard postlude header.
The mongocxx v_noabi macro guard prelude header.
Declares entities representing options to use with various commands.
Declares entities whose ABI stability is NOT guaranteed.
The top-level namespace within which all mongocxx library entities are declared.
Provides bsoncxx::v_noabi::string::view_or_value.
Provides mongocxx::v1::pool.
Provides std::optional-related polyfills for library API usage.
Provides mongocxx::v_noabi::client.
Provides mongocxx::v_noabi::database.
Provides mongocxx::v_noabi::options::pool.
Declares mongocxx::v_noabi::pool.
Provides mongocxx::v_noabi::uri.