##// END OF EJS Templates
Adapts sort() method to 2-dim array data (2)...
Alexandre Leroux -
r505:c4a0c9f4308e
parent child
Show More
@@ -9,6 +9,42
9 9
10 10 #include <memory>
11 11
12 template <int Dim>
13 class ArrayData;
14
15 using DataContainer = QVector<QVector<double> >;
16
17 namespace arraydata_detail {
18
19 /// Struct used to sort ArrayData
20 template <int Dim>
21 struct Sort {
22 static std::shared_ptr<ArrayData<Dim> > sort(const DataContainer &data,
23 const std::vector<int> &sortPermutation)
24 {
25 auto nbComponents = data.size();
26 auto sortedData = DataContainer(nbComponents);
27
28 for (auto i = 0; i < nbComponents; ++i) {
29 sortedData[i] = SortUtils::sort(data.at(i), sortPermutation);
30 }
31
32 return std::make_shared<ArrayData<Dim> >(std::move(sortedData));
33 }
34 };
35
36 /// Specialization for uni-dimensional ArrayData
37 template <>
38 struct Sort<1> {
39 static std::shared_ptr<ArrayData<1> > sort(const DataContainer &data,
40 const std::vector<int> &sortPermutation)
41 {
42 return std::make_shared<ArrayData<1> >(SortUtils::sort(data.at(0), sortPermutation));
43 }
44 };
45
46 } // namespace arraydata_detail
47
12 48 /**
13 49 * @brief The ArrayData class represents a dataset for a data series.
14 50 *
@@ -40,7 +76,7 public:
40 76 * @remarks if the number of values is not the same for each component, no value is set
41 77 */
42 78 template <int D = Dim, typename = std::enable_if_t<D == 2> >
43 explicit ArrayData(QVector<QVector<double> > data)
79 explicit ArrayData(DataContainer data)
44 80 {
45 81 auto nbComponents = data.size();
46 82 if (nbComponents < 2) {
@@ -57,7 +93,7 public:
57 93 m_Data = std::move(data);
58 94 }
59 95 else {
60 m_Data = QVector<QVector<double> >{nbComponents, QVector<double>{}};
96 m_Data = DataContainer{nbComponents, QVector<double>{}};
61 97 }
62 98 }
63 99
@@ -141,11 +177,10 public:
141 177 return m_Data[0].size();
142 178 }
143 179
144 template <int D = Dim, typename = std::enable_if_t<D == 1> >
145 180 std::shared_ptr<ArrayData<Dim> > sort(const std::vector<int> &sortPermutation)
146 181 {
147 182 QReadLocker locker{&m_Lock};
148 return std::make_shared<ArrayData<Dim> >(SortUtils::sort(m_Data.at(0), sortPermutation));
183 return arraydata_detail::Sort<Dim>::sort(m_Data, sortPermutation);
149 184 }
150 185
151 186 void clear()
@@ -159,7 +194,7 public:
159 194 }
160 195
161 196 private:
162 QVector<QVector<double> > m_Data;
197 DataContainer m_Data;
163 198 mutable QReadWriteLock m_Lock;
164 199 };
165 200
General Comments 0
You need to be logged in to leave comments. Login now