From 4857ffd69466ba17da55ae0b55ae924e2031ad6f 2017-06-14 12:52:22 From: Alexandre Leroux Date: 2017-06-14 12:52:22 Subject: [PATCH] Creates ArrayData (struct that holds data as a vector of double) --- diff --git a/core/include/Data/ArrayData.h b/core/include/Data/ArrayData.h new file mode 100644 index 0000000..b08f0c2 --- /dev/null +++ b/core/include/Data/ArrayData.h @@ -0,0 +1,56 @@ +#ifndef SCIQLOP_ARRAYDATA_H +#define SCIQLOP_ARRAYDATA_H + +#include + +/** + * @brief The ArrayData class represents a dataset for a data series. + * + * A dataset can be unidimensional or two-dimensional. This property is determined by the Dim + * template-parameter. + * + * @tparam Dim the dimension of the ArrayData (one or two) + * @sa IDataSeries + */ +template +class ArrayData { +public: + /** + * Ctor for a unidimensional ArrayData + * @param nbColumns the number of values the ArrayData will hold + */ + template > + explicit ArrayData(int nbColumns) : m_Data{1, QVector{}} + { + m_Data[0].resize(nbColumns); + } + + /** + * Sets a data at a specified index. The index has to be valid to be effective + * @param index the index to which the data will be set + * @param data the data to set + * @remarks this method is only available for a unidimensional ArrayData + */ + template > + void setData(int index, double data) noexcept + { + if (index >= 0 && index < m_Data.at(0).size()) { + m_Data[0].replace(index, data); + } + } + + /** + * @return the data as a vector + * @remarks this method is only available for a unidimensional ArrayData + */ + template > + QVector data() const noexcept + { + return m_Data.at(0); + } + +private: + QVector > m_Data; +}; + +#endif // SCIQLOP_ARRAYDATA_H