Coverage Report

Created: 2026-04-29 06:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/poco/Foundation/include/Poco/Dynamic/VarIterator.h
Line
Count
Source
1
//
2
// VarIterator.h
3
//
4
// Library: Foundation
5
// Package: Dynamic
6
// Module:  VarIterator
7
//
8
// Definition of the VarIterator class.
9
//
10
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
11
// and Contributors.
12
//
13
// SPDX-License-Identifier: BSL-1.0
14
//
15
16
17
#ifndef Foundation_VarIterator_INCLUDED
18
#define Foundation_VarIterator_INCLUDED
19
20
21
#include "Poco/Exception.h"
22
#include <iterator>
23
#include <algorithm>
24
25
26
namespace Poco::Dynamic {
27
28
29
class Var;
30
31
32
class Foundation_API VarIterator
33
  /// VarIterator class.
34
{
35
public:
36
  using iterator_category = std::bidirectional_iterator_tag;
37
  using value_type = Var;
38
  using difference_type = std::ptrdiff_t;
39
  using pointer = Var *;
40
  using reference = Var &;
41
42
  static const std::size_t POSITION_END;
43
    /// End position indicator.
44
45
  VarIterator(Var* pVar, bool positionEnd);
46
    /// Creates the VarIterator and positions it at the end of
47
    /// the recordset if positionEnd is true. Otherwise, it is
48
    /// positioned at the beginning.
49
50
  VarIterator(const VarIterator& other);
51
    /// Creates a copy of other VarIterator.
52
53
  VarIterator(VarIterator&& other) noexcept;
54
    /// Moves another VarIterator.
55
56
  ~VarIterator();
57
    /// Destroys the VarIterator.
58
59
  VarIterator& operator = (const VarIterator& other);
60
    /// Assigns the other VarIterator.
61
62
  VarIterator& operator = (VarIterator&& other) noexcept;
63
    /// Assigns the other VarIterator.
64
65
  bool operator == (const VarIterator& other) const;
66
    /// Equality operator.
67
68
  bool operator != (const VarIterator& other) const;
69
    /// Inequality operator.
70
71
  bool operator < (const VarIterator& other) const;
72
    /// Less than operator.
73
74
  bool operator > (const VarIterator& other) const;
75
    /// Greater than operator.
76
77
  bool operator <= (const VarIterator& other) const;
78
    /// Less than or equal to operator.
79
80
  bool operator >= (const VarIterator& other) const;
81
    /// Greater than or equal to operator.
82
83
  Var& operator * () const;
84
    /// Returns value at the current position.
85
86
  Var* operator -> () const;
87
    /// Returns pointer to the value at current position.
88
89
  const VarIterator& operator ++ () const;
90
    /// Advances by one position and returns current position.
91
92
  VarIterator operator ++ (int) const;
93
    /// Advances by one position and returns copy of the iterator with
94
    /// previous current position.
95
96
  const VarIterator& operator -- () const;
97
    /// Goes back by one position and returns copy of the iterator with
98
    /// previous current position.
99
100
  VarIterator operator -- (int) const;
101
    /// Goes back by one position and returns previous current position.
102
103
  VarIterator operator + (std::size_t diff) const;
104
    /// Returns a copy the VarIterator advanced by diff positions.
105
106
  VarIterator operator - (std::size_t diff) const;
107
    /// Returns a copy the VarIterator backed by diff positions.
108
    /// Throws RangeException if diff is larger than current position.
109
110
  void swap(VarIterator& other);
111
    /// Swaps the VarIterator with another one.
112
113
private:
114
  VarIterator();
115
116
  void increment() const;
117
    /// Increments the iterator position by one.
118
    /// Throws RangeException if position is out of range.
119
120
  void decrement() const;
121
    /// Decrements the iterator position by one.
122
    /// Throws RangeException if position is out of range.
123
124
  void setPosition(std::size_t pos) const;
125
    /// Sets the iterator position.
126
    /// Throws RangeException if position is out of range.
127
128
  Var*                _pVar;
129
  mutable std::size_t _position;
130
131
  friend class Var;
132
};
133
134
135
///
136
/// inlines
137
///
138
139
140
inline bool VarIterator::operator == (const VarIterator& other) const
141
0
{
142
0
  return _pVar == other._pVar && _position == other._position;
143
0
}
144
145
146
inline bool VarIterator::operator != (const VarIterator& other) const
147
0
{
148
0
  return _pVar != other._pVar || _position != other._position;
149
0
}
150
151
152
inline bool VarIterator::operator < (const VarIterator& other) const
153
0
{
154
0
  return _position < other._position;
155
0
}
156
157
158
inline bool VarIterator::operator > (const VarIterator& other) const
159
0
{
160
0
  return _position > other._position;
161
0
}
162
163
164
inline bool VarIterator::operator <= (const VarIterator& other) const
165
0
{
166
0
  return _position <= other._position;
167
0
}
168
169
170
inline bool VarIterator::operator >= (const VarIterator& other) const
171
0
{
172
0
  return _position >= other._position;
173
0
}
174
175
176
} // namespace Poco::Dynamic
177
178
179
namespace std
180
{
181
  template<>
182
  inline void swap<Poco::Dynamic::VarIterator>(Poco::Dynamic::VarIterator& s1, Poco::Dynamic::VarIterator& s2) noexcept
183
    /// Full template specialization of std:::swap for VarIterator
184
0
  {
185
0
    s1.swap(s2);
186
0
  }
187
}
188
189
190
#endif // Foundation_VarIterator_INCLUDED