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/pool-fwd.hpp> // IWYU pragma: export
18
19//
20
23
24#include <mongocxx/v1/pool.hpp> // IWYU pragma: export
25
26#include <cstddef>
27#include <functional>
28#include <memory>
29#include <utility>
30
31#include <mongocxx/options/auto_encryption-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
32
35
36#include <mongocxx/client.hpp>
37#include <mongocxx/database.hpp>
39#include <mongocxx/uri.hpp>
40
42
43namespace mongocxx {
44namespace v_noabi {
45
65class pool {
66 private:
67 v1::pool _pool;
68
69 public:
82 v_noabi::uri const& mongodb_uri = {},
84
88 ~pool() = default;
89
90 pool(pool&&) = delete;
91 pool& operator=(pool&&) = delete;
92
93 pool(pool const&) = delete;
94 pool& operator=(pool const&) = delete;
95
104 class entry {
105 public:
107 v_noabi::client* operator->() const& noexcept {
108 return _client.get();
109 }
110 v_noabi::client* operator->() && = delete;
111
113 v_noabi::client& operator*() const& noexcept {
114 return *_client;
115 }
116 v_noabi::client& operator*() && = delete;
117
119 entry& operator=(std::nullptr_t) noexcept {
120 _client.reset();
121 return *this;
122 }
123
125 explicit operator bool() const noexcept {
126 return _client != nullptr;
127 }
128
129 // Allows the pool_entry["db_name"] syntax to be used to access a database within the
130 // entry's underlying client.
132 return (*_client)[name];
133 }
135
136 class internal;
137
138 private:
139 using ptr_type = std::unique_ptr<v_noabi::client, std::function<void MONGOCXX_ABI_CDECL(v_noabi::client*)>>;
140
141 ptr_type _client;
142
143 /* explicit(false) */ entry(ptr_type client) : _client{std::move(client)} {}
144 };
145
151
157
179
180 class internal;
181};
182
183} // namespace v_noabi
184} // namespace mongocxx
185
187
Declares mongocxx::v_noabi::options::auto_encryption.
A polyfill for std::optional<T>.
Definition optional.hpp:799
A polyfill for std::string_view.
Definition string_view.hpp:412
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:49
A client connection to a MongoDB server.
Definition client.hpp:80
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:104
v_noabi::client * operator->() const &noexcept
Access a member of the client instance.
Definition pool.hpp:107
entry & operator=(std::nullptr_t) noexcept
Assign nullptr to this entry to release its client to the pool.
Definition pool.hpp:119
v_noabi::client & operator*() const &noexcept
Retrieve a reference to the client.
Definition pool.hpp:113
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.
~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_UNSTABLE(...)
Equivalent to MONGOCXX_ABI_EXPORT_UNSTABLE with MONGOCXX_ABI_CDECL.
Definition config.hpp:28
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 std::string_view-related polyfills for library API usage.
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.