MongoDB C++ Driver mongocxx-4.0.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/uri.hpp>
29
31
32namespace mongocxx {
33namespace v_noabi {
34
51class pool {
52 public:
64 explicit MONGOCXX_ABI_EXPORT_CDECL() pool(const uri& mongodb_uri = mongocxx::v_noabi::uri(),
65 const options::pool& options = options::pool());
66
71
72 pool(pool&&) = delete;
73 pool& operator=(pool&&) = delete;
74
75 pool(const pool&) = delete;
76 pool& operator=(const pool&) = delete;
77
85 class entry {
86 public:
89 client* operator->() && = delete;
90
92 MONGOCXX_ABI_EXPORT_CDECL(client&) operator*() const& noexcept;
93 client& operator*() && = delete;
94
96 MONGOCXX_ABI_EXPORT_CDECL(entry&) operator=(std::nullptr_t) noexcept;
97
99 explicit MONGOCXX_ABI_EXPORT_CDECL() operator bool() const noexcept;
100
101 // Allows the pool_entry["db_name"] syntax to be used to access a database within the
102 // entry's underlying client.
103 mongocxx::v_noabi::database operator[](
104 bsoncxx::v_noabi::string::view_or_value name) const& {
105 return (**this)[name];
106 }
107
109 delete;
110
111 private:
112 friend ::mongocxx::v_noabi::pool;
113
114 using unique_client =
115 std::unique_ptr<client, std::function<void MONGOCXX_ABI_CDECL(client*)>>;
116
117 explicit entry(unique_client);
118
119 unique_client _client;
120 };
121
127
133
134 private:
135 friend ::mongocxx::v_noabi::options::auto_encryption;
136
137 void _release(client* client);
138
139 class impl;
140 const std::unique_ptr<impl> _impl;
141};
142
143} // namespace v_noabi
144} // namespace mongocxx
145
147
Declares mongocxx::v_noabi::options::auto_encryption.
A polyfill for std::optional<T>.
Definition optional.hpp:826
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:61
Class representing a MongoDB database.
Definition database.hpp:46
An entry is a handle on a client object acquired via the pool. Similar to std::unique_ptr.
Definition pool.hpp:85
client * operator->() const &noexcept
Access a member of the client instance.
A pool of client objects associated with a MongoDB deployment.
Definition pool.hpp:51
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:196
#define MONGOCXX_ABI_EXPORT_CDECL(...)
Equivalent to MONGOCXX_ABI_EXPORT with MONGOCXX_ABI_CDECL.
Definition fwd.hpp:204
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.
Provides mongocxx::v_noabi::uri.