summaryrefslogtreecommitdiffstats
path: root/src/corelib/serialization/qjsonarray.h
diff options
context:
space:
mode:
authorTatiana Borisova <tatiana.borisova@qt.io>2024-03-21 16:28:23 +0100
committerTatiana Borisova <tatiana.borisova@qt.io>2024-03-26 23:11:09 +0100
commite7667357712fe35b66a140916c18d8616b2e4f9c (patch)
tree4db7c386b8c70ace5d5c4e9e8096f4f0059cf9eb /src/corelib/serialization/qjsonarray.h
parent3b186ceef81e233fcaab94a10c98a582c27cfcfd (diff)
QJsonArray iterators: use new comparison helper macros
New comparison macros are used for following classes: - QJsonArray::iterator - QJsonArray::const_iterator Replace public operators operator==(), operator!=(), operator!<(), etc of classes to friend methods comparesEqual(), compareThreeWay(); Use *_helper methods to have an access to protected members of QCborValueConstRef class from friend functions. Task-number: QTBUG-120300 Change-Id: I9b41b619107ce69d8b6dab4938232fab841aab51 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/serialization/qjsonarray.h')
-rw-r--r--src/corelib/serialization/qjsonarray.h93
1 files changed, 84 insertions, 9 deletions
diff --git a/src/corelib/serialization/qjsonarray.h b/src/corelib/serialization/qjsonarray.h
index a2baa7738c..26a04e9196 100644
--- a/src/corelib/serialization/qjsonarray.h
+++ b/src/corelib/serialization/qjsonarray.h
@@ -94,24 +94,26 @@ public:
inline QJsonValueRef *operator->() { return &item; }
inline QJsonValueRef operator[](qsizetype j) const { return *(*this + j); }
+#if QT_CORE_REMOVED_SINCE(6, 8)
inline bool operator==(const iterator &o) const
{ return item.d == o.item.d && item.index == o.item.index; }
- inline bool operator!=(const iterator &o) const { return !(*this == o); }
+ inline bool operator!=(const iterator &o) const { return !operator==(o); }
inline bool operator<(const iterator &other) const
{ Q_ASSERT(item.d == other.item.d); return item.index < other.item.index; }
inline bool operator<=(const iterator &other) const
{ Q_ASSERT(item.d == other.item.d); return item.index <= other.item.index; }
- inline bool operator>(const iterator &other) const { return !(*this <= other); }
- inline bool operator>=(const iterator &other) const { return !(*this < other); }
+ inline bool operator>(const iterator &other) const { return !operator<=(other); }
+ inline bool operator>=(const iterator &other) const { return !operator<(other); }
inline bool operator==(const const_iterator &o) const
{ return item.d == o.item.d && item.index == o.item.index; }
- inline bool operator!=(const const_iterator &o) const { return !(*this == o); }
+ inline bool operator!=(const const_iterator &o) const { return !operator==(o); }
inline bool operator<(const const_iterator &other) const
{ Q_ASSERT(item.d == other.item.d); return item.index < other.item.index; }
inline bool operator<=(const const_iterator &other) const
{ Q_ASSERT(item.d == other.item.d); return item.index <= other.item.index; }
- inline bool operator>(const const_iterator &other) const { return !(*this <= other); }
- inline bool operator>=(const const_iterator &other) const { return !(*this < other); }
+ inline bool operator>(const const_iterator &other) const { return !operator<=(other); }
+ inline bool operator>=(const const_iterator &other) const { return !operator<(other); }
+#endif
inline iterator &operator++() { ++item.index; return *this; }
inline iterator operator++(int) { iterator n = *this; ++item.index; return n; }
inline iterator &operator--() { item.index--; return *this; }
@@ -123,6 +125,53 @@ public:
inline qsizetype operator-(iterator j) const { return item.index - j.item.index; }
private:
+ // Helper functions
+ static bool comparesEqual_helper(const iterator &lhs, const iterator &rhs) noexcept
+ {
+ return lhs.item.d == rhs.item.d && lhs.item.index == rhs.item.index;
+ }
+
+ static bool comparesEqual_helper(const iterator &lhs, const const_iterator &rhs) noexcept
+ {
+ return lhs.item.d == rhs.item.d && lhs.item.index == rhs.item.index;
+ }
+
+ static Qt::strong_ordering compareThreeWay_helper(const iterator &lhs,
+ const iterator &rhs) noexcept
+ {
+ Q_ASSERT(lhs.item.d == rhs.item.d);
+ return Qt::compareThreeWay(lhs.item.index, rhs.item.index);
+ }
+
+ static Qt::strong_ordering compareThreeWay_helper(const iterator &lhs,
+ const const_iterator &rhs) noexcept
+ {
+ Q_ASSERT(lhs.item.d == rhs.item.d);
+ return Qt::compareThreeWay(lhs.item.index, rhs.item.index);
+ }
+
+ // Compare friends
+ friend bool comparesEqual(const iterator &lhs, const iterator &rhs) noexcept
+ {
+ return comparesEqual_helper(lhs, rhs);
+ }
+ friend Qt::strong_ordering compareThreeWay(const iterator &lhs,
+ const iterator &rhs) noexcept
+ {
+ return compareThreeWay_helper(lhs, rhs);
+ }
+ Q_DECLARE_STRONGLY_ORDERED(iterator)
+ friend bool comparesEqual(const iterator &lhs, const const_iterator &rhs) noexcept
+ {
+ return comparesEqual_helper(lhs, rhs);
+ }
+ friend Qt::strong_ordering compareThreeWay(const iterator &lhs,
+ const const_iterator &rhs) noexcept
+ {
+ return compareThreeWay_helper(lhs, rhs);
+ }
+ Q_DECLARE_STRONGLY_ORDERED(iterator, const_iterator)
+
QJsonValueRef item;
friend class QJsonArray;
};
@@ -152,15 +201,17 @@ public:
inline const QJsonValueConstRef *operator->() const { return &item; }
inline QJsonValueConstRef operator[](qsizetype j) const { return *(*this + j); }
+#if QT_CORE_REMOVED_SINCE(6, 8)
inline bool operator==(const const_iterator &o) const
{ return item.d == o.item.d && item.index == o.item.index; }
- inline bool operator!=(const const_iterator &o) const { return !(*this == o); }
+ inline bool operator!=(const const_iterator &o) const { return !operator==(o); }
inline bool operator<(const const_iterator &other) const
{ Q_ASSERT(item.d == other.item.d); return item.index < other.item.index; }
inline bool operator<=(const const_iterator &other) const
{ Q_ASSERT(item.d == other.item.d); return item.index <= other.item.index; }
- inline bool operator>(const const_iterator &other) const { return !(*this <= other); }
- inline bool operator>=(const const_iterator &other) const { return !(*this < other); }
+ inline bool operator>(const const_iterator &other) const { return !operator<=(other); }
+ inline bool operator>=(const const_iterator &other) const { return !operator<(other); }
+#endif
inline const_iterator &operator++() { ++item.index; return *this; }
inline const_iterator operator++(int) { const_iterator n = *this; ++item.index; return n; }
inline const_iterator &operator--() { item.index--; return *this; }
@@ -172,6 +223,30 @@ public:
inline qsizetype operator-(const_iterator j) const { return item.index - j.item.index; }
private:
+ // Helper functions
+ static bool comparesEqual_helper(const const_iterator &lhs,
+ const const_iterator &rhs) noexcept
+ {
+ return lhs.item.d == rhs.item.d && lhs.item.index == rhs.item.index;
+ }
+ static Qt::strong_ordering compareThreeWay_helper(const const_iterator &lhs,
+ const const_iterator &rhs) noexcept
+ {
+ Q_ASSERT(lhs.item.d == rhs.item.d);
+ return Qt::compareThreeWay(lhs.item.index, rhs.item.index);
+ }
+
+ // Compare friends
+ friend bool comparesEqual(const const_iterator &lhs, const const_iterator &rhs) noexcept
+ {
+ return comparesEqual_helper(lhs, rhs);
+ }
+ friend Qt::strong_ordering compareThreeWay(const const_iterator &lhs,
+ const const_iterator &rhs) noexcept
+ {
+ return compareThreeWay_helper(lhs, rhs);
+ }
+ Q_DECLARE_STRONGLY_ORDERED(const_iterator)
QJsonValueConstRef item;
friend class QJsonArray;
};