diff --git a/src/models/data.h b/src/models/data.h index 6a2c0cff..dd905442 100644 --- a/src/models/data.h +++ b/src/models/data.h @@ -203,7 +203,87 @@ struct FrameLocation Data::Location location; }; -using ItemCost = std::valarray; +class ItemCost +{ +public: + ItemCost(std::size_t size = 0) + : m_cost(size) + { + } + + ItemCost(qint64 value, std::size_t count) + : m_cost(value, count) + { + } + + ItemCost(std::valarray cost) + : m_cost(std::move(cost)) + { + } + + void resize(std::size_t newSize, qint64 value = 0) + { + m_cost.resize(newSize, value); + } + std::size_t size() const + { + return m_cost.size(); + } + + ItemCost operator+(const ItemCost& rhs) const + { + return {m_cost + rhs.m_cost}; + } + + ItemCost operator-(const ItemCost& rhs) const + { + return {m_cost - rhs.m_cost}; + } + + ItemCost& operator+=(const ItemCost& rhs) + { + m_cost += rhs.m_cost; + return *this; + } + + ItemCost& operator-=(const ItemCost& rhs) + { + m_cost -= rhs.m_cost; + return *this; + } + + qint64& operator[](int index) + { + if (static_cast(index) >= m_cost.size()) { + resize(index + 1); + } + return m_cost[index]; + } + qint64 operator[](int index) const + { + if (static_cast(index) < m_cost.size()) { + return m_cost[index]; + } + return 0; + } + + qint64 sum() const + { + return m_cost.sum(); + } + + auto begin() const + { + return std::begin(m_cost); + } + auto end() const + { + return std::end(m_cost); + } + +private: + std::valarray m_cost; +}; QDebug operator<<(QDebug stream, const ItemCost& cost); diff --git a/src/recordpage.cpp b/src/recordpage.cpp index f29b12b0..d58325f1 100644 --- a/src/recordpage.cpp +++ b/src/recordpage.cpp @@ -40,6 +40,8 @@ #include #include +#include + #include "multiconfigwidget.h" #include "perfoutputwidgetkonsole.h" #include "perfoutputwidgettext.h" diff --git a/src/util.h b/src/util.h index cd72922d..c1ba483b 100644 --- a/src/util.h +++ b/src/util.h @@ -7,7 +7,6 @@ #pragma once -#include #include #include @@ -20,7 +19,7 @@ struct Symbol; struct FileLine; struct LocationCost; class Costs; -using ItemCost = std::valarray; +class ItemCost; } namespace KParts {