MongoDB C++ Driver  mongocxx-3.0.2
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 <cstdint>
18 #include <string>
19 #include <memory>
20 
21 #include <bsoncxx/document/view_or_value.hpp>
22 #include <bsoncxx/stdx/optional.hpp>
23 #include <mongocxx/stdx.hpp>
24 
25 #include <mongocxx/config/prelude.hpp>
26 
27 namespace mongocxx {
28 MONGOCXX_INLINE_NAMESPACE_BEGIN
29 
30 class client;
31 class collection;
32 class database;
33 class uri;
34 
54 class MONGOCXX_API read_preference {
55  public:
67  enum class read_mode : std::uint8_t {
71  k_primary = 0x01,
72 
76  k_primary_preferred = 0x05,
77 
81  k_secondary = 0x02,
82 
86  k_secondary_preferred = 0x06,
87 
91  k_nearest = 0x0A
92  };
93 
100  explicit read_preference(read_mode mode = read_mode::k_primary);
101 
113 
118 
122  read_preference& operator=(const read_preference&);
123 
127  read_preference(read_preference&&) noexcept;
128 
132  read_preference& operator=(read_preference&&) noexcept;
133 
137  ~read_preference();
138 
145  void mode(read_mode mode);
146 
152  read_mode mode() const;
153 
160  void tags(bsoncxx::document::view_or_value tags);
161 
167  stdx::optional<bsoncxx::document::view> tags() const;
168 
169  private:
170  friend client;
171  friend collection;
172  friend database;
173  friend uri;
174  friend MONGOCXX_API bool MONGOCXX_CALL
175  operator==(const read_preference&, const read_preference&);
176 
177  class MONGOCXX_PRIVATE impl;
178 
179  MONGOCXX_PRIVATE read_preference(std::unique_ptr<impl>&& implementation);
180 
181  std::unique_ptr<impl> _impl;
182 };
183 
184 MONGOCXX_INLINE_NAMESPACE_END
185 } // namespace mongocxx
186 
187 #include <mongocxx/config/postlude.hpp>
Class representing a MongoDB connection string URI.
Definition: uri.hpp:40
Definition: bulk_write.hpp:22
Definition: error_code.hpp:69
Class representing a client connection to MongoDB.
Definition: client.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
read_mode
Determines which members in a replica set are acceptable to read from.
Definition: read_preference.hpp:67
Definition: element.hpp:24
Class representing server side document groupings within a MongoDB database.
Definition: collection.hpp:74