@@ -0,0 +1,56 | |||||
|
1 | #ifndef SCIQLOP_ARRAYDATA_H | |||
|
2 | #define SCIQLOP_ARRAYDATA_H | |||
|
3 | ||||
|
4 | #include <QVector> | |||
|
5 | ||||
|
6 | /** | |||
|
7 | * @brief The ArrayData class represents a dataset for a data series. | |||
|
8 | * | |||
|
9 | * A dataset can be unidimensional or two-dimensional. This property is determined by the Dim | |||
|
10 | * template-parameter. | |||
|
11 | * | |||
|
12 | * @tparam Dim the dimension of the ArrayData (one or two) | |||
|
13 | * @sa IDataSeries | |||
|
14 | */ | |||
|
15 | template <int Dim> | |||
|
16 | class ArrayData { | |||
|
17 | public: | |||
|
18 | /** | |||
|
19 | * Ctor for a unidimensional ArrayData | |||
|
20 | * @param nbColumns the number of values the ArrayData will hold | |||
|
21 | */ | |||
|
22 | template <int D = Dim, typename = std::enable_if_t<D == 1> > | |||
|
23 | explicit ArrayData(int nbColumns) : m_Data{1, QVector<double>{}} | |||
|
24 | { | |||
|
25 | m_Data[0].resize(nbColumns); | |||
|
26 | } | |||
|
27 | ||||
|
28 | /** | |||
|
29 | * Sets a data at a specified index. The index has to be valid to be effective | |||
|
30 | * @param index the index to which the data will be set | |||
|
31 | * @param data the data to set | |||
|
32 | * @remarks this method is only available for a unidimensional ArrayData | |||
|
33 | */ | |||
|
34 | template <int D = Dim, typename = std::enable_if_t<D == 1> > | |||
|
35 | void setData(int index, double data) noexcept | |||
|
36 | { | |||
|
37 | if (index >= 0 && index < m_Data.at(0).size()) { | |||
|
38 | m_Data[0].replace(index, data); | |||
|
39 | } | |||
|
40 | } | |||
|
41 | ||||
|
42 | /** | |||
|
43 | * @return the data as a vector | |||
|
44 | * @remarks this method is only available for a unidimensional ArrayData | |||
|
45 | */ | |||
|
46 | template <int D = Dim, typename = std::enable_if_t<D == 1> > | |||
|
47 | QVector<double> data() const noexcept | |||
|
48 | { | |||
|
49 | return m_Data.at(0); | |||
|
50 | } | |||
|
51 | ||||
|
52 | private: | |||
|
53 | QVector<QVector<double> > m_Data; | |||
|
54 | }; | |||
|
55 | ||||
|
56 | #endif // SCIQLOP_ARRAYDATA_H |
General Comments 0
You need to be logged in to leave comments.
Login now