MongoDB C++ Driver  mongocxx-3.3.0
All Classes Namespaces Functions 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 collection;
28 
29 class MONGOCXX_API change_stream {
30  public:
31  class MONGOCXX_API iterator;
32 
36  change_stream(change_stream&& other) noexcept;
37 
41  change_stream& operator=(change_stream&& other) noexcept;
42 
46  ~change_stream();
47 
68  iterator begin() const;
69 
77  iterator end() const;
78 
79  private:
80  friend class collection;
81  friend class change_stream::iterator;
82 
83  MONGOCXX_PRIVATE change_stream(void* change_stream_ptr);
84 
85  class MONGOCXX_PRIVATE impl;
86  std::unique_ptr<impl> _impl;
87 };
88 
89 class MONGOCXX_API change_stream::iterator {
90  public:
91  // Support input-iterator (caveat of post-increment returning void)
92  using difference_type = std::int64_t;
93  using value_type = const bsoncxx::document::view;
94  using pointer = std::add_pointer<value_type>::type;
95  using reference = std::add_lvalue_reference<value_type>::type;
96  using iterator_category = std::input_iterator_tag;
97 
103  iterator();
104 
108  const bsoncxx::document::view& operator*() const;
109 
113  const bsoncxx::document::view* operator->() const;
114 
125  iterator& operator++();
126 
137  void operator++(int);
138 
139  private:
140  friend class change_stream;
141  enum class iter_type { k_tracking, k_default_constructed, k_end };
142 
143  MONGOCXX_PRIVATE explicit iterator(iter_type type, const change_stream* change_stream);
144 
153  friend MONGOCXX_API bool MONGOCXX_CALL operator==(const change_stream::iterator&,
154  const change_stream::iterator&) noexcept;
155 
156  friend MONGOCXX_API bool MONGOCXX_CALL operator!=(const change_stream::iterator&,
157  const change_stream::iterator&) noexcept;
161 
162  MONGOCXX_PRIVATE bool is_exhausted() const;
163 
164  // iter_type==k_default_constructed is equivalent to _change_stream==nullptr
165  iter_type _type;
166  const change_stream* _change_stream;
167 };
168 
169 MONGOCXX_INLINE_NAMESPACE_END
170 } // namespace mongocxx
171 
172 #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
Definition: change_stream.hpp:29
Definition: change_stream.hpp:89
Class representing server side document groupings within a MongoDB database.
Definition: collection.hpp:87