2023-02-08 11:04:11 +00:00
|
|
|
//
|
|
|
|
// 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 <algorithm>
|
2023-02-13 09:22:33 +00:00
|
|
|
#include <iterator>
|
|
|
|
#include "Poco/Exception.h"
|
2023-02-08 11:04:11 +00:00
|
|
|
|
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
namespace Poco
|
|
|
|
{
|
|
|
|
namespace Dynamic
|
|
|
|
{
|
2023-02-08 11:04:11 +00:00
|
|
|
|
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
class Var;
|
2023-02-08 11:04:11 +00:00
|
|
|
|
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
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;
|
2023-02-08 11:04:11 +00:00
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
static const std::size_t POSITION_END;
|
|
|
|
/// End position indicator.
|
2023-02-08 11:04:11 +00:00
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
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.
|
2023-02-08 11:04:11 +00:00
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
VarIterator(const VarIterator & other);
|
|
|
|
/// Creates a copy of other VarIterator.
|
2023-02-08 11:04:11 +00:00
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
~VarIterator();
|
|
|
|
/// Destroys the VarIterator.
|
2023-02-08 11:04:11 +00:00
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
VarIterator & operator=(const VarIterator & other);
|
|
|
|
/// Assigns the other VarIterator.
|
2023-02-08 11:04:11 +00:00
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
bool operator==(const VarIterator & other) const;
|
|
|
|
/// Equality operator.
|
2023-02-08 11:04:11 +00:00
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
bool operator!=(const VarIterator & other) const;
|
|
|
|
/// Inequality operator.
|
2023-02-08 11:04:11 +00:00
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
Var & operator*() const;
|
|
|
|
/// Returns value at the current position.
|
2023-02-08 11:04:11 +00:00
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
Var * operator->() const;
|
|
|
|
/// Returns pointer to the value at current position.
|
2023-02-08 11:04:11 +00:00
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
const VarIterator & operator++() const;
|
|
|
|
/// Advances by one position and returns current position.
|
2023-02-08 11:04:11 +00:00
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
VarIterator operator++(int) const;
|
|
|
|
/// Advances by one position and returns copy of the iterator with
|
|
|
|
/// previous current position.
|
2023-02-08 11:04:11 +00:00
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
const VarIterator & operator--() const;
|
|
|
|
/// Goes back by one position and returns copy of the iterator with
|
|
|
|
/// previous current position.
|
2023-02-08 11:04:11 +00:00
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
VarIterator operator--(int) const;
|
|
|
|
/// Goes back by one position and returns previous current position.
|
2023-02-08 11:04:11 +00:00
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
VarIterator operator+(std::size_t diff) const;
|
|
|
|
/// Returns a copy the VarIterator advanced by diff positions.
|
2023-02-08 11:04:11 +00:00
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
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.
|
2023-02-08 11:04:11 +00:00
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
void swap(VarIterator & other);
|
|
|
|
/// Swaps the VarIterator with another one.
|
2023-02-08 11:04:11 +00:00
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
private:
|
|
|
|
VarIterator();
|
2023-02-08 11:04:11 +00:00
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
void increment() const;
|
|
|
|
/// Increments the iterator position by one.
|
|
|
|
/// Throws RangeException if position is out of range.
|
2023-02-08 11:04:11 +00:00
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
void decrement() const;
|
|
|
|
/// Decrements the iterator position by one.
|
|
|
|
/// Throws RangeException if position is out of range.
|
2023-02-08 11:04:11 +00:00
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
void setPosition(std::size_t pos) const;
|
|
|
|
/// Sets the iterator position.
|
|
|
|
/// Throws RangeException if position is out of range.
|
2023-02-08 11:04:11 +00:00
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
Var * _pVar;
|
|
|
|
mutable std::size_t _position;
|
2023-02-08 11:04:11 +00:00
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
friend class Var;
|
|
|
|
};
|
2023-02-08 11:04:11 +00:00
|
|
|
|
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
///
|
|
|
|
/// inlines
|
|
|
|
///
|
2023-02-08 11:04:11 +00:00
|
|
|
|
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
inline bool VarIterator::operator==(const VarIterator & other) const
|
|
|
|
{
|
|
|
|
return _pVar == other._pVar && _position == other._position;
|
|
|
|
}
|
2023-02-08 11:04:11 +00:00
|
|
|
|
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
inline bool VarIterator::operator!=(const VarIterator & other) const
|
|
|
|
{
|
|
|
|
return _pVar != other._pVar || _position != other._position;
|
|
|
|
}
|
2023-02-08 11:04:11 +00:00
|
|
|
|
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
}
|
|
|
|
} // namespace Poco::Dynamic
|
2023-02-08 11:04:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace std
|
|
|
|
{
|
2023-02-13 09:22:33 +00:00
|
|
|
template <>
|
|
|
|
inline void swap<Poco::Dynamic::VarIterator>(Poco::Dynamic::VarIterator & s1, Poco::Dynamic::VarIterator & s2)
|
|
|
|
/// Full template specialization of std:::swap for VarIterator
|
|
|
|
{
|
|
|
|
s1.swap(s2);
|
|
|
|
}
|
2023-02-08 11:04:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif // Foundation_VarIterator_INCLUDED
|