Loading...
Searching...
No Matches
topology_description.hpp
Go to the documentation of this file.
// Copyright 2009-present MongoDB, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <mongocxx/events/topology_description-fwd.hpp> // IWYU pragma: export
//
#include <mongocxx/v1/events/topology_description.hpp> // IWYU pragma: export
#include <cstddef>
#include <vector>
#include <bsoncxx/stdx/string_view.hpp>
#include <mongocxx/events/server_description.hpp>
#include <mongocxx/read_preference.hpp>
#include <mongocxx/config/prelude.hpp>
namespace mongocxx {
namespace v_noabi {
namespace events {
class topology_description {
private:
v1::events::topology_description _td;
public:
class server_descriptions {
private:
using container = std::vector<server_description>;
public:
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE() server_descriptions(server_descriptions&&) noexcept;
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(server_descriptions&) operator=(server_descriptions&&) noexcept;
server_descriptions(server_descriptions const&) = delete;
server_descriptions& operator=(server_descriptions const&) = delete;
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE() ~server_descriptions();
using iterator = container::iterator;
using const_iterator = container::const_iterator;
iterator begin() noexcept {
return _container.begin();
}
const_iterator begin() const noexcept {
return _container.begin();
}
iterator end() noexcept {
return _container.end();
}
const_iterator end() const noexcept {
return _container.begin();
}
std::size_t size() const noexcept {
return _container.size();
}
private:
friend topology_description;
server_descriptions(void* sds, std::size_t size);
container _container;
void* _sds;
std::size_t _size;
};
explicit MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE() topology_description(void const* td);
/* explicit(false) */ topology_description(v1::events::topology_description const& td) : _td{td} {}
explicit operator v1::events::topology_description() const {
return _td;
}
bsoncxx::v_noabi::stdx::string_view type() const {
return _td.type();
}
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(bool) has_readable_server(v_noabi::read_preference const& pref) const;
bool has_writable_server() const {
return _td.has_writable_server();
}
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(server_descriptions) servers() const;
};
} // namespace events
} // namespace v_noabi
} // namespace mongocxx
namespace mongocxx {
namespace v_noabi {
inline v_noabi::events::topology_description from_v1(v1::events::topology_description const& v) {
return {v};
}
inline v1::events::topology_description to_v1(v_noabi::events::topology_description const& v) {
return v1::events::topology_description{v};
}
} // namespace v_noabi
} // namespace mongocxx
#include <mongocxx/config/postlude.hpp>
bsoncxx::v1::stdx::string_view
A polyfill for std::string_view.
Definition string_view.hpp:412
mongocxx::events::topology_description::server_descriptions::server_descriptions
server_descriptions(server_descriptions &&) noexcept
Move constructs a server_descriptions array.
mongocxx::v1::events::topology_description
TopologyDescription from the SDAM Logging and Monitoring specification.
Definition topology_description.hpp:42
mongocxx::v_noabi::events::topology_description::server_descriptions
An array of server_description instances.
Definition topology_description.hpp:51
mongocxx::v_noabi::events::topology_description::server_descriptions::end
iterator end() noexcept
Returns an iterator to the end.
Definition topology_description.hpp:101
mongocxx::v_noabi::events::topology_description::server_descriptions::begin
iterator begin() noexcept
Returns an iterator to the beginning.
Definition topology_description.hpp:88
mongocxx::v_noabi::events::topology_description::server_descriptions::end
const_iterator end() const noexcept
Returns an iterator to the end.
Definition topology_description.hpp:104
mongocxx::v_noabi::events::topology_description::server_descriptions::server_descriptions
server_descriptions(server_descriptions &&) noexcept
Move constructs a server_descriptions array.
mongocxx::v_noabi::events::topology_description::server_descriptions::iterator
container::iterator iterator
The array's iterator type.
Definition topology_description.hpp:77
mongocxx::v_noabi::events::topology_description::server_descriptions::const_iterator
container::const_iterator const_iterator
The array's const iterator type.
Definition topology_description.hpp:82
mongocxx::v_noabi::events::topology_description::server_descriptions::begin
const_iterator begin() const noexcept
Returns an iterator to the beginning.
Definition topology_description.hpp:91
mongocxx::v_noabi::events::topology_description::server_descriptions::size
std::size_t size() const noexcept
The number of server_description instances in the array.
Definition topology_description.hpp:113
mongocxx::v_noabi::events::topology_description
A description of the topology of one or more connected MongoDB servers.
Definition topology_description.hpp:43
mongocxx::v_noabi::events::topology_description::has_readable_server
bool has_readable_server(v_noabi::read_preference const &pref) const
Determines if the topology has a readable server available. Servers are filtered by the given read pr...
mongocxx::v_noabi::events::topology_description::has_writable_server
bool has_writable_server() const
Determines if the topology has a writable server available, such as a primary, mongos,...
Definition topology_description.hpp:170
mongocxx::v_noabi::events::topology_description::type
bsoncxx::v_noabi::stdx::string_view type() const
The topology type: "Unknown", "Sharded", "ReplicaSetNoPrimary", "ReplicaSetWithPrimary",...
Definition topology_description.hpp:147
mongocxx::v_noabi::events::topology_description::servers
server_descriptions servers() const
Fetches descriptions for all known servers in the topology.
mongocxx::v_noabi::read_preference
Describes how MongoDB clients route read operations to the members of a replica set or sharded cluste...
Definition read_preference.hpp:59
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE
#define MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(...)
Equivalent to MONGOCXX_ABI_EXPORT_UNSTABLE with MONGOCXX_ABI_CDECL.
Definition config.hpp:28
postlude.hpp
The mongocxx v_noabi macro guard postlude header.
prelude.hpp
The mongocxx v_noabi macro guard prelude header.
mongocxx::v1
Declares entities whose ABI stability is guaranteed for documented symbols.
mongocxx::v_noabi::events
Declares entities describing APM events.
mongocxx::v_noabi
Declares entities whose ABI stability is NOT guaranteed.
mongocxx::v_noabi::to_v1
v1::bulk_write to_v1(v_noabi::bulk_write v)
Convert to the mongocxx::v1 equivalent of v.
Definition bulk_write.hpp:162
mongocxx::v_noabi::from_v1
v_noabi::bulk_write from_v1(v1::bulk_write v)
Convert to the mongocxx::v_noabi equivalent of v.
Definition bulk_write.hpp:155
mongocxx
The top-level namespace within which all mongocxx library entities are declared.
topology_description.hpp
Provides mongocxx::v1::events::topology_description.
string_view.hpp
Provides std::string_view-related polyfills for library API usage.
server_description.hpp
Provides mongocxx::v_noabi::events::server_description.
topology_description-fwd.hpp
Declares mongocxx::v_noabi::events::topology_description.
read_preference.hpp
Provides mongocxx::v_noabi::read_preference.