##// END OF EJS Templates
Creates ctor for two-dimensional ArrayData
Alexandre Leroux -
r501:9f279df280f0
parent child
Show More
@@ -11,7 +11,8
11 * @brief The ArrayData class represents a dataset for a data series.
11 * @brief The ArrayData class represents a dataset for a data series.
12 *
12 *
13 * A dataset can be unidimensional or two-dimensional. This property is determined by the Dim
13 * A dataset can be unidimensional or two-dimensional. This property is determined by the Dim
14 * template-parameter.
14 * template-parameter. In a case of a two-dimensional dataset, each dataset component has the same
15 * number of values
15 *
16 *
16 * @tparam Dim the dimension of the ArrayData (one or two)
17 * @tparam Dim the dimension of the ArrayData (one or two)
17 * @sa IDataSeries
18 * @sa IDataSeries
@@ -29,6 +30,35 public:
29 m_Data[0] = std::move(data);
30 m_Data[0] = std::move(data);
30 }
31 }
31
32
33 /**
34 * Ctor for a two-dimensional ArrayData. The number of components (number of vectors) must be
35 * greater than 2 and each component must have the same number of values
36 * @param data the data the ArrayData will hold
37 * @throws std::invalid_argument if the number of components is less than 2
38 * @remarks if the number of values is not the same for each component, no value is set
39 */
40 template <int D = Dim, typename = std::enable_if_t<D == 2> >
41 explicit ArrayData(QVector<QVector<double> > data)
42 {
43 auto nbComponents = data.size();
44 if (nbComponents < 2) {
45 throw std::invalid_argument{
46 QString{"A multidimensional ArrayData must have at least 2 components (found: %1"}
47 .arg(data.size())
48 .toStdString()};
49 }
50
51 auto nbValues = data.front().size();
52 if (std::all_of(data.cbegin(), data.cend(), [nbValues](const auto &component) {
53 return component.size() == nbValues;
54 })) {
55 m_Data = std::move(data);
56 }
57 else {
58 m_Data = QVector<QVector<double> >{nbComponents, QVector<double>{}};
59 }
60 }
61
32 /// Copy ctor
62 /// Copy ctor
33 explicit ArrayData(const ArrayData &other)
63 explicit ArrayData(const ArrayData &other)
34 {
64 {
General Comments 0
You need to be logged in to leave comments. Login now