MongoDB C++ Driver  mongocxx-3.6.2
All Classes Namespaces Functions Typedefs Enumerations Enumerator Friends Pages
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 
24 namespace mongocxx {
25 MONGOCXX_INLINE_NAMESPACE_BEGIN
26 
27 class client;
28 class collection;
29 class database;
30 
31 class MONGOCXX_API change_stream {
32  public:
33  class MONGOCXX_API iterator;
34 
38  change_stream(change_stream&& other) noexcept;
39 
44 
49 
70  iterator begin() const;
71 
79  iterator end() const;
80 
104  bsoncxx::stdx::optional<bsoncxx::document::view> get_resume_token() const;
105 
106  private:
107  friend class client;
108  friend class collection;
109  friend class database;
110  friend class change_stream::iterator;
111 
112  MONGOCXX_PRIVATE change_stream(void* change_stream_ptr);
113 
114  class MONGOCXX_PRIVATE impl;
115  std::unique_ptr<impl> _impl;
116 };
117 
118 class MONGOCXX_API change_stream::iterator {
119  public:
120  // Support input-iterator (caveat of post-increment returning void)
121  using difference_type = std::int64_t;
122  using value_type = const bsoncxx::document::view;
123  using pointer = std::add_pointer<value_type>::type;
124  using reference = std::add_lvalue_reference<value_type>::type;
125  using iterator_category = std::input_iterator_tag;
126 
133 
138 
143 
155 
166  void operator++(int);
167 
168  private:
169  friend class change_stream;
170  enum class iter_type { k_tracking, k_default_constructed, k_end };
171 
172  MONGOCXX_PRIVATE explicit iterator(iter_type type, const change_stream* change_stream);
173 
182  friend MONGOCXX_API bool MONGOCXX_CALL operator==(const change_stream::iterator&,
183  const change_stream::iterator&) noexcept;
184 
185  friend MONGOCXX_API bool MONGOCXX_CALL operator!=(const change_stream::iterator&,
186  const change_stream::iterator&) noexcept;
190 
191  MONGOCXX_PRIVATE bool is_exhausted() const;
192 
193  // iter_type==k_default_constructed is equivalent to _change_stream==nullptr
194  iter_type _type;
195  const change_stream* _change_stream;
196 };
197 
198 MONGOCXX_INLINE_NAMESPACE_END
199 } // namespace mongocxx
200 
201 #include <mongocxx/config/postlude.hpp>
mongocxx::change_stream::iterator::operator++
iterator & operator++()
Pre-increments the iterator to move to the next document.
mongocxx::change_stream
Definition: change_stream.hpp:31
mongocxx
Top level namespace for the MongoDB C++ driver.
Definition: bulk_write.hpp:24
mongocxx::change_stream::end
iterator end() const
A change_stream::iterator indicating stream exhaustion, meaning that no notifications are available f...
mongocxx::change_stream::iterator::operator++
void operator++(int)
Post-increments the iterator to move to the next document.
mongocxx::change_stream::iterator::iterator
iterator()
Default-construct an iterator.
mongocxx::change_stream::operator=
change_stream & operator=(change_stream &&other) noexcept
Move assigns a change_stream.
mongocxx::client
Class representing a client connection to MongoDB.
Definition: client.hpp:58
mongocxx::change_stream::iterator::operator->
const bsoncxx::document::view * operator->() const
Accesses a member of the dereferenced document currently being pointed to.
mongocxx::change_stream::iterator::operator*
const bsoncxx::document::view & operator*() const
Dereferences the view for the document currently being pointed to.
mongocxx::change_stream::~change_stream
~change_stream()
Destroys a change_stream.
mongocxx::change_stream::iterator
Definition: change_stream.hpp:118
mongocxx::change_stream::change_stream
change_stream(change_stream &&other) noexcept
Move constructs a change_stream.
mongocxx::change_stream::iterator::operator!=
friend bool operator!=(const change_stream::iterator &, const change_stream::iterator &) noexcept
Compare two iterators for (in)-equality.
mongocxx::change_stream::begin
iterator begin() const
A change_stream::iterator points to the beginning of any available notifications.
mongocxx::database
Class representing a MongoDB database.
Definition: database.hpp:43
mongocxx::collection
Class representing server side document groupings within a MongoDB database.
Definition: collection.hpp:81
mongocxx::change_stream::get_resume_token
bsoncxx::stdx::optional< bsoncxx::document::view > get_resume_token() const
Returns a resume token for this change stream.
mongocxx::change_stream::iterator::operator==
friend bool operator==(const change_stream::iterator &, const change_stream::iterator &) noexcept
Compare two iterators for (in)-equality.
bsoncxx::document::view
A read-only, non-owning view of a BSON document.
Definition: view.hpp:33