MongoDB C++ Driver 4.2.0
Loading...
Searching...
No Matches
change_stream.hpp
Go to the documentation of this file.
1// Copyright 2009-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 <mongocxx/change_stream-fwd.hpp> // IWYU pragma: export
18
19//
20
21#include <mongocxx/v1/change_stream.hpp> // IWYU pragma: export
22
23#include <cstdint>
24#include <iterator>
25#include <memory> // IWYU pragma: keep: backward compatibility, to be removed.
26#include <type_traits>
27#include <utility>
28
29#include <mongocxx/client-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
30#include <mongocxx/collection-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
31#include <mongocxx/database-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
32
35
37
38namespace mongocxx {
39namespace v_noabi {
40
45 private:
46 v1::change_stream _stream;
48
49 public:
51 class iterator;
52
57
62
66 change_stream(change_stream const& other) = delete;
67
71 change_stream& operator=(change_stream const& other) = delete;
72
77
81 /* explicit(false) */ change_stream(v1::change_stream stream) : _stream{std::move(stream)} {}
82
91 explicit operator v1::change_stream() && {
92 return std::move(_stream);
93 }
94
98 explicit operator v1::change_stream() const& = delete;
99
123
132
157 bsoncxx::v1::stdx::optional<bsoncxx::v_noabi::document::view> get_resume_token() const {
158 return _stream.get_resume_token();
159 }
160};
161
166 public:
167 // Support input-iterator (caveat of post-increment returning void)
168 using difference_type = std::int64_t;
169 using value_type = bsoncxx::v_noabi::document::view const;
170 using pointer = std::add_pointer<value_type>::type;
171 using reference = std::add_lvalue_reference<value_type>::type;
172 using iterator_category = std::input_iterator_tag;
173
180
190 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::document::view const&) operator*() const;
191
201 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::document::view const*) operator->() const;
202
217
231 void operator++(int) {
232 this->operator++();
233 }
234
245 change_stream::iterator const& lhs,
246 change_stream::iterator const& rhs) noexcept;
247
248 friend bool operator!=(change_stream::iterator const& lhs, change_stream::iterator const& rhs) noexcept {
249 return !(lhs == rhs);
250 }
251
253
254 private:
255 friend change_stream;
256
257 explicit iterator(change_stream* change_stream, bool is_end);
258
259 bool is_exhausted() const;
260
261 change_stream* _change_stream;
262 bool _is_end;
263};
264
269 return {std::move(v)};
270}
271
276 return v1::change_stream{std::move(v)};
277}
278
279} // namespace v_noabi
280} // namespace mongocxx
281
283
A read-only, non-owning view of a BSON document.
Definition view.hpp:40
A MongoDB change stream iterator.
Definition change_stream.hpp:165
change_stream(change_stream &&other) noexcept
Move constructs a change_stream.
A MongoDB change stream.
Definition change_stream.hpp:50
A MongoDB change stream iterator.
Definition change_stream.hpp:165
friend bool operator==(change_stream::iterator const &lhs, change_stream::iterator const &rhs) noexcept
Compare two iterators for (in)-equality.
iterator()
Default-construct an iterator. Default-constucted iterators can be compared (all default-constructed ...
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
iterator & operator++()
Pre-increments the iterator to move to the next document.
A MongoDB change stream.
Definition change_stream.hpp:44
iterator end() const
A change_stream::iterator indicating stream exhaustion, meaning that no notifications are available f...
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
iterator begin() const
A change_stream::iterator points to the beginning of any available notifications.
change_stream(change_stream &&other) noexcept
Move constructs a change_stream.
#define MONGOCXX_ABI_EXPORT_CDECL(...)
Equivalent to MONGOCXX_ABI_EXPORT with MONGOCXX_ABI_CDECL.
Definition export.hpp:52
The mongocxx v_noabi macro guard postlude header.
The mongocxx v_noabi macro guard prelude header.
The top-level namespace within which all bsoncxx library entities are declared.
Declares entities whose ABI stability is guaranteed for documented symbols.
Declares entities whose ABI stability is NOT guaranteed.
v1::bulk_write to_v1(v_noabi::bulk_write v)
Convert to the mongocxx::v1 equivalent of v.
Definition bulk_write.hpp:162
v_noabi::bulk_write from_v1(v1::bulk_write v)
Convert to the mongocxx::v_noabi equivalent of v.
Definition bulk_write.hpp:155
The top-level namespace within which all mongocxx library entities are declared.
Provides mongocxx::v1::change_stream.
Provides bsoncxx::v_noabi::document::view.
Provides std::optional-related polyfills for library API usage.
Declares mongocxx::v_noabi::change_stream.
Declares mongocxx::v_noabi::client.
Declares mongocxx::v_noabi::collection.
Declares mongocxx::v_noabi::database.