MongoDB C++ Driver mongocxx-3.11.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 <functional>
18#include <memory>
19
21#include <mongocxx/pool-fwd.hpp>
22
24
25#include <mongocxx/client.hpp>
26#include <mongocxx/database.hpp>
28#include <mongocxx/stdx.hpp>
29#include <mongocxx/uri.hpp>
30
32
33namespace mongocxx {
34namespace v_noabi {
35
52class pool {
53 public:
65 explicit MONGOCXX_ABI_EXPORT_CDECL() pool(const uri& mongodb_uri = mongocxx::v_noabi::uri(),
66 const options::pool& options = options::pool());
67
72
73 pool(pool&&) = delete;
74 pool& operator=(pool&&) = delete;
75
76 pool(const pool&) = delete;
77 pool& operator=(const pool&) = delete;
78
86 class entry {
87 public:
90 client* operator->() && = delete;
91
93 MONGOCXX_ABI_EXPORT_CDECL(client&) operator*() const& noexcept;
94 client& operator*() && = delete;
95
97 MONGOCXX_ABI_EXPORT_CDECL(entry&) operator=(std::nullptr_t) noexcept;
98
100 explicit MONGOCXX_ABI_EXPORT_CDECL() operator bool() const noexcept;
101
102 // Allows the pool_entry["db_name"] syntax to be used to access a database within the
103 // entry's underlying client.
104 mongocxx::v_noabi::database operator[](
105 bsoncxx::v_noabi::string::view_or_value name) const& {
106 return (**this)[name];
107 }
108
110 delete;
111
112 private:
113 friend ::mongocxx::v_noabi::pool;
114
115 using unique_client =
116 std::unique_ptr<client, std::function<void MONGOCXX_ABI_CDECL(client*)>>;
117
118 explicit entry(unique_client);
119
120 unique_client _client;
121 };
122
128
134
135 private:
136 friend ::mongocxx::v_noabi::options::auto_encryption;
137
138 void _release(client* client);
139
140 class impl;
141 const std::unique_ptr<impl> _impl;
142};
143
144} // namespace v_noabi
145} // namespace mongocxx
146
148
Declares mongocxx::v_noabi::options::auto_encryption.
A polyfill for std::optional<T>.
Definition optional.hpp:874
Class representing a view-or-value variant type for strings.
Definition view_or_value.hpp:41
Class representing a client connection to MongoDB.
Definition client.hpp:62
Class representing a MongoDB database.
Definition database.hpp:47
An entry is a handle on a client object acquired via the pool. Similar to std::unique_ptr.
Definition pool.hpp:86
client * operator->() const &noexcept
Access a member of the client instance.
A pool of client objects associated with a MongoDB deployment.
Definition pool.hpp:52
entry acquire()
Acquires a client from the pool. The calling thread will block until a connection is available.
Class representing a MongoDB connection string URI.
Definition uri.hpp:43
Provides mongocxx::v_noabi::client.
Provides mongocxx::v_noabi::database.
#define MONGOCXX_ABI_CDECL
Expands to __cdecl when built with MSVC on Windows.
Definition fwd.hpp:214
#define MONGOCXX_ABI_EXPORT_CDECL(...)
Equivalent to MONGOCXX_ABI_EXPORT with MONGOCXX_ABI_CDECL.
Definition fwd.hpp:222
The mongocxx macro guard postlude header.
The mongocxx macro guard prelude header.
The top-level namespace within which all bsoncxx library entities are declared.
The top-level namespace within which all mongocxx library entities are declared.
The top-level namespace reserved for the C++ standard library.
Provides std::optional-related polyfills for library API usage.
Provides mongocxx::v_noabi::options::pool.
Declares mongocxx::v_noabi::pool.
Redeclares bsoncxx::v_noabi::stdx in mongocxx::v_noabi::stdx for internal use.
Provides mongocxx::v_noabi::uri.