Commit 986496c7 authored by Brett Stottlemyer's avatar Brett Stottlemyer
Browse files

Improve POD (in)equality operator


Change POD (in)equality operators from member function
to non-member, non-friend.

Change-Id: I7e8893fcbe1734f4ff97026fecd99d93b8ea4e55
Reviewed-by: default avatarBrett Stottlemyer <bstottle@ford.com>
Reviewed-by: default avatarKevin Funk <kevin.funk@kdab.com>
Reviewed-by: default avatarContinuous Integration (KDAB) <build@kdab.com>
Reviewed-by: default avatarMarc Mutz <marc.mutz@kdab.com>
Showing with 9 additions and 8 deletions
......@@ -268,7 +268,7 @@ void RepCodeGenerator::generatePOD(QTextStream &out, const POD &pod)
{
QStringList equalityCheck;
foreach (const PODAttribute &attr, pod.attributes) {
equalityCheck << QStringLiteral("_%1 == other._%1").arg(attr.name);
equalityCheck << QStringLiteral("left.%1() == right.%1()").arg(attr.name);
}
out << "class " << pod.name << "\n"
"{\n"
......@@ -277,16 +277,17 @@ void RepCodeGenerator::generatePOD(QTextStream &out, const POD &pod)
<< "public:\n"
<< formatConstructors(pod)
<< formatPropertyGettersAndSetters(pod)
<< " bool operator==(const " << pod.name << " &other) const {\n"
<< " return " << equalityCheck.join(QStringLiteral(" && ")) << ";\n"
<< " }\n"
<< " bool operator!=(const " << pod.name << " &other) const {\n"
<< " return !(*this == other);\n"
<< " }\n"
<< "private:\n"
<< formatDataMembers(pod)
<< "};\n"
"\n"
<< "\n"
<< "inline bool operator==(const " << pod.name << " &left, const " << pod.name << " &right) Q_DECL_NOTHROW {\n"
<< " return " << equalityCheck.join(QStringLiteral(" && ")) << ";\n"
<< "}\n"
<< "inline bool operator!=(const " << pod.name << " &left, const " << pod.name << " &right) Q_DECL_NOTHROW {\n"
<< " return !(left == right);\n"
<< "}\n"
<< "\n"
<< formatMarshallingOperators(pod)
<< "\n"
"\n"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment