##// END OF EJS Templates
Merge branch 'feature/PurgeDataSeries' into develop
Alexandre Leroux -
r680:e899bacb01d9 merge
parent child
Show More
@@ -39,19 +39,58 struct Sort<1> {
39 }
39 }
40 };
40 };
41
41
42 template <int Dim, bool IsConst>
43 class IteratorValue;
44
45 template <int Dim, bool IsConst>
46 struct IteratorValueBuilder {
47 };
48
49 template <int Dim>
50 struct IteratorValueBuilder<Dim, true> {
51 using DataContainerIterator = DataContainer::const_iterator;
52
53 static void swap(IteratorValue<Dim, true> &o1, IteratorValue<Dim, true> &o2) {}
54 };
55
42 template <int Dim>
56 template <int Dim>
57 struct IteratorValueBuilder<Dim, false> {
58 using DataContainerIterator = DataContainer::iterator;
59
60 static void swap(IteratorValue<Dim, false> &o1, IteratorValue<Dim, false> &o2)
61 {
62 for (auto i = 0; i < o1.m_NbComponents; ++i) {
63 std::iter_swap(o1.m_It + i, o2.m_It + i);
64 }
65 }
66 };
67
68 template <int Dim, bool IsConst>
43 class IteratorValue : public ArrayDataIteratorValue::Impl {
69 class IteratorValue : public ArrayDataIteratorValue::Impl {
44 public:
70 public:
71 friend class ArrayData<Dim>;
72 friend class IteratorValueBuilder<Dim, IsConst>;
73
74 using DataContainerIterator =
75 typename IteratorValueBuilder<Dim, IsConst>::DataContainerIterator;
76
77 template <bool IC = IsConst, typename = std::enable_if_t<IC == true> >
45 explicit IteratorValue(const DataContainer &container, int nbComponents, bool begin)
78 explicit IteratorValue(const DataContainer &container, int nbComponents, bool begin)
46 : m_It{begin ? container.cbegin() : container.cend()}, m_NbComponents{nbComponents}
79 : m_It{begin ? container.cbegin() : container.cend()}, m_NbComponents{nbComponents}
47 {
80 {
48 }
81 }
49
82
83 template <bool IC = IsConst, typename = std::enable_if_t<IC == false> >
84 explicit IteratorValue(DataContainer &container, int nbComponents, bool begin)
85 : m_It{begin ? container.begin() : container.end()}, m_NbComponents{nbComponents}
86 {
87 }
88
50 IteratorValue(const IteratorValue &other) = default;
89 IteratorValue(const IteratorValue &other) = default;
51
90
52 std::unique_ptr<ArrayDataIteratorValue::Impl> clone() const override
91 std::unique_ptr<ArrayDataIteratorValue::Impl> clone() const override
53 {
92 {
54 return std::make_unique<IteratorValue<Dim> >(*this);
93 return std::make_unique<IteratorValue<Dim, IsConst> >(*this);
55 }
94 }
56
95
57 bool equals(const ArrayDataIteratorValue::Impl &other) const override try {
96 bool equals(const ArrayDataIteratorValue::Impl &other) const override try {
@@ -97,8 +136,14 public:
97 return result;
136 return result;
98 }
137 }
99
138
139 void swap(ArrayDataIteratorValue::Impl &other) override
140 {
141 auto &otherImpl = dynamic_cast<IteratorValue &>(other);
142 IteratorValueBuilder<Dim, IsConst>::swap(*this, otherImpl);
143 }
144
100 private:
145 private:
101 DataContainer::const_iterator m_It;
146 DataContainerIterator m_It;
102 int m_NbComponents;
147 int m_NbComponents;
103 };
148 };
104
149
@@ -223,18 +268,44 public:
223 // Iterators //
268 // Iterators //
224 // ///////// //
269 // ///////// //
225
270
271 ArrayDataIterator begin()
272 {
273 return ArrayDataIterator{
274 ArrayDataIteratorValue{std::make_unique<arraydata_detail::IteratorValue<Dim, false> >(
275 m_Data, m_NbComponents, true)}};
276 }
277
278 ArrayDataIterator end()
279 {
280 return ArrayDataIterator{
281 ArrayDataIteratorValue{std::make_unique<arraydata_detail::IteratorValue<Dim, false> >(
282 m_Data, m_NbComponents, false)}};
283 }
284
226 ArrayDataIterator cbegin() const
285 ArrayDataIterator cbegin() const
227 {
286 {
228 return ArrayDataIterator{ArrayDataIteratorValue{
287 return ArrayDataIterator{
229 std::make_unique<arraydata_detail::IteratorValue<Dim> >(m_Data, m_NbComponents, true)}};
288 ArrayDataIteratorValue{std::make_unique<arraydata_detail::IteratorValue<Dim, true> >(
289 m_Data, m_NbComponents, true)}};
230 }
290 }
291
231 ArrayDataIterator cend() const
292 ArrayDataIterator cend() const
232 {
293 {
233 return ArrayDataIterator{
294 return ArrayDataIterator{
234 ArrayDataIteratorValue{std::make_unique<arraydata_detail::IteratorValue<Dim> >(
295 ArrayDataIteratorValue{std::make_unique<arraydata_detail::IteratorValue<Dim, true> >(
235 m_Data, m_NbComponents, false)}};
296 m_Data, m_NbComponents, false)}};
236 }
297 }
237
298
299 void erase(ArrayDataIterator first, ArrayDataIterator last)
300 {
301 auto firstImpl = dynamic_cast<arraydata_detail::IteratorValue<Dim, false> *>(first->impl());
302 auto lastImpl = dynamic_cast<arraydata_detail::IteratorValue<Dim, false> *>(last->impl());
303
304 if (firstImpl && lastImpl) {
305 m_Data.erase(firstImpl->m_It, lastImpl->m_It);
306 }
307 }
308
238 /// Inserts at the end of the array data the values passed as a parameter. This
309 /// 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
310 /// 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
311 /// if it's ensured that the total size of the vector is consistent with the number of
@@ -27,11 +27,12 public:
27 virtual double min() const = 0;
27 virtual double min() const = 0;
28 virtual double max() const = 0;
28 virtual double max() const = 0;
29 virtual QVector<double> values() const = 0;
29 virtual QVector<double> values() const = 0;
30
31 virtual void swap(Impl &other) = 0;
30 };
32 };
31
33
32 explicit ArrayDataIteratorValue(std::unique_ptr<Impl> impl);
34 explicit ArrayDataIteratorValue(std::unique_ptr<Impl> impl);
33 ArrayDataIteratorValue(const ArrayDataIteratorValue &other);
35 ArrayDataIteratorValue(const ArrayDataIteratorValue &other);
34 ArrayDataIteratorValue(ArrayDataIteratorValue &&other) = default;
35 ArrayDataIteratorValue &operator=(ArrayDataIteratorValue other);
36 ArrayDataIteratorValue &operator=(ArrayDataIteratorValue other);
36
37
37 bool equals(const ArrayDataIteratorValue &other) const;
38 bool equals(const ArrayDataIteratorValue &other) const;
@@ -51,6 +52,13 public:
51 /// Gets all values
52 /// Gets all values
52 QVector<double> values() const;
53 QVector<double> values() const;
53
54
55 Impl *impl();
56
57 friend void swap(ArrayDataIteratorValue &lhs, ArrayDataIteratorValue &rhs)
58 {
59 std::swap(lhs.m_Impl, rhs.m_Impl);
60 }
61
54 private:
62 private:
55 std::unique_ptr<Impl> m_Impl;
63 std::unique_ptr<Impl> m_Impl;
56 };
64 };
@@ -27,20 +27,31 class DataSeries;
27
27
28 namespace dataseries_detail {
28 namespace dataseries_detail {
29
29
30 template <int Dim>
30 template <int Dim, bool IsConst>
31 class IteratorValue : public DataSeriesIteratorValue::Impl {
31 class IteratorValue : public DataSeriesIteratorValue::Impl {
32 public:
32 public:
33 friend class DataSeries<Dim>;
34
35 template <bool IC = IsConst, typename = std::enable_if_t<IC == false> >
36 explicit IteratorValue(DataSeries<Dim> &dataSeries, bool begin)
37 : m_XIt(begin ? dataSeries.xAxisData()->begin() : dataSeries.xAxisData()->end()),
38 m_ValuesIt(begin ? dataSeries.valuesData()->begin() : dataSeries.valuesData()->end())
39 {
40 }
41
42 template <bool IC = IsConst, typename = std::enable_if_t<IC == true> >
33 explicit IteratorValue(const DataSeries<Dim> &dataSeries, bool begin)
43 explicit IteratorValue(const DataSeries<Dim> &dataSeries, bool begin)
34 : m_XIt(begin ? dataSeries.xAxisData()->cbegin() : dataSeries.xAxisData()->cend()),
44 : m_XIt(begin ? dataSeries.xAxisData()->cbegin() : dataSeries.xAxisData()->cend()),
35 m_ValuesIt(begin ? dataSeries.valuesData()->cbegin()
45 m_ValuesIt(begin ? dataSeries.valuesData()->cbegin()
36 : dataSeries.valuesData()->cend())
46 : dataSeries.valuesData()->cend())
37 {
47 {
38 }
48 }
49
39 IteratorValue(const IteratorValue &other) = default;
50 IteratorValue(const IteratorValue &other) = default;
40
51
41 std::unique_ptr<DataSeriesIteratorValue::Impl> clone() const override
52 std::unique_ptr<DataSeriesIteratorValue::Impl> clone() const override
42 {
53 {
43 return std::make_unique<IteratorValue<Dim> >(*this);
54 return std::make_unique<IteratorValue<Dim, IsConst> >(*this);
44 }
55 }
45
56
46 bool equals(const DataSeriesIteratorValue::Impl &other) const override try {
57 bool equals(const DataSeriesIteratorValue::Impl &other) const override try {
@@ -70,6 +81,13 public:
70 double maxValue() const override { return m_ValuesIt->max(); }
81 double maxValue() const override { return m_ValuesIt->max(); }
71 QVector<double> values() const override { return m_ValuesIt->values(); }
82 QVector<double> values() const override { return m_ValuesIt->values(); }
72
83
84 void swap(DataSeriesIteratorValue::Impl &other) override
85 {
86 auto &otherImpl = dynamic_cast<IteratorValue &>(other);
87 m_XIt->impl()->swap(*otherImpl.m_XIt->impl());
88 m_ValuesIt->impl()->swap(*otherImpl.m_ValuesIt->impl());
89 }
90
73 private:
91 private:
74 ArrayDataIterator m_XIt;
92 ArrayDataIterator m_XIt;
75 ArrayDataIterator m_ValuesIt;
93 ArrayDataIterator m_ValuesIt;
@@ -145,20 +163,59 public:
145 dataSeries->unlock();
163 dataSeries->unlock();
146 }
164 }
147
165
166 void purge(double min, double max) override
167 {
168 if (min > max) {
169 std::swap(min, max);
170 }
171
172 lockWrite();
173
174 auto it = std::remove_if(
175 begin(), end(), [min, max](const auto &it) { return it.x() < min || it.x() > max; });
176 erase(it, end());
177
178 unlock();
179 }
180
148 // ///////// //
181 // ///////// //
149 // Iterators //
182 // Iterators //
150 // ///////// //
183 // ///////// //
151
184
185 DataSeriesIterator begin() override
186 {
187 return DataSeriesIterator{DataSeriesIteratorValue{
188 std::make_unique<dataseries_detail::IteratorValue<Dim, false> >(*this, true)}};
189 }
190
191 DataSeriesIterator end() override
192 {
193 return DataSeriesIterator{DataSeriesIteratorValue{
194 std::make_unique<dataseries_detail::IteratorValue<Dim, false> >(*this, false)}};
195 }
196
152 DataSeriesIterator cbegin() const override
197 DataSeriesIterator cbegin() const override
153 {
198 {
154 return DataSeriesIterator{DataSeriesIteratorValue{
199 return DataSeriesIterator{DataSeriesIteratorValue{
155 std::make_unique<dataseries_detail::IteratorValue<Dim> >(*this, true)}};
200 std::make_unique<dataseries_detail::IteratorValue<Dim, true> >(*this, true)}};
156 }
201 }
157
202
158 DataSeriesIterator cend() const override
203 DataSeriesIterator cend() const override
159 {
204 {
160 return DataSeriesIterator{DataSeriesIteratorValue{
205 return DataSeriesIterator{DataSeriesIteratorValue{
161 std::make_unique<dataseries_detail::IteratorValue<Dim> >(*this, false)}};
206 std::make_unique<dataseries_detail::IteratorValue<Dim, true> >(*this, false)}};
207 }
208
209 void erase(DataSeriesIterator first, DataSeriesIterator last)
210 {
211 auto firstImpl
212 = dynamic_cast<dataseries_detail::IteratorValue<Dim, false> *>(first->impl());
213 auto lastImpl = dynamic_cast<dataseries_detail::IteratorValue<Dim, false> *>(last->impl());
214
215 if (firstImpl && lastImpl) {
216 m_XAxisData->erase(firstImpl->m_XIt, lastImpl->m_XIt);
217 m_ValuesData->erase(firstImpl->m_ValuesIt, lastImpl->m_ValuesIt);
218 }
162 }
219 }
163
220
164 /// @sa IDataSeries::minXAxisData()
221 /// @sa IDataSeries::minXAxisData()
@@ -29,11 +29,12 public:
29 virtual double minValue() const = 0;
29 virtual double minValue() const = 0;
30 virtual double maxValue() const = 0;
30 virtual double maxValue() const = 0;
31 virtual QVector<double> values() const = 0;
31 virtual QVector<double> values() const = 0;
32
33 virtual void swap(Impl &other) = 0;
32 };
34 };
33
35
34 explicit DataSeriesIteratorValue(std::unique_ptr<Impl> impl);
36 explicit DataSeriesIteratorValue(std::unique_ptr<Impl> impl);
35 DataSeriesIteratorValue(const DataSeriesIteratorValue &other);
37 DataSeriesIteratorValue(const DataSeriesIteratorValue &other);
36 DataSeriesIteratorValue(DataSeriesIteratorValue &&other) = default;
37 DataSeriesIteratorValue &operator=(DataSeriesIteratorValue other);
38 DataSeriesIteratorValue &operator=(DataSeriesIteratorValue other);
38
39
39 bool equals(const DataSeriesIteratorValue &other) const;
40 bool equals(const DataSeriesIteratorValue &other) const;
@@ -55,6 +56,13 public:
55 /// Gets all values data
56 /// Gets all values data
56 QVector<double> values() const;
57 QVector<double> values() const;
57
58
59 Impl *impl();
60
61 friend void swap(DataSeriesIteratorValue &lhs, DataSeriesIteratorValue &rhs)
62 {
63 std::swap(lhs.m_Impl, rhs.m_Impl);
64 }
65
58 private:
66 private:
59 std::unique_ptr<Impl> m_Impl;
67 std::unique_ptr<Impl> m_Impl;
60 };
68 };
@@ -57,6 +57,9 public:
57 virtual Unit valuesUnit() const = 0;
57 virtual Unit valuesUnit() const = 0;
58
58
59 virtual void merge(IDataSeries *dataSeries) = 0;
59 virtual void merge(IDataSeries *dataSeries) = 0;
60 /// Removes from data series all entries whose value on the x-axis is not between min and max
61 virtual void purge(double min, double max) = 0;
62
60 /// @todo Review the name and signature of this method
63 /// @todo Review the name and signature of this method
61 virtual std::shared_ptr<IDataSeries> subDataSeries(const SqpRange &range) = 0;
64 virtual std::shared_ptr<IDataSeries> subDataSeries(const SqpRange &range) = 0;
62
65
@@ -69,6 +72,8 public:
69
72
70 virtual DataSeriesIterator cbegin() const = 0;
73 virtual DataSeriesIterator cbegin() const = 0;
71 virtual DataSeriesIterator cend() const = 0;
74 virtual DataSeriesIterator cend() const = 0;
75 virtual DataSeriesIterator begin() = 0;
76 virtual DataSeriesIterator end() = 0;
72
77
73 /// @return the iterator to the first entry of the data series whose x-axis data is greater than
78 /// @return the iterator to the first entry of the data series whose x-axis data is greater than
74 /// or equal to the value passed in parameter, or the end iterator if there is no matching value
79 /// or equal to the value passed in parameter, or the end iterator if there is no matching value
@@ -22,9 +22,7 public:
22
22
23 virtual ~SqpIterator() noexcept = default;
23 virtual ~SqpIterator() noexcept = default;
24 SqpIterator(const SqpIterator &) = default;
24 SqpIterator(const SqpIterator &) = default;
25 SqpIterator(SqpIterator &&) = default;
25 SqpIterator &operator=(SqpIterator other) { swap(m_CurrentValue, other.m_CurrentValue); }
26 SqpIterator &operator=(const SqpIterator &) = default;
27 SqpIterator &operator=(SqpIterator &&) = default;
28
26
29 SqpIterator &operator++()
27 SqpIterator &operator++()
30 {
28 {
@@ -38,8 +36,10 public:
38 return *this;
36 return *this;
39 }
37 }
40
38
41 pointer operator->() const { return &m_CurrentValue; }
39 const T *operator->() const { return &m_CurrentValue; }
42 reference operator*() const { return m_CurrentValue; }
40 const T &operator*() const { return m_CurrentValue; }
41 T *operator->() { return &m_CurrentValue; }
42 T &operator*() { return m_CurrentValue; }
43
43
44 bool operator==(const SqpIterator &other) const
44 bool operator==(const SqpIterator &other) const
45 {
45 {
@@ -57,7 +57,6 public:
57
57
58 QVector<SqpRange> provideNotInCacheRangeList(const SqpRange &range) const noexcept;
58 QVector<SqpRange> provideNotInCacheRangeList(const SqpRange &range) const noexcept;
59 QVector<SqpRange> provideInCacheRangeList(const SqpRange &range) const noexcept;
59 QVector<SqpRange> provideInCacheRangeList(const SqpRange &range) const noexcept;
60 void setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
61 void mergeDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
60 void mergeDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
62
61
63 signals:
62 signals:
@@ -12,7 +12,7 ArrayDataIteratorValue::ArrayDataIteratorValue(const ArrayDataIteratorValue &oth
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 m_Impl->swap(*other.m_Impl);
16 return *this;
16 return *this;
17 }
17 }
18
18
@@ -55,3 +55,8 QVector<double> ArrayDataIteratorValue::values() const
55 {
55 {
56 return m_Impl->values();
56 return m_Impl->values();
57 }
57 }
58
59 ArrayDataIteratorValue::Impl *ArrayDataIteratorValue::impl()
60 {
61 return m_Impl.get();
62 }
@@ -13,7 +13,7 DataSeriesIteratorValue::DataSeriesIteratorValue(const DataSeriesIteratorValue &
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 m_Impl->swap(*other.m_Impl);
17 return *this;
17 return *this;
18 }
18 }
19
19
@@ -61,3 +61,8 QVector<double> DataSeriesIteratorValue::values() const
61 {
61 {
62 return m_Impl->values();
62 return m_Impl->values();
63 }
63 }
64
65 DataSeriesIteratorValue::Impl *DataSeriesIteratorValue::impl()
66 {
67 return m_Impl.get();
68 }
@@ -24,6 +24,14 struct Variable::VariablePrivate {
24 void lockWrite() { m_Lock.lockForWrite(); }
24 void lockWrite() { m_Lock.lockForWrite(); }
25 void unlock() { m_Lock.unlock(); }
25 void unlock() { m_Lock.unlock(); }
26
26
27 void purgeDataSeries()
28 {
29 if (m_DataSeries) {
30 m_DataSeries->purge(m_CacheRange.m_TStart, m_CacheRange.m_TEnd);
31 }
32 updateRealRange();
33 }
34
27 /// Updates real range according to current variable range and data series
35 /// Updates real range according to current variable range and data series
28 void updateRealRange()
36 void updateRealRange()
29 {
37 {
@@ -94,7 +102,10 SqpRange Variable::cacheRange() const noexcept
94 void Variable::setCacheRange(const SqpRange &cacheRange) noexcept
102 void Variable::setCacheRange(const SqpRange &cacheRange) noexcept
95 {
103 {
96 impl->lockWrite();
104 impl->lockWrite();
97 impl->m_CacheRange = cacheRange;
105 if (cacheRange != impl->m_CacheRange) {
106 impl->m_CacheRange = cacheRange;
107 impl->purgeDataSeries();
108 }
98 impl->unlock();
109 impl->unlock();
99 }
110 }
100
111
@@ -103,20 +114,6 SqpRange Variable::realRange() const noexcept
103 return impl->m_RealRange;
114 return impl->m_RealRange;
104 }
115 }
105
116
106 void Variable::setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept
107 {
108 qCDebug(LOG_Variable()) << "TORM Variable::setDataSeries"
109 << QThread::currentThread()->objectName();
110 if (!dataSeries) {
111 /// @todo ALX : log
112 return;
113 }
114 impl->lockWrite();
115 impl->m_DataSeries = dataSeries->clone();
116 impl->updateRealRange();
117 impl->unlock();
118 }
119
120 void Variable::mergeDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept
117 void Variable::mergeDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept
121 {
118 {
122 qCDebug(LOG_Variable()) << "TORM Variable::mergeDataSeries"
119 qCDebug(LOG_Variable()) << "TORM Variable::mergeDataSeries"
@@ -127,7 +124,6 void Variable::mergeDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept
127 }
124 }
128
125
129 // Add or merge the data
126 // Add or merge the data
130 // Inits the data series of the variable
131 impl->lockWrite();
127 impl->lockWrite();
132 if (!impl->m_DataSeries) {
128 if (!impl->m_DataSeries) {
133 impl->m_DataSeries = dataSeries->clone();
129 impl->m_DataSeries = dataSeries->clone();
@@ -135,13 +131,8 void Variable::mergeDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept
135 else {
131 else {
136 impl->m_DataSeries->merge(dataSeries.get());
132 impl->m_DataSeries->merge(dataSeries.get());
137 }
133 }
134 impl->purgeDataSeries();
138 impl->unlock();
135 impl->unlock();
139
140 // sub the data
141 auto subData = this->dataSeries()->subDataSeries(this->cacheRange());
142 qCDebug(LOG_Variable()) << "TORM: Variable::mergeDataSeries sub" << subData->range();
143 this->setDataSeries(subData);
144 qCDebug(LOG_Variable()) << "TORM: Variable::mergeDataSeries set" << this->dataSeries()->range();
145 }
136 }
146
137
147 std::shared_ptr<IDataSeries> Variable::dataSeries() const noexcept
138 std::shared_ptr<IDataSeries> Variable::dataSeries() const noexcept
@@ -22,6 +22,20 void validateRange(DataSeriesIterator first, DataSeriesIterator last, const QVec
22 [](const auto &it, const auto &expectedVal) { return it.value() == expectedVal; }));
22 [](const auto &it, const auto &expectedVal) { return it.value() == expectedVal; }));
23 }
23 }
24
24
25 void validateRange(DataSeriesIterator first, DataSeriesIterator last, const QVector<double> &xData,
26 const QVector<QVector<double> > &valuesData)
27 {
28 QVERIFY(std::equal(first, last, xData.cbegin(), xData.cend(),
29 [](const auto &it, const auto &expectedX) { return it.x() == expectedX; }));
30 for (auto i = 0; i < valuesData.size(); ++i) {
31 auto componentData = valuesData.at(i);
32
33 QVERIFY(std::equal(
34 first, last, componentData.cbegin(), componentData.cend(),
35 [i](const auto &it, const auto &expectedVal) { return it.value(i) == expectedVal; }));
36 }
37 }
38
25 } // namespace
39 } // namespace
26
40
27 class TestDataSeries : public QObject {
41 class TestDataSeries : public QObject {
@@ -75,7 +89,42 private:
75 }
89 }
76 }
90 }
77
91
92 template <typename T>
93 void testPurgeStructure()
94 {
95 // ////////////// //
96 // Test structure //
97 // ////////////// //
98
99 // Data series to purge
100 QTest::addColumn<std::shared_ptr<T> >("dataSeries");
101 QTest::addColumn<double>("min");
102 QTest::addColumn<double>("max");
103
104 // Expected values after purge
105 QTest::addColumn<QVector<double> >("expectedXAxisData");
106 QTest::addColumn<QVector<QVector<double> > >("expectedValuesData");
107 }
108
109 template <typename T>
110 void testPurge()
111 {
112 QFETCH(std::shared_ptr<T>, dataSeries);
113 QFETCH(double, min);
114 QFETCH(double, max);
115
116 dataSeries->purge(min, max);
117
118 // Validates results
119 QFETCH(QVector<double>, expectedXAxisData);
120 QFETCH(QVector<QVector<double> >, expectedValuesData);
121
122 validateRange(dataSeries->cbegin(), dataSeries->cend(), expectedXAxisData,
123 expectedValuesData);
124 }
125
78 private slots:
126 private slots:
127
79 /// Input test data
128 /// Input test data
80 /// @sa testCtor()
129 /// @sa testCtor()
81 void testCtor_data();
130 void testCtor_data();
@@ -91,6 +140,20 private slots:
91 void testMerge();
140 void testMerge();
92
141
93 /// Input test data
142 /// Input test data
143 /// @sa testPurgeScalar()
144 void testPurgeScalar_data();
145
146 /// Tests purge of a scalar series
147 void testPurgeScalar();
148
149 /// Input test data
150 /// @sa testPurgeVector()
151 void testPurgeVector_data();
152
153 /// Tests purge of a vector series
154 void testPurgeVector();
155
156 /// Input test data
94 /// @sa testMinXAxisData()
157 /// @sa testMinXAxisData()
95 void testMinXAxisData_data();
158 void testMinXAxisData_data();
96
159
@@ -261,6 +324,62 void TestDataSeries::testMerge()
261 validateRange(dataSeries->cbegin(), dataSeries->cend(), expectedXAxisData, expectedValuesData);
324 validateRange(dataSeries->cbegin(), dataSeries->cend(), expectedXAxisData, expectedValuesData);
262 }
325 }
263
326
327 void TestDataSeries::testPurgeScalar_data()
328 {
329 testPurgeStructure<ScalarSeries>();
330
331 // ////////// //
332 // Test cases //
333 // ////////// //
334
335 QTest::newRow("purgeScalar") << createScalarSeries({1., 2., 3., 4., 5.},
336 {100., 200., 300., 400., 500.})
337 << 2. << 4. << QVector<double>{2., 3., 4.}
338 << QVector<QVector<double> >{{200., 300., 400.}};
339 QTest::newRow("purgeScalar2") << createScalarSeries({1., 2., 3., 4., 5.},
340 {100., 200., 300., 400., 500.})
341 << 0. << 2.5 << QVector<double>{1., 2.}
342 << QVector<QVector<double> >{{100., 200.}};
343 QTest::newRow("purgeScalar3") << createScalarSeries({1., 2., 3., 4., 5.},
344 {100., 200., 300., 400., 500.})
345 << 3.5 << 7. << QVector<double>{4., 5.}
346 << QVector<QVector<double> >{{400., 500.}};
347 QTest::newRow("purgeScalar4") << createScalarSeries({1., 2., 3., 4., 5.},
348 {100., 200., 300., 400., 500.})
349 << 0. << 7. << QVector<double>{1., 2., 3., 4., 5.}
350 << QVector<QVector<double> >{{100., 200., 300., 400., 500.}};
351 QTest::newRow("purgeScalar5") << createScalarSeries({1., 2., 3., 4., 5.},
352 {100., 200., 300., 400., 500.})
353 << 5.5 << 7. << QVector<double>{}
354 << QVector<QVector<double> >{{}};
355 }
356
357 void TestDataSeries::testPurgeScalar()
358 {
359 testPurge<ScalarSeries>();
360 }
361
362 void TestDataSeries::testPurgeVector_data()
363 {
364 testPurgeStructure<VectorSeries>();
365
366 // ////////// //
367 // Test cases //
368 // ////////// //
369
370 QTest::newRow("purgeVector") << createVectorSeries({1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.},
371 {11., 12., 13., 14., 15.},
372 {16., 17., 18., 19., 20.})
373 << 2. << 4. << QVector<double>{2., 3., 4.}
374 << QVector<QVector<double> >{
375 {7., 8., 9.}, {12., 13., 14.}, {17., 18., 19.}};
376 }
377
378 void TestDataSeries::testPurgeVector()
379 {
380 testPurge<VectorSeries>();
381 }
382
264 void TestDataSeries::testMinXAxisData_data()
383 void TestDataSeries::testMinXAxisData_data()
265 {
384 {
266 // ////////////// //
385 // ////////////// //
@@ -11,10 +11,14 DataSeriesMergeHelper\.h:\d+:.*IPSIS_S01.*
11
11
12 # 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
13 ArrayData\.h:\d+:.*IPSIS_S04_METHOD.*found: push_back
14 ArrayData\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (const_iterator)
14 ArrayData\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (D)
15 ArrayData\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (D)
16 ArrayData\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (IC)
15 ArrayData\.h:\d+:.*IPSIS_S04_NAMESPACE.*found: (arraydata_detail)
17 ArrayData\.h:\d+:.*IPSIS_S04_NAMESPACE.*found: (arraydata_detail)
16 ArrayData\.h:\d+:.*IPSIS_S06.*found: (D)
18 ArrayData\.h:\d+:.*IPSIS_S06.*found: (D)
17 ArrayData\.h:\d+:.*IPSIS_S06.*found: (Dim)
19 ArrayData\.h:\d+:.*IPSIS_S06.*found: (Dim)
20 ArrayData\.h:\d+:.*IPSIS_S06.*found: (IC)
21 ArrayData\.h:\d+:.*IPSIS_S06.*found: (IsConst)
18 DataSeries\.h:\d+:.*IPSIS_S04_METHOD.*found: LOG_DataSeries
22 DataSeries\.h:\d+:.*IPSIS_S04_METHOD.*found: LOG_DataSeries
19 DataSeries\.h:\d+:.*IPSIS_S04_METHOD.*found: push_back
23 DataSeries\.h:\d+:.*IPSIS_S04_METHOD.*found: push_back
20 DataSeries\.h:\d+:.*IPSIS_S04_VARIABLE.*
24 DataSeries\.h:\d+:.*IPSIS_S04_VARIABLE.*
@@ -22,6 +26,9 DataSeries\.h:\d+:.*IPSIS_S04_NAMESPACE.*found: (dataseries_detail)
22 DataSeries\.h:\d+:.*IPSIS_S05.*
26 DataSeries\.h:\d+:.*IPSIS_S05.*
23 DataSeries\.h:\d+:.*IPSIS_S06.*found: (value_type)
27 DataSeries\.h:\d+:.*IPSIS_S06.*found: (value_type)
24 DataSeries\.h:\d+:.*IPSIS_S06.*found: (DataSeriesIteratorValue)
28 DataSeries\.h:\d+:.*IPSIS_S06.*found: (DataSeriesIteratorValue)
29 DataSeries\.h:\d+:.*IPSIS_S06.*found: (Dim)
30 DataSeries\.h:\d+:.*IPSIS_S06.*found: (IC)
31 DataSeries\.h:\d+:.*IPSIS_S06.*found: (IsConst)
25
32
26 # Ignore false positive relative to iterators
33 # Ignore false positive relative to iterators
27 SqpIterator\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (forward_iterator_tag)
34 SqpIterator\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (forward_iterator_tag)
General Comments 0
You need to be logged in to leave comments. Login now