MongoDB C++ Driver 4.1.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
54class pool {
55 public:
68 uri const& mongodb_uri = mongocxx::v_noabi::uri(),
69 options::pool const& options = options::pool());
70
75
76 pool(pool&&) = delete;
77 pool& operator=(pool&&) = delete;
78
79 pool(pool const&) = delete;
80 pool& operator=(pool const&) = delete;
81
90 class entry {
91 public:
94 client* operator->() && = delete;
95
97 MONGOCXX_ABI_EXPORT_CDECL(client&) operator*() const& noexcept;
98 client& operator*() && = delete;
99
101 MONGOCXX_ABI_EXPORT_CDECL(entry&) operator=(std::nullptr_t) noexcept;
102
104 explicit MONGOCXX_ABI_EXPORT_CDECL() operator bool() const noexcept;
105
106 // Allows the pool_entry["db_name"] syntax to be used to access a database within the
107 // entry's underlying client.
108 mongocxx::v_noabi::database operator[](bsoncxx::v_noabi::string::view_or_value name) const& {
109 return (**this)[name];
110 }
111
113
114 private:
115 friend ::mongocxx::v_noabi::pool;
116
117 using unique_client = std::unique_ptr<client, std::function<void MONGOCXX_ABI_CDECL(client*)>>;
118
119 explicit entry(unique_client);
120
121 unique_client _client;
122 };
123
129
135
136 private:
137 friend ::mongocxx::v_noabi::options::auto_encryption;
138
139 void _release(client* client);
140
141 class impl;
142 std::unique_ptr<impl> const _impl;
143};
144
145} // namespace v_noabi
146} // namespace mongocxx
147
149
Declares mongocxx::v_noabi::options::auto_encryption.
A polyfill for std::optional<T>.
Definition optional.hpp:800
A view-or-value variant type for strings.
Definition view_or_value.hpp:41
pool(uri const &mongodb_uri=mongocxx::v_noabi::uri(), options::pool const &options=options::pool())
Creates a pool associated with a connection string.
A client connection to a MongoDB server.
Definition client.hpp:61
A MongoDB database.
Definition database.hpp:46
An owning handle to a client obtained from a pool.
Definition pool.hpp:90
client * operator->() const &noexcept
Access a member of the client instance.
pool(uri const &mongodb_uri=mongocxx::v_noabi::uri(), options::pool const &options=options::pool())
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: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 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.
The top-level namespace within which all bsoncxx library entities are declared.
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 mongocxx::v_noabi::options::pool.
Declares mongocxx::v_noabi::pool.
Provides mongocxx::v_noabi::uri.
Provides std::optional-related polyfills for library API usage.