MongoDB C++ Driver  mongocxx-3.0.0
client.hpp
1 // Copyright 2014 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 <memory>
18 
19 #include <bsoncxx/string/view_or_value.hpp>
20 #include <mongocxx/database.hpp>
21 #include <mongocxx/options/client.hpp>
22 #include <mongocxx/read_concern.hpp>
23 #include <mongocxx/read_preference.hpp>
24 #include <mongocxx/stdx.hpp>
25 #include <mongocxx/uri.hpp>
26 #include <mongocxx/write_concern.hpp>
27 
28 #include <mongocxx/config/prelude.hpp>
29 
30 namespace mongocxx {
31 MONGOCXX_INLINE_NAMESPACE_BEGIN
32 
49 class MONGOCXX_API client {
50  public:
56  client() noexcept;
57 
66  client(const class uri& mongodb_uri, const options::client& options = options::client());
67 
71  client(client&&) noexcept;
72 
76  client& operator=(client&&) noexcept;
77 
81  ~client();
82 
87  explicit operator bool() const noexcept;
88 
101  void read_concern(class read_concern rc);
102 
108  class read_concern read_concern() const;
109 
122  void read_preference(class read_preference rp);
123 
131  class read_preference read_preference() const;
132 
138  class uri uri() const;
139 
150  void write_concern(class write_concern wc);
151 
156  class write_concern write_concern() const;
157 
168  class database database(bsoncxx::string::view_or_value name) const&;
169  class database database(bsoncxx::string::view_or_value name) const&& = delete;
170 
182  MONGOCXX_INLINE class database operator[](bsoncxx::string::view_or_value name) const&;
183  MONGOCXX_INLINE class database operator[](bsoncxx::string::view_or_value name) const&& = delete;
184 
198  cursor list_databases() const;
199 
200  private:
201  friend class collection;
202  friend class database;
203  friend class pool;
204 
205  MONGOCXX_PRIVATE explicit client(void* implementation);
206 
207  class MONGOCXX_PRIVATE impl;
208 
209  MONGOCXX_PRIVATE impl& _get_impl();
210  MONGOCXX_PRIVATE const impl& _get_impl() const;
211 
212  std::unique_ptr<impl> _impl;
213 };
214 
215 MONGOCXX_INLINE database client::operator[](bsoncxx::string::view_or_value name) const & {
216  return database(name);
217 }
218 
219 MONGOCXX_INLINE_NAMESPACE_END
220 } // namespace mongocxx
221 
222 #include <mongocxx/config/postlude.hpp>
Class representing a MongoDB connection string URI.
Definition: uri.hpp:40
Definition: bulk_write.hpp:22
Class representing the optional arguments to a MongoDB driver client object.
Definition: client.hpp:33
Class representing a pointer to the result set of a query on a MongoDB server.
Definition: cursor.hpp:35
Class representing a client connection to MongoDB.
Definition: client.hpp:49
A pool of client objects associated with a MongoDB deployment.
Definition: pool.hpp:49
Class representing a MongoDB database.
Definition: database.hpp:43
Class representing a preference for how the driver routes read operations to members of a replica set...
Definition: read_preference.hpp:54
A class to represent the read concern.
Definition: read_concern.hpp:46
Class representing the server-side requirement for reporting the success of a write operation...
Definition: write_concern.hpp:54
Class representing server side document groupings within a MongoDB database.
Definition: collection.hpp:74