Valgrind Parser: Hide Tool enum in cpp

Replace some explicit iterators with auto.

Change-Id: I30aad955e02cbffbfd4ffe100d381e32202fea05
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2023-07-25 13:08:24 +02:00
parent 35602deb82
commit 18a9436330
2 changed files with 21 additions and 23 deletions

View File

@@ -59,6 +59,13 @@ namespace {
namespace Valgrind { namespace Valgrind {
namespace XmlProtocol { namespace XmlProtocol {
enum class Tool {
Unknown,
Memcheck,
Ptrcheck,
Helgrind
};
class Parser::Private class Parser::Private
{ {
public: public:
@@ -91,12 +98,12 @@ private:
bool notAtEnd() const; bool notAtEnd() const;
QString blockingReadElementText(); QString blockingReadElementText();
Tool tool; Tool tool = Tool::Unknown;
QXmlStreamReader reader; QXmlStreamReader reader;
QHash<QString, MemcheckErrorKind> errorKindsByName_memcheck; QHash<QString, MemcheckErrorKind> errorKindsByName_memcheck;
QHash<QString, HelgrindErrorKind> errorKindsByName_helgrind; QHash<QString, HelgrindErrorKind> errorKindsByName_helgrind;
QHash<QString, PtrcheckErrorKind> errorKindsByName_ptrcheck; QHash<QString, PtrcheckErrorKind> errorKindsByName_ptrcheck;
QHash<QString, Parser::Tool> toolsByName; QHash<QString, Tool> toolsByName;
private: private:
Parser *const q; Parser *const q;
@@ -109,11 +116,10 @@ private:
Parser::Private::Private(Parser *qq) Parser::Private::Private(Parser *qq)
: q(qq) : q(qq)
{ {
tool = Parser::Unknown; toolsByName.insert("memcheck", Tool::Memcheck);
toolsByName.insert("memcheck", Parser::Memcheck); toolsByName.insert("ptrcheck", Tool::Ptrcheck);
toolsByName.insert("ptrcheck", Parser::Ptrcheck); toolsByName.insert("exp-ptrcheck", Tool::Ptrcheck);
toolsByName.insert("exp-ptrcheck", Parser::Ptrcheck); toolsByName.insert("helgrind", Tool::Helgrind);
toolsByName.insert("helgrind", Parser::Helgrind);
ADD_ENUM(memcheck, ClientCheck) ADD_ENUM(memcheck, ClientCheck)
ADD_ENUM(memcheck, InvalidFree) ADD_ENUM(memcheck, InvalidFree)
@@ -257,8 +263,7 @@ void Parser::Private::checkProtocolVersion(const QString &versionStr)
void Parser::Private::checkTool(const QString &reportedStr) void Parser::Private::checkTool(const QString &reportedStr)
{ {
const QHash<QString,Parser::Tool>::ConstIterator reported = toolsByName.constFind(reportedStr); const auto reported = toolsByName.constFind(reportedStr);
if (reported == toolsByName.constEnd()) if (reported == toolsByName.constEnd())
throw ParserException(Tr::tr("Valgrind tool \"%1\" not supported").arg(reportedStr)); 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) MemcheckErrorKind Parser::Private::parseMemcheckErrorKind(const QString &kind)
{ {
const QHash<QString,MemcheckErrorKind>::ConstIterator it = errorKindsByName_memcheck.constFind(kind); const auto it = errorKindsByName_memcheck.constFind(kind);
if (it != errorKindsByName_memcheck.constEnd()) if (it != errorKindsByName_memcheck.constEnd())
return *it; return *it;
else else
@@ -324,7 +329,7 @@ MemcheckErrorKind Parser::Private::parseMemcheckErrorKind(const QString &kind)
HelgrindErrorKind Parser::Private::parseHelgrindErrorKind(const QString &kind) HelgrindErrorKind Parser::Private::parseHelgrindErrorKind(const QString &kind)
{ {
const QHash<QString,HelgrindErrorKind>::ConstIterator it = errorKindsByName_helgrind.constFind(kind); const auto it = errorKindsByName_helgrind.constFind(kind);
if (it != errorKindsByName_helgrind.constEnd()) if (it != errorKindsByName_helgrind.constEnd())
return *it; return *it;
else else
@@ -333,7 +338,7 @@ HelgrindErrorKind Parser::Private::parseHelgrindErrorKind(const QString &kind)
PtrcheckErrorKind Parser::Private::parsePtrcheckErrorKind(const QString &kind) PtrcheckErrorKind Parser::Private::parsePtrcheckErrorKind(const QString &kind)
{ {
const QHash<QString,PtrcheckErrorKind>::ConstIterator it = errorKindsByName_ptrcheck.constFind(kind); const auto it = errorKindsByName_ptrcheck.constFind(kind);
if (it != errorKindsByName_ptrcheck.constEnd()) if (it != errorKindsByName_ptrcheck.constEnd())
return *it; return *it;
else else
@@ -343,13 +348,13 @@ PtrcheckErrorKind Parser::Private::parsePtrcheckErrorKind(const QString &kind)
int Parser::Private::parseErrorKind(const QString &kind) int Parser::Private::parseErrorKind(const QString &kind)
{ {
switch (tool) { switch (tool) {
case Memcheck: case Tool::Memcheck:
return parseMemcheckErrorKind(kind); return parseMemcheckErrorKind(kind);
case Ptrcheck: case Tool::Ptrcheck:
return parsePtrcheckErrorKind(kind); return parsePtrcheckErrorKind(kind);
case Helgrind: case Tool::Helgrind:
return parseHelgrindErrorKind(kind); return parseHelgrindErrorKind(kind);
case Unknown: case Tool::Unknown:
default: default:
break; break;
} }

View File

@@ -24,13 +24,6 @@ class Parser : public QObject
Q_OBJECT Q_OBJECT
public: public:
enum Tool {
Unknown,
Memcheck,
Ptrcheck,
Helgrind
};
explicit Parser(QObject *parent = nullptr); explicit Parser(QObject *parent = nullptr);
~Parser() override; ~Parser() override;