MongoDB C++ Driver  mongocxx-3.7.0
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 <bsoncxx/stdx/string_view.hpp>
20 #include <mongocxx/events/server_description.hpp>
21 #include <mongocxx/read_preference.hpp>
22 
23 #include <mongocxx/config/prelude.hpp>
24 
25 namespace mongocxx {
26 MONGOCXX_INLINE_NAMESPACE_BEGIN
27 
28 namespace events {
29 
31 
36 class MONGOCXX_API topology_description {
37  public:
41  class MONGOCXX_API server_descriptions {
42  private:
43  using container = std::vector<server_description>;
44 
45  public:
50 
54  server_descriptions& operator=(server_descriptions&&) noexcept;
55 
57  server_descriptions& operator=(const server_descriptions&) = delete;
58 
63 
67  using iterator = container::iterator;
68 
72  using const_iterator = container::const_iterator;
73 
79  iterator begin() noexcept;
80  const_iterator begin() const noexcept;
81 
85 
91  iterator end() noexcept;
92  const_iterator end() const noexcept;
93 
97 
101  std::size_t size() const noexcept;
102 
103  private:
104  friend topology_description;
105  MONGOCXX_PRIVATE explicit server_descriptions(void* sds, std::size_t size);
106  MONGOCXX_PRIVATE void swap(server_descriptions& other) noexcept;
107  container _container;
108  void* _sds;
109  std::size_t _size;
110  };
111 
112  MONGOCXX_PRIVATE explicit topology_description(void* event);
113 
118 
125  bsoncxx::stdx::string_view type() const;
126 
136  bool has_readable_server(const mongocxx::read_preference& pref) const;
137 
146  bool has_writable_server() const;
147 
153  server_descriptions servers() const;
154 
155  private:
156  // Non-const since mongoc_topology_description_has_readable_server/writable_server take
157  // non-const. They do server selection, which modifies the mongoc_topology_description_t.
158  void* _td;
159 };
160 
161 } // namespace events
162 MONGOCXX_INLINE_NAMESPACE_END
163 } // namespace mongocxx
164 
165 #include <mongocxx/config/postlude.hpp>
mongocxx
Top level namespace for the MongoDB C++ driver.
Definition: bulk_write.hpp:24
bsoncxx
Top level namespace for MongoDB C++ BSON functionality.
Definition: element.hpp:24
mongocxx::read_preference
Class representing a preference for how the driver routes read operations to members of a replica set...
Definition: read_preference.hpp:63
mongocxx::events::topology_description::server_descriptions::const_iterator
container::const_iterator const_iterator
The array's const iterator type.
Definition: topology_description.hpp:72
mongocxx::events::topology_description::server_descriptions::iterator
container::iterator iterator
The array's iterator type.
Definition: topology_description.hpp:67
mongocxx::events::topology_description::server_descriptions
An array of server_description instances.
Definition: topology_description.hpp:41
mongocxx::events::topology_description
Class representing what the driver knows about a topology of MongoDB servers: either a standalone,...
Definition: topology_description.hpp:36