MongoDB C++ Driver  mongocxx-3.10.2
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 <mongocxx/change_stream-fwd.hpp>
20 #include <mongocxx/client-fwd.hpp>
21 #include <mongocxx/collection-fwd.hpp>
22 #include <mongocxx/database-fwd.hpp>
23 
24 #include <bsoncxx/document/view.hpp>
25 #include <bsoncxx/stdx/optional.hpp>
26 
27 #include <mongocxx/config/prelude.hpp>
28 
29 namespace mongocxx {
30 namespace v_noabi {
31 
36  public:
38  class MONGOCXX_API iterator;
39 
43  change_stream(change_stream&& other) noexcept;
44 
49 
54 
75  iterator begin() const;
76 
84  iterator end() const;
85 
109  bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view> get_resume_token() const;
110 
111  private:
112  friend ::mongocxx::v_noabi::client;
113  friend ::mongocxx::v_noabi::collection;
114  friend ::mongocxx::v_noabi::database;
115 
116  friend ::mongocxx::v_noabi::change_stream::iterator;
117 
118  MONGOCXX_PRIVATE change_stream(void* change_stream_ptr);
119 
120  class MONGOCXX_PRIVATE impl;
121  std::unique_ptr<impl> _impl;
122 };
123 
128  public:
129  // Support input-iterator (caveat of post-increment returning void)
130  using difference_type = std::int64_t;
132  using pointer = std::add_pointer<value_type>::type;
133  using reference = std::add_lvalue_reference<value_type>::type;
134  using iterator_category = std::input_iterator_tag;
135 
142 
150 
158 
173 
187  void operator++(int);
188 
189  private:
190  friend ::mongocxx::v_noabi::change_stream;
191 
192  enum class iter_type { k_tracking, k_default_constructed, k_end };
193 
194  MONGOCXX_PRIVATE explicit iterator(iter_type type, const change_stream* change_stream);
195 
204  friend MONGOCXX_API bool MONGOCXX_CALL operator==(const change_stream::iterator&,
205  const change_stream::iterator&) noexcept;
206 
207  friend MONGOCXX_API bool MONGOCXX_CALL operator!=(const change_stream::iterator&,
208  const change_stream::iterator&) noexcept;
212 
213  MONGOCXX_PRIVATE bool is_exhausted() const;
214 
215  // iter_type==k_default_constructed is equivalent to _change_stream==nullptr
216  iter_type _type;
217  const change_stream* _change_stream;
218 };
219 
220 } // namespace v_noabi
221 } // namespace mongocxx
222 
223 #include <mongocxx/config/postlude.hpp>
A read-only, non-owning view of a BSON document.
Definition: view.hpp:35
Class representing a MongoDB change stream iterator.
Definition: change_stream.hpp:127
friend bool operator==(const change_stream::iterator &, const change_stream::iterator &) noexcept
Compare two iterators for (in)-equality.
iterator()
Default-construct an iterator.
void operator++(int)
Post-increments the iterator to move to the next document.
const bsoncxx::v_noabi::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.
const bsoncxx::v_noabi::document::view * operator->() const
Accesses a member of the dereferenced document currently being pointed to.
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:35
~change_stream()
Destroys a change_stream.
iterator end() const
A change_stream::iterator indicating stream exhaustion, meaning that no notifications are available f...
iterator begin() const
A change_stream::iterator points to the beginning of any available notifications.
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::document::view > get_resume_token() const
Returns a resume token for this change stream.
change_stream & operator=(change_stream &&other) noexcept
Move assigns a change_stream.
change_stream(change_stream &&other) noexcept
Move constructs a change_stream.
The top-level namespace for mongocxx library entities.
Definition: bulk_write-fwd.hpp:19