MongoDB C++ Driver current
Loading...
Searching...
No Matches
change_stream.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 <memory>
18
19#include <bsoncxx/document/view.hpp>
20#include <bsoncxx/stdx/optional.hpp>
21
22#include <mongocxx/config/prelude.hpp>
23
24namespace mongocxx {
25inline namespace v_noabi {
26class client;
27class collection;
28class database;
29
33class MONGOCXX_API change_stream {
34 public:
36 class MONGOCXX_API iterator;
37
41 change_stream(change_stream&& other) noexcept;
42
47
52
73 iterator begin() const;
74
82 iterator end() const;
83
107 bsoncxx::stdx::optional<bsoncxx::document::view> get_resume_token() const;
108
109 private:
110 friend class client;
111 friend class collection;
112 friend class database;
113 friend class change_stream::iterator;
114
115 MONGOCXX_PRIVATE change_stream(void* change_stream_ptr);
116
117 class MONGOCXX_PRIVATE impl;
118 std::unique_ptr<impl> _impl;
119};
120
124class MONGOCXX_API change_stream::iterator {
125 public:
126 // Support input-iterator (caveat of post-increment returning void)
127 using difference_type = std::int64_t;
128 using value_type = const bsoncxx::document::view;
129 using pointer = std::add_pointer<value_type>::type;
130 using reference = std::add_lvalue_reference<value_type>::type;
131 using iterator_category = std::input_iterator_tag;
132
139
146 const bsoncxx::document::view& operator*() const;
147
154 const bsoncxx::document::view* operator->() const;
155
170
184 void operator++(int);
185
186 private:
187 friend class change_stream;
188 enum class iter_type { k_tracking, k_default_constructed, k_end };
189
190 MONGOCXX_PRIVATE explicit iterator(iter_type type, const change_stream* change_stream);
191
200 friend MONGOCXX_API bool MONGOCXX_CALL operator==(const change_stream::iterator&,
201 const change_stream::iterator&) noexcept;
202
203 friend MONGOCXX_API bool MONGOCXX_CALL operator!=(const change_stream::iterator&,
204 const change_stream::iterator&) noexcept;
208
209 MONGOCXX_PRIVATE bool is_exhausted() const;
210
211 // iter_type==k_default_constructed is equivalent to _change_stream==nullptr
212 iter_type _type;
213 const change_stream* _change_stream;
214};
215
216} // namespace v_noabi
217} // namespace mongocxx
218
219#include <mongocxx/config/postlude.hpp>
Class representing a MongoDB change stream iterator.
Definition change_stream.hpp:124
friend bool operator==(const change_stream::iterator &, const change_stream::iterator &) noexcept
Compare two iterators for (in)-equality.
const bsoncxx::document::view * operator->() const
Accesses a member of the dereferenced document currently being pointed to.
iterator()
Default-construct an iterator.
void operator++(int)
Post-increments the iterator to move to the next document.
const bsoncxx::document::view & operator*() const
Dereferences the view for the document currently being pointed to.
iterator & operator++()
Pre-increments the iterator to move to the next document.
friend bool operator!=(const change_stream::iterator &, const change_stream::iterator &) noexcept
Compare two iterators for (in)-equality.
Class representing a MongoDB change stream.
Definition change_stream.hpp:33
~change_stream()
Destroys a change_stream.
iterator end() const
A change_stream::iterator indicating stream exhaustion, meaning that no notifications are available f...
change_stream & operator=(change_stream &&other) noexcept
Move assigns a change_stream.
bsoncxx::stdx::optional< bsoncxx::document::view > get_resume_token() const
Returns a resume token for this change stream.
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.
Class representing a client connection to MongoDB.
Definition client.hpp:54
Class representing server side document groupings within a MongoDB database.
Definition collection.hpp:85
Class representing a MongoDB database.
Definition database.hpp:44
The top-level namespace for mongocxx library entities.
Definition bulk_write.hpp:24