Make QJsonObject::iterator a true random access iterator

Amends and fixes 7236721bf8
where the iterator category was changed from bidirectional
to random access without adding all the required functions.

Fixes: QTBUG-57353
Change-Id: I2c96448facb222c8b8f9ad4423cb0dbd1ed098f4
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Lars Knoll 2019-10-10 11:27:42 +02:00
parent 8d8140dffa
commit d0b83adfe7
2 changed files with 123 additions and 0 deletions

View File

@ -1092,6 +1092,23 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const
Returns a pointer to a modifiable reference to the current item.
*/
/*! \fn QJsonValueRef QJsonObject::iterator::operator[](int j) const
Returns a modifiable reference to the item at offset \a j from the
item pointed to by this iterator (the item at position \c{*this + j}).
This function is provided to make QJsonObject iterators behave like C++
pointers.
The return value is of type QJsonValueRef, a helper class for QJsonArray
and QJsonObject. When you get an object of type QJsonValueRef, you can
use it as if it were a reference to a QJsonValue. If you assign to it,
the assignment will apply to the element in the QJsonArray or QJsonObject
from which you got the reference.
\sa operator+()
*/
/*!
\fn bool QJsonObject::iterator::operator==(const iterator &other) const
\fn bool QJsonObject::iterator::operator==(const const_iterator &other) const
@ -1112,6 +1129,38 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const
\sa operator==()
*/
/*!
\fn bool QJsonObject::iterator::operator<(const iterator& other) const
\fn bool QJsonObject::iterator::operator<(const const_iterator& other) const
Returns \c true if the item pointed to by this iterator is less than
the item pointed to by the \a other iterator.
*/
/*!
\fn bool QJsonObject::iterator::operator<=(const iterator& other) const
\fn bool QJsonObject::iterator::operator<=(const const_iterator& other) const
Returns \c true if the item pointed to by this iterator is less than
or equal to the item pointed to by the \a other iterator.
*/
/*!
\fn bool QJsonObject::iterator::operator>(const iterator& other) const
\fn bool QJsonObject::iterator::operator>(const const_iterator& other) const
Returns \c true if the item pointed to by this iterator is greater
than the item pointed to by the \a other iterator.
*/
/*!
\fn bool QJsonObject::iterator::operator>=(const iterator& other) const
\fn bool QJsonObject::iterator::operator>=(const const_iterator& other) const
Returns \c true if the item pointed to by this iterator is greater
than or equal to the item pointed to by the \a other iterator.
*/
/*! \fn QJsonObject::iterator QJsonObject::iterator::operator++()
The prefix ++ operator, \c{++i}, advances the iterator to the
@ -1185,6 +1234,12 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const
\sa operator+=(), operator-()
*/
/*! \fn int QJsonObject::iterator::operator-(iterator other) const
Returns the number of items between the item pointed to by \a
other and the item pointed to by this iterator.
*/
/*!
\class QJsonObject::const_iterator
\inmodule QtCore
@ -1288,6 +1343,18 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const
Returns a pointer to the current item.
*/
/*! \fn QJsonValue QJsonObject::const_iterator::operator[](int j) const
Returns the item at offset \a j from the item pointed to by this iterator (the item at
position \c{*this + j}).
This function is provided to make QJsonObject iterators behave like C++
pointers.
\sa operator+()
*/
/*! \fn bool QJsonObject::const_iterator::operator==(const const_iterator &other) const
\fn bool QJsonObject::const_iterator::operator==(const iterator &other) const
@ -1306,6 +1373,34 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const
\sa operator==()
*/
/*!
\fn bool QJsonObject::const_iterator::operator<(const const_iterator& other) const
Returns \c true if the item pointed to by this iterator is less than
the item pointed to by the \a other iterator.
*/
/*!
\fn bool QJsonObject::const_iterator::operator<=(const const_iterator& other) const
Returns \c true if the item pointed to by this iterator is less than
or equal to the item pointed to by the \a other iterator.
*/
/*!
\fn bool QJsonObject::const_iterator::operator>(const const_iterator& other) const
Returns \c true if the item pointed to by this iterator is greater
than the item pointed to by the \a other iterator.
*/
/*!
\fn bool QJsonObject::const_iterator::operator>=(const const_iterator& other) const
Returns \c true if the item pointed to by this iterator is greater
than or equal to the item pointed to by the \a other iterator.
*/
/*! \fn QJsonObject::const_iterator QJsonObject::const_iterator::operator++()
The prefix ++ operator, \c{++i}, advances the iterator to the
@ -1386,6 +1481,12 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const
\sa operator+=(), operator-()
*/
/*! \fn int QJsonObject::const_iterator::operator-(const_iterator other) const
Returns the number of items between the item pointed to by \a
other and the item pointed to by this iterator.
*/
/*!
\internal

View File

@ -154,8 +154,14 @@ public:
#else
inline QJsonValueRefPtr operator->() const { return QJsonValueRefPtr(o, i); }
#endif
const QJsonValueRef operator[](int j) { return QJsonValueRef(o, i + j); }
inline bool operator==(const iterator &other) const { return i == other.i; }
inline bool operator!=(const iterator &other) const { return i != other.i; }
bool operator<(const iterator& other) const { return i < other.i; }
bool operator<=(const iterator& other) const { return i <= other.i; }
bool operator>(const iterator& other) const { return i > other.i; }
bool operator>=(const iterator& other) const { return i >= other.i; }
inline iterator &operator++() { ++i; return *this; }
inline iterator operator++(int) { iterator r = *this; ++i; return r; }
@ -166,10 +172,15 @@ public:
inline iterator operator-(int j) const { return operator+(-j); }
inline iterator &operator+=(int j) { i += j; return *this; }
inline iterator &operator-=(int j) { i -= j; return *this; }
int operator-(iterator j) const { return i - j.i; }
public:
inline bool operator==(const const_iterator &other) const { return i == other.i; }
inline bool operator!=(const const_iterator &other) const { return i != other.i; }
bool operator<(const const_iterator& other) const { return i < other.i; }
bool operator<=(const const_iterator& other) const { return i <= other.i; }
bool operator>(const const_iterator& other) const { return i > other.i; }
bool operator>=(const const_iterator& other) const { return i >= other.i; }
};
friend class iterator;
@ -200,8 +211,14 @@ public:
#else
inline QJsonValuePtr operator->() const { return QJsonValuePtr(o->valueAt(i)); }
#endif
const QJsonValue operator[](int j) { return o->valueAt(i + j); }
inline bool operator==(const const_iterator &other) const { return i == other.i; }
inline bool operator!=(const const_iterator &other) const { return i != other.i; }
bool operator<(const const_iterator& other) const { return i < other.i; }
bool operator<=(const const_iterator& other) const { return i <= other.i; }
bool operator>(const const_iterator& other) const { return i > other.i; }
bool operator>=(const const_iterator& other) const { return i >= other.i; }
inline const_iterator &operator++() { ++i; return *this; }
inline const_iterator operator++(int) { const_iterator r = *this; ++i; return r; }
@ -212,9 +229,14 @@ public:
inline const_iterator operator-(int j) const { return operator+(-j); }
inline const_iterator &operator+=(int j) { i += j; return *this; }
inline const_iterator &operator-=(int j) { i -= j; return *this; }
int operator-(iterator j) const { return i - j.i; }
inline bool operator==(const iterator &other) const { return i == other.i; }
inline bool operator!=(const iterator &other) const { return i != other.i; }
bool operator<(const iterator& other) const { return i < other.i; }
bool operator<=(const iterator& other) const { return i <= other.i; }
bool operator>(const iterator& other) const { return i > other.i; }
bool operator>=(const iterator& other) const { return i >= other.i; }
};
friend class const_iterator;