Skip to content

Commit

Permalink
Add missing relational operators to VarIterator (pocoproject#4714)
Browse files Browse the repository at this point in the history
* Add missing relational operators to VarIterator

* Add tests for relational operators of VarIterator
  • Loading branch information
vfjpl authored Oct 3, 2024
1 parent f3975eb commit 64c751f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
36 changes: 36 additions & 0 deletions Foundation/include/Poco/Dynamic/VarIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ class Foundation_API VarIterator
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.

Expand Down Expand Up @@ -138,6 +150,30 @@ inline bool VarIterator::operator != (const VarIterator& other) const
}


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


Expand Down
3 changes: 1 addition & 2 deletions Foundation/src/VarIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ void VarIterator::increment() const
{
if (POSITION_END == _position)
throw RangeException("End of iterator reached.");

if (_position < _pVar->size() - 1)
else if (_position < _pVar->size() - 1)
++_position;
else
_position = POSITION_END;
Expand Down
6 changes: 6 additions & 0 deletions Foundation/testsuite/src/VarTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3161,6 +3161,8 @@ void VarTest::testIterator()

da = Poco::Dynamic::Array();
assertTrue(da.begin() == da.end());
assertTrue(da.begin() <= da.end());
assertTrue(da.begin() >= da.end());

da = 1;
assertTrue (!da.isEmpty());
Expand All @@ -3172,6 +3174,10 @@ void VarTest::testIterator()
}
catch (RangeException&) {}
assertTrue (da.begin() != da.end());
assertTrue (da.begin() <= da.end());
assertTrue (da.begin() < da.end());
assertTrue (da.end() >= da.begin());
assertTrue (da.end() > da.begin());

Var::Iterator it = da.begin();
Var::Iterator end = da.end();
Expand Down

0 comments on commit 64c751f

Please sign in to comment.