MongoDB C++ Driver  mongocxx-3.10.2
topology_description.hpp
1 // Copyright 2018-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 <vector>
18 
19 #include <mongocxx/events/topology_description-fwd.hpp>
20 
21 #include <bsoncxx/stdx/string_view.hpp>
22 #include <mongocxx/events/server_description.hpp>
23 #include <mongocxx/read_preference.hpp>
24 
25 #include <mongocxx/config/prelude.hpp>
26 
27 namespace mongocxx {
28 namespace v_noabi {
29 namespace events {
30 
32 
38  public:
42  class MONGOCXX_API server_descriptions {
43  private:
44  using container = std::vector<server_description>;
45 
46  public:
51 
55  server_descriptions& operator=(server_descriptions&&) noexcept;
56 
58  server_descriptions& operator=(const server_descriptions&) = delete;
59 
64 
68  using iterator = container::iterator;
69 
73  using const_iterator = container::const_iterator;
74 
80  iterator begin() noexcept;
81  const_iterator begin() const noexcept;
82 
86 
92  iterator end() noexcept;
93  const_iterator end() const noexcept;
94 
98 
102  std::size_t size() const noexcept;
103 
104  private:
105  friend ::mongocxx::v_noabi::events::topology_description;
106 
107  MONGOCXX_PRIVATE explicit server_descriptions(void* sds, std::size_t size);
108  MONGOCXX_PRIVATE void swap(server_descriptions& other) noexcept;
109 
110  container _container;
111  void* _sds;
112  std::size_t _size;
113  };
114 
115  MONGOCXX_PRIVATE explicit topology_description(void* event);
116 
121 
128  bsoncxx::v_noabi::stdx::string_view type() const;
129 
139  bool has_readable_server(const mongocxx::v_noabi::read_preference& pref) const;
140 
149  bool has_writable_server() const;
150 
157 
158  private:
159  // Non-const since mongoc_topology_description_has_readable_server/writable_server take
160  // non-const. They do server selection, which modifies the mongoc_topology_description_t.
161  void* _td;
162 };
163 
164 } // namespace events
165 } // namespace v_noabi
166 } // namespace mongocxx
167 
168 namespace mongocxx {
169 namespace events {
170 
171 using ::mongocxx::v_noabi::events::read_preference; // Deprecated.
172 
173 } // namespace events
174 } // namespace mongocxx
175 
176 #include <mongocxx/config/postlude.hpp>
An array of server_description instances.
Definition: topology_description.hpp:42
server_descriptions(server_descriptions &&) noexcept
Move constructs a server_descriptions array.
container::iterator iterator
The array's iterator type.
Definition: topology_description.hpp:68
container::const_iterator const_iterator
The array's const iterator type.
Definition: topology_description.hpp:73
Class representing what the driver knows about a topology of MongoDB servers: either a standalone,...
Definition: topology_description.hpp:37
bool has_readable_server(const mongocxx::v_noabi::read_preference &pref) const
Determines if the topology has a readable server available.
bool has_writable_server() const
Determines if the topology has a writable server available, such as a primary, mongos,...
bsoncxx::v_noabi::stdx::string_view type() const
The topology type: "Unknown", "Sharded", "ReplicaSetNoPrimary", "ReplicaSetWithPrimary",...
server_descriptions servers() const
Fetches descriptions for all known servers in the topology.
Class representing a preference for how the driver routes read operations to members of a replica set...
Definition: read_preference.hpp:63
The top-level namespace for bsoncxx library entities.
Definition: element-fwd.hpp:19
The top-level namespace for mongocxx library entities.
Definition: bulk_write-fwd.hpp:19