From 18a9436330b4f3f615c378e3c18aa324f29cacf7 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Tue, 25 Jul 2023 13:08:24 +0200 Subject: [PATCH] Valgrind Parser: Hide Tool enum in cpp Replace some explicit iterators with auto. Change-Id: I30aad955e02cbffbfd4ffe100d381e32202fea05 Reviewed-by: hjk --- src/plugins/valgrind/xmlprotocol/parser.cpp | 37 ++++++++++++--------- src/plugins/valgrind/xmlprotocol/parser.h | 7 ---- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/plugins/valgrind/xmlprotocol/parser.cpp b/src/plugins/valgrind/xmlprotocol/parser.cpp index 342277b7f1d..749e9f2327b 100644 --- a/src/plugins/valgrind/xmlprotocol/parser.cpp +++ b/src/plugins/valgrind/xmlprotocol/parser.cpp @@ -59,6 +59,13 @@ namespace { namespace Valgrind { namespace XmlProtocol { +enum class Tool { + Unknown, + Memcheck, + Ptrcheck, + Helgrind +}; + class Parser::Private { public: @@ -91,12 +98,12 @@ private: bool notAtEnd() const; QString blockingReadElementText(); - Tool tool; + Tool tool = Tool::Unknown; QXmlStreamReader reader; QHash errorKindsByName_memcheck; QHash errorKindsByName_helgrind; QHash errorKindsByName_ptrcheck; - QHash toolsByName; + QHash toolsByName; private: Parser *const q; @@ -109,11 +116,10 @@ private: Parser::Private::Private(Parser *qq) : q(qq) { - tool = Parser::Unknown; - toolsByName.insert("memcheck", Parser::Memcheck); - toolsByName.insert("ptrcheck", Parser::Ptrcheck); - toolsByName.insert("exp-ptrcheck", Parser::Ptrcheck); - toolsByName.insert("helgrind", Parser::Helgrind); + toolsByName.insert("memcheck", Tool::Memcheck); + toolsByName.insert("ptrcheck", Tool::Ptrcheck); + toolsByName.insert("exp-ptrcheck", Tool::Ptrcheck); + toolsByName.insert("helgrind", Tool::Helgrind); ADD_ENUM(memcheck, ClientCheck) ADD_ENUM(memcheck, InvalidFree) @@ -257,8 +263,7 @@ void Parser::Private::checkProtocolVersion(const QString &versionStr) void Parser::Private::checkTool(const QString &reportedStr) { - const QHash::ConstIterator reported = toolsByName.constFind(reportedStr); - + const auto reported = toolsByName.constFind(reportedStr); if (reported == toolsByName.constEnd()) throw ParserException(Tr::tr("Valgrind tool \"%1\" not supported").arg(reportedStr)); @@ -315,7 +320,7 @@ XauxWhat Parser::Private::parseXauxWhat() MemcheckErrorKind Parser::Private::parseMemcheckErrorKind(const QString &kind) { - const QHash::ConstIterator it = errorKindsByName_memcheck.constFind(kind); + const auto it = errorKindsByName_memcheck.constFind(kind); if (it != errorKindsByName_memcheck.constEnd()) return *it; else @@ -324,7 +329,7 @@ MemcheckErrorKind Parser::Private::parseMemcheckErrorKind(const QString &kind) HelgrindErrorKind Parser::Private::parseHelgrindErrorKind(const QString &kind) { - const QHash::ConstIterator it = errorKindsByName_helgrind.constFind(kind); + const auto it = errorKindsByName_helgrind.constFind(kind); if (it != errorKindsByName_helgrind.constEnd()) return *it; else @@ -333,7 +338,7 @@ HelgrindErrorKind Parser::Private::parseHelgrindErrorKind(const QString &kind) PtrcheckErrorKind Parser::Private::parsePtrcheckErrorKind(const QString &kind) { - const QHash::ConstIterator it = errorKindsByName_ptrcheck.constFind(kind); + const auto it = errorKindsByName_ptrcheck.constFind(kind); if (it != errorKindsByName_ptrcheck.constEnd()) return *it; else @@ -343,13 +348,13 @@ PtrcheckErrorKind Parser::Private::parsePtrcheckErrorKind(const QString &kind) int Parser::Private::parseErrorKind(const QString &kind) { switch (tool) { - case Memcheck: + case Tool::Memcheck: return parseMemcheckErrorKind(kind); - case Ptrcheck: + case Tool::Ptrcheck: return parsePtrcheckErrorKind(kind); - case Helgrind: + case Tool::Helgrind: return parseHelgrindErrorKind(kind); - case Unknown: + case Tool::Unknown: default: break; } diff --git a/src/plugins/valgrind/xmlprotocol/parser.h b/src/plugins/valgrind/xmlprotocol/parser.h index 5be623a3513..069696cba64 100644 --- a/src/plugins/valgrind/xmlprotocol/parser.h +++ b/src/plugins/valgrind/xmlprotocol/parser.h @@ -24,13 +24,6 @@ class Parser : public QObject Q_OBJECT public: - enum Tool { - Unknown, - Memcheck, - Ptrcheck, - Helgrind - }; - explicit Parser(QObject *parent = nullptr); ~Parser() override;