MongoDB C++ Driver mongocxx-3.1.1
Loading...
Searching...
No Matches
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
21#include <mongocxx/config/prelude.hpp>
22
23namespace mongocxx {
24MONGOCXX_INLINE_NAMESPACE_BEGIN
25
26class collection;
27
35class MONGOCXX_API cursor {
36 public:
37 enum class type { k_non_tailable, k_tailable, k_tailable_await };
38
39 class MONGOCXX_API iterator;
40
44 cursor(cursor&&) noexcept;
45
49 cursor& operator=(cursor&&) noexcept;
50
55
65 iterator begin();
66
71 iterator end();
72
73 private:
74 friend class collection;
75 friend class client;
76 friend class database;
77
78 MONGOCXX_PRIVATE cursor(void* cursor_ptr);
79
80 class MONGOCXX_PRIVATE impl;
81 std::unique_ptr<impl> _impl;
82};
83
93class MONGOCXX_API cursor::iterator
94 : public std::iterator<std::input_iterator_tag, bsoncxx::document::view> {
95 public:
100
105
112
118 void operator++(int);
119
120 private:
121 friend class cursor;
122
130 friend MONGOCXX_API bool MONGOCXX_CALL operator==(const iterator&, const iterator&);
131 friend MONGOCXX_API bool MONGOCXX_CALL operator!=(const iterator&, const iterator&);
135
136 MONGOCXX_PRIVATE explicit iterator(cursor* cursor);
137
138 // If this pointer is null, the iterator is considered "past-the-end".
139 cursor* _cursor;
140};
141
142MONGOCXX_INLINE_NAMESPACE_END
143} // namespace mongocxx
144
145#include <mongocxx/config/postlude.hpp>
A read-only, non-owning view of a BSON document.
Definition view.hpp:33
Class representing a client connection to MongoDB.
Definition client.hpp:52
Class representing server side document groupings within a MongoDB database.
Definition collection.hpp:74
Class representing an input iterator of documents in a MongoDB cursor result set.
Definition cursor.hpp:94
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.
const bsoncxx::document::view & operator*() const
Dereferences the view for the document currently being pointed to.
void operator++(int)
Post-increments the iterator to move to the next document.
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.
Class representing a pointer to the result set of a query on a MongoDB server.
Definition cursor.hpp:35
cursor(cursor &&) noexcept
Move constructs a cursor.
Class representing a MongoDB database.
Definition database.hpp:44
Top level namespace for MongoDB C++ BSON functionality.
Definition element.hpp:24
Top level namespace for the MongoDB C++ driver.
Definition bulk_write.hpp:22