MongoDB C++ Driver  mongocxx-3.4.0
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 
43  change_stream& operator=(change_stream&& other) noexcept;
44 
48  ~change_stream();
49 
70  iterator begin() const;
71 
79  iterator end() const;
80 
81  private:
82  friend class client;
83  friend class collection;
84  friend class database;
85  friend class change_stream::iterator;
86 
87  MONGOCXX_PRIVATE change_stream(void* change_stream_ptr);
88 
89  class MONGOCXX_PRIVATE impl;
90  std::unique_ptr<impl> _impl;
91 };
92 
93 class MONGOCXX_API change_stream::iterator {
94  public:
95  // Support input-iterator (caveat of post-increment returning void)
96  using difference_type = std::int64_t;
97  using value_type = const bsoncxx::document::view;
98  using pointer = std::add_pointer<value_type>::type;
99  using reference = std::add_lvalue_reference<value_type>::type;
100  using iterator_category = std::input_iterator_tag;
101 
107  iterator();
108 
112  const bsoncxx::document::view& operator*() const;
113 
117  const bsoncxx::document::view* operator->() const;
118 
129  iterator& operator++();
130 
141  void operator++(int);
142 
143  private:
144  friend class change_stream;
145  enum class iter_type { k_tracking, k_default_constructed, k_end };
146 
147  MONGOCXX_PRIVATE explicit iterator(iter_type type, const change_stream* change_stream);
148 
157  friend MONGOCXX_API bool MONGOCXX_CALL operator==(const change_stream::iterator&,
158  const change_stream::iterator&) noexcept;
159 
160  friend MONGOCXX_API bool MONGOCXX_CALL operator!=(const change_stream::iterator&,
161  const change_stream::iterator&) noexcept;
165 
166  MONGOCXX_PRIVATE bool is_exhausted() const;
167 
168  // iter_type==k_default_constructed is equivalent to _change_stream==nullptr
169  iter_type _type;
170  const change_stream* _change_stream;
171 };
172 
173 MONGOCXX_INLINE_NAMESPACE_END
174 } // namespace mongocxx
175 
176 #include <mongocxx/config/postlude.hpp>
Top level namespace for the MongoDB C++ driver.
Definition: bulk_write.hpp:24
A read-only, non-owning view of a BSON document.
Definition: view.hpp:33
Class representing a client connection to MongoDB.
Definition: client.hpp:57
Class representing a MongoDB database.
Definition: database.hpp:44
Definition: change_stream.hpp:31
Definition: change_stream.hpp:93
Class representing server side document groupings within a MongoDB database.
Definition: collection.hpp:85