##// END OF EJS Templates
Updates merge() method (1)...
Alexandre Leroux -
r668:aaf56376a038
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,334 +1,297
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(); }
70 QVector<double> values() const override { return m_ValuesIt->values(); }
71 QVector<double> values() const override { return m_ValuesIt->values(); }
71
72
72 private:
73 private:
73 ArrayDataIterator m_XIt;
74 ArrayDataIterator m_XIt;
74 ArrayDataIterator m_ValuesIt;
75 ArrayDataIterator m_ValuesIt;
75 };
76 };
76 } // namespace dataseries_detail
77 } // namespace dataseries_detail
77
78
78 /**
79 /**
79 * @brief The DataSeries class is the base (abstract) implementation of IDataSeries.
80 * @brief The DataSeries class is the base (abstract) implementation of IDataSeries.
80 *
81 *
81 * It proposes to set a dimension for the values ​​data.
82 * It proposes to set a dimension for the values ​​data.
82 *
83 *
83 * A DataSeries is always sorted on its x-axis data.
84 * A DataSeries is always sorted on its x-axis data.
84 *
85 *
85 * @tparam Dim The dimension of the values data
86 * @tparam Dim The dimension of the values data
86 *
87 *
87 */
88 */
88 template <int Dim>
89 template <int Dim>
89 class SCIQLOP_CORE_EXPORT DataSeries : public IDataSeries {
90 class SCIQLOP_CORE_EXPORT DataSeries : public IDataSeries {
91 friend class DataSeriesMergeHelper;
92
90 public:
93 public:
91 /// @sa IDataSeries::xAxisData()
94 /// @sa IDataSeries::xAxisData()
92 std::shared_ptr<ArrayData<1> > xAxisData() override { return m_XAxisData; }
95 std::shared_ptr<ArrayData<1> > xAxisData() override { return m_XAxisData; }
93 const std::shared_ptr<ArrayData<1> > xAxisData() const { return m_XAxisData; }
96 const std::shared_ptr<ArrayData<1> > xAxisData() const { return m_XAxisData; }
94
97
95 /// @sa IDataSeries::xAxisUnit()
98 /// @sa IDataSeries::xAxisUnit()
96 Unit xAxisUnit() const override { return m_XAxisUnit; }
99 Unit xAxisUnit() const override { return m_XAxisUnit; }
97
100
98 /// @return the values dataset
101 /// @return the values dataset
99 std::shared_ptr<ArrayData<Dim> > valuesData() { return m_ValuesData; }
102 std::shared_ptr<ArrayData<Dim> > valuesData() { return m_ValuesData; }
100 const std::shared_ptr<ArrayData<Dim> > valuesData() const { return m_ValuesData; }
103 const std::shared_ptr<ArrayData<Dim> > valuesData() const { return m_ValuesData; }
101
104
102 /// @sa IDataSeries::valuesUnit()
105 /// @sa IDataSeries::valuesUnit()
103 Unit valuesUnit() const override { return m_ValuesUnit; }
106 Unit valuesUnit() const override { return m_ValuesUnit; }
104
107
105
108
106 SqpRange range() const override
109 SqpRange range() const override
107 {
110 {
108 if (!m_XAxisData->cdata().isEmpty()) {
111 if (!m_XAxisData->cdata().isEmpty()) {
109 return SqpRange{m_XAxisData->cdata().first(), m_XAxisData->cdata().last()};
112 return SqpRange{m_XAxisData->cdata().first(), m_XAxisData->cdata().last()};
110 }
113 }
111
114
112 return SqpRange{};
115 return SqpRange{};
113 }
116 }
114
117
115 void clear()
118 void clear()
116 {
119 {
117 m_XAxisData->clear();
120 m_XAxisData->clear();
118 m_ValuesData->clear();
121 m_ValuesData->clear();
119 }
122 }
120
123
124 bool isEmpty() const noexcept { return m_XAxisData->size() == 0; }
125
121 /// Merges into the data series an other data series
126 /// Merges into the data series an other data series
122 /// @remarks the data series to merge with is cleared after the operation
127 /// @remarks the data series to merge with is cleared after the operation
123 void merge(IDataSeries *dataSeries) override
128 void merge(IDataSeries *dataSeries) override
124 {
129 {
125 dataSeries->lockWrite();
130 dataSeries->lockWrite();
126 lockWrite();
131 lockWrite();
127
132
128 if (auto other = dynamic_cast<DataSeries<Dim> *>(dataSeries)) {
133 if (auto other = dynamic_cast<DataSeries<Dim> *>(dataSeries)) {
129 const auto &otherXAxisData = other->xAxisData()->cdata();
134 DataSeriesMergeHelper::merge(*other, *this);
130 const auto &xAxisData = m_XAxisData->cdata();
131
132 // As data series are sorted, we can improve performances of merge, by call the sort
133 // method only if the two data series overlap.
134 if (!otherXAxisData.empty()) {
135 auto firstValue = otherXAxisData.front();
136 auto lastValue = otherXAxisData.back();
137
138 auto xAxisDataBegin = xAxisData.cbegin();
139 auto xAxisDataEnd = xAxisData.cend();
140
141 bool prepend;
142 bool sortNeeded;
143
144 if (std::lower_bound(xAxisDataBegin, xAxisDataEnd, firstValue) == xAxisDataEnd) {
145 // Other data series if after data series
146 prepend = false;
147 sortNeeded = false;
148 }
149 else if (std::upper_bound(xAxisDataBegin, xAxisDataEnd, lastValue)
150 == xAxisDataBegin) {
151 // Other data series if before data series
152 prepend = true;
153 sortNeeded = false;
154 }
155 else {
156 // The two data series overlap
157 prepend = false;
158 sortNeeded = true;
159 }
160
161 // Makes the merge
162 m_XAxisData->add(*other->xAxisData(), prepend);
163 m_ValuesData->add(*other->valuesData(), prepend);
164
165 if (sortNeeded) {
166 sort();
167 }
168 }
169
170 // Clears the other data series
171 other->clear();
172 }
135 }
173 else {
136 else {
174 qCWarning(LOG_DataSeries())
137 qCWarning(LOG_DataSeries())
175 << QObject::tr("Detection of a type of IDataSeries we cannot merge with !");
138 << QObject::tr("Detection of a type of IDataSeries we cannot merge with !");
176 }
139 }
177 unlock();
140 unlock();
178 dataSeries->unlock();
141 dataSeries->unlock();
179 }
142 }
180
143
181 // ///////// //
144 // ///////// //
182 // Iterators //
145 // Iterators //
183 // ///////// //
146 // ///////// //
184
147
185 DataSeriesIterator cbegin() const override
148 DataSeriesIterator cbegin() const override
186 {
149 {
187 return DataSeriesIterator{DataSeriesIteratorValue{
150 return DataSeriesIterator{DataSeriesIteratorValue{
188 std::make_unique<dataseries_detail::IteratorValue<Dim> >(*this, true)}};
151 std::make_unique<dataseries_detail::IteratorValue<Dim> >(*this, true)}};
189 }
152 }
190
153
191 DataSeriesIterator cend() const override
154 DataSeriesIterator cend() const override
192 {
155 {
193 return DataSeriesIterator{DataSeriesIteratorValue{
156 return DataSeriesIterator{DataSeriesIteratorValue{
194 std::make_unique<dataseries_detail::IteratorValue<Dim> >(*this, false)}};
157 std::make_unique<dataseries_detail::IteratorValue<Dim> >(*this, false)}};
195 }
158 }
196
159
197 /// @sa IDataSeries::minXAxisData()
160 /// @sa IDataSeries::minXAxisData()
198 DataSeriesIterator minXAxisData(double minXAxisData) const override
161 DataSeriesIterator minXAxisData(double minXAxisData) const override
199 {
162 {
200 return std::lower_bound(
163 return std::lower_bound(
201 cbegin(), cend(), minXAxisData,
164 cbegin(), cend(), minXAxisData,
202 [](const auto &itValue, const auto &value) { return itValue.x() < value; });
165 [](const auto &itValue, const auto &value) { return itValue.x() < value; });
203 }
166 }
204
167
205 /// @sa IDataSeries::maxXAxisData()
168 /// @sa IDataSeries::maxXAxisData()
206 DataSeriesIterator maxXAxisData(double maxXAxisData) const override
169 DataSeriesIterator maxXAxisData(double maxXAxisData) const override
207 {
170 {
208 // Gets the first element that greater than max value
171 // Gets the first element that greater than max value
209 auto it = std::upper_bound(
172 auto it = std::upper_bound(
210 cbegin(), cend(), maxXAxisData,
173 cbegin(), cend(), maxXAxisData,
211 [](const auto &value, const auto &itValue) { return value < itValue.x(); });
174 [](const auto &value, const auto &itValue) { return value < itValue.x(); });
212
175
213 return it == cbegin() ? cend() : --it;
176 return it == cbegin() ? cend() : --it;
214 }
177 }
215
178
216 std::pair<DataSeriesIterator, DataSeriesIterator> xAxisRange(double minXAxisData,
179 std::pair<DataSeriesIterator, DataSeriesIterator> xAxisRange(double minXAxisData,
217 double maxXAxisData) const override
180 double maxXAxisData) const override
218 {
181 {
219 if (minXAxisData > maxXAxisData) {
182 if (minXAxisData > maxXAxisData) {
220 std::swap(minXAxisData, maxXAxisData);
183 std::swap(minXAxisData, maxXAxisData);
221 }
184 }
222
185
223 auto begin = cbegin();
186 auto begin = cbegin();
224 auto end = cend();
187 auto end = cend();
225
188
226 auto lowerIt = std::lower_bound(
189 auto lowerIt = std::lower_bound(
227 begin, end, minXAxisData,
190 begin, end, minXAxisData,
228 [](const auto &itValue, const auto &value) { return itValue.x() < value; });
191 [](const auto &itValue, const auto &value) { return itValue.x() < value; });
229 auto upperIt = std::upper_bound(
192 auto upperIt = std::upper_bound(
230 begin, end, maxXAxisData,
193 begin, end, maxXAxisData,
231 [](const auto &value, const auto &itValue) { return value < itValue.x(); });
194 [](const auto &value, const auto &itValue) { return value < itValue.x(); });
232
195
233 return std::make_pair(lowerIt, upperIt);
196 return std::make_pair(lowerIt, upperIt);
234 }
197 }
235
198
236 std::pair<DataSeriesIterator, DataSeriesIterator>
199 std::pair<DataSeriesIterator, DataSeriesIterator>
237 valuesBounds(double minXAxisData, double maxXAxisData) const override
200 valuesBounds(double minXAxisData, double maxXAxisData) const override
238 {
201 {
239 // Places iterators to the correct x-axis range
202 // Places iterators to the correct x-axis range
240 auto xAxisRangeIts = xAxisRange(minXAxisData, maxXAxisData);
203 auto xAxisRangeIts = xAxisRange(minXAxisData, maxXAxisData);
241
204
242 // Returns end iterators if the range is empty
205 // Returns end iterators if the range is empty
243 if (xAxisRangeIts.first == xAxisRangeIts.second) {
206 if (xAxisRangeIts.first == xAxisRangeIts.second) {
244 return std::make_pair(cend(), cend());
207 return std::make_pair(cend(), cend());
245 }
208 }
246
209
247 // Gets the iterator on the min of all values data
210 // Gets the iterator on the min of all values data
248 auto minIt = std::min_element(
211 auto minIt = std::min_element(
249 xAxisRangeIts.first, xAxisRangeIts.second, [](const auto &it1, const auto &it2) {
212 xAxisRangeIts.first, xAxisRangeIts.second, [](const auto &it1, const auto &it2) {
250 return SortUtils::minCompareWithNaN(it1.minValue(), it2.minValue());
213 return SortUtils::minCompareWithNaN(it1.minValue(), it2.minValue());
251 });
214 });
252
215
253 // Gets the iterator on the max of all values data
216 // Gets the iterator on the max of all values data
254 auto maxIt = std::max_element(
217 auto maxIt = std::max_element(
255 xAxisRangeIts.first, xAxisRangeIts.second, [](const auto &it1, const auto &it2) {
218 xAxisRangeIts.first, xAxisRangeIts.second, [](const auto &it1, const auto &it2) {
256 return SortUtils::maxCompareWithNaN(it1.maxValue(), it2.maxValue());
219 return SortUtils::maxCompareWithNaN(it1.maxValue(), it2.maxValue());
257 });
220 });
258
221
259 return std::make_pair(minIt, maxIt);
222 return std::make_pair(minIt, maxIt);
260 }
223 }
261
224
262 // /////// //
225 // /////// //
263 // Mutexes //
226 // Mutexes //
264 // /////// //
227 // /////// //
265
228
266 virtual void lockRead() { m_Lock.lockForRead(); }
229 virtual void lockRead() { m_Lock.lockForRead(); }
267 virtual void lockWrite() { m_Lock.lockForWrite(); }
230 virtual void lockWrite() { m_Lock.lockForWrite(); }
268 virtual void unlock() { m_Lock.unlock(); }
231 virtual void unlock() { m_Lock.unlock(); }
269
232
270 protected:
233 protected:
271 /// Protected ctor (DataSeries is abstract). The vectors must have the same size, otherwise a
234 /// Protected ctor (DataSeries is abstract). The vectors must have the same size, otherwise a
272 /// DataSeries with no values will be created.
235 /// DataSeries with no values will be created.
273 /// @remarks data series is automatically sorted on its x-axis data
236 /// @remarks data series is automatically sorted on its x-axis data
274 explicit DataSeries(std::shared_ptr<ArrayData<1> > xAxisData, const Unit &xAxisUnit,
237 explicit DataSeries(std::shared_ptr<ArrayData<1> > xAxisData, const Unit &xAxisUnit,
275 std::shared_ptr<ArrayData<Dim> > valuesData, const Unit &valuesUnit)
238 std::shared_ptr<ArrayData<Dim> > valuesData, const Unit &valuesUnit)
276 : m_XAxisData{xAxisData},
239 : m_XAxisData{xAxisData},
277 m_XAxisUnit{xAxisUnit},
240 m_XAxisUnit{xAxisUnit},
278 m_ValuesData{valuesData},
241 m_ValuesData{valuesData},
279 m_ValuesUnit{valuesUnit}
242 m_ValuesUnit{valuesUnit}
280 {
243 {
281 if (m_XAxisData->size() != m_ValuesData->size()) {
244 if (m_XAxisData->size() != m_ValuesData->size()) {
282 clear();
245 clear();
283 }
246 }
284
247
285 // Sorts data if it's not the case
248 // Sorts data if it's not the case
286 const auto &xAxisCData = m_XAxisData->cdata();
249 const auto &xAxisCData = m_XAxisData->cdata();
287 if (!std::is_sorted(xAxisCData.cbegin(), xAxisCData.cend())) {
250 if (!std::is_sorted(xAxisCData.cbegin(), xAxisCData.cend())) {
288 sort();
251 sort();
289 }
252 }
290 }
253 }
291
254
292 /// Copy ctor
255 /// Copy ctor
293 explicit DataSeries(const DataSeries<Dim> &other)
256 explicit DataSeries(const DataSeries<Dim> &other)
294 : m_XAxisData{std::make_shared<ArrayData<1> >(*other.m_XAxisData)},
257 : m_XAxisData{std::make_shared<ArrayData<1> >(*other.m_XAxisData)},
295 m_XAxisUnit{other.m_XAxisUnit},
258 m_XAxisUnit{other.m_XAxisUnit},
296 m_ValuesData{std::make_shared<ArrayData<Dim> >(*other.m_ValuesData)},
259 m_ValuesData{std::make_shared<ArrayData<Dim> >(*other.m_ValuesData)},
297 m_ValuesUnit{other.m_ValuesUnit}
260 m_ValuesUnit{other.m_ValuesUnit}
298 {
261 {
299 // Since a series is ordered from its construction and is always ordered, it is not
262 // Since a series is ordered from its construction and is always ordered, it is not
300 // necessary to call the sort method here ('other' is sorted)
263 // necessary to call the sort method here ('other' is sorted)
301 }
264 }
302
265
303 /// Assignment operator
266 /// Assignment operator
304 template <int D>
267 template <int D>
305 DataSeries &operator=(DataSeries<D> other)
268 DataSeries &operator=(DataSeries<D> other)
306 {
269 {
307 std::swap(m_XAxisData, other.m_XAxisData);
270 std::swap(m_XAxisData, other.m_XAxisData);
308 std::swap(m_XAxisUnit, other.m_XAxisUnit);
271 std::swap(m_XAxisUnit, other.m_XAxisUnit);
309 std::swap(m_ValuesData, other.m_ValuesData);
272 std::swap(m_ValuesData, other.m_ValuesData);
310 std::swap(m_ValuesUnit, other.m_ValuesUnit);
273 std::swap(m_ValuesUnit, other.m_ValuesUnit);
311
274
312 return *this;
275 return *this;
313 }
276 }
314
277
315 private:
278 private:
316 /**
279 /**
317 * Sorts data series on its x-axis data
280 * Sorts data series on its x-axis data
318 */
281 */
319 void sort() noexcept
282 void sort() noexcept
320 {
283 {
321 auto permutation = SortUtils::sortPermutation(*m_XAxisData, std::less<double>());
284 auto permutation = SortUtils::sortPermutation(*m_XAxisData, std::less<double>());
322 m_XAxisData = m_XAxisData->sort(permutation);
285 m_XAxisData = m_XAxisData->sort(permutation);
323 m_ValuesData = m_ValuesData->sort(permutation);
286 m_ValuesData = m_ValuesData->sort(permutation);
324 }
287 }
325
288
326 std::shared_ptr<ArrayData<1> > m_XAxisData;
289 std::shared_ptr<ArrayData<1> > m_XAxisData;
327 Unit m_XAxisUnit;
290 Unit m_XAxisUnit;
328 std::shared_ptr<ArrayData<Dim> > m_ValuesData;
291 std::shared_ptr<ArrayData<Dim> > m_ValuesData;
329 Unit m_ValuesUnit;
292 Unit m_ValuesUnit;
330
293
331 QReadWriteLock m_Lock;
294 QReadWriteLock m_Lock;
332 };
295 };
333
296
334 #endif // SCIQLOP_DATASERIES_H
297 #endif // SCIQLOP_DATASERIES_H
General Comments 0
You need to be logged in to leave comments. Login now