diff options
author | Tatiana Borisova <tatiana.borisova@qt.io> | 2024-03-14 17:28:57 +0100 |
---|---|---|
committer | Tatiana Borisova <tatiana.borisova@qt.io> | 2024-03-20 19:50:01 +0100 |
commit | cd5dd8b95bbda1e9531af52c251ea926f125c8ea (patch) | |
tree | 01a9e72e2294c7276d4bf31f89ab17b8d495bb2c /src/corelib/serialization/qxmlstream.h | |
parent | c8fb376de50683c81cbf64b4422058d4dd2e9f07 (diff) |
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 <ivan.solovev@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/serialization/qxmlstream.h')
-rw-r--r-- | src/corelib/serialization/qxmlstream.h | 82 |
1 files changed, 59 insertions, 23 deletions
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 <QtCore/qcompare.h> #include <QtCore/qlist.h> #include <QtCore/qscopedpointer.h> #include <QtCore/qstring.h> @@ -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); |