MongoDB C++ Driver  mongocxx-3.6.6
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 MONGOCXX_INLINE_NAMESPACE_BEGIN
26 
27 class collection;
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 database;
85  friend class index_view;
86  friend class cursor::iterator;
87 
88  MONGOCXX_PRIVATE cursor(void* cursor_ptr,
89  bsoncxx::stdx::optional<type> cursor_type = bsoncxx::stdx::nullopt);
90 
91  class MONGOCXX_PRIVATE impl;
92  std::unique_ptr<impl> _impl;
93 };
94 
113 class MONGOCXX_API cursor::iterator
114  : public std::iterator<std::input_iterator_tag, bsoncxx::document::view> {
115  public:
120 
125 
132 
138  void operator++(int);
139 
140  private:
141  friend class cursor;
142 
151  friend MONGOCXX_API bool MONGOCXX_CALL operator==(const iterator&, const iterator&);
152  friend MONGOCXX_API bool MONGOCXX_CALL operator!=(const iterator&, const iterator&);
156 
157  MONGOCXX_PRIVATE bool is_exhausted() const;
158 
159  MONGOCXX_PRIVATE explicit iterator(cursor* cursor);
160 
161  // If this pointer is null, the iterator is considered "past-the-end".
162  cursor* _cursor;
163 };
164 
165 MONGOCXX_INLINE_NAMESPACE_END
166 } // namespace mongocxx
167 
168 #include <mongocxx/config/postlude.hpp>
mongocxx
Top level namespace for the MongoDB C++ driver.
Definition: bulk_write.hpp:24
bsoncxx
Top level namespace for MongoDB C++ BSON functionality.
Definition: element.hpp:24
mongocxx::client
Class representing a client connection to MongoDB.
Definition: client.hpp:58
mongocxx::cursor::iterator::operator++
iterator & operator++()
Pre-increments the iterator to move to the next document.
mongocxx::cursor::iterator::operator!=
friend bool operator!=(const iterator &, const iterator &)
Compare two iterators for (in)-equality.
mongocxx::index_view
Definition: index_view.hpp:32
mongocxx::cursor::iterator
Class representing an input iterator of documents in a MongoDB cursor result set.
Definition: cursor.hpp:114
mongocxx::cursor::iterator::operator->
const bsoncxx::document::view * operator->() const
Accesses a member of the dereferenced document currently being pointed to.
mongocxx::cursor::iterator::operator++
void operator++(int)
Post-increments the iterator to move to the next document.
mongocxx::cursor::iterator::operator*
const bsoncxx::document::view & operator*() const
Dereferences the view for the document currently being pointed to.
mongocxx::cursor::iterator::operator==
friend bool operator==(const iterator &, const iterator &)
Compare two iterators for (in)-equality.
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::cursor::cursor
cursor(cursor &&) noexcept
Move constructs a cursor.
mongocxx::cursor
Class representing a pointer to the result set of a query on a MongoDB server.
Definition: cursor.hpp:36
bsoncxx::document::view
A read-only, non-owning view of a BSON document.
Definition: view.hpp:33