MongoDB C++ Driver  mongocxx-3.3.1
All Classes Namespaces Functions Enumerations Enumerator Friends Pages
read_preference.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 <chrono>
18 #include <cstdint>
19 #include <memory>
20 #include <string>
21 
22 #include <bsoncxx/document/view_or_value.hpp>
23 #include <bsoncxx/stdx/optional.hpp>
24 #include <mongocxx/stdx.hpp>
25 
26 #include <mongocxx/config/prelude.hpp>
27 
28 namespace mongocxx {
29 MONGOCXX_INLINE_NAMESPACE_BEGIN
30 
31 class client;
32 class collection;
33 class database;
34 class uri;
35 
57 class MONGOCXX_API read_preference {
58  public:
70  enum class read_mode : std::uint8_t {
74  k_primary,
75 
79  k_primary_preferred,
80 
84  k_secondary,
85 
89  k_secondary_preferred,
90 
94  k_nearest
95  };
96 
100  read_preference();
101 
102  struct deprecated_tag {};
103 
112  MONGOCXX_DEPRECATED read_preference(read_mode mode);
114 
127  MONGOCXX_DEPRECATED read_preference(read_mode mode, bsoncxx::document::view_or_value tags);
129 
134 
138  read_preference& operator=(const read_preference&);
139 
143  read_preference(read_preference&&) noexcept;
144 
148  read_preference& operator=(read_preference&&) noexcept;
149 
153  ~read_preference();
154 
165  read_preference& mode(read_mode mode);
166 
172  read_mode mode() const;
173 
186  read_preference& tags(bsoncxx::document::view_or_value tags);
187 
195  stdx::optional<bsoncxx::document::view> tags() const;
196 
227  read_preference& max_staleness(std::chrono::seconds max_staleness);
228 
234  stdx::optional<std::chrono::seconds> max_staleness() const;
235 
236  private:
237  friend client;
238  friend collection;
239  friend database;
240  friend uri;
241 
249  friend MONGOCXX_API bool MONGOCXX_CALL operator==(const read_preference&,
250  const read_preference&);
251  friend MONGOCXX_API bool MONGOCXX_CALL operator!=(const read_preference&,
252  const read_preference&);
256 
257  class MONGOCXX_PRIVATE impl;
258 
259  MONGOCXX_PRIVATE read_preference(std::unique_ptr<impl>&& implementation);
260 
261  std::unique_ptr<impl> _impl;
262 };
263 
264 MONGOCXX_INLINE_NAMESPACE_END
265 } // namespace mongocxx
266 
267 #include <mongocxx/config/postlude.hpp>
Class representing a MongoDB connection string URI.
Definition: uri.hpp:40
Top level namespace for the MongoDB C++ driver.
Definition: bulk_write.hpp:24
Definition: error_code.hpp:117
Class representing a client connection to MongoDB.
Definition: client.hpp:57
Definition: read_preference.hpp:102
Class representing a MongoDB database.
Definition: database.hpp:47
Class representing a preference for how the driver routes read operations to members of a replica set...
Definition: read_preference.hpp:57
read_mode
Determines which members in a replica set are acceptable to read from.
Definition: read_preference.hpp:70
Top level namespace for MongoDB C++ BSON functionality.
Definition: element.hpp:24
Class representing server side document groupings within a MongoDB database.
Definition: collection.hpp:87