File: VarIterator.h

package info (click to toggle)
poco 1.14.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 56,460 kB
  • sloc: cpp: 340,542; ansic: 245,601; makefile: 1,742; yacc: 1,005; sh: 698; sql: 312; lex: 282; xml: 128; perl: 29; python: 24
file content (191 lines) | stat: -rw-r--r-- 4,593 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
//
// VarIterator.h
//
// Library: Foundation
// Package: Dynamic
// Module:  VarIterator
//
// Definition of the VarIterator class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier:	BSL-1.0
//


#ifndef Foundation_VarIterator_INCLUDED
#define Foundation_VarIterator_INCLUDED


#include "Poco/Exception.h"
#include <iterator>
#include <algorithm>


namespace Poco {
namespace Dynamic {


class Var;


class Foundation_API VarIterator
	/// VarIterator class.
{
public:
	typedef std::bidirectional_iterator_tag iterator_category;
	typedef Var                             value_type;
	typedef std::ptrdiff_t                  difference_type;
	typedef Var*                            pointer;
	typedef Var&                            reference;

	static const std::size_t POSITION_END;
		/// End position indicator.

	VarIterator(Var* pVar, bool positionEnd);
		/// Creates the VarIterator and positions it at the end of
		/// the recordset if positionEnd is true. Otherwise, it is
		/// positioned at the beginning.

	VarIterator(const VarIterator& other);
		/// Creates a copy of other VarIterator.

	VarIterator(VarIterator&& other) noexcept;
		/// Moves another VarIterator.

	~VarIterator();
		/// Destroys the VarIterator.

	VarIterator& operator = (const VarIterator& other);
		/// Assigns the other VarIterator.

	VarIterator& operator = (VarIterator&& other) noexcept;
		/// Assigns the other VarIterator.

	bool operator == (const VarIterator& other) const;
		/// Equality operator.

	bool operator != (const VarIterator& other) const;
		/// Inequality operator.

	bool operator < (const VarIterator& other) const;
		/// Less than operator.

	bool operator > (const VarIterator& other) const;
		/// Greater than operator.

	bool operator <= (const VarIterator& other) const;
		/// Less than or equal to operator.

	bool operator >= (const VarIterator& other) const;
		/// Greater than or equal to operator.

	Var& operator * () const;
		/// Returns value at the current position.

	Var* operator -> () const;
		/// Returns pointer to the value at current position.

	const VarIterator& operator ++ () const;
		/// Advances by one position and returns current position.

	VarIterator operator ++ (int) const;
		/// Advances by one position and returns copy of the iterator with
		/// previous current position.

	const VarIterator& operator -- () const;
		/// Goes back by one position and returns copy of the iterator with
		/// previous current position.

	VarIterator operator -- (int) const;
		/// Goes back by one position and returns previous current position.

	VarIterator operator + (std::size_t diff) const;
		/// Returns a copy the VarIterator advanced by diff positions.

	VarIterator operator - (std::size_t diff) const;
		/// Returns a copy the VarIterator backed by diff positions.
		/// Throws RangeException if diff is larger than current position.

	void swap(VarIterator& other);
		/// Swaps the VarIterator with another one.

private:
	VarIterator();

	void increment() const;
		/// Increments the iterator position by one.
		/// Throws RangeException if position is out of range.

	void decrement() const;
		/// Decrements the iterator position by one.
		/// Throws RangeException if position is out of range.

	void setPosition(std::size_t pos) const;
		/// Sets the iterator position.
		/// Throws RangeException if position is out of range.

	Var*                _pVar;
	mutable std::size_t _position;

	friend class Var;
};


///
/// inlines
///


inline bool VarIterator::operator == (const VarIterator& other) const
{
	return _pVar == other._pVar && _position == other._position;
}


inline bool VarIterator::operator != (const VarIterator& other) const
{
	return _pVar != other._pVar || _position != other._position;
}


inline bool VarIterator::operator < (const VarIterator& other) const
{
	return _position < other._position;
}


inline bool VarIterator::operator > (const VarIterator& other) const
{
	return _position > other._position;
}


inline bool VarIterator::operator <= (const VarIterator& other) const
{
	return _position <= other._position;
}


inline bool VarIterator::operator >= (const VarIterator& other) const
{
	return _position >= other._position;
}


} } // namespace Poco::Dynamic


namespace std
{
	template<>
	inline void swap<Poco::Dynamic::VarIterator>(Poco::Dynamic::VarIterator& s1, Poco::Dynamic::VarIterator& s2) noexcept
		/// Full template specialization of std:::swap for VarIterator
	{
		s1.swap(s2);
	}
}


#endif // Foundation_VarIterator_INCLUDED