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
6
7
#include <iterator>
8
9
#include <
userver/formats/yaml/value.hpp
>
10
11
USERVER_NAMESPACE_BEGIN
12
13
namespace
yaml_config
{
14
16
template
<
typename
IterTraits>
17
class
Iterator final {
18
public
:
19
using
YamlIterator = formats::yaml::Value::const_iterator;
20
using
iterator_category = std::forward_iterator_tag;
21
using
difference_type = std::ptrdiff_t;
22
using
value_type =
typename
IterTraits::value_type;
23
using
reference =
typename
IterTraits::reference;
24
using
pointer =
typename
IterTraits::pointer;
25
26
Iterator();
27
28
Iterator(
const
value_type& container, YamlIterator it)
29
: container_(&container),
30
it_(std::move(it))
31
{}
32
33
Iterator(
const
Iterator& other);
34
Iterator(Iterator&& other)
noexcept
;
35
Iterator& operator=(
const
Iterator&);
36
Iterator& operator=(Iterator&&)
noexcept
;
37
38
Iterator operator++(
int
);
39
Iterator& operator++();
40
41
reference operator*()
const
{
42
UpdateValue();
43
return
*current_;
44
}
45
pointer operator->()
const
{
46
UpdateValue();
47
return
&(*current_);
48
}
49
52
formats::common::Type
GetIteratorType
()
const
{
return
it_.GetIteratorType(); }
53
54
// Get member name - only if iterator is over object
55
std::string GetName()
const
;
56
57
bool
operator==(
const
Iterator
& other)
const
{
return
it_ == other.it_; }
58
bool
operator!=(
const
Iterator& other)
const
{
return
it_ != other.it_; }
59
60
private
:
61
void
UpdateValue()
const
;
62
void
IncrementInternalIterator();
63
64
// Pointer to the 'container' yaml - because substitution parsing
65
// only works with container[index/key] statements
66
const
value_type* container_{
nullptr
};
67
// Iterator over container. We actually only use its GetIndex/GetName
68
// members
69
YamlIterator it_;
70
mutable
std::optional<value_type> current_;
71
};
72
73
}
// namespace yaml_config
74
75
USERVER_NAMESPACE_END
userver
yaml_config
iterator.hpp
Generated on
for userver by
Doxygen
1.17.0