Skip to content

Commit

Permalink
static anlyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
maruncz committed Oct 2, 2023
1 parent 3f518de commit 0344ba6
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 59 deletions.
11 changes: 6 additions & 5 deletions CombatLog/CombatLog.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#include "CombatLog.h"
#include "exceptions.h"
#include <QFile>
#include <utility>

CombatLog::CombatLog(const QList<LogLine> &lines,
const QStringList &sourceNames,
const QStringList &targetNames)
: lines{lines}, sourceNames{sourceNames}, targetNames{targetNames}
CombatLog::CombatLog(const QList<LogLine>& 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};

Expand Down
6 changes: 3 additions & 3 deletions CombatLog/CombatLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ class CombatLog
{
public:
CombatLog() = default;
CombatLog(const QList<LogLine> &lines, const QStringList &sourceNames,
const QStringList &targetNames);
CombatLog(const QList<LogLine>& lines, QStringList sourceNames,
QStringList targetNames);

[[nodiscard]] static CombatLog fromFile(QString filename);
[[nodiscard]] static CombatLog fromFile(const QString& filename);

[[nodiscard]] const QList<LogLine> &getLines() const;

Expand Down
11 changes: 6 additions & 5 deletions CombatLog/LogLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
#include "defs.h"
#include "exceptions.h"
#include <QDebug>
#include <utility>

LogLine::LogLine(const QDateTime &timestamp, 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)}
{
}

Expand Down
5 changes: 2 additions & 3 deletions CombatLog/LogLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
class LogLine
{
public:
LogLine(const QDateTime &timestamp, 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;

Expand Down
23 changes: 12 additions & 11 deletions CombatLog/SubEvents.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include "SubEvents.h"
#include "LineParser.h"
#include "exceptions.h"
#include "LineParser.h"
#include <utility>

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")
Expand Down Expand Up @@ -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}
{
}

Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)}
{
}

Expand Down Expand Up @@ -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
{
Expand Down
14 changes: 7 additions & 7 deletions CombatLog/SubEvents.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion CombatLog/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ enum RaidFlags
COMBATLOG_OBJECT_RAIDTARGET_MASK = 0x000000FF
};

enum class SpellSchool
enum class SpellSchool : unsigned
{
Physical = 1,
Holy = 2,
Expand Down
12 changes: 8 additions & 4 deletions DataModels/ObjectListModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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 {};
}
Expand All @@ -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();
}
Expand Down
10 changes: 8 additions & 2 deletions DataModels/healdatamodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,29 @@ QVariant HealDataModel::headerData(int section, Qt::Orientation orientation,
int HealDataModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid())
{
return 0;
}

return combatlog->getLines().size();
}

int HealDataModel::columnCount(const QModelIndex &parent) const
{
if (parent.isValid())
{
return 0;
}

return header.size();
}

QVariant HealDataModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
{
return {};
}

if (role == Qt::DisplayRole)
{
Expand Down Expand Up @@ -94,5 +100,5 @@ QVariant HealDataModel::data(const QModelIndex &index, int role) const
}
}

return QVariant();
return {};
}
15 changes: 9 additions & 6 deletions DataModels/healdatamodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string_view>(
Expand Down
12 changes: 6 additions & 6 deletions filters/SubSampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@
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;
}

std::optional<QList<std::pair<qreal, qreal>>> addValue(qreal x, qreal y);

std::pair<qreal, qreal> finalize();

std::pair<qreal, qreal> getMinmaxX() const;
[[nodiscard]] std::pair<qreal, qreal> getMinmaxX() const;

std::pair<qreal, qreal> getMinmaxY() const;
[[nodiscard]] std::pair<qreal, qreal> getMinmaxY() const;

private:
QList<std::pair<qreal, qreal>> advance(qreal timepoint);
Expand Down
10 changes: 5 additions & 5 deletions forms/DamagePerSecond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ DamagePerSecond::~DamagePerSecond()

void DamagePerSecond::updateChart()
{
if (!originalLog)
if (originalLog == nullptr)
{
throw std::runtime_error("log ptr null");
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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<qreal>(lineOffset)};

Expand Down
2 changes: 1 addition & 1 deletion forms/DamagePerSecond.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private slots:
QStringList sourceNamesList;
QStringList targetNamesList;

CombatLog *originalLog;
CombatLog* originalLog {nullptr};
QChart chart;
QValueAxis axisX;
QValueAxis axisY;
Expand Down

0 comments on commit 0344ba6

Please sign in to comment.