QJson{Array,Object}: rewrite & simplify some iterator functions
Instead of manipulating indices in multiple functions, make some call the others. This reduces the number of places porting must happen at, if we wanted to. Change-Id: I89446ea06b5742efb194fffd16bb78d24e0528b2 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
This commit is contained in:
parent
01fe59a3b7
commit
a747ab0b72
@ -128,8 +128,7 @@ public:
|
||||
inline QJsonValueRef operator*() const { return item; }
|
||||
inline const QJsonValueConstRef *operator->() const { return &item; }
|
||||
inline QJsonValueRef *operator->() { return &item; }
|
||||
inline QJsonValueRef operator[](qsizetype j) const
|
||||
{ return { item.a, qsizetype(item.index) + j }; }
|
||||
inline QJsonValueRef operator[](qsizetype j) const { return *(*this + j); }
|
||||
|
||||
inline bool operator==(const iterator &o) const
|
||||
{ return item.a == o.item.a && item.index == o.item.index; }
|
||||
@ -155,10 +154,8 @@ public:
|
||||
inline iterator operator--(int) { iterator n = *this; item.index--; return n; }
|
||||
inline iterator &operator+=(qsizetype j) { item.index += quint64(j); return *this; }
|
||||
inline iterator &operator-=(qsizetype j) { item.index -= quint64(j); return *this; }
|
||||
inline iterator operator+(qsizetype j) const
|
||||
{ return iterator(item.a, qsizetype(item.index) + j); }
|
||||
inline iterator operator-(qsizetype j) const
|
||||
{ return iterator(item.a, qsizetype(item.index) - j); }
|
||||
inline iterator operator+(qsizetype j) const { iterator r = *this; return r += j; }
|
||||
inline iterator operator-(qsizetype j) const { return operator+(-j); }
|
||||
inline qsizetype operator-(iterator j) const { return item.index - j.item.index; }
|
||||
|
||||
private:
|
||||
@ -191,8 +188,7 @@ public:
|
||||
inline const QJsonValueConstRef operator*() const { return item; }
|
||||
inline const QJsonValueConstRef *operator->() const { return &item; }
|
||||
|
||||
inline QJsonValueConstRef operator[](qsizetype j) const
|
||||
{ return QJsonValueRef{ item.a, qsizetype(item.index) + j }; }
|
||||
inline QJsonValueConstRef operator[](qsizetype j) const { return *(*this + j); }
|
||||
inline bool operator==(const const_iterator &o) const
|
||||
{ return item.a == o.item.a && item.index == o.item.index; }
|
||||
inline bool operator!=(const const_iterator &o) const { return !(*this == o); }
|
||||
@ -208,10 +204,8 @@ public:
|
||||
inline const_iterator operator--(int) { const_iterator n = *this; item.index--; return n; }
|
||||
inline const_iterator &operator+=(qsizetype j) { item.index += quint64(j); return *this; }
|
||||
inline const_iterator &operator-=(qsizetype j) { item.index -= quint64(j); return *this; }
|
||||
inline const_iterator operator+(qsizetype j) const
|
||||
{ return const_iterator(item.a, qsizetype(item.index) + j); }
|
||||
inline const_iterator operator-(qsizetype j) const
|
||||
{ return const_iterator(item.a, qsizetype(item.index) - j); }
|
||||
inline const_iterator operator+(qsizetype j) const { const_iterator r = *this; return r += j; }
|
||||
inline const_iterator operator-(qsizetype j) const { return operator+(-j); }
|
||||
inline qsizetype operator-(const_iterator j) const { return item.index - j.item.index; }
|
||||
|
||||
private:
|
||||
|
@ -1012,7 +1012,7 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const
|
||||
Returns a pointer to a constant reference to the current item.
|
||||
*/
|
||||
|
||||
/*! \fn const QJsonValueRef QJsonObject::iterator::operator[](qsizetype j)
|
||||
/*! \fn const QJsonValueRef QJsonObject::iterator::operator[](qsizetype 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}).
|
||||
@ -1263,7 +1263,7 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const
|
||||
Returns a pointer to the current item.
|
||||
*/
|
||||
|
||||
/*! \fn const QJsonValueConstRef QJsonObject::const_iterator::operator[](qsizetype j)
|
||||
/*! \fn const QJsonValueConstRef QJsonObject::const_iterator::operator[](qsizetype j) const
|
||||
|
||||
Returns the item at offset \a j from the item pointed to by this iterator (the item at
|
||||
position \c{*this + j}).
|
||||
|
@ -146,7 +146,7 @@ public:
|
||||
inline QJsonValueRef operator*() const { return item; }
|
||||
inline const QJsonValueConstRef *operator->() const { return &item; }
|
||||
inline QJsonValueRef *operator->() { return &item; }
|
||||
const QJsonValueRef operator[](qsizetype j) { return { item.o, qsizetype(item.index) + j }; }
|
||||
inline QJsonValueRef operator[](qsizetype j) const { return *(*this + j); }
|
||||
|
||||
inline bool operator==(const iterator &other) const
|
||||
{ return item.o == other.item.o && item.index == other.item.index; }
|
||||
@ -162,8 +162,7 @@ public:
|
||||
inline iterator operator++(int) { iterator r = *this; ++item.index; return r; }
|
||||
inline iterator &operator--() { --item.index; return *this; }
|
||||
inline iterator operator--(int) { iterator r = *this; --item.index; return r; }
|
||||
inline iterator operator+(qsizetype j) const
|
||||
{ iterator r = *this; r.item.index += quint64(j); return r; }
|
||||
inline iterator operator+(qsizetype j) const { iterator r = *this; return r += j; }
|
||||
inline iterator operator-(qsizetype j) const { return operator+(-j); }
|
||||
inline iterator &operator+=(qsizetype j) { item.index += quint64(j); return *this; }
|
||||
inline iterator &operator-=(qsizetype j) { item.index -= quint64(j); return *this; }
|
||||
@ -212,7 +211,7 @@ public:
|
||||
inline QJsonValueConstRef value() const { return item; }
|
||||
inline const QJsonValueConstRef operator*() const { return item; }
|
||||
inline const QJsonValueConstRef *operator->() const { return &item; }
|
||||
const QJsonValueConstRef operator[](qsizetype j) { return { item.o, qsizetype(item.index) + j }; }
|
||||
inline QJsonValueConstRef operator[](qsizetype j) const { return *(*this + j); }
|
||||
|
||||
inline bool operator==(const const_iterator &other) const
|
||||
{ return item.o == other.item.o && item.index == other.item.index; }
|
||||
@ -228,8 +227,7 @@ public:
|
||||
inline const_iterator operator++(int) { const_iterator r = *this; ++item.index; return r; }
|
||||
inline const_iterator &operator--() { --item.index; return *this; }
|
||||
inline const_iterator operator--(int) { const_iterator r = *this; --item.index; return r; }
|
||||
inline const_iterator operator+(qsizetype j) const
|
||||
{ const_iterator r = *this; r.item.index += quint64(j); return r; }
|
||||
inline const_iterator operator+(qsizetype j) const { const_iterator r = *this; return r += j; }
|
||||
inline const_iterator operator-(qsizetype j) const { return operator+(-j); }
|
||||
inline const_iterator &operator+=(qsizetype j) { item.index += quint64(j); return *this; }
|
||||
inline const_iterator &operator-=(qsizetype j) { item.index -= quint64(j); return *this; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user