MongoDB C++ Driver  mongocxx-3.9.0
All Classes Namespaces Functions Typedefs Enumerations Enumerator Friends Pages
pool.hpp
1 // Copyright 2015 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 
20 #include <bsoncxx/stdx/optional.hpp>
21 #include <mongocxx/options/pool.hpp>
22 #include <mongocxx/stdx.hpp>
23 #include <mongocxx/uri.hpp>
24 
25 #include <mongocxx/config/prelude.hpp>
26 
27 namespace mongocxx {
28 inline namespace v_noabi {
29 class client;
30 
46 class MONGOCXX_API pool {
47  public:
58  explicit pool(const uri& mongodb_uri = mongocxx::uri(),
59  const options::pool& options = options::pool());
60 
64  ~pool();
65 
73  class MONGOCXX_API entry {
74  public:
76  client* operator->() const& noexcept;
77  client* operator->() && = delete;
78 
80  client& operator*() const& noexcept;
81  client& operator*() && = delete;
82 
84  entry& operator=(std::nullptr_t) noexcept;
85 
87  explicit operator bool() const noexcept;
88 
89  private:
90  friend class pool;
91 
92  using unique_client = std::unique_ptr<client, std::function<void MONGOCXX_CALL(client*)>>;
93 
94  MONGOCXX_PRIVATE explicit entry(unique_client);
95 
96  unique_client _client;
97  };
98 
103  entry acquire();
104 
109  stdx::optional<entry> try_acquire();
110 
111  private:
112  friend class options::auto_encryption;
113 
114  MONGOCXX_PRIVATE void _release(client* client);
115 
116  class MONGOCXX_PRIVATE impl;
117  const std::unique_ptr<impl> _impl;
118 };
119 
120 } // namespace v_noabi
121 } // namespace mongocxx
122 
123 #include <mongocxx/config/postlude.hpp>
Class representing a client connection to MongoDB.
Definition: client.hpp:54
Class representing the optional arguments to a MongoDB driver pool object.
Definition: pool.hpp:29
An entry is a handle on a client object acquired via the pool.
Definition: pool.hpp:73
client * operator->() const &noexcept
Access a member of the client instance.
A pool of client objects associated with a MongoDB deployment.
Definition: pool.hpp:46
pool(const uri &mongodb_uri=mongocxx::uri(), const options::pool &options=options::pool())
Creates a pool associated with a connection string.
~pool()
Destroys a pool.
Class representing a MongoDB connection string URI.
Definition: uri.hpp:42
The top-level namespace for mongocxx library entities.
Definition: bulk_write.hpp:24