MongoDB C++ Driver  mongocxx-3.9.0
All Classes Namespaces Functions Typedefs Enumerations Enumerator Friends Pages
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 <bsoncxx/document/view.hpp>
20 #include <bsoncxx/stdx/optional.hpp>
21 
22 #include <mongocxx/config/prelude.hpp>
23 
24 namespace mongocxx {
25 inline namespace v_noabi {
26 class collection;
27 class search_index_view;
28 
36 class MONGOCXX_API cursor {
37  public:
38  enum class type { k_non_tailable, k_tailable, k_tailable_await };
39 
40  class MONGOCXX_API iterator;
41 
45  cursor(cursor&&) noexcept;
46 
50  cursor& operator=(cursor&&) noexcept;
51 
55  ~cursor();
56 
71  iterator begin();
72 
79  iterator end();
80 
81  private:
82  friend class collection;
83  friend class client;
84  friend class client_encryption;
85  friend class database;
86  friend class index_view;
87  friend class search_index_view;
88  friend class cursor::iterator;
89 
90  MONGOCXX_PRIVATE cursor(void* cursor_ptr,
91  bsoncxx::stdx::optional<type> cursor_type = bsoncxx::stdx::nullopt);
92 
93  class MONGOCXX_PRIVATE impl;
94  std::unique_ptr<impl> _impl;
95 };
96 
115 class MONGOCXX_API cursor::iterator {
116  public:
120  using value_type = bsoncxx::document::view;
121  using reference = bsoncxx::document::view&;
122  using pointer = bsoncxx::document::view*;
123  using iterator_category = std::input_iterator_tag;
124  using difference_type = std::ptrdiff_t;
125 
129  const bsoncxx::document::view& operator*() const;
130 
134  const bsoncxx::document::view* operator->() const;
135 
142 
148  void operator++(int);
149 
150  private:
151  friend class cursor;
152 
161  friend MONGOCXX_API bool MONGOCXX_CALL operator==(const iterator&, const iterator&);
162  friend MONGOCXX_API bool MONGOCXX_CALL operator!=(const iterator&, const iterator&);
166 
167  MONGOCXX_PRIVATE bool is_exhausted() const;
168 
169  MONGOCXX_PRIVATE explicit iterator(cursor* cursor);
170 
171  // If this pointer is null, the iterator is considered "past-the-end".
172  cursor* _cursor;
173 };
174 
175 } // namespace v_noabi
176 } // namespace mongocxx
177 
178 #include <mongocxx/config/postlude.hpp>
Class supporting operations for MongoDB Client-Side Field Level Encryption.
Definition: client_encryption.hpp:38
Class representing a client connection to MongoDB.
Definition: client.hpp:54
Class representing server side document groupings within a MongoDB database.
Definition: collection.hpp:85
Class representing an input iterator of documents in a MongoDB cursor result set.
Definition: cursor.hpp:115
friend bool operator!=(const iterator &, const iterator &)
Compare two iterators for (in)-equality.
const bsoncxx::document::view & operator*() const
Dereferences the view for the document currently being pointed to.
const bsoncxx::document::view * operator->() const
Accesses a member of the dereferenced 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.
bsoncxx::document::view value_type
std::iterator_traits
Definition: cursor.hpp:120
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:36
cursor(cursor &&) noexcept
Move constructs a cursor.
Class representing a MongoDB database.
Definition: database.hpp:44
Class representing a MongoDB index view.
Definition: index_view.hpp:34
Class representing a MongoDB search index view.
Definition: search_index_view.hpp:19
The top-level namespace for bsoncxx library entities.
Definition: element.hpp:24
The top-level namespace for mongocxx library entities.
Definition: bulk_write.hpp:24