MongoDB C++ Driver 4.2.0
Loading...
Searching...
No Matches
cursor.hpp
Go to the documentation of this file.
1// Copyright 2009-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 <mongocxx/cursor-fwd.hpp> // IWYU pragma: export
18
19//
20
21#include <mongocxx/v1/cursor.hpp> // IWYU pragma: export
22
23#include <cstddef>
24#include <iterator>
25#include <memory> // IWYU pragma: keep: backward compatibility, to be removed.
26#include <utility>
27
28#include <mongocxx/client-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
29#include <mongocxx/client_encryption-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
30#include <mongocxx/collection-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
31#include <mongocxx/database-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
32#include <mongocxx/index_view-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
33#include <mongocxx/search_index_view-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
34
36#include <bsoncxx/stdx/optional.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
37
39
40namespace mongocxx {
41namespace v_noabi {
42
50class cursor {
51 private:
52 v1::cursor _cursor;
54
55 public:
56 using type = v1::cursor::type;
57
58 class iterator;
59
64
68 MONGOCXX_ABI_EXPORT_CDECL(cursor&) operator=(cursor&& other) noexcept;
69
74
78 cursor(cursor const& other) = delete;
82 cursor& operator=(cursor const& other) = delete;
83
87 /* explicit(false) */ cursor(v1::cursor cursor) : _cursor{std::move(cursor)} {}
88
97 explicit operator v1::cursor() && {
98 return std::move(_cursor);
99 }
100
104 explicit operator v1::cursor() const& = delete;
105
124
132
133 class internal;
134};
135
154class cursor::iterator {
155 public:
160 using reference = bsoncxx::v_noabi::document::view&;
161 using pointer = bsoncxx::v_noabi::document::view*;
162 using iterator_category = std::input_iterator_tag;
163 using difference_type = std::ptrdiff_t;
164
169
174
181
187 void operator++(int) {
188 this->operator++();
189 }
190
198 friend MONGOCXX_ABI_EXPORT_CDECL(bool) operator==(iterator const&, iterator const&);
199
200 friend bool operator!=(cursor::iterator const& lhs, cursor::iterator const& rhs) noexcept {
201 return !(lhs == rhs);
202 }
203
205
206 private:
207 friend cursor;
208
209 explicit iterator(cursor* cursor);
210
211 bool is_exhausted() const;
212
213 // If this pointer is null, the iterator is considered "past-the-end".
214 cursor* _cursor;
215};
216
217} // namespace v_noabi
218} // namespace mongocxx
219
220namespace mongocxx {
221namespace v_noabi {
222
227 return {std::move(v)};
228}
229
234 return v1::cursor{std::move(v)};
235}
236
237} // namespace v_noabi
238} // namespace mongocxx
239
241
A read-only, non-owning view of a BSON document.
Definition view.hpp:40
An input iterator of documents in a MongoDB cursor result set.
Definition cursor.hpp:154
cursor(cursor &&other) noexcept
Move constructs a cursor.
A MongoDB cursor.
Definition cursor.hpp:41
type
Enumeration identifying the type of the cursor.
Definition cursor.hpp:50
An input iterator of documents in a MongoDB cursor result set.
Definition cursor.hpp:154
friend bool operator==(iterator const &, iterator const &)
Compare two iterators for (in)-equality. Iterators compare equal if they point to the same underlying...
iterator & operator++()
Pre-increments the iterator to move to the next document.
bsoncxx::v_noabi::document::view const * operator->() const
Accesses a member of the dereferenced document currently being pointed to.
bsoncxx::v_noabi::document::view const & operator*() const
Dereferences the view for the document currently being pointed to.
bsoncxx::v_noabi::document::view value_type
std::iterator_traits
Definition cursor.hpp:159
friend bool operator!=(cursor::iterator const &lhs, cursor::iterator const &rhs) noexcept
Compare two iterators for (in)-equality. Iterators compare equal if they point to the same underlying...
Definition cursor.hpp:200
void operator++(int)
Post-increments the iterator to move to the next document.
Definition cursor.hpp:187
A cursor over the documents returned by a query to a MongoDB server.
Definition cursor.hpp:50
iterator end()
A cursor::iterator indicating cursor exhaustion, meaning that no documents are available from the cur...
iterator begin()
A cursor::iterator points to the beginning of any available results.
cursor(cursor &&other) noexcept
Move constructs a cursor.
Declares mongocxx::v_noabi::index_view.
#define MONGOCXX_ABI_EXPORT_CDECL(...)
Equivalent to MONGOCXX_ABI_EXPORT with MONGOCXX_ABI_CDECL.
Definition export.hpp:52
The mongocxx v_noabi macro guard postlude header.
The mongocxx v_noabi macro guard prelude header.
Declares entities whose ABI stability is guaranteed for documented symbols.
Declares entities whose ABI stability is NOT guaranteed.
v1::bulk_write to_v1(v_noabi::bulk_write v)
Convert to the mongocxx::v1 equivalent of v.
Definition bulk_write.hpp:162
v_noabi::bulk_write from_v1(v1::bulk_write v)
Convert to the mongocxx::v_noabi equivalent of v.
Definition bulk_write.hpp:155
The top-level namespace within which all mongocxx library entities are declared.
Declares mongocxx::v_noabi::search_index_view.
Provides mongocxx::v1::cursor.
Provides bsoncxx::v_noabi::document::view.
Provides std::optional-related polyfills for library API usage.
Declares mongocxx::v_noabi::client.
Declares mongocxx::v_noabi::client_encryption.
Declares mongocxx::v_noabi::collection.
Declares mongocxx::v_noabi::cursor.
Declares mongocxx::v_noabi::database.