userver
C++ Async Framework
Loading...
Searching...
No Matches
cursor.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/storages/mongo/cursor.hpp
4
/// @brief @copybrief storages::mongo::Cursor
5
6
#
include
<
iterator
>
7
#
include
<
memory
>
8
9
#
include
<
userver
/
formats
/
bson
/
document
.
hpp
>
10
11
USERVER_NAMESPACE_BEGIN
12
13
namespace
storages::mongo {
14
namespace
impl {
15
class
CursorImpl;
16
}
// namespace impl
17
18
/// Interface for MongoDB query cursors
19
class
Cursor
{
20
public
:
21
explicit
Cursor(std::unique_ptr<impl::CursorImpl>&&);
22
~Cursor();
23
24
Cursor(
Cursor
&&)
noexcept
;
25
Cursor
& operator=(
Cursor
&&)
noexcept
;
26
27
class
Iterator
{
28
public
:
29
using
iterator_category = std::input_iterator_tag;
30
using
difference_type = ptrdiff_t;
31
using
value_type =
formats
::
bson
::
Document
;
32
using
reference =
const
value_type&;
33
using
pointer =
const
value_type*;
34
35
explicit
Iterator() =
default
;
36
explicit
Iterator(
Cursor
*);
37
38
class
DocHolder
{
39
public
:
40
explicit
DocHolder(value_type doc) : doc_(std::move(doc)) {}
41
42
value_type& operator*() {
return
doc_; }
43
44
private
:
45
value_type doc_;
46
};
47
DocHolder
operator++(
int
);
48
Iterator
& operator++();
49
reference operator*()
const
;
50
pointer operator->()
const
;
51
52
bool
operator==(
const
Iterator
&)
const
;
53
bool
operator!=(
const
Iterator
&)
const
;
54
55
private
:
56
Cursor
* cursor_;
57
};
58
59
bool
HasMore()
const
;
60
explicit
operator
bool
()
const
{
return
HasMore(); }
61
62
/// Retrieve the cursor batch size; returns zero if the cursor uses the server-defined maximum batch size.
63
std::
uint32_t
GetBatchSize
()
const
;
64
65
/// Set the cursor batch size; set to zero to force the cursor to use the server-defined maximum batch size.
66
void
SetBatchSize
(std::uint32_t);
67
68
Iterator
begin();
69
Iterator
end();
70
71
private
:
72
std::unique_ptr<impl::CursorImpl> impl_;
73
};
74
75
}
// namespace storages::mongo
76
77
USERVER_NAMESPACE_END
userver
storages
mongo
cursor.hpp
Generated on Mon Sep 29 2025 12:41:45 for userver by
Doxygen
1.13.2