MongoDB C++ Driver  mongocxx-3.0.2
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 
23 namespace mongocxx {
24 MONGOCXX_INLINE_NAMESPACE_BEGIN
25 
26 class collection;
27 
35 class 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 
54  ~cursor();
55 
62  iterator begin();
63 
68  iterator end();
69 
70  private:
71  friend class collection;
72  friend class client;
73  friend class database;
74 
75  MONGOCXX_PRIVATE cursor(void* cursor_ptr);
76 
77  class MONGOCXX_PRIVATE impl;
78  std::unique_ptr<impl> _impl;
79 };
80 
84 class MONGOCXX_API cursor::iterator
85  : public std::iterator<std::input_iterator_tag, bsoncxx::document::view> {
86  public:
90  const bsoncxx::document::view& operator*() const;
91 
95  const bsoncxx::document::view* operator->() const;
96 
102  iterator& operator++();
103 
109  void operator++(int);
110 
111  private:
112  friend class cursor;
113 
121  friend MONGOCXX_API bool MONGOCXX_CALL operator==(const iterator&, const iterator&);
122  friend MONGOCXX_API bool MONGOCXX_CALL operator!=(const iterator&, const iterator&);
126 
127  MONGOCXX_PRIVATE explicit iterator(cursor* cursor);
128 
129  cursor* _cursor;
131 };
132 
133 MONGOCXX_INLINE_NAMESPACE_END
134 } // namespace mongocxx
135 
136 #include <mongocxx/config/postlude.hpp>
Definition: bulk_write.hpp:22
A read-only, non-owning view of a BSON document.
Definition: view.hpp:33
Class representing a pointer to the result set of a query on a MongoDB server.
Definition: cursor.hpp:35
Class representing a client connection to MongoDB.
Definition: client.hpp:49
Class representing a MongoDB database.
Definition: database.hpp:43
Class representing an input iterator of documents in a MongoDB cursor result set. ...
Definition: cursor.hpp:84
Class representing server side document groupings within a MongoDB database.
Definition: collection.hpp:74