##// END OF EJS Templates
Merge pull request 253 from SCIQLOP-Initialisation develop...
leroux -
r672:195beffe7a75 merge
parent child
Show More
@@ -0,0 +1,132
1 #ifndef SCIQLOP_DATASERIESMERGEHELPER_H
2 #define SCIQLOP_DATASERIESMERGEHELPER_H
3
4 template <int Dim>
5 class DataSeries;
6
7 namespace detail {
8
9 /**
10 * Scope that can be used for a merge operation
11 * @tparam FEnd the type of function that will be executed at the end of the scope
12 */
13 template <typename FEnd>
14 struct MergeScope {
15 explicit MergeScope(FEnd end) : m_End{end} {}
16 virtual ~MergeScope() noexcept { m_End(); }
17 FEnd m_End;
18 };
19
20 /**
21 * Creates a scope for merge operation
22 * @tparam end the function executed at the end of the scope
23 */
24 template <typename FEnd>
25 MergeScope<FEnd> scope(FEnd end)
26 {
27 return MergeScope<FEnd>{end};
28 }
29
30 /**
31 * Enum used to position a data series relative to another during a merge operation
32 */
33 enum class MergePosition { LOWER_THAN, GREATER_THAN, EQUAL, OVERLAP };
34
35 /**
36 * Computes the position of the first data series relative to the second data series
37 * @param lhs the first data series
38 * @param rhs the second data series
39 * @return the merge position computed
40 * @remarks the data series must not be empty
41 */
42 template <int Dim>
43 MergePosition mergePosition(DataSeries<Dim> &lhs, DataSeries<Dim> &rhs)
44 {
45 Q_ASSERT(!lhs.isEmpty() && !rhs.isEmpty());
46
47 // Case lhs < rhs
48 auto lhsLast = --lhs.cend();
49 auto rhsFirst = rhs.cbegin();
50 if (lhsLast->x() < rhsFirst->x()) {
51 return MergePosition::LOWER_THAN;
52 }
53
54 // Case lhs > rhs
55 auto lhsFirst = lhs.cbegin();
56 auto rhsLast = --rhs.cend();
57 if (lhsFirst->x() > rhsLast->x()) {
58 return MergePosition::GREATER_THAN;
59 }
60
61 // Other cases
62 auto equal = std::equal(lhs.cbegin(), lhs.cend(), rhs.cbegin(), rhs.cend(),
63 [](const auto &it1, const auto &it2) {
64 return it1.x() == it2.x() && it1.values() == it2.values();
65 });
66 return equal ? MergePosition::EQUAL : MergePosition::OVERLAP;
67 }
68
69 } // namespace detail
70
71
72 /// Helper used to merge two DataSeries
73 /// @sa DataSeries
74 struct DataSeriesMergeHelper {
75 /// Merges the source data series into the dest data series. Data of the source data series are
76 /// consumed
77 template <int Dim>
78 static void merge(DataSeries<Dim> &source, DataSeries<Dim> &dest)
79 {
80 // Creates a scope to clear source data series at the end of the merge
81 auto _ = detail::scope([&source]() { source.clear(); });
82
83 // Case : source data series is empty -> no merge is made
84 if (source.isEmpty()) {
85 return;
86 }
87
88 // Case : dest data series is empty -> we simply swap the data
89 if (dest.isEmpty()) {
90 std::swap(dest.m_XAxisData, source.m_XAxisData);
91 std::swap(dest.m_ValuesData, source.m_ValuesData);
92 return;
93 }
94
95 // Gets the position of the source in relation to the destination
96 auto sourcePosition = detail::mergePosition(source, dest);
97
98 switch (sourcePosition) {
99 case detail::MergePosition::LOWER_THAN:
100 case detail::MergePosition::GREATER_THAN: {
101 auto prepend = sourcePosition == detail::MergePosition::LOWER_THAN;
102 dest.m_XAxisData->add(*source.m_XAxisData, prepend);
103 dest.m_ValuesData->add(*source.m_ValuesData, prepend);
104 break;
105 }
106 case detail::MergePosition::EQUAL:
107 // the data series equal each other : no merge made
108 break;
109 case detail::MergePosition::OVERLAP: {
110 // the two data series overlap : merge is made
111 auto temp = dest.clone();
112 if (auto tempSeries = dynamic_cast<DataSeries<Dim> *>(temp.get())) {
113 // Makes the merge :
114 // - Data are sorted by x-axis values
115 // - If two entries are in the source range and the other range, only one entry
116 // is retained as result
117 // - The results are stored directly in the data series
118 dest.clear();
119 std::set_union(
120 tempSeries->cbegin(), tempSeries->cend(), source.cbegin(), source.cend(),
121 std::back_inserter(dest),
122 [](const auto &it1, const auto &it2) { return it1.x() < it2.x(); });
123 }
124 break;
125 }
126 default:
127 Q_ASSERT(false);
128 }
129 }
130 };
131
132 #endif // SCIQLOP_DATASERIESMERGEHELPER_H
@@ -1,271 +1,282
1 #ifndef SCIQLOP_ARRAYDATA_H
1 #ifndef SCIQLOP_ARRAYDATA_H
2 #define SCIQLOP_ARRAYDATA_H
2 #define SCIQLOP_ARRAYDATA_H
3
3
4 #include "Data/ArrayDataIterator.h"
4 #include "Data/ArrayDataIterator.h"
5 #include <Common/SortUtils.h>
5 #include <Common/SortUtils.h>
6
6
7 #include <QReadLocker>
7 #include <QReadLocker>
8 #include <QReadWriteLock>
8 #include <QReadWriteLock>
9 #include <QVector>
9 #include <QVector>
10
10
11 #include <memory>
11 #include <memory>
12
12
13 template <int Dim>
13 template <int Dim>
14 class ArrayData;
14 class ArrayData;
15
15
16 using DataContainer = QVector<double>;
16 using DataContainer = QVector<double>;
17
17
18 namespace arraydata_detail {
18 namespace arraydata_detail {
19
19
20 /// Struct used to sort ArrayData
20 /// Struct used to sort ArrayData
21 template <int Dim>
21 template <int Dim>
22 struct Sort {
22 struct Sort {
23 static std::shared_ptr<ArrayData<Dim> > sort(const DataContainer &data, int nbComponents,
23 static std::shared_ptr<ArrayData<Dim> > sort(const DataContainer &data, int nbComponents,
24 const std::vector<int> &sortPermutation)
24 const std::vector<int> &sortPermutation)
25 {
25 {
26 return std::make_shared<ArrayData<Dim> >(
26 return std::make_shared<ArrayData<Dim> >(
27 SortUtils::sort(data, nbComponents, sortPermutation), nbComponents);
27 SortUtils::sort(data, nbComponents, sortPermutation), nbComponents);
28 }
28 }
29 };
29 };
30
30
31 /// Specialization for uni-dimensional ArrayData
31 /// Specialization for uni-dimensional ArrayData
32 template <>
32 template <>
33 struct Sort<1> {
33 struct Sort<1> {
34 static std::shared_ptr<ArrayData<1> > sort(const DataContainer &data, int nbComponents,
34 static std::shared_ptr<ArrayData<1> > sort(const DataContainer &data, int nbComponents,
35 const std::vector<int> &sortPermutation)
35 const std::vector<int> &sortPermutation)
36 {
36 {
37 Q_UNUSED(nbComponents)
37 Q_UNUSED(nbComponents)
38 return std::make_shared<ArrayData<1> >(SortUtils::sort(data, 1, sortPermutation));
38 return std::make_shared<ArrayData<1> >(SortUtils::sort(data, 1, sortPermutation));
39 }
39 }
40 };
40 };
41
41
42 template <int Dim>
42 template <int Dim>
43 class IteratorValue : public ArrayDataIteratorValue::Impl {
43 class IteratorValue : public ArrayDataIteratorValue::Impl {
44 public:
44 public:
45 explicit IteratorValue(const DataContainer &container, int nbComponents, bool begin)
45 explicit IteratorValue(const DataContainer &container, int nbComponents, bool begin)
46 : m_It{begin ? container.cbegin() : container.cend()}, m_NbComponents{nbComponents}
46 : m_It{begin ? container.cbegin() : container.cend()}, m_NbComponents{nbComponents}
47 {
47 {
48 }
48 }
49
49
50 IteratorValue(const IteratorValue &other) = default;
50 IteratorValue(const IteratorValue &other) = default;
51
51
52 std::unique_ptr<ArrayDataIteratorValue::Impl> clone() const override
52 std::unique_ptr<ArrayDataIteratorValue::Impl> clone() const override
53 {
53 {
54 return std::make_unique<IteratorValue<Dim> >(*this);
54 return std::make_unique<IteratorValue<Dim> >(*this);
55 }
55 }
56
56
57 bool equals(const ArrayDataIteratorValue::Impl &other) const override try {
57 bool equals(const ArrayDataIteratorValue::Impl &other) const override try {
58 const auto &otherImpl = dynamic_cast<const IteratorValue &>(other);
58 const auto &otherImpl = dynamic_cast<const IteratorValue &>(other);
59 return std::tie(m_It, m_NbComponents) == std::tie(otherImpl.m_It, otherImpl.m_NbComponents);
59 return std::tie(m_It, m_NbComponents) == std::tie(otherImpl.m_It, otherImpl.m_NbComponents);
60 }
60 }
61 catch (const std::bad_cast &) {
61 catch (const std::bad_cast &) {
62 return false;
62 return false;
63 }
63 }
64
64
65 void next() override { std::advance(m_It, m_NbComponents); }
65 void next() override { std::advance(m_It, m_NbComponents); }
66 void prev() override { std::advance(m_It, -m_NbComponents); }
66 void prev() override { std::advance(m_It, -m_NbComponents); }
67
67
68 double at(int componentIndex) const override { return *(m_It + componentIndex); }
68 double at(int componentIndex) const override { return *(m_It + componentIndex); }
69 double first() const override { return *m_It; }
69 double first() const override { return *m_It; }
70 double min() const override
70 double min() const override
71 {
71 {
72 auto values = this->values();
72 auto values = this->values();
73 auto end = values.cend();
73 auto end = values.cend();
74 auto it = std::min_element(values.cbegin(), end, [](const auto &v1, const auto &v2) {
74 auto it = std::min_element(values.cbegin(), end, [](const auto &v1, const auto &v2) {
75 return SortUtils::minCompareWithNaN(v1, v2);
75 return SortUtils::minCompareWithNaN(v1, v2);
76 });
76 });
77
77
78 return it != end ? *it : std::numeric_limits<double>::quiet_NaN();
78 return it != end ? *it : std::numeric_limits<double>::quiet_NaN();
79 }
79 }
80 double max() const override
80 double max() const override
81 {
81 {
82 auto values = this->values();
82 auto values = this->values();
83 auto end = values.cend();
83 auto end = values.cend();
84 auto it = std::max_element(values.cbegin(), end, [](const auto &v1, const auto &v2) {
84 auto it = std::max_element(values.cbegin(), end, [](const auto &v1, const auto &v2) {
85 return SortUtils::maxCompareWithNaN(v1, v2);
85 return SortUtils::maxCompareWithNaN(v1, v2);
86 });
86 });
87 return it != end ? *it : std::numeric_limits<double>::quiet_NaN();
87 return it != end ? *it : std::numeric_limits<double>::quiet_NaN();
88 }
88 }
89
89
90 private:
90 QVector<double> values() const override
91 std::vector<double> values() const
92 {
91 {
93 auto result = std::vector<double>{};
92 auto result = QVector<double>{};
94 for (auto i = 0; i < m_NbComponents; ++i) {
93 for (auto i = 0; i < m_NbComponents; ++i) {
95 result.push_back(*(m_It + i));
94 result.push_back(*(m_It + i));
96 }
95 }
97
96
98 return result;
97 return result;
99 }
98 }
100
99
100 private:
101 DataContainer::const_iterator m_It;
101 DataContainer::const_iterator m_It;
102 int m_NbComponents;
102 int m_NbComponents;
103 };
103 };
104
104
105 } // namespace arraydata_detail
105 } // namespace arraydata_detail
106
106
107 /**
107 /**
108 * @brief The ArrayData class represents a dataset for a data series.
108 * @brief The ArrayData class represents a dataset for a data series.
109 *
109 *
110 * A dataset can be unidimensional or two-dimensional. This property is determined by the Dim
110 * A dataset can be unidimensional or two-dimensional. This property is determined by the Dim
111 * template-parameter. In a case of a two-dimensional dataset, each dataset component has the same
111 * template-parameter. In a case of a two-dimensional dataset, each dataset component has the same
112 * number of values
112 * number of values
113 *
113 *
114 * @tparam Dim the dimension of the ArrayData (one or two)
114 * @tparam Dim the dimension of the ArrayData (one or two)
115 * @sa IDataSeries
115 * @sa IDataSeries
116 */
116 */
117 template <int Dim>
117 template <int Dim>
118 class ArrayData {
118 class ArrayData {
119 public:
119 public:
120 // ///// //
120 // ///// //
121 // Ctors //
121 // Ctors //
122 // ///// //
122 // ///// //
123
123
124 /**
124 /**
125 * Ctor for a unidimensional ArrayData
125 * Ctor for a unidimensional ArrayData
126 * @param data the data the ArrayData will hold
126 * @param data the data the ArrayData will hold
127 */
127 */
128 template <int D = Dim, typename = std::enable_if_t<D == 1> >
128 template <int D = Dim, typename = std::enable_if_t<D == 1> >
129 explicit ArrayData(DataContainer data) : m_Data{std::move(data)}, m_NbComponents{1}
129 explicit ArrayData(DataContainer data) : m_Data{std::move(data)}, m_NbComponents{1}
130 {
130 {
131 }
131 }
132
132
133 /**
133 /**
134 * Ctor for a two-dimensional ArrayData. The number of components (number of lines) must be
134 * Ctor for a two-dimensional ArrayData. The number of components (number of lines) must be
135 * greater than 2 and must be a divisor of the total number of data in the vector
135 * greater than 2 and must be a divisor of the total number of data in the vector
136 * @param data the data the ArrayData will hold
136 * @param data the data the ArrayData will hold
137 * @param nbComponents the number of components
137 * @param nbComponents the number of components
138 * @throws std::invalid_argument if the number of components is less than 2 or is not a divisor
138 * @throws std::invalid_argument if the number of components is less than 2 or is not a divisor
139 * of the size of the data
139 * of the size of the data
140 */
140 */
141 template <int D = Dim, typename = std::enable_if_t<D == 2> >
141 template <int D = Dim, typename = std::enable_if_t<D == 2> >
142 explicit ArrayData(DataContainer data, int nbComponents)
142 explicit ArrayData(DataContainer data, int nbComponents)
143 : m_Data{std::move(data)}, m_NbComponents{nbComponents}
143 : m_Data{std::move(data)}, m_NbComponents{nbComponents}
144 {
144 {
145 if (nbComponents < 2) {
145 if (nbComponents < 2) {
146 throw std::invalid_argument{
146 throw std::invalid_argument{
147 QString{"A multidimensional ArrayData must have at least 2 components (found: %1)"}
147 QString{"A multidimensional ArrayData must have at least 2 components (found: %1)"}
148 .arg(nbComponents)
148 .arg(nbComponents)
149 .toStdString()};
149 .toStdString()};
150 }
150 }
151
151
152 if (m_Data.size() % m_NbComponents != 0) {
152 if (m_Data.size() % m_NbComponents != 0) {
153 throw std::invalid_argument{QString{
153 throw std::invalid_argument{QString{
154 "The number of components (%1) is inconsistent with the total number of data (%2)"}
154 "The number of components (%1) is inconsistent with the total number of data (%2)"}
155 .arg(m_Data.size(), nbComponents)
155 .arg(m_Data.size(), nbComponents)
156 .toStdString()};
156 .toStdString()};
157 }
157 }
158 }
158 }
159
159
160 /// Copy ctor
160 /// Copy ctor
161 explicit ArrayData(const ArrayData &other)
161 explicit ArrayData(const ArrayData &other)
162 {
162 {
163 QReadLocker otherLocker{&other.m_Lock};
163 QReadLocker otherLocker{&other.m_Lock};
164 m_Data = other.m_Data;
164 m_Data = other.m_Data;
165 m_NbComponents = other.m_NbComponents;
165 m_NbComponents = other.m_NbComponents;
166 }
166 }
167
167
168 // /////////////// //
168 // /////////////// //
169 // General methods //
169 // General methods //
170 // /////////////// //
170 // /////////////// //
171
171
172 /**
172 /**
173 * Merges into the array data an other array data. The two array datas must have the same number
173 * Merges into the array data an other array data. The two array datas must have the same number
174 * of components so the merge can be done
174 * of components so the merge can be done
175 * @param other the array data to merge with
175 * @param other the array data to merge with
176 * @param prepend if true, the other array data is inserted at the beginning, otherwise it is
176 * @param prepend if true, the other array data is inserted at the beginning, otherwise it is
177 * inserted at the end
177 * inserted at the end
178 */
178 */
179 void add(const ArrayData<Dim> &other, bool prepend = false)
179 void add(const ArrayData<Dim> &other, bool prepend = false)
180 {
180 {
181 QWriteLocker locker{&m_Lock};
181 QWriteLocker locker{&m_Lock};
182 QReadLocker otherLocker{&other.m_Lock};
182 QReadLocker otherLocker{&other.m_Lock};
183
183
184 if (m_NbComponents != other.componentCount()) {
184 if (m_NbComponents != other.componentCount()) {
185 return;
185 return;
186 }
186 }
187
187
188 if (prepend) {
188 if (prepend) {
189 auto otherDataSize = other.m_Data.size();
189 auto otherDataSize = other.m_Data.size();
190 m_Data.insert(m_Data.begin(), otherDataSize, 0.);
190 m_Data.insert(m_Data.begin(), otherDataSize, 0.);
191 for (auto i = 0; i < otherDataSize; ++i) {
191 for (auto i = 0; i < otherDataSize; ++i) {
192 m_Data.replace(i, other.m_Data.at(i));
192 m_Data.replace(i, other.m_Data.at(i));
193 }
193 }
194 }
194 }
195 else {
195 else {
196 m_Data.append(other.m_Data);
196 m_Data.append(other.m_Data);
197 }
197 }
198 }
198 }
199
199
200 void clear()
200 void clear()
201 {
201 {
202 QWriteLocker locker{&m_Lock};
202 QWriteLocker locker{&m_Lock};
203 m_Data.clear();
203 m_Data.clear();
204 }
204 }
205
205
206 int componentCount() const noexcept { return m_NbComponents; }
206 int componentCount() const noexcept { return m_NbComponents; }
207
207
208 /// @return the size (i.e. number of values) of a single component
208 /// @return the size (i.e. number of values) of a single component
209 /// @remarks in a case of a two-dimensional ArrayData, each component has the same size
209 /// @remarks in a case of a two-dimensional ArrayData, each component has the same size
210 int size() const
210 int size() const
211 {
211 {
212 QReadLocker locker{&m_Lock};
212 QReadLocker locker{&m_Lock};
213 return m_Data.size() / m_NbComponents;
213 return m_Data.size() / m_NbComponents;
214 }
214 }
215
215
216 std::shared_ptr<ArrayData<Dim> > sort(const std::vector<int> &sortPermutation)
216 std::shared_ptr<ArrayData<Dim> > sort(const std::vector<int> &sortPermutation)
217 {
217 {
218 QReadLocker locker{&m_Lock};
218 QReadLocker locker{&m_Lock};
219 return arraydata_detail::Sort<Dim>::sort(m_Data, m_NbComponents, sortPermutation);
219 return arraydata_detail::Sort<Dim>::sort(m_Data, m_NbComponents, sortPermutation);
220 }
220 }
221
221
222 // ///////// //
222 // ///////// //
223 // Iterators //
223 // Iterators //
224 // ///////// //
224 // ///////// //
225
225
226 ArrayDataIterator cbegin() const
226 ArrayDataIterator cbegin() const
227 {
227 {
228 return ArrayDataIterator{ArrayDataIteratorValue{
228 return ArrayDataIterator{ArrayDataIteratorValue{
229 std::make_unique<arraydata_detail::IteratorValue<Dim> >(m_Data, m_NbComponents, true)}};
229 std::make_unique<arraydata_detail::IteratorValue<Dim> >(m_Data, m_NbComponents, true)}};
230 }
230 }
231 ArrayDataIterator cend() const
231 ArrayDataIterator cend() const
232 {
232 {
233 return ArrayDataIterator{
233 return ArrayDataIterator{
234 ArrayDataIteratorValue{std::make_unique<arraydata_detail::IteratorValue<Dim> >(
234 ArrayDataIteratorValue{std::make_unique<arraydata_detail::IteratorValue<Dim> >(
235 m_Data, m_NbComponents, false)}};
235 m_Data, m_NbComponents, false)}};
236 }
236 }
237
237
238 /// Inserts at the end of the array data the values passed as a parameter. This
239 /// method is intended to be used in the context of generating a back insert iterator, or only
240 /// if it's ensured that the total size of the vector is consistent with the number of
241 /// components of the array data
242 /// @param values the values to insert
243 /// @sa http://en.cppreference.com/w/cpp/iterator/back_inserter
244 void push_back(const QVector<double> &values)
245 {
246 Q_ASSERT(values.size() % m_NbComponents == 0);
247 m_Data.append(values);
248 }
238
249
239 /**
250 /**
240 * @return the data at a specified index
251 * @return the data at a specified index
241 * @remarks index must be a valid position
252 * @remarks index must be a valid position
242 */
253 */
243 double at(int index) const noexcept
254 double at(int index) const noexcept
244 {
255 {
245 QReadLocker locker{&m_Lock};
256 QReadLocker locker{&m_Lock};
246 return m_Data.at(index);
257 return m_Data.at(index);
247 }
258 }
248
259
249 // ///////////// //
260 // ///////////// //
250 // 1-dim methods //
261 // 1-dim methods //
251 // ///////////// //
262 // ///////////// //
252
263
253 /**
264 /**
254 * @return the data as a vector, as a const reference
265 * @return the data as a vector, as a const reference
255 * @remarks this method is only available for a unidimensional ArrayData
266 * @remarks this method is only available for a unidimensional ArrayData
256 */
267 */
257 template <int D = Dim, typename = std::enable_if_t<D == 1> >
268 template <int D = Dim, typename = std::enable_if_t<D == 1> >
258 const QVector<double> &cdata() const noexcept
269 const QVector<double> &cdata() const noexcept
259 {
270 {
260 QReadLocker locker{&m_Lock};
271 QReadLocker locker{&m_Lock};
261 return m_Data;
272 return m_Data;
262 }
273 }
263
274
264 private:
275 private:
265 DataContainer m_Data;
276 DataContainer m_Data;
266 /// Number of components (lines). Is always 1 in a 1-dim ArrayData
277 /// Number of components (lines). Is always 1 in a 1-dim ArrayData
267 int m_NbComponents;
278 int m_NbComponents;
268 mutable QReadWriteLock m_Lock;
279 mutable QReadWriteLock m_Lock;
269 };
280 };
270
281
271 #endif // SCIQLOP_ARRAYDATA_H
282 #endif // SCIQLOP_ARRAYDATA_H
@@ -1,56 +1,60
1 #ifndef SCIQLOP_ARRAYDATAITERATOR_H
1 #ifndef SCIQLOP_ARRAYDATAITERATOR_H
2 #define SCIQLOP_ARRAYDATAITERATOR_H
2 #define SCIQLOP_ARRAYDATAITERATOR_H
3
3
4 #include "CoreGlobal.h"
4 #include "CoreGlobal.h"
5 #include "Data/SqpIterator.h"
5 #include "Data/SqpIterator.h"
6
6
7 #include <QVector>
7 #include <memory>
8 #include <memory>
8
9
9 /**
10 /**
10 * @brief The ArrayDataIteratorValue class represents the current value of an array data iterator.
11 * @brief The ArrayDataIteratorValue class represents the current value of an array data iterator.
11 * It offers standard access methods for the data in the series (at(), first()), but it is up to
12 * It offers standard access methods for the data in the series (at(), first()), but it is up to
12 * each array data to define its own implementation of how to retrieve this data (one-dim or two-dim
13 * each array data to define its own implementation of how to retrieve this data (one-dim or two-dim
13 * array), by implementing the ArrayDataIteratorValue::Impl interface
14 * array), by implementing the ArrayDataIteratorValue::Impl interface
14 * @sa ArrayDataIterator
15 * @sa ArrayDataIterator
15 */
16 */
16 class SCIQLOP_CORE_EXPORT ArrayDataIteratorValue {
17 class SCIQLOP_CORE_EXPORT ArrayDataIteratorValue {
17 public:
18 public:
18 struct Impl {
19 struct Impl {
19 virtual ~Impl() noexcept = default;
20 virtual ~Impl() noexcept = default;
20 virtual std::unique_ptr<Impl> clone() const = 0;
21 virtual std::unique_ptr<Impl> clone() const = 0;
21 virtual bool equals(const Impl &other) const = 0;
22 virtual bool equals(const Impl &other) const = 0;
22 virtual void next() = 0;
23 virtual void next() = 0;
23 virtual void prev() = 0;
24 virtual void prev() = 0;
24 virtual double at(int componentIndex) const = 0;
25 virtual double at(int componentIndex) const = 0;
25 virtual double first() const = 0;
26 virtual double first() const = 0;
26 virtual double min() const = 0;
27 virtual double min() const = 0;
27 virtual double max() const = 0;
28 virtual double max() const = 0;
29 virtual QVector<double> values() const = 0;
28 };
30 };
29
31
30 explicit ArrayDataIteratorValue(std::unique_ptr<Impl> impl);
32 explicit ArrayDataIteratorValue(std::unique_ptr<Impl> impl);
31 ArrayDataIteratorValue(const ArrayDataIteratorValue &other);
33 ArrayDataIteratorValue(const ArrayDataIteratorValue &other);
32 ArrayDataIteratorValue(ArrayDataIteratorValue &&other) = default;
34 ArrayDataIteratorValue(ArrayDataIteratorValue &&other) = default;
33 ArrayDataIteratorValue &operator=(ArrayDataIteratorValue other);
35 ArrayDataIteratorValue &operator=(ArrayDataIteratorValue other);
34
36
35 bool equals(const ArrayDataIteratorValue &other) const;
37 bool equals(const ArrayDataIteratorValue &other) const;
36
38
37 /// Advances to the next value
39 /// Advances to the next value
38 void next();
40 void next();
39 /// Moves back to the previous value
41 /// Moves back to the previous value
40 void prev();
42 void prev();
41 /// Gets value of a specified component
43 /// Gets value of a specified component
42 double at(int componentIndex) const;
44 double at(int componentIndex) const;
43 /// Gets value of first component
45 /// Gets value of first component
44 double first() const;
46 double first() const;
45 /// Gets min value among all components
47 /// Gets min value among all components
46 double min() const;
48 double min() const;
47 /// Gets max value among all components
49 /// Gets max value among all components
48 double max() const;
50 double max() const;
51 /// Gets all values
52 QVector<double> values() const;
49
53
50 private:
54 private:
51 std::unique_ptr<Impl> m_Impl;
55 std::unique_ptr<Impl> m_Impl;
52 };
56 };
53
57
54 using ArrayDataIterator = SqpIterator<ArrayDataIteratorValue>;
58 using ArrayDataIterator = SqpIterator<ArrayDataIteratorValue>;
55
59
56 #endif // SCIQLOP_ARRAYDATAITERATOR_H
60 #endif // SCIQLOP_ARRAYDATAITERATOR_H
@@ -1,333 +1,317
1 #ifndef SCIQLOP_DATASERIES_H
1 #ifndef SCIQLOP_DATASERIES_H
2 #define SCIQLOP_DATASERIES_H
2 #define SCIQLOP_DATASERIES_H
3
3
4 #include "CoreGlobal.h"
4 #include "CoreGlobal.h"
5
5
6 #include <Common/SortUtils.h>
6 #include <Common/SortUtils.h>
7
7
8 #include <Data/ArrayData.h>
8 #include <Data/ArrayData.h>
9 #include <Data/DataSeriesMergeHelper.h>
9 #include <Data/IDataSeries.h>
10 #include <Data/IDataSeries.h>
10
11
11 #include <QLoggingCategory>
12 #include <QLoggingCategory>
12 #include <QReadLocker>
13 #include <QReadLocker>
13 #include <QReadWriteLock>
14 #include <QReadWriteLock>
14 #include <memory>
15 #include <memory>
15
16
16 // We don't use the Qt macro since the log is used in the header file, which causes multiple log
17 // We don't use the Qt macro since the log is used in the header file, which causes multiple log
17 // definitions with inheritance. Inline method is used instead
18 // definitions with inheritance. Inline method is used instead
18 inline const QLoggingCategory &LOG_DataSeries()
19 inline const QLoggingCategory &LOG_DataSeries()
19 {
20 {
20 static const QLoggingCategory category{"DataSeries"};
21 static const QLoggingCategory category{"DataSeries"};
21 return category;
22 return category;
22 }
23 }
23
24
24 template <int Dim>
25 template <int Dim>
25 class DataSeries;
26 class DataSeries;
26
27
27 namespace dataseries_detail {
28 namespace dataseries_detail {
28
29
29 template <int Dim>
30 template <int Dim>
30 class IteratorValue : public DataSeriesIteratorValue::Impl {
31 class IteratorValue : public DataSeriesIteratorValue::Impl {
31 public:
32 public:
32 explicit IteratorValue(const DataSeries<Dim> &dataSeries, bool begin)
33 explicit IteratorValue(const DataSeries<Dim> &dataSeries, bool begin)
33 : m_XIt(begin ? dataSeries.xAxisData()->cbegin() : dataSeries.xAxisData()->cend()),
34 : m_XIt(begin ? dataSeries.xAxisData()->cbegin() : dataSeries.xAxisData()->cend()),
34 m_ValuesIt(begin ? dataSeries.valuesData()->cbegin()
35 m_ValuesIt(begin ? dataSeries.valuesData()->cbegin()
35 : dataSeries.valuesData()->cend())
36 : dataSeries.valuesData()->cend())
36 {
37 {
37 }
38 }
38 IteratorValue(const IteratorValue &other) = default;
39 IteratorValue(const IteratorValue &other) = default;
39
40
40 std::unique_ptr<DataSeriesIteratorValue::Impl> clone() const override
41 std::unique_ptr<DataSeriesIteratorValue::Impl> clone() const override
41 {
42 {
42 return std::make_unique<IteratorValue<Dim> >(*this);
43 return std::make_unique<IteratorValue<Dim> >(*this);
43 }
44 }
44
45
45 bool equals(const DataSeriesIteratorValue::Impl &other) const override try {
46 bool equals(const DataSeriesIteratorValue::Impl &other) const override try {
46 const auto &otherImpl = dynamic_cast<const IteratorValue &>(other);
47 const auto &otherImpl = dynamic_cast<const IteratorValue &>(other);
47 return std::tie(m_XIt, m_ValuesIt) == std::tie(otherImpl.m_XIt, otherImpl.m_ValuesIt);
48 return std::tie(m_XIt, m_ValuesIt) == std::tie(otherImpl.m_XIt, otherImpl.m_ValuesIt);
48 }
49 }
49 catch (const std::bad_cast &) {
50 catch (const std::bad_cast &) {
50 return false;
51 return false;
51 }
52 }
52
53
53 void next() override
54 void next() override
54 {
55 {
55 ++m_XIt;
56 ++m_XIt;
56 ++m_ValuesIt;
57 ++m_ValuesIt;
57 }
58 }
58
59
59 void prev() override
60 void prev() override
60 {
61 {
61 --m_XIt;
62 --m_XIt;
62 --m_ValuesIt;
63 --m_ValuesIt;
63 }
64 }
64
65
65 double x() const override { return m_XIt->at(0); }
66 double x() const override { return m_XIt->at(0); }
66 double value() const override { return m_ValuesIt->at(0); }
67 double value() const override { return m_ValuesIt->at(0); }
67 double value(int componentIndex) const override { return m_ValuesIt->at(componentIndex); }
68 double value(int componentIndex) const override { return m_ValuesIt->at(componentIndex); }
68 double minValue() const override { return m_ValuesIt->min(); }
69 double minValue() const override { return m_ValuesIt->min(); }
69 double maxValue() const override { return m_ValuesIt->max(); }
70 double maxValue() const override { return m_ValuesIt->max(); }
71 QVector<double> values() const override { return m_ValuesIt->values(); }
70
72
71 private:
73 private:
72 ArrayDataIterator m_XIt;
74 ArrayDataIterator m_XIt;
73 ArrayDataIterator m_ValuesIt;
75 ArrayDataIterator m_ValuesIt;
74 };
76 };
75 } // namespace dataseries_detail
77 } // namespace dataseries_detail
76
78
77 /**
79 /**
78 * @brief The DataSeries class is the base (abstract) implementation of IDataSeries.
80 * @brief The DataSeries class is the base (abstract) implementation of IDataSeries.
79 *
81 *
80 * It proposes to set a dimension for the values ​​data.
82 * It proposes to set a dimension for the values ​​data.
81 *
83 *
82 * A DataSeries is always sorted on its x-axis data.
84 * A DataSeries is always sorted on its x-axis data.
83 *
85 *
84 * @tparam Dim The dimension of the values data
86 * @tparam Dim The dimension of the values data
85 *
87 *
86 */
88 */
87 template <int Dim>
89 template <int Dim>
88 class SCIQLOP_CORE_EXPORT DataSeries : public IDataSeries {
90 class SCIQLOP_CORE_EXPORT DataSeries : public IDataSeries {
91 friend class DataSeriesMergeHelper;
92
89 public:
93 public:
94 /// Tag needed to define the push_back() method
95 /// @sa push_back()
96 using value_type = DataSeriesIteratorValue;
97
90 /// @sa IDataSeries::xAxisData()
98 /// @sa IDataSeries::xAxisData()
91 std::shared_ptr<ArrayData<1> > xAxisData() override { return m_XAxisData; }
99 std::shared_ptr<ArrayData<1> > xAxisData() override { return m_XAxisData; }
92 const std::shared_ptr<ArrayData<1> > xAxisData() const { return m_XAxisData; }
100 const std::shared_ptr<ArrayData<1> > xAxisData() const { return m_XAxisData; }
93
101
94 /// @sa IDataSeries::xAxisUnit()
102 /// @sa IDataSeries::xAxisUnit()
95 Unit xAxisUnit() const override { return m_XAxisUnit; }
103 Unit xAxisUnit() const override { return m_XAxisUnit; }
96
104
97 /// @return the values dataset
105 /// @return the values dataset
98 std::shared_ptr<ArrayData<Dim> > valuesData() { return m_ValuesData; }
106 std::shared_ptr<ArrayData<Dim> > valuesData() { return m_ValuesData; }
99 const std::shared_ptr<ArrayData<Dim> > valuesData() const { return m_ValuesData; }
107 const std::shared_ptr<ArrayData<Dim> > valuesData() const { return m_ValuesData; }
100
108
101 /// @sa IDataSeries::valuesUnit()
109 /// @sa IDataSeries::valuesUnit()
102 Unit valuesUnit() const override { return m_ValuesUnit; }
110 Unit valuesUnit() const override { return m_ValuesUnit; }
103
111
104
112
105 SqpRange range() const override
113 SqpRange range() const override
106 {
114 {
107 if (!m_XAxisData->cdata().isEmpty()) {
115 if (!m_XAxisData->cdata().isEmpty()) {
108 return SqpRange{m_XAxisData->cdata().first(), m_XAxisData->cdata().last()};
116 return SqpRange{m_XAxisData->cdata().first(), m_XAxisData->cdata().last()};
109 }
117 }
110
118
111 return SqpRange{};
119 return SqpRange{};
112 }
120 }
113
121
114 void clear()
122 void clear()
115 {
123 {
116 m_XAxisData->clear();
124 m_XAxisData->clear();
117 m_ValuesData->clear();
125 m_ValuesData->clear();
118 }
126 }
119
127
128 bool isEmpty() const noexcept { return m_XAxisData->size() == 0; }
129
120 /// Merges into the data series an other data series
130 /// Merges into the data series an other data series
121 /// @remarks the data series to merge with is cleared after the operation
131 /// @remarks the data series to merge with is cleared after the operation
122 void merge(IDataSeries *dataSeries) override
132 void merge(IDataSeries *dataSeries) override
123 {
133 {
124 dataSeries->lockWrite();
134 dataSeries->lockWrite();
125 lockWrite();
135 lockWrite();
126
136
127 if (auto other = dynamic_cast<DataSeries<Dim> *>(dataSeries)) {
137 if (auto other = dynamic_cast<DataSeries<Dim> *>(dataSeries)) {
128 const auto &otherXAxisData = other->xAxisData()->cdata();
138 DataSeriesMergeHelper::merge(*other, *this);
129 const auto &xAxisData = m_XAxisData->cdata();
130
131 // As data series are sorted, we can improve performances of merge, by call the sort
132 // method only if the two data series overlap.
133 if (!otherXAxisData.empty()) {
134 auto firstValue = otherXAxisData.front();
135 auto lastValue = otherXAxisData.back();
136
137 auto xAxisDataBegin = xAxisData.cbegin();
138 auto xAxisDataEnd = xAxisData.cend();
139
140 bool prepend;
141 bool sortNeeded;
142
143 if (std::lower_bound(xAxisDataBegin, xAxisDataEnd, firstValue) == xAxisDataEnd) {
144 // Other data series if after data series
145 prepend = false;
146 sortNeeded = false;
147 }
148 else if (std::upper_bound(xAxisDataBegin, xAxisDataEnd, lastValue)
149 == xAxisDataBegin) {
150 // Other data series if before data series
151 prepend = true;
152 sortNeeded = false;
153 }
154 else {
155 // The two data series overlap
156 prepend = false;
157 sortNeeded = true;
158 }
159
160 // Makes the merge
161 m_XAxisData->add(*other->xAxisData(), prepend);
162 m_ValuesData->add(*other->valuesData(), prepend);
163
164 if (sortNeeded) {
165 sort();
166 }
167 }
168
169 // Clears the other data series
170 other->clear();
171 }
139 }
172 else {
140 else {
173 qCWarning(LOG_DataSeries())
141 qCWarning(LOG_DataSeries())
174 << QObject::tr("Detection of a type of IDataSeries we cannot merge with !");
142 << QObject::tr("Detection of a type of IDataSeries we cannot merge with !");
175 }
143 }
176 unlock();
144 unlock();
177 dataSeries->unlock();
145 dataSeries->unlock();
178 }
146 }
179
147
180 // ///////// //
148 // ///////// //
181 // Iterators //
149 // Iterators //
182 // ///////// //
150 // ///////// //
183
151
184 DataSeriesIterator cbegin() const override
152 DataSeriesIterator cbegin() const override
185 {
153 {
186 return DataSeriesIterator{DataSeriesIteratorValue{
154 return DataSeriesIterator{DataSeriesIteratorValue{
187 std::make_unique<dataseries_detail::IteratorValue<Dim> >(*this, true)}};
155 std::make_unique<dataseries_detail::IteratorValue<Dim> >(*this, true)}};
188 }
156 }
189
157
190 DataSeriesIterator cend() const override
158 DataSeriesIterator cend() const override
191 {
159 {
192 return DataSeriesIterator{DataSeriesIteratorValue{
160 return DataSeriesIterator{DataSeriesIteratorValue{
193 std::make_unique<dataseries_detail::IteratorValue<Dim> >(*this, false)}};
161 std::make_unique<dataseries_detail::IteratorValue<Dim> >(*this, false)}};
194 }
162 }
195
163
196 /// @sa IDataSeries::minXAxisData()
164 /// @sa IDataSeries::minXAxisData()
197 DataSeriesIterator minXAxisData(double minXAxisData) const override
165 DataSeriesIterator minXAxisData(double minXAxisData) const override
198 {
166 {
199 return std::lower_bound(
167 return std::lower_bound(
200 cbegin(), cend(), minXAxisData,
168 cbegin(), cend(), minXAxisData,
201 [](const auto &itValue, const auto &value) { return itValue.x() < value; });
169 [](const auto &itValue, const auto &value) { return itValue.x() < value; });
202 }
170 }
203
171
204 /// @sa IDataSeries::maxXAxisData()
172 /// @sa IDataSeries::maxXAxisData()
205 DataSeriesIterator maxXAxisData(double maxXAxisData) const override
173 DataSeriesIterator maxXAxisData(double maxXAxisData) const override
206 {
174 {
207 // Gets the first element that greater than max value
175 // Gets the first element that greater than max value
208 auto it = std::upper_bound(
176 auto it = std::upper_bound(
209 cbegin(), cend(), maxXAxisData,
177 cbegin(), cend(), maxXAxisData,
210 [](const auto &value, const auto &itValue) { return value < itValue.x(); });
178 [](const auto &value, const auto &itValue) { return value < itValue.x(); });
211
179
212 return it == cbegin() ? cend() : --it;
180 return it == cbegin() ? cend() : --it;
213 }
181 }
214
182
215 std::pair<DataSeriesIterator, DataSeriesIterator> xAxisRange(double minXAxisData,
183 std::pair<DataSeriesIterator, DataSeriesIterator> xAxisRange(double minXAxisData,
216 double maxXAxisData) const override
184 double maxXAxisData) const override
217 {
185 {
218 if (minXAxisData > maxXAxisData) {
186 if (minXAxisData > maxXAxisData) {
219 std::swap(minXAxisData, maxXAxisData);
187 std::swap(minXAxisData, maxXAxisData);
220 }
188 }
221
189
222 auto begin = cbegin();
190 auto begin = cbegin();
223 auto end = cend();
191 auto end = cend();
224
192
225 auto lowerIt = std::lower_bound(
193 auto lowerIt = std::lower_bound(
226 begin, end, minXAxisData,
194 begin, end, minXAxisData,
227 [](const auto &itValue, const auto &value) { return itValue.x() < value; });
195 [](const auto &itValue, const auto &value) { return itValue.x() < value; });
228 auto upperIt = std::upper_bound(
196 auto upperIt = std::upper_bound(
229 begin, end, maxXAxisData,
197 begin, end, maxXAxisData,
230 [](const auto &value, const auto &itValue) { return value < itValue.x(); });
198 [](const auto &value, const auto &itValue) { return value < itValue.x(); });
231
199
232 return std::make_pair(lowerIt, upperIt);
200 return std::make_pair(lowerIt, upperIt);
233 }
201 }
234
202
235 std::pair<DataSeriesIterator, DataSeriesIterator>
203 std::pair<DataSeriesIterator, DataSeriesIterator>
236 valuesBounds(double minXAxisData, double maxXAxisData) const override
204 valuesBounds(double minXAxisData, double maxXAxisData) const override
237 {
205 {
238 // Places iterators to the correct x-axis range
206 // Places iterators to the correct x-axis range
239 auto xAxisRangeIts = xAxisRange(minXAxisData, maxXAxisData);
207 auto xAxisRangeIts = xAxisRange(minXAxisData, maxXAxisData);
240
208
241 // Returns end iterators if the range is empty
209 // Returns end iterators if the range is empty
242 if (xAxisRangeIts.first == xAxisRangeIts.second) {
210 if (xAxisRangeIts.first == xAxisRangeIts.second) {
243 return std::make_pair(cend(), cend());
211 return std::make_pair(cend(), cend());
244 }
212 }
245
213
246 // Gets the iterator on the min of all values data
214 // Gets the iterator on the min of all values data
247 auto minIt = std::min_element(
215 auto minIt = std::min_element(
248 xAxisRangeIts.first, xAxisRangeIts.second, [](const auto &it1, const auto &it2) {
216 xAxisRangeIts.first, xAxisRangeIts.second, [](const auto &it1, const auto &it2) {
249 return SortUtils::minCompareWithNaN(it1.minValue(), it2.minValue());
217 return SortUtils::minCompareWithNaN(it1.minValue(), it2.minValue());
250 });
218 });
251
219
252 // Gets the iterator on the max of all values data
220 // Gets the iterator on the max of all values data
253 auto maxIt = std::max_element(
221 auto maxIt = std::max_element(
254 xAxisRangeIts.first, xAxisRangeIts.second, [](const auto &it1, const auto &it2) {
222 xAxisRangeIts.first, xAxisRangeIts.second, [](const auto &it1, const auto &it2) {
255 return SortUtils::maxCompareWithNaN(it1.maxValue(), it2.maxValue());
223 return SortUtils::maxCompareWithNaN(it1.maxValue(), it2.maxValue());
256 });
224 });
257
225
258 return std::make_pair(minIt, maxIt);
226 return std::make_pair(minIt, maxIt);
259 }
227 }
260
228
261 // /////// //
229 // /////// //
262 // Mutexes //
230 // Mutexes //
263 // /////// //
231 // /////// //
264
232
265 virtual void lockRead() { m_Lock.lockForRead(); }
233 virtual void lockRead() { m_Lock.lockForRead(); }
266 virtual void lockWrite() { m_Lock.lockForWrite(); }
234 virtual void lockWrite() { m_Lock.lockForWrite(); }
267 virtual void unlock() { m_Lock.unlock(); }
235 virtual void unlock() { m_Lock.unlock(); }
268
236
237 // ///// //
238 // Other //
239 // ///// //
240
241 /// Inserts at the end of the data series the value of the iterator passed as a parameter. This
242 /// method is intended to be used in the context of generating a back insert iterator
243 /// @param iteratorValue the iterator value containing the values to insert
244 /// @sa http://en.cppreference.com/w/cpp/iterator/back_inserter
245 /// @sa merge()
246 /// @sa value_type
247 void push_back(const value_type &iteratorValue)
248 {
249 m_XAxisData->push_back(QVector<double>{iteratorValue.x()});
250 m_ValuesData->push_back(iteratorValue.values());
251 }
252
269 protected:
253 protected:
270 /// Protected ctor (DataSeries is abstract). The vectors must have the same size, otherwise a
254 /// Protected ctor (DataSeries is abstract). The vectors must have the same size, otherwise a
271 /// DataSeries with no values will be created.
255 /// DataSeries with no values will be created.
272 /// @remarks data series is automatically sorted on its x-axis data
256 /// @remarks data series is automatically sorted on its x-axis data
273 explicit DataSeries(std::shared_ptr<ArrayData<1> > xAxisData, const Unit &xAxisUnit,
257 explicit DataSeries(std::shared_ptr<ArrayData<1> > xAxisData, const Unit &xAxisUnit,
274 std::shared_ptr<ArrayData<Dim> > valuesData, const Unit &valuesUnit)
258 std::shared_ptr<ArrayData<Dim> > valuesData, const Unit &valuesUnit)
275 : m_XAxisData{xAxisData},
259 : m_XAxisData{xAxisData},
276 m_XAxisUnit{xAxisUnit},
260 m_XAxisUnit{xAxisUnit},
277 m_ValuesData{valuesData},
261 m_ValuesData{valuesData},
278 m_ValuesUnit{valuesUnit}
262 m_ValuesUnit{valuesUnit}
279 {
263 {
280 if (m_XAxisData->size() != m_ValuesData->size()) {
264 if (m_XAxisData->size() != m_ValuesData->size()) {
281 clear();
265 clear();
282 }
266 }
283
267
284 // Sorts data if it's not the case
268 // Sorts data if it's not the case
285 const auto &xAxisCData = m_XAxisData->cdata();
269 const auto &xAxisCData = m_XAxisData->cdata();
286 if (!std::is_sorted(xAxisCData.cbegin(), xAxisCData.cend())) {
270 if (!std::is_sorted(xAxisCData.cbegin(), xAxisCData.cend())) {
287 sort();
271 sort();
288 }
272 }
289 }
273 }
290
274
291 /// Copy ctor
275 /// Copy ctor
292 explicit DataSeries(const DataSeries<Dim> &other)
276 explicit DataSeries(const DataSeries<Dim> &other)
293 : m_XAxisData{std::make_shared<ArrayData<1> >(*other.m_XAxisData)},
277 : m_XAxisData{std::make_shared<ArrayData<1> >(*other.m_XAxisData)},
294 m_XAxisUnit{other.m_XAxisUnit},
278 m_XAxisUnit{other.m_XAxisUnit},
295 m_ValuesData{std::make_shared<ArrayData<Dim> >(*other.m_ValuesData)},
279 m_ValuesData{std::make_shared<ArrayData<Dim> >(*other.m_ValuesData)},
296 m_ValuesUnit{other.m_ValuesUnit}
280 m_ValuesUnit{other.m_ValuesUnit}
297 {
281 {
298 // Since a series is ordered from its construction and is always ordered, it is not
282 // Since a series is ordered from its construction and is always ordered, it is not
299 // necessary to call the sort method here ('other' is sorted)
283 // necessary to call the sort method here ('other' is sorted)
300 }
284 }
301
285
302 /// Assignment operator
286 /// Assignment operator
303 template <int D>
287 template <int D>
304 DataSeries &operator=(DataSeries<D> other)
288 DataSeries &operator=(DataSeries<D> other)
305 {
289 {
306 std::swap(m_XAxisData, other.m_XAxisData);
290 std::swap(m_XAxisData, other.m_XAxisData);
307 std::swap(m_XAxisUnit, other.m_XAxisUnit);
291 std::swap(m_XAxisUnit, other.m_XAxisUnit);
308 std::swap(m_ValuesData, other.m_ValuesData);
292 std::swap(m_ValuesData, other.m_ValuesData);
309 std::swap(m_ValuesUnit, other.m_ValuesUnit);
293 std::swap(m_ValuesUnit, other.m_ValuesUnit);
310
294
311 return *this;
295 return *this;
312 }
296 }
313
297
314 private:
298 private:
315 /**
299 /**
316 * Sorts data series on its x-axis data
300 * Sorts data series on its x-axis data
317 */
301 */
318 void sort() noexcept
302 void sort() noexcept
319 {
303 {
320 auto permutation = SortUtils::sortPermutation(*m_XAxisData, std::less<double>());
304 auto permutation = SortUtils::sortPermutation(*m_XAxisData, std::less<double>());
321 m_XAxisData = m_XAxisData->sort(permutation);
305 m_XAxisData = m_XAxisData->sort(permutation);
322 m_ValuesData = m_ValuesData->sort(permutation);
306 m_ValuesData = m_ValuesData->sort(permutation);
323 }
307 }
324
308
325 std::shared_ptr<ArrayData<1> > m_XAxisData;
309 std::shared_ptr<ArrayData<1> > m_XAxisData;
326 Unit m_XAxisUnit;
310 Unit m_XAxisUnit;
327 std::shared_ptr<ArrayData<Dim> > m_ValuesData;
311 std::shared_ptr<ArrayData<Dim> > m_ValuesData;
328 Unit m_ValuesUnit;
312 Unit m_ValuesUnit;
329
313
330 QReadWriteLock m_Lock;
314 QReadWriteLock m_Lock;
331 };
315 };
332
316
333 #endif // SCIQLOP_DATASERIES_H
317 #endif // SCIQLOP_DATASERIES_H
@@ -1,60 +1,64
1 #ifndef SCIQLOP_DATASERIESITERATOR_H
1 #ifndef SCIQLOP_DATASERIESITERATOR_H
2 #define SCIQLOP_DATASERIESITERATOR_H
2 #define SCIQLOP_DATASERIESITERATOR_H
3
3
4 #include "CoreGlobal.h"
4 #include "CoreGlobal.h"
5 #include "Data/SqpIterator.h"
5 #include "Data/SqpIterator.h"
6
6
7 #include <QVector>
7 #include <memory>
8 #include <memory>
8
9
9 /**
10 /**
10 * @brief The DataSeriesIteratorValue class represents the current value of a data series iterator.
11 * @brief The DataSeriesIteratorValue class represents the current value of a data series iterator.
11 * It offers standard access methods for the data in the series (x-axis, values), but it is up to
12 * It offers standard access methods for the data in the series (x-axis, values), but it is up to
12 * each series to define its own implementation of how to retrieve this data, by implementing the
13 * each series to define its own implementation of how to retrieve this data, by implementing the
13 * DataSeriesIteratorValue::Impl interface
14 * DataSeriesIteratorValue::Impl interface
14 *
15 *
15 * @sa DataSeriesIterator
16 * @sa DataSeriesIterator
16 */
17 */
17 class SCIQLOP_CORE_EXPORT DataSeriesIteratorValue {
18 class SCIQLOP_CORE_EXPORT DataSeriesIteratorValue {
18 public:
19 public:
19 struct Impl {
20 struct Impl {
20 virtual ~Impl() noexcept = default;
21 virtual ~Impl() noexcept = default;
21 virtual std::unique_ptr<Impl> clone() const = 0;
22 virtual std::unique_ptr<Impl> clone() const = 0;
22 virtual bool equals(const Impl &other) const = 0;
23 virtual bool equals(const Impl &other) const = 0;
23 virtual void next() = 0;
24 virtual void next() = 0;
24 virtual void prev() = 0;
25 virtual void prev() = 0;
25 virtual double x() const = 0;
26 virtual double x() const = 0;
26 virtual double value() const = 0;
27 virtual double value() const = 0;
27 virtual double value(int componentIndex) const = 0;
28 virtual double value(int componentIndex) const = 0;
28 virtual double minValue() const = 0;
29 virtual double minValue() const = 0;
29 virtual double maxValue() const = 0;
30 virtual double maxValue() const = 0;
31 virtual QVector<double> values() const = 0;
30 };
32 };
31
33
32 explicit DataSeriesIteratorValue(std::unique_ptr<Impl> impl);
34 explicit DataSeriesIteratorValue(std::unique_ptr<Impl> impl);
33 DataSeriesIteratorValue(const DataSeriesIteratorValue &other);
35 DataSeriesIteratorValue(const DataSeriesIteratorValue &other);
34 DataSeriesIteratorValue(DataSeriesIteratorValue &&other) = default;
36 DataSeriesIteratorValue(DataSeriesIteratorValue &&other) = default;
35 DataSeriesIteratorValue &operator=(DataSeriesIteratorValue other);
37 DataSeriesIteratorValue &operator=(DataSeriesIteratorValue other);
36
38
37 bool equals(const DataSeriesIteratorValue &other) const;
39 bool equals(const DataSeriesIteratorValue &other) const;
38
40
39 /// Advances to the next value
41 /// Advances to the next value
40 void next();
42 void next();
41 /// Moves back to the previous value
43 /// Moves back to the previous value
42 void prev();
44 void prev();
43 /// Gets x-axis data
45 /// Gets x-axis data
44 double x() const;
46 double x() const;
45 /// Gets value data
47 /// Gets value data
46 double value() const;
48 double value() const;
47 /// Gets value data depending on an index
49 /// Gets value data depending on an index
48 double value(int componentIndex) const;
50 double value(int componentIndex) const;
49 /// Gets min of all values data
51 /// Gets min of all values data
50 double minValue() const;
52 double minValue() const;
51 /// Gets max of all values data
53 /// Gets max of all values data
52 double maxValue() const;
54 double maxValue() const;
55 /// Gets all values data
56 QVector<double> values() const;
53
57
54 private:
58 private:
55 std::unique_ptr<Impl> m_Impl;
59 std::unique_ptr<Impl> m_Impl;
56 };
60 };
57
61
58 using DataSeriesIterator = SqpIterator<DataSeriesIteratorValue>;
62 using DataSeriesIterator = SqpIterator<DataSeriesIteratorValue>;
59
63
60 #endif // SCIQLOP_DATASERIESITERATOR_H
64 #endif // SCIQLOP_DATASERIESITERATOR_H
@@ -1,52 +1,57
1 #include "Data/ArrayDataIterator.h"
1 #include "Data/ArrayDataIterator.h"
2
2
3 ArrayDataIteratorValue::ArrayDataIteratorValue(std::unique_ptr<ArrayDataIteratorValue::Impl> impl)
3 ArrayDataIteratorValue::ArrayDataIteratorValue(std::unique_ptr<ArrayDataIteratorValue::Impl> impl)
4 : m_Impl{std::move(impl)}
4 : m_Impl{std::move(impl)}
5 {
5 {
6 }
6 }
7
7
8 ArrayDataIteratorValue::ArrayDataIteratorValue(const ArrayDataIteratorValue &other)
8 ArrayDataIteratorValue::ArrayDataIteratorValue(const ArrayDataIteratorValue &other)
9 : m_Impl{other.m_Impl->clone()}
9 : m_Impl{other.m_Impl->clone()}
10 {
10 {
11 }
11 }
12
12
13 ArrayDataIteratorValue &ArrayDataIteratorValue::operator=(ArrayDataIteratorValue other)
13 ArrayDataIteratorValue &ArrayDataIteratorValue::operator=(ArrayDataIteratorValue other)
14 {
14 {
15 std::swap(m_Impl, other.m_Impl);
15 std::swap(m_Impl, other.m_Impl);
16 return *this;
16 return *this;
17 }
17 }
18
18
19 bool ArrayDataIteratorValue::equals(const ArrayDataIteratorValue &other) const
19 bool ArrayDataIteratorValue::equals(const ArrayDataIteratorValue &other) const
20 {
20 {
21 return m_Impl->equals(*other.m_Impl);
21 return m_Impl->equals(*other.m_Impl);
22 }
22 }
23
23
24 void ArrayDataIteratorValue::next()
24 void ArrayDataIteratorValue::next()
25 {
25 {
26 m_Impl->next();
26 m_Impl->next();
27 }
27 }
28
28
29 void ArrayDataIteratorValue::prev()
29 void ArrayDataIteratorValue::prev()
30 {
30 {
31 m_Impl->prev();
31 m_Impl->prev();
32 }
32 }
33
33
34 double ArrayDataIteratorValue::at(int componentIndex) const
34 double ArrayDataIteratorValue::at(int componentIndex) const
35 {
35 {
36 return m_Impl->at(componentIndex);
36 return m_Impl->at(componentIndex);
37 }
37 }
38
38
39 double ArrayDataIteratorValue::first() const
39 double ArrayDataIteratorValue::first() const
40 {
40 {
41 return m_Impl->first();
41 return m_Impl->first();
42 }
42 }
43
43
44 double ArrayDataIteratorValue::min() const
44 double ArrayDataIteratorValue::min() const
45 {
45 {
46 return m_Impl->min();
46 return m_Impl->min();
47 }
47 }
48
48
49 double ArrayDataIteratorValue::max() const
49 double ArrayDataIteratorValue::max() const
50 {
50 {
51 return m_Impl->max();
51 return m_Impl->max();
52 }
52 }
53
54 QVector<double> ArrayDataIteratorValue::values() const
55 {
56 return m_Impl->values();
57 }
@@ -1,58 +1,63
1 #include "Data/DataSeriesIterator.h"
1 #include "Data/DataSeriesIterator.h"
2
2
3 DataSeriesIteratorValue::DataSeriesIteratorValue(
3 DataSeriesIteratorValue::DataSeriesIteratorValue(
4 std::unique_ptr<DataSeriesIteratorValue::Impl> impl)
4 std::unique_ptr<DataSeriesIteratorValue::Impl> impl)
5 : m_Impl{std::move(impl)}
5 : m_Impl{std::move(impl)}
6 {
6 {
7 }
7 }
8
8
9 DataSeriesIteratorValue::DataSeriesIteratorValue(const DataSeriesIteratorValue &other)
9 DataSeriesIteratorValue::DataSeriesIteratorValue(const DataSeriesIteratorValue &other)
10 : m_Impl{other.m_Impl->clone()}
10 : m_Impl{other.m_Impl->clone()}
11 {
11 {
12 }
12 }
13
13
14 DataSeriesIteratorValue &DataSeriesIteratorValue::operator=(DataSeriesIteratorValue other)
14 DataSeriesIteratorValue &DataSeriesIteratorValue::operator=(DataSeriesIteratorValue other)
15 {
15 {
16 std::swap(m_Impl, other.m_Impl);
16 std::swap(m_Impl, other.m_Impl);
17 return *this;
17 return *this;
18 }
18 }
19
19
20 bool DataSeriesIteratorValue::equals(const DataSeriesIteratorValue &other) const
20 bool DataSeriesIteratorValue::equals(const DataSeriesIteratorValue &other) const
21 {
21 {
22 return m_Impl->equals(*other.m_Impl);
22 return m_Impl->equals(*other.m_Impl);
23 }
23 }
24
24
25 void DataSeriesIteratorValue::next()
25 void DataSeriesIteratorValue::next()
26 {
26 {
27 m_Impl->next();
27 m_Impl->next();
28 }
28 }
29
29
30 void DataSeriesIteratorValue::prev()
30 void DataSeriesIteratorValue::prev()
31 {
31 {
32 m_Impl->prev();
32 m_Impl->prev();
33 }
33 }
34
34
35 double DataSeriesIteratorValue::x() const
35 double DataSeriesIteratorValue::x() const
36 {
36 {
37 return m_Impl->x();
37 return m_Impl->x();
38 }
38 }
39
39
40 double DataSeriesIteratorValue::value() const
40 double DataSeriesIteratorValue::value() const
41 {
41 {
42 return m_Impl->value();
42 return m_Impl->value();
43 }
43 }
44
44
45 double DataSeriesIteratorValue::value(int componentIndex) const
45 double DataSeriesIteratorValue::value(int componentIndex) const
46 {
46 {
47 return m_Impl->value(componentIndex);
47 return m_Impl->value(componentIndex);
48 }
48 }
49
49
50 double DataSeriesIteratorValue::minValue() const
50 double DataSeriesIteratorValue::minValue() const
51 {
51 {
52 return m_Impl->minValue();
52 return m_Impl->minValue();
53 }
53 }
54
54
55 double DataSeriesIteratorValue::maxValue() const
55 double DataSeriesIteratorValue::maxValue() const
56 {
56 {
57 return m_Impl->maxValue();
57 return m_Impl->maxValue();
58 }
58 }
59
60 QVector<double> DataSeriesIteratorValue::values() const
61 {
62 return m_Impl->values();
63 }
@@ -1,39 +1,45
1 # On ignore toutes les règles vera++ pour le fichier spimpl
1 # On ignore toutes les règles vera++ pour le fichier spimpl
2 Common/spimpl\.h:\d+:.*
2 Common/spimpl\.h:\d+:.*
3
3
4 # Ignore false positive relative to two class definitions in a same file
4 # Ignore false positive relative to two class definitions in a same file
5 ArrayData\.h:\d+:.*IPSIS_S01.*
5 ArrayData\.h:\d+:.*IPSIS_S01.*
6 ArrayDataIterator\.h:\d+:.*IPSIS_S01.*
6 ArrayDataIterator\.h:\d+:.*IPSIS_S01.*
7 DataSourceItem\.h:\d+:.*IPSIS_S01.*
7 DataSourceItem\.h:\d+:.*IPSIS_S01.*
8 DataSeries\.h:\d+:.*IPSIS_S01.*
8 DataSeries\.h:\d+:.*IPSIS_S01.*
9 DataSeriesIterator\.h:\d+:.*IPSIS_S01.*
9 DataSeriesIterator\.h:\d+:.*IPSIS_S01.*
10 DataSeriesMergeHelper\.h:\d+:.*IPSIS_S01.*
10
11
11 # Ignore false positive relative to a template class
12 # Ignore false positive relative to a template class
13 ArrayData\.h:\d+:.*IPSIS_S04_METHOD.*found: push_back
12 ArrayData\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (D)
14 ArrayData\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (D)
13 ArrayData\.h:\d+:.*IPSIS_S04_NAMESPACE.*found: (arraydata_detail)
15 ArrayData\.h:\d+:.*IPSIS_S04_NAMESPACE.*found: (arraydata_detail)
14 ArrayData\.h:\d+:.*IPSIS_S06.*found: (D)
16 ArrayData\.h:\d+:.*IPSIS_S06.*found: (D)
15 ArrayData\.h:\d+:.*IPSIS_S06.*found: (Dim)
17 ArrayData\.h:\d+:.*IPSIS_S06.*found: (Dim)
16 DataSeries\.h:\d+:.*IPSIS_S04_METHOD.*found: LOG_DataSeries
18 DataSeries\.h:\d+:.*IPSIS_S04_METHOD.*found: LOG_DataSeries
19 DataSeries\.h:\d+:.*IPSIS_S04_METHOD.*found: push_back
17 DataSeries\.h:\d+:.*IPSIS_S04_VARIABLE.*
20 DataSeries\.h:\d+:.*IPSIS_S04_VARIABLE.*
18 DataSeries\.h:\d+:.*IPSIS_S04_NAMESPACE.*found: (dataseries_detail)
21 DataSeries\.h:\d+:.*IPSIS_S04_NAMESPACE.*found: (dataseries_detail)
22 DataSeries\.h:\d+:.*IPSIS_S05.*
23 DataSeries\.h:\d+:.*IPSIS_S06.*found: (value_type)
24 DataSeries\.h:\d+:.*IPSIS_S06.*found: (DataSeriesIteratorValue)
19
25
20 # Ignore false positive relative to iterators
26 # Ignore false positive relative to iterators
21 SqpIterator\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (forward_iterator_tag)
27 SqpIterator\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (forward_iterator_tag)
22 SqpIterator\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (T)
28 SqpIterator\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (T)
23 SqpIterator\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (ptrdiff_t)
29 SqpIterator\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (ptrdiff_t)
24 SqpIterator\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (value_type)
30 SqpIterator\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (value_type)
25 SqpIterator\.h:\d+:.*IPSIS_S06.*found: (iterator_category)
31 SqpIterator\.h:\d+:.*IPSIS_S06.*found: (iterator_category)
26 SqpIterator\.h:\d+:.*IPSIS_S06.*found: (forward_iterator_tag)
32 SqpIterator\.h:\d+:.*IPSIS_S06.*found: (forward_iterator_tag)
27 SqpIterator\.h:\d+:.*IPSIS_S06.*found: (value_type)
33 SqpIterator\.h:\d+:.*IPSIS_S06.*found: (value_type)
28 SqpIterator\.h:\d+:.*IPSIS_S06.*found: (T)
34 SqpIterator\.h:\d+:.*IPSIS_S06.*found: (T)
29 SqpIterator\.h:\d+:.*IPSIS_S06.*found: (difference_type)
35 SqpIterator\.h:\d+:.*IPSIS_S06.*found: (difference_type)
30 SqpIterator\.h:\d+:.*IPSIS_S06.*found: (ptrdiff_t)
36 SqpIterator\.h:\d+:.*IPSIS_S06.*found: (ptrdiff_t)
31 SqpIterator\.h:\d+:.*IPSIS_S06.*found: (pointer)
37 SqpIterator\.h:\d+:.*IPSIS_S06.*found: (pointer)
32 SqpIterator\.h:\d+:.*IPSIS_S06.*found: (reference)
38 SqpIterator\.h:\d+:.*IPSIS_S06.*found: (reference)
33 SqpIterator\.h:\d+:.*IPSIS_S06.*found: (value_type)
39 SqpIterator\.h:\d+:.*IPSIS_S06.*found: (value_type)
34
40
35 # Ignore false positive relative to an alias
41 # Ignore false positive relative to an alias
36 DataSourceItemAction\.h:\d+:.*IPSIS_S06.*found: (ExecuteFunction)
42 DataSourceItemAction\.h:\d+:.*IPSIS_S06.*found: (ExecuteFunction)
37
43
38 # Ignore false positive relative to unnamed namespace
44 # Ignore false positive relative to unnamed namespace
39 VariableController\.cpp:\d+:.*IPSIS_F13.*
45 VariableController\.cpp:\d+:.*IPSIS_F13.*
General Comments 0
You need to be logged in to leave comments. Login now