userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
iterator.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/formats/json/iterator.hpp
4
/// @brief @copybrief formats::json::Iterator
5
6
#
include
<
iterator
>
7
#
include
<
optional
>
8
#
include
<
string
>
9
10
#
include
<
userver
/
formats
/
common
/
iterator_direction
.
hpp
>
11
12
USERVER_NAMESPACE_BEGIN
13
14
namespace
formats::
json
{
15
16
/// @brief Iterator for `formats::json::Value`
17
template
<
typename
Traits, common::
IteratorDirection
Direction = common::
IteratorDirection
::kForward>
18
class
Iterator final {
19
public
:
20
using
iterator_category = std::forward_iterator_tag;
21
using
difference_type = std::ptrdiff_t;
22
using
value_type =
typename
Traits::ValueType;
23
using
reference =
typename
Traits::Reference;
24
using
pointer =
typename
Traits::Pointer;
25
26
using
ContainerType =
typename
Traits::ContainerType;
27
28
Iterator();
29
30
Iterator(ContainerType container,
int
pos);
31
32
Iterator(
const
Iterator& other);
33
Iterator(Iterator&& other)
noexcept
;
34
Iterator& operator=(
const
Iterator& other);
35
Iterator& operator=(Iterator&& other)
noexcept
;
36
37
~Iterator();
38
39
Iterator operator++(
int
);
40
Iterator& operator++();
41
reference operator*()
const
;
42
pointer operator->()
const
;
43
44
bool
operator==(
const
Iterator& other)
const
;
45
bool
operator!=(
const
Iterator& other)
const
;
46
47
/// @brief Returns name of the referenced field
48
/// @throws `TypeMismatchException` if iterated value is not an object
49
template
<
typename
T =
void
>
50
std::string
GetName
()
const
{
51
static_assert
(
52
Direction == common::
IteratorDirection
::kForward,
53
"Reverse iterator should be used only on arrays or null, "
54
"they do not have GetName()"
55
);
56
return
GetNameImpl();
57
}
58
59
/// @brief Returns index of the referenced field
60
/// @throws `TypeMismatchException` if iterated value is not an array
61
size_t
GetIndex
()
const
;
62
63
private
:
64
bool
IsValid()
const
;
65
std::string GetNameImpl()
const
;
66
Iterator(ContainerType&& container,
int
type,
int
pos)
noexcept
;
67
68
void
UpdateValue()
const
;
69
70
/// Container being iterated
71
ContainerType container_;
72
/// Internal container type
73
int
type_;
74
/// Position inside container being iterated
75
int
pos_;
76
// Temporary object replaced on every value access.
77
mutable
std::optional<value_type> current_;
78
};
79
80
}
// namespace formats::json
81
82
USERVER_NAMESPACE_END
userver
formats
json
iterator.hpp
Generated on
for userver by
Doxygen
1.17.0