From 0344ba60446e5e61613cc7ae5e07de67f0ba61f5 Mon Sep 17 00:00:00 2001 From: maruncz Date: Mon, 2 Oct 2023 17:14:32 +0200 Subject: [PATCH] static anlyzer --- CombatLog/CombatLog.cpp | 11 ++++++----- CombatLog/CombatLog.h | 6 +++--- CombatLog/LogLine.cpp | 11 ++++++----- CombatLog/LogLine.h | 5 ++--- CombatLog/SubEvents.cpp | 23 ++++++++++++----------- CombatLog/SubEvents.h | 14 +++++++------- CombatLog/defs.h | 2 +- DataModels/ObjectListModel.cpp | 12 ++++++++---- DataModels/healdatamodel.cpp | 10 ++++++++-- DataModels/healdatamodel.h | 15 +++++++++------ filters/SubSampler.h | 12 ++++++------ forms/DamagePerSecond.cpp | 10 +++++----- forms/DamagePerSecond.h | 2 +- 13 files changed, 74 insertions(+), 59 deletions(-) diff --git a/CombatLog/CombatLog.cpp b/CombatLog/CombatLog.cpp index 151c311..ea1426a 100644 --- a/CombatLog/CombatLog.cpp +++ b/CombatLog/CombatLog.cpp @@ -1,15 +1,16 @@ #include "CombatLog.h" #include "exceptions.h" #include +#include -CombatLog::CombatLog(const QList &lines, - const QStringList &sourceNames, - const QStringList &targetNames) - : lines{lines}, sourceNames{sourceNames}, targetNames{targetNames} +CombatLog::CombatLog(const QList& lines, QStringList sourceNames, + QStringList targetNames) + : lines {lines}, sourceNames {std::move(sourceNames)}, + targetNames {std::move(targetNames)} { } -CombatLog CombatLog::fromFile(QString filename) +CombatLog CombatLog::fromFile(const QString& filename) { QFile file{filename}; diff --git a/CombatLog/CombatLog.h b/CombatLog/CombatLog.h index 6f67c9a..d355aba 100644 --- a/CombatLog/CombatLog.h +++ b/CombatLog/CombatLog.h @@ -10,10 +10,10 @@ class CombatLog { public: CombatLog() = default; - CombatLog(const QList &lines, const QStringList &sourceNames, - const QStringList &targetNames); + CombatLog(const QList& lines, QStringList sourceNames, + QStringList targetNames); - [[nodiscard]] static CombatLog fromFile(QString filename); + [[nodiscard]] static CombatLog fromFile(const QString& filename); [[nodiscard]] const QList &getLines() const; diff --git a/CombatLog/LogLine.cpp b/CombatLog/LogLine.cpp index 7f3bf6b..3b3b88c 100644 --- a/CombatLog/LogLine.cpp +++ b/CombatLog/LogLine.cpp @@ -2,12 +2,13 @@ #include "defs.h" #include "exceptions.h" #include +#include -LogLine::LogLine(const QDateTime ×tamp, const Object &sourceObject, - const Object &destObject, SubEvent subeventType, - const variant_t &subEventValue) - : timestamp{timestamp}, sourceObject{sourceObject}, destObject{destObject}, - subeventType{subeventType}, subEventValue{subEventValue} +LogLine::LogLine(QDateTime timestamp, Object sourceObject, Object destObject, + SubEvent subeventType, variant_t subEventValue) + : timestamp {std::move(timestamp)}, sourceObject {std::move(sourceObject)}, + destObject {std::move(destObject)}, subeventType {subeventType}, + subEventValue {std::move(subEventValue)} { } diff --git a/CombatLog/LogLine.h b/CombatLog/LogLine.h index cdafa9c..4eac0f0 100644 --- a/CombatLog/LogLine.h +++ b/CombatLog/LogLine.h @@ -9,9 +9,8 @@ class LogLine { public: - LogLine(const QDateTime ×tamp, const Object &sourceObject, - const Object &destObject, SubEvent subeventType, - const variant_t &subEventValue); + LogLine(QDateTime timestamp, Object sourceObject, Object destObject, + SubEvent subeventType, variant_t subEventValue); LogLine() = default; diff --git a/CombatLog/SubEvents.cpp b/CombatLog/SubEvents.cpp index a337c5c..f4abafd 100644 --- a/CombatLog/SubEvents.cpp +++ b/CombatLog/SubEvents.cpp @@ -1,11 +1,12 @@ #include "SubEvents.h" -#include "LineParser.h" #include "exceptions.h" +#include "LineParser.h" +#include UnitFlags UnitFlags::fromNum(uint32_t n) { - static constexpr uint32_t unusedBits{Reaction::unused | Type::unused}; - if (n & unusedBits) + static constexpr uint32_t unusedBits {Reaction::unused | Type::unused}; + if ((n & unusedBits) != 0u) { throw CombatLogParserException( QStringLiteral("undefined bits set: 0x%1") @@ -82,8 +83,8 @@ SpellInfo::SpellInfo(const QStringList& list) school = LineParser::parseSpellSchool(list.at(2)); } -SpellInfo::SpellInfo(const QString &name, uint32_t id, uint8_t school) - : name{name}, id{id}, school{school} +SpellInfo::SpellInfo(QString name, uint32_t id, uint8_t school) + : name {std::move(name)}, id {id}, school {school} { } @@ -121,7 +122,7 @@ Item::Item(const QStringList& list) name = LineParser::removequotes(list.at(1)); } -Item::Item(uint32_t id, const QString &name) : id{id}, name{name} {} +Item::Item(uint32_t id, QString name) : id {id}, name {std::move(name)} {} bool Item::operator==(const Item &o) const { @@ -261,7 +262,7 @@ detail::suffix::AuraAppliedDose::AuraAppliedDose(const QStringList& list) detail::suffix::Missed::Missed(const QStringList& list) { - if (list.size() < 1) + if (list.empty()) { throw CombatLogParserException( QStringLiteral("wrong list size, expected 1, got %1") @@ -312,7 +313,7 @@ bool detail::suffix::Missed::operator==(Missed o) const PartyKill::PartyKill(const QStringList& list) { - if (list.size() != 0) + if (!list.empty()) { throw CombatLogParserException( QStringLiteral("wrong list size, expected 0, got %1 : %2") @@ -350,8 +351,8 @@ EnchantApplied::EnchantApplied(const QStringList& list) : item {list.mid(1)} name = LineParser::removequotes(list.at(0)); } -EnchantApplied::EnchantApplied(const QString &name, const Item &item) - : name{name}, item{item} +EnchantApplied::EnchantApplied(QString name, Item item) + : name {std::move(name)}, item {std::move(item)} { } @@ -405,7 +406,7 @@ detail::suffix::Drain::Drain(const QStringList& list) extraAmount = LineParser::parseDamageAmount(list.at(2)); } -detail::prefix::Range::Range(const SpellInfo &spell) : spell{spell} {} +detail::prefix::Range::Range(SpellInfo spell) : spell {std::move(spell)} {} bool detail::prefix::Range::operator==(const Range &o) const { diff --git a/CombatLog/SubEvents.h b/CombatLog/SubEvents.h index 2d997e0..b96ea21 100644 --- a/CombatLog/SubEvents.h +++ b/CombatLog/SubEvents.h @@ -77,7 +77,7 @@ struct Object struct SpellInfo { SpellInfo(const QStringList& list); - SpellInfo(const QString &name, uint32_t id, uint8_t school); + SpellInfo(QString name, uint32_t id, uint8_t school); [[nodiscard]] bool operator==(const SpellInfo &o) const; @@ -89,7 +89,7 @@ struct SpellInfo struct Item { Item(const QStringList& list); - Item(uint32_t id, const QString &name); + Item(uint32_t id, QString name); [[nodiscard]] bool operator==(const Item &o) const; @@ -109,7 +109,7 @@ struct Swing struct Range { Range(const QStringList& list) : spell {list} {} - Range(const SpellInfo &spell); + Range(SpellInfo spell); SpellInfo spell; [[nodiscard]] bool operator==(const Range &o) const; @@ -173,8 +173,8 @@ struct HealAbsorbed { Object extra; SpellInfo extraSpell; - uint32_t absorbedAmount; - uint32_t totalAmount; + uint32_t absorbedAmount {0}; + uint32_t totalAmount {0}; }; struct Absorbed @@ -437,9 +437,9 @@ struct SpellCastFailed : public detail::prefix::Spell, struct EnchantApplied { EnchantApplied(const QStringList& list); - EnchantApplied(const QString &name, const Item &item); + EnchantApplied(QString name, Item item); - [[nodiscard]] bool operator==(const EnchantApplied &o) const; + [[nodiscard]] bool operator==(const EnchantApplied& o) const; QString name; Item item; diff --git a/CombatLog/defs.h b/CombatLog/defs.h index 24718ec..56a7689 100644 --- a/CombatLog/defs.h +++ b/CombatLog/defs.h @@ -88,7 +88,7 @@ enum RaidFlags COMBATLOG_OBJECT_RAIDTARGET_MASK = 0x000000FF }; -enum class SpellSchool +enum class SpellSchool : unsigned { Physical = 1, Holy = 2, diff --git a/DataModels/ObjectListModel.cpp b/DataModels/ObjectListModel.cpp index c980234..1472f33 100644 --- a/DataModels/ObjectListModel.cpp +++ b/DataModels/ObjectListModel.cpp @@ -10,9 +10,11 @@ int ObjectListModel::rowCount(const QModelIndex &parent) const // list's size. For all other (valid) parents, rowCount() should return 0 so // that it does not become a tree model. if (parent.isValid()) + { return 0; + } - if (!list) + if (list == nullptr) { return 0; } @@ -23,9 +25,11 @@ int ObjectListModel::rowCount(const QModelIndex &parent) const QVariant ObjectListModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) - return QVariant(); + { + return {}; + } - if (!list) + if (list == nullptr) { return {}; } @@ -41,7 +45,7 @@ QVariant ObjectListModel::data(const QModelIndex &index, int role) const void ObjectListModel::setList(const QStringList *newList) { auto oldRows{0}; - if (list) + if (list != nullptr) { oldRows = list->size(); } diff --git a/DataModels/healdatamodel.cpp b/DataModels/healdatamodel.cpp index 77b9070..286e8e5 100644 --- a/DataModels/healdatamodel.cpp +++ b/DataModels/healdatamodel.cpp @@ -20,7 +20,9 @@ QVariant HealDataModel::headerData(int section, Qt::Orientation orientation, int HealDataModel::rowCount(const QModelIndex &parent) const { if (parent.isValid()) + { return 0; + } return combatlog->getLines().size(); } @@ -28,7 +30,9 @@ int HealDataModel::rowCount(const QModelIndex &parent) const int HealDataModel::columnCount(const QModelIndex &parent) const { if (parent.isValid()) + { return 0; + } return header.size(); } @@ -36,7 +40,9 @@ int HealDataModel::columnCount(const QModelIndex &parent) const QVariant HealDataModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) - return QVariant(); + { + return {}; + } if (role == Qt::DisplayRole) { @@ -94,5 +100,5 @@ QVariant HealDataModel::data(const QModelIndex &index, int role) const } } - return QVariant(); + return {}; } diff --git a/DataModels/healdatamodel.h b/DataModels/healdatamodel.h index 9530f73..48805b7 100644 --- a/DataModels/healdatamodel.h +++ b/DataModels/healdatamodel.h @@ -17,15 +17,18 @@ class HealDataModel : public QAbstractTableModel explicit HealDataModel(CombatLog *log, QObject *parent = nullptr); // Header: - QVariant headerData(int section, Qt::Orientation orientation, - int role = Qt::DisplayRole) const override; + [[nodiscard]] QVariant headerData(int section, Qt::Orientation orientation, + int role + = Qt::DisplayRole) const override; // Basic functionality: - int rowCount(const QModelIndex &parent = QModelIndex()) const override; - int columnCount(const QModelIndex &parent = QModelIndex()) const override; + [[nodiscard]] int rowCount(const QModelIndex& parent + = QModelIndex()) const override; + [[nodiscard]] int columnCount(const QModelIndex& parent + = QModelIndex()) const override; - QVariant data(const QModelIndex &index, - int role = Qt::DisplayRole) const override; + [[nodiscard]] QVariant data(const QModelIndex& index, + int role = Qt::DisplayRole) const override; private: static constexpr auto header = std::to_array( diff --git a/filters/SubSampler.h b/filters/SubSampler.h index 17dc30d..b72b019 100644 --- a/filters/SubSampler.h +++ b/filters/SubSampler.h @@ -8,11 +8,11 @@ class SubSampler { public: - SubSampler(qreal period, qreal startTime) : samplePeriod(period) + SubSampler(qreal period, qreal startTime) + : samplePeriod(period), + currentTimepoint((std::floor(startTime / samplePeriod) * samplePeriod) + + samplePeriod) { - currentTimepoint = - (std::floor(startTime / samplePeriod) * samplePeriod) + - samplePeriod; minmaxX.first = currentTimepoint; } @@ -20,9 +20,9 @@ class SubSampler std::pair finalize(); - std::pair getMinmaxX() const; + [[nodiscard]] std::pair getMinmaxX() const; - std::pair getMinmaxY() const; + [[nodiscard]] std::pair getMinmaxY() const; private: QList> advance(qreal timepoint); diff --git a/forms/DamagePerSecond.cpp b/forms/DamagePerSecond.cpp index f376335..8c5cfd9 100644 --- a/forms/DamagePerSecond.cpp +++ b/forms/DamagePerSecond.cpp @@ -24,7 +24,7 @@ DamagePerSecond::~DamagePerSecond() void DamagePerSecond::updateChart() { - if (!originalLog) + if (originalLog == nullptr) { throw std::runtime_error("log ptr null"); } @@ -56,9 +56,9 @@ void DamagePerSecond::updateChart() return false; } - if (!((l.getSubeventType() == SubEvent::SPELL_DAMAGE) || - (l.getSubeventType() == SubEvent::SPELL_PERIODIC_DAMAGE) || - (l.getSubeventType() == SubEvent::SWING_DAMAGE))) + if ((l.getSubeventType() != SubEvent::SPELL_DAMAGE) + && (l.getSubeventType() != SubEvent::SPELL_PERIODIC_DAMAGE) + && (l.getSubeventType() != SubEvent::SWING_DAMAGE)) { return false; } @@ -85,7 +85,7 @@ void DamagePerSecond::updateChart() temporaryLog.getLines().front().getTimestamp().toMSecsSinceEpoch() - timeOffset; - auto line = new QLineSeries(this); + auto* line = new QLineSeries(this); SubSampler sampler{ui->doubleSpinBoxFilter->value() * 1000, static_cast(lineOffset)}; diff --git a/forms/DamagePerSecond.h b/forms/DamagePerSecond.h index 4bed090..582c585 100644 --- a/forms/DamagePerSecond.h +++ b/forms/DamagePerSecond.h @@ -45,7 +45,7 @@ private slots: QStringList sourceNamesList; QStringList targetNamesList; - CombatLog *originalLog; + CombatLog* originalLog {nullptr}; QChart chart; QValueAxis axisX; QValueAxis axisY;