##// END OF EJS Templates
Update ArrayData to make it better
perrinel -
r294:321e9d8b134b
parent child
Show More
@@ -1,82 +1,82
1 1 #ifndef SCIQLOP_ARRAYDATA_H
2 2 #define SCIQLOP_ARRAYDATA_H
3 3
4 4 #include <QVector>
5 5
6 6 /**
7 7 * @brief The ArrayData class represents a dataset for a data series.
8 8 *
9 9 * A dataset can be unidimensional or two-dimensional. This property is determined by the Dim
10 10 * template-parameter.
11 11 *
12 12 * @tparam Dim the dimension of the ArrayData (one or two)
13 13 * @sa IDataSeries
14 14 */
15 15 template <int Dim>
16 16 class ArrayData {
17 17 public:
18 18 /**
19 19 * Ctor for a unidimensional ArrayData
20 20 * @param nbColumns the number of values the ArrayData will hold
21 21 */
22 22 template <int D = Dim, typename = std::enable_if_t<D == 1> >
23 23 explicit ArrayData(int nbColumns) : m_Data{1, QVector<double>{}}
24 24 {
25 25 m_Data[0].resize(nbColumns);
26 26 }
27 27
28 28 /**
29 29 * Sets a data at a specified index. The index has to be valid to be effective
30 30 * @param index the index to which the data will be set
31 31 * @param data the data to set
32 32 * @remarks this method is only available for a unidimensional ArrayData
33 33 */
34 34 template <int D = Dim, typename = std::enable_if_t<D == 1> >
35 35 void setData(int index, double data) noexcept
36 36 {
37 37 if (index >= 0 && index < m_Data.at(0).size()) {
38 38 m_Data[0].replace(index, data);
39 39 }
40 40 }
41 41
42 42 /**
43 43 * @return the data as a vector
44 44 * @remarks this method is only available for a unidimensional ArrayData
45 45 */
46 46 template <int D = Dim, typename = std::enable_if_t<D == 1> >
47 QVector<double> data() const noexcept
47 const QVector<double> &data() const noexcept
48 48 {
49 return m_Data.at(0);
49 return m_Data[0];
50 50 }
51 51
52 52 /**
53 53 * @return the data as a vector
54 54 * @remarks this method is only available for a unidimensional ArrayData
55 55 */
56 56 template <int D = Dim, typename = std::enable_if_t<D == 1> >
57 57 const QVector<double> &data(double tStart, double tEnd) const noexcept
58 58 {
59 59 return m_Data.at(tStart);
60 60 }
61 61
62 62 // TODO Comment
63 63 template <int D = Dim, typename = std::enable_if_t<D == 1> >
64 void merge(ArrayData<1> *arrayData)
64 void merge(const ArrayData<1> &arrayData)
65 65 {
66 66 if (!m_Data.empty()) {
67 m_Data[0] += arrayData->data();
67 m_Data[0] += arrayData.data();
68 68 }
69 69 }
70 70
71 71 template <int D = Dim, typename = std::enable_if_t<D == 1> >
72 72 int size()
73 73 {
74 74 return m_Data[0].size();
75 75 }
76 76
77 77
78 78 private:
79 79 QVector<QVector<double> > m_Data;
80 80 };
81 81
82 82 #endif // SCIQLOP_ARRAYDATA_H
General Comments 0
You need to be logged in to leave comments. Login now