Loading...
Searching...
No Matches
change_stream.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/change_stream-fwd.hpp> // IWYU pragma: export
//
#include <mongocxx/v1/change_stream.hpp> // IWYU pragma: export
#include <cstdint>
#include <iterator>
#include <memory> // IWYU pragma: keep: backward compatibility, to be removed.
#include <type_traits>
#include <utility>
#include <mongocxx/client-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <mongocxx/collection-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <mongocxx/database-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <bsoncxx/document/view.hpp>
#include <bsoncxx/stdx/optional.hpp>
#include <mongocxx/config/prelude.hpp>
namespace mongocxx {
namespace v_noabi {
class change_stream {
private:
v1::change_stream _stream;
bsoncxx::v_noabi::document::view _doc;
public:
class iterator;
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE() change_stream(change_stream&& other) noexcept;
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(change_stream&) operator=(change_stream&& other) noexcept;
change_stream(change_stream const& other) = delete;
change_stream& operator=(change_stream const& other) = delete;
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE() ~change_stream();
/* explicit(false) */ change_stream(v1::change_stream stream) : _stream{std::move(stream)} {}
explicit operator v1::change_stream() && {
return std::move(_stream);
}
explicit operator v1::change_stream() const& = delete;
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(iterator) begin() const;
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(iterator) end() const;
bsoncxx::v1::stdx::optional<bsoncxx::v_noabi::document::view> get_resume_token() const {
return _stream.get_resume_token();
}
};
class change_stream::iterator {
public:
// Support input-iterator (caveat of post-increment returning void)
using difference_type = std::int64_t;
using value_type = bsoncxx::v_noabi::document::view const;
using pointer = std::add_pointer<value_type>::type;
using reference = std::add_lvalue_reference<value_type>::type;
using iterator_category = std::input_iterator_tag;
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE() iterator();
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(bsoncxx::v_noabi::document::view const&) operator*() const;
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(bsoncxx::v_noabi::document::view const*) operator->() const;
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(iterator&) operator++();
void operator++(int) {
this->operator++();
}
friend MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(bool) operator==(
change_stream::iterator const& lhs,
change_stream::iterator const& rhs) noexcept;
friend bool operator!=(change_stream::iterator const& lhs, change_stream::iterator const& rhs) noexcept {
return !(lhs == rhs);
}
private:
friend change_stream;
explicit iterator(change_stream* change_stream, bool is_end);
bool is_exhausted() const;
change_stream* _change_stream;
bool _is_end;
};
inline v_noabi::change_stream from_v1(v1::change_stream v) {
return {std::move(v)};
}
inline v1::change_stream to_v1(v_noabi::change_stream v) {
return v1::change_stream{std::move(v)};
}
} // namespace v_noabi
} // namespace mongocxx
#include <mongocxx/config/postlude.hpp>
bsoncxx::v_noabi::document::view
A read-only, non-owning view of a BSON document.
Definition view.hpp:40
mongocxx::change_stream::iterator
A MongoDB change stream iterator.
Definition change_stream.hpp:165
mongocxx::change_stream::change_stream
change_stream(change_stream &&other) noexcept
Move constructs a change_stream.
mongocxx::v1::change_stream
A MongoDB change stream.
Definition change_stream.hpp:48
mongocxx::v_noabi::change_stream::iterator
A MongoDB change stream iterator.
Definition change_stream.hpp:165
mongocxx::v_noabi::change_stream::iterator::operator==
friend bool operator==(change_stream::iterator const &lhs, change_stream::iterator const &rhs) noexcept
Compare two iterators for (in)-equality.
mongocxx::v_noabi::change_stream::iterator::iterator
iterator()
Default-construct an iterator. Default-constucted iterators can be compared (all default-constructed ...
mongocxx::v_noabi::change_stream::iterator::operator!=
friend bool operator!=(change_stream::iterator const &lhs, change_stream::iterator const &rhs) noexcept
Compare two iterators for (in)-equality.
Definition change_stream.hpp:248
mongocxx::v_noabi::change_stream::iterator::operator++
iterator & operator++()
Pre-increments the iterator to move to the next document.
mongocxx::v_noabi::change_stream
A MongoDB change stream.
Definition change_stream.hpp:44
mongocxx::v_noabi::change_stream::end
iterator end() const
A change_stream::iterator indicating stream exhaustion, meaning that no notifications are available f...
mongocxx::v_noabi::change_stream::get_resume_token
bsoncxx::v1::stdx::optional< bsoncxx::v_noabi::document::view > get_resume_token() const
Returns a resume token for this change stream.
Definition change_stream.hpp:157
mongocxx::v_noabi::change_stream::begin
iterator begin() const
A change_stream::iterator points to the beginning of any available notifications.
mongocxx::v_noabi::change_stream::change_stream
change_stream(change_stream &&other) noexcept
Move constructs a change_stream.
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.
bsoncxx
The top-level namespace within which all bsoncxx library entities are declared.
mongocxx::v1
Declares entities whose ABI stability is guaranteed for documented symbols.
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.
change_stream.hpp
Provides mongocxx::v1::change_stream.
view.hpp
Provides bsoncxx::v_noabi::document::view.
optional.hpp
Provides std::optional-related polyfills for library API usage.
change_stream-fwd.hpp
Declares mongocxx::v_noabi::change_stream.
client-fwd.hpp
Declares mongocxx::v_noabi::client.
collection-fwd.hpp
Declares mongocxx::v_noabi::collection.
database-fwd.hpp
Declares mongocxx::v_noabi::database.