From cd5dd8b95bbda1e9531af52c251ea926f125c8ea Mon Sep 17 00:00:00 2001 From: Tatiana Borisova Date: Thu, 14 Mar 2024 17:28:57 +0100 Subject: Xml: use new comparison helper macros New comparison macros are used for following classes: -QXmlStreamAttribute -QXmlStreamNamespaceDeclaration -QXmlStreamNotationDeclaration -QXmlStreamEntityDeclaration Replace public operators operator==(), operator!=() of classes to friend methods comparesEqual(); Use QT_CORE_REMOVED_SINCE to get rid of current comparison methods and replace them with a friend. Add checkStreamNotationDeclarations()/checkStreamEntityDeclarations() test-cases to test change. Task-number: QTBUG-120300 Change-Id: I0b5642b2e23cc21ede7bc4888f0a9bddd6c08d07 Reviewed-by: Ivan Solovev Reviewed-by: Thiago Macieira --- src/corelib/serialization/qxmlstream.h | 82 ++++++++++++++++++++++++---------- 1 file changed, 59 insertions(+), 23 deletions(-) (limited to 'src/corelib/serialization/qxmlstream.h') diff --git a/src/corelib/serialization/qxmlstream.h b/src/corelib/serialization/qxmlstream.h index e6dd25117a..7eeaa1c1cc 100644 --- a/src/corelib/serialization/qxmlstream.h +++ b/src/corelib/serialization/qxmlstream.h @@ -8,6 +8,7 @@ #if QT_CONFIG(xmlstream) +#include #include #include #include @@ -58,13 +59,23 @@ public: } inline QStringView value() const { return m_value; } inline bool isDefault() const { return m_isDefault; } - inline bool operator==(const QXmlStreamAttribute &other) const { - return (value() == other.value() - && (namespaceUri().isNull() ? (qualifiedName() == other.qualifiedName()) - : (namespaceUri() == other.namespaceUri() && name() == other.name()))); - } +#if QT_CORE_REMOVED_SINCE(6, 8) + inline bool operator==(const QXmlStreamAttribute &other) const + { return comparesEqual(*this, other); } inline bool operator!=(const QXmlStreamAttribute &other) const - { return !operator==(other); } + { return !operator==(other); } +#endif + +private: + friend bool comparesEqual(const QXmlStreamAttribute &lhs, + const QXmlStreamAttribute &rhs) noexcept + { + return (lhs.value() == rhs.value() + && (lhs.namespaceUri().isNull() ? (lhs.qualifiedName() == rhs.qualifiedName()) + : (lhs.namespaceUri() == rhs.namespaceUri() + && lhs.name() == rhs.name()))); + } + Q_DECLARE_EQUALITY_COMPARABLE(QXmlStreamAttribute) }; Q_DECLARE_TYPEINFO(QXmlStreamAttribute, Q_RELOCATABLE_TYPE); @@ -111,11 +122,19 @@ public: inline QStringView prefix() const { return m_prefix; } inline QStringView namespaceUri() const { return m_namespaceUri; } - inline bool operator==(const QXmlStreamNamespaceDeclaration &other) const { - return (prefix() == other.prefix() && namespaceUri() == other.namespaceUri()); - } +#if QT_CORE_REMOVED_SINCE(6, 8) + inline bool operator==(const QXmlStreamNamespaceDeclaration &other) const + { return comparesEqual(*this, other); } inline bool operator!=(const QXmlStreamNamespaceDeclaration &other) const - { return !operator==(other); } + { return !operator==(other); } +#endif +private: + friend bool comparesEqual(const QXmlStreamNamespaceDeclaration &lhs, + const QXmlStreamNamespaceDeclaration &rhs) noexcept + { + return (lhs.prefix() == rhs.prefix() && lhs.namespaceUri() == rhs.namespaceUri()); + } + Q_DECLARE_EQUALITY_COMPARABLE(QXmlStreamNamespaceDeclaration) }; Q_DECLARE_TYPEINFO(QXmlStreamNamespaceDeclaration, Q_RELOCATABLE_TYPE); @@ -131,12 +150,20 @@ public: inline QStringView name() const { return m_name; } inline QStringView systemId() const { return m_systemId; } inline QStringView publicId() const { return m_publicId; } - inline bool operator==(const QXmlStreamNotationDeclaration &other) const { - return (name() == other.name() && systemId() == other.systemId() - && publicId() == other.publicId()); - } +#if QT_CORE_REMOVED_SINCE(6, 8) + inline bool operator==(const QXmlStreamNotationDeclaration &other) const + { return comparesEqual(*this, other); } inline bool operator!=(const QXmlStreamNotationDeclaration &other) const - { return !operator==(other); } + { return !operator==(other); } +#endif +private: + friend bool comparesEqual(const QXmlStreamNotationDeclaration &lhs, + const QXmlStreamNotationDeclaration &rhs) noexcept + { + return (lhs.name() == rhs.name() && lhs.systemId() == rhs.systemId() + && lhs.publicId() == rhs.publicId()); + } + Q_DECLARE_EQUALITY_COMPARABLE(QXmlStreamNotationDeclaration) }; Q_DECLARE_TYPEINFO(QXmlStreamNotationDeclaration, Q_RELOCATABLE_TYPE); @@ -154,15 +181,24 @@ public: inline QStringView systemId() const { return m_systemId; } inline QStringView publicId() const { return m_publicId; } inline QStringView value() const { return m_value; } - inline bool operator==(const QXmlStreamEntityDeclaration &other) const { - return (name() == other.name() - && notationName() == other.notationName() - && systemId() == other.systemId() - && publicId() == other.publicId() - && value() == other.value()); - } +#if QT_CORE_REMOVED_SINCE(6, 8) + inline bool operator==(const QXmlStreamEntityDeclaration &other) const + { return comparesEqual(*this, other); } inline bool operator!=(const QXmlStreamEntityDeclaration &other) const - { return !operator==(other); } + { return !operator==(other); } +#endif + +private: + friend bool comparesEqual(const QXmlStreamEntityDeclaration &lhs, + const QXmlStreamEntityDeclaration &rhs) noexcept + { + return (lhs.name() == rhs.name() + && lhs.notationName() == rhs.notationName() + && lhs.systemId() == rhs.systemId() + && lhs.publicId() == rhs.publicId() + && lhs.value() == rhs.value()); + } + Q_DECLARE_EQUALITY_COMPARABLE(QXmlStreamEntityDeclaration) }; Q_DECLARE_TYPEINFO(QXmlStreamEntityDeclaration, Q_RELOCATABLE_TYPE); -- cgit v1.2.3