MongoDB C++ Driver  mongocxx-3.10.2
cursor.hpp
1 // Copyright 2014 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/client-fwd.hpp>
20 #include <mongocxx/client_encryption-fwd.hpp>
21 #include <mongocxx/collection-fwd.hpp>
22 #include <mongocxx/cursor-fwd.hpp>
23 #include <mongocxx/database-fwd.hpp>
24 #include <mongocxx/index_view-fwd.hpp>
25 #include <mongocxx/search_index_view-fwd.hpp>
26 
27 #include <bsoncxx/document/view.hpp>
28 #include <bsoncxx/stdx/optional.hpp>
29 
30 #include <mongocxx/config/prelude.hpp>
31 
32 namespace mongocxx {
33 namespace v_noabi {
34 
42 class cursor {
43  public:
44  enum class type { k_non_tailable, k_tailable, k_tailable_await };
45 
46  class MONGOCXX_API iterator;
47 
51  cursor(cursor&&) noexcept;
52 
56  cursor& operator=(cursor&&) noexcept;
57 
61  ~cursor();
62 
78 
86 
87  private:
88  friend ::mongocxx::v_noabi::client_encryption;
89  friend ::mongocxx::v_noabi::client;
90  friend ::mongocxx::v_noabi::collection;
91  friend ::mongocxx::v_noabi::database;
92  friend ::mongocxx::v_noabi::index_view;
93  friend ::mongocxx::v_noabi::search_index_view;
94 
95  friend ::mongocxx::v_noabi::cursor::iterator;
96 
97  MONGOCXX_PRIVATE cursor(
98  void* cursor_ptr,
99  bsoncxx::v_noabi::stdx::optional<type> cursor_type = bsoncxx::v_noabi::stdx::nullopt);
100 
101  class MONGOCXX_PRIVATE impl;
102  std::unique_ptr<impl> _impl;
103 };
104 
123 class cursor::iterator {
124  public:
131  using iterator_category = std::input_iterator_tag;
132  using difference_type = std::ptrdiff_t;
133 
138 
143 
150 
156  void operator++(int);
157 
158  private:
159  friend ::mongocxx::v_noabi::cursor;
160 
169  friend MONGOCXX_API bool MONGOCXX_CALL operator==(const iterator&, const iterator&);
170  friend MONGOCXX_API bool MONGOCXX_CALL operator!=(const iterator&, const iterator&);
174 
175  MONGOCXX_PRIVATE bool is_exhausted() const;
176 
177  MONGOCXX_PRIVATE explicit iterator(cursor* cursor);
178 
179  // If this pointer is null, the iterator is considered "past-the-end".
180  cursor* _cursor;
181 };
182 
183 } // namespace v_noabi
184 } // namespace mongocxx
185 
186 #include <mongocxx/config/postlude.hpp>
A read-only, non-owning view of a BSON document.
Definition: view.hpp:35
Class supporting operations for MongoDB Client-Side Field Level Encryption.
Definition: client_encryption.hpp:40
Class representing a client connection to MongoDB.
Definition: client.hpp:61
Class representing server side document groupings within a MongoDB database.
Definition: collection.hpp:86
Class representing an input iterator of documents in a MongoDB cursor result set.
Definition: cursor.hpp:123
friend bool operator!=(const iterator &, const iterator &)
Compare two iterators for (in)-equality.
const bsoncxx::v_noabi::document::view * operator->() const
Accesses a member of the dereferenced document currently being pointed to.
const bsoncxx::v_noabi::document::view & operator*() const
Dereferences the view for the document currently being pointed to.
friend bool operator==(const iterator &, const iterator &)
Compare two iterators for (in)-equality.
iterator & operator++()
Pre-increments the iterator to move to the next document.
void operator++(int)
Post-increments the iterator to move to the next document.
Class representing a pointer to the result set of a query on a MongoDB server.
Definition: cursor.hpp:42
iterator end()
A cursor::iterator indicating cursor exhaustion, meaning that no documents are available from the cur...
iterator begin()
A cursor::iterator that points to the beginning of any available results.
cursor(cursor &&) noexcept
Move constructs a cursor.
Class representing a MongoDB database.
Definition: database.hpp:46
Class representing a MongoDB index view.
Definition: index_view.hpp:38
Class representing a MongoDB search index view.
Definition: search_index_view.hpp:23
The top-level namespace for bsoncxx library entities.
Definition: element-fwd.hpp:19
The top-level namespace for mongocxx library entities.
Definition: bulk_write-fwd.hpp:19