MongoDB C++ Driver 4.1.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 <memory>
18
26
29
31
32namespace mongocxx {
33namespace v_noabi {
34
42class cursor {
43 public:
44 enum class type { k_non_tailable, k_tailable, k_tailable_await };
45
46 class iterator;
47
52
56 MONGOCXX_ABI_EXPORT_CDECL(cursor&) operator=(cursor&&) noexcept;
57
62
63 cursor(cursor const&) = delete;
64 cursor& operator=(cursor const&) = delete;
65
81
89
90 private:
92 friend ::mongocxx::v_noabi::client;
93 friend ::mongocxx::v_noabi::collection;
94 friend ::mongocxx::v_noabi::database;
95 friend ::mongocxx::v_noabi::index_view;
97
98 friend ::mongocxx::v_noabi::cursor::iterator;
99
100 cursor(void* cursor_ptr, bsoncxx::v_noabi::stdx::optional<type> cursor_type = bsoncxx::v_noabi::stdx::nullopt);
101
102 class impl;
103 std::unique_ptr<impl> _impl;
104};
105
124class cursor::iterator {
125 public:
130 using reference = bsoncxx::v_noabi::document::view&;
131 using pointer = bsoncxx::v_noabi::document::view*;
132 using iterator_category = std::input_iterator_tag;
133 using difference_type = std::ptrdiff_t;
134
139
144
151
158
159 private:
160 friend ::mongocxx::v_noabi::cursor;
161
169 friend MONGOCXX_ABI_EXPORT_CDECL(bool) operator==(iterator const&, iterator const&);
170 friend MONGOCXX_ABI_EXPORT_CDECL(bool) operator!=(iterator const&, iterator const&);
173
174 bool is_exhausted() const;
175
176 explicit iterator(cursor* cursor);
177
178 // If this pointer is null, the iterator is considered "past-the-end".
179 cursor* _cursor;
180};
181
182} // namespace v_noabi
183} // namespace mongocxx
184
186
A read-only, non-owning view of a BSON document.
Definition view.hpp:35
An input iterator of documents in a MongoDB cursor result set.
Definition cursor.hpp:124
cursor(cursor &&) noexcept
Move constructs a cursor.
Supports MongoDB Client-Side Field Level Encryption operations.
Definition client_encryption.hpp:42
A client connection to a MongoDB server.
Definition client.hpp:61
A MongoDB collection.
Definition collection.hpp:87
An input iterator of documents in a MongoDB cursor result set.
Definition cursor.hpp:124
friend bool operator!=(iterator const &, iterator const &)
Compare two iterators for (in)-equality. Iterators compare equal if they point to the same underlying...
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:129
void operator++(int)
Post-increments the iterator to move to the next document.
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. If begin() is called more t...
cursor(cursor &&) noexcept
Move constructs a cursor.
A MongoDB database.
Definition database.hpp:46
A MongoDB index.
Definition index_view.hpp:42
A MongoDB Atlas Search Index.
Definition search_index_view.hpp:26
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.
Provides bsoncxx::v_noabi::document::view.
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.
The top-level namespace within which all bsoncxx library entities are declared.
Declares entities whose ABI stability is NOT guaranteed.
The top-level namespace within which all mongocxx library entities are declared.
Declares mongocxx::v_noabi::search_index_view.
Provides std::optional-related polyfills for library API usage.