MongoDB C++ Driver  mongocxx-3.4.0
All Classes Namespaces Functions Typedefs Enumerations Enumerator Friends Pages
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 
32 
37 class MONGOCXX_API topology_description {
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 topology_description;
106  MONGOCXX_PRIVATE explicit server_descriptions(void* sds, std::size_t size);
107  MONGOCXX_PRIVATE void swap(server_descriptions& other) noexcept;
108  container _container;
109  void* _sds;
110  std::size_t _size;
111  };
112 
113  MONGOCXX_PRIVATE explicit topology_description(void* event);
114 
118  ~topology_description();
119 
126  bsoncxx::stdx::string_view type() const;
127 
137  bool has_readable_server(const mongocxx::read_preference& pref) const;
138 
147  bool has_writable_server() const;
148 
154  server_descriptions servers() const;
155 
156  private:
157  // Non-const since mongoc_topology_description_has_readable_server/writable_server take
158  // non-const. They do server selection, which modifies the mongoc_topology_description_t.
159  void* _td;
160 };
161 
162 } // namespace events
163 MONGOCXX_INLINE_NAMESPACE_END
164 } // namespace mongocxx
165 
166 #include <mongocxx/config/postlude.hpp>
Top level namespace for the MongoDB C++ driver.
Definition: bulk_write.hpp:24
Definition: error_code.hpp:117
container::iterator iterator
The array&#39;s iterator type.
Definition: topology_description.hpp:68
Class representing what the driver knows about a MongoDB server.
Definition: server_description.hpp:30
container::const_iterator const_iterator
The array&#39;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
Class representing a preference for how the driver routes read operations to members of a replica set...
Definition: read_preference.hpp:62
An array of server_description instances.
Definition: topology_description.hpp:42
Top level namespace for MongoDB C++ BSON functionality.
Definition: element.hpp:24