From 64ba0d56cf7e52b6e3ae22650622d5007bc2f510 2017-09-06 07:43:03 From: leroux Date: 2017-09-06 07:43:03 Subject: [PATCH] Merge pull request #261 from SCIQLOP-Initialisation develop Develop --- diff --git a/core/include/Common/SortUtils.h b/core/include/Common/SortUtils.h index 0536439..f0fda7b 100644 --- a/core/include/Common/SortUtils.h +++ b/core/include/Common/SortUtils.h @@ -77,7 +77,7 @@ struct SortUtils { for (auto i = 0, componentIndex = 0, permutationIndex = 0; i < containerSize; ++i, componentIndex = i % nbValues, permutationIndex = i / nbValues) { auto insertIndex = sortPermutation.at(permutationIndex) * nbValues + componentIndex; - sortedData.append(container.at(insertIndex)); + sortedData.push_back(container.at(insertIndex)); } return sortedData; diff --git a/core/include/Data/ArrayData.h b/core/include/Data/ArrayData.h index e14f532..a1aad29 100644 --- a/core/include/Data/ArrayData.h +++ b/core/include/Data/ArrayData.h @@ -13,7 +13,7 @@ template class ArrayData; -using DataContainer = QVector; +using DataContainer = std::vector; namespace arraydata_detail { @@ -121,13 +121,11 @@ public: std::unique_ptr advance(int offset) const override { auto result = clone(); - while (offset--) { - result->next(); - } + result->next(offset); return result; } - void next() override { std::advance(m_It, m_NbComponents); } + void next(int offset) override { std::advance(m_It, offset * m_NbComponents); } void prev() override { std::advance(m_It, -m_NbComponents); } double at(int componentIndex) const override { return *(m_It + componentIndex); } @@ -256,16 +254,7 @@ public: return; } - if (prepend) { - auto otherDataSize = other.m_Data.size(); - m_Data.insert(m_Data.begin(), otherDataSize, 0.); - for (auto i = 0; i < otherDataSize; ++i) { - m_Data.replace(i, other.m_Data.at(i)); - } - } - else { - m_Data.append(other.m_Data); - } + insert(other.cbegin(), other.cend(), prepend); } void clear() @@ -332,16 +321,16 @@ public: } } - /// Inserts at the end of the array data the values passed as a parameter. This - /// method is intended to be used in the context of generating a back insert iterator, or only - /// if it's ensured that the total size of the vector is consistent with the number of - /// components of the array data - /// @param values the values to insert - /// @sa http://en.cppreference.com/w/cpp/iterator/back_inserter - void push_back(const QVector &values) + void insert(ArrayDataIterator first, ArrayDataIterator last, bool prepend = false) { - Q_ASSERT(values.size() % m_NbComponents == 0); - m_Data.append(values); + auto firstImpl = dynamic_cast *>(first->impl()); + auto lastImpl = dynamic_cast *>(last->impl()); + + if (firstImpl && lastImpl) { + auto insertIt = prepend ? m_Data.begin() : m_Data.end(); + + m_Data.insert(insertIt, firstImpl->m_It, lastImpl->m_It); + } } /** @@ -363,9 +352,8 @@ public: * @remarks this method is only available for a unidimensional ArrayData */ template > - const QVector &cdata() const noexcept + DataContainer cdata() const noexcept { - QReadLocker locker{&m_Lock}; return m_Data; } diff --git a/core/include/Data/ArrayDataIterator.h b/core/include/Data/ArrayDataIterator.h index 040f5f1..0bca05d 100644 --- a/core/include/Data/ArrayDataIterator.h +++ b/core/include/Data/ArrayDataIterator.h @@ -23,7 +23,7 @@ public: virtual bool equals(const Impl &other) const = 0; virtual bool lowerThan(const Impl &other) const = 0; virtual std::unique_ptr advance(int offset) const = 0; - virtual void next() = 0; + virtual void next(int offset) = 0; virtual void prev() = 0; virtual double at(int componentIndex) const = 0; virtual double first() const = 0; @@ -44,7 +44,7 @@ public: ArrayDataIteratorValue advance(int offset) const; /// Advances to the next value - void next(); + void next(int offset = 1); /// Moves back to the previous value void prev(); /// Gets value of a specified component diff --git a/core/include/Data/DataSeries.h b/core/include/Data/DataSeries.h index a5a9d68..63684ea 100644 --- a/core/include/Data/DataSeries.h +++ b/core/include/Data/DataSeries.h @@ -81,16 +81,14 @@ public: std::unique_ptr advance(int offset) const override { auto result = clone(); - while (offset--) { - result->next(); - } + result->next(offset); return result; } - void next() override + void next(int offset) override { - ++m_XIt; - ++m_ValuesIt; + m_XIt->next(offset); + m_ValuesIt->next(offset); } void prev() override @@ -134,10 +132,6 @@ class SCIQLOP_CORE_EXPORT DataSeries : public IDataSeries { friend class DataSeriesMergeHelper; public: - /// Tag needed to define the push_back() method - /// @sa push_back() - using value_type = DataSeriesIteratorValue; - /// @sa IDataSeries::xAxisData() std::shared_ptr > xAxisData() override { return m_XAxisData; } const std::shared_ptr > xAxisData() const { return m_XAxisData; } @@ -155,8 +149,8 @@ public: SqpRange range() const override { - if (!m_XAxisData->cdata().isEmpty()) { - return SqpRange{m_XAxisData->cdata().first(), m_XAxisData->cdata().last()}; + if (!m_XAxisData->cdata().empty()) { + return SqpRange{m_XAxisData->cdata().front(), m_XAxisData->cdata().back()}; } return SqpRange{}; @@ -254,6 +248,17 @@ public: } } + void insert(DataSeriesIterator first, DataSeriesIterator last, bool prepend = false) + { + auto firstImpl = dynamic_cast *>(first->impl()); + auto lastImpl = dynamic_cast *>(last->impl()); + + if (firstImpl && lastImpl) { + m_XAxisData->insert(firstImpl->m_XIt, lastImpl->m_XIt, prepend); + m_ValuesData->insert(firstImpl->m_ValuesIt, lastImpl->m_ValuesIt, prepend); + } + } + /// @sa IDataSeries::minXAxisData() DataSeriesIterator minXAxisData(double minXAxisData) const override { @@ -287,7 +292,7 @@ public: begin, end, minXAxisData, [](const auto &itValue, const auto &value) { return itValue.x() < value; }); auto upperIt = std::upper_bound( - begin, end, maxXAxisData, + lowerIt, end, maxXAxisData, [](const auto &value, const auto &itValue) { return value < itValue.x(); }); return std::make_pair(lowerIt, upperIt); @@ -327,22 +332,6 @@ public: virtual void lockWrite() { m_Lock.lockForWrite(); } virtual void unlock() { m_Lock.unlock(); } - // ///// // - // Other // - // ///// // - - /// Inserts at the end of the data series the value of the iterator passed as a parameter. This - /// method is intended to be used in the context of generating a back insert iterator - /// @param iteratorValue the iterator value containing the values to insert - /// @sa http://en.cppreference.com/w/cpp/iterator/back_inserter - /// @sa merge() - /// @sa value_type - void push_back(const value_type &iteratorValue) - { - m_XAxisData->push_back(QVector{iteratorValue.x()}); - m_ValuesData->push_back(iteratorValue.values()); - } - protected: /// Protected ctor (DataSeries is abstract). The vectors must have the same size, otherwise a /// DataSeries with no values will be created. diff --git a/core/include/Data/DataSeriesIterator.h b/core/include/Data/DataSeriesIterator.h index ae0f7fa..a6b1f05 100644 --- a/core/include/Data/DataSeriesIterator.h +++ b/core/include/Data/DataSeriesIterator.h @@ -24,7 +24,7 @@ public: virtual bool equals(const Impl &other) const = 0; virtual bool lowerThan(const Impl &other) const = 0; virtual std::unique_ptr advance(int offset) const = 0; - virtual void next() = 0; + virtual void next(int offset) = 0; virtual void prev() = 0; virtual double x() const = 0; virtual double value() const = 0; @@ -46,7 +46,7 @@ public: DataSeriesIteratorValue advance(int offset) const; /// Advances to the next value - void next(); + void next(int offset = 1); /// Moves back to the previous value void prev(); /// Gets x-axis data diff --git a/core/include/Data/DataSeriesMergeHelper.h b/core/include/Data/DataSeriesMergeHelper.h index 0f45a02..90d7c26 100644 --- a/core/include/Data/DataSeriesMergeHelper.h +++ b/core/include/Data/DataSeriesMergeHelper.h @@ -27,45 +27,6 @@ MergeScope scope(FEnd end) return MergeScope{end}; } -/** - * Enum used to position a data series relative to another during a merge operation - */ -enum class MergePosition { LOWER_THAN, GREATER_THAN, EQUAL, OVERLAP }; - -/** - * Computes the position of the first data series relative to the second data series - * @param lhs the first data series - * @param rhs the second data series - * @return the merge position computed - * @remarks the data series must not be empty - */ -template -MergePosition mergePosition(DataSeries &lhs, DataSeries &rhs) -{ - Q_ASSERT(!lhs.isEmpty() && !rhs.isEmpty()); - - // Case lhs < rhs - auto lhsLast = --lhs.cend(); - auto rhsFirst = rhs.cbegin(); - if (lhsLast->x() < rhsFirst->x()) { - return MergePosition::LOWER_THAN; - } - - // Case lhs > rhs - auto lhsFirst = lhs.cbegin(); - auto rhsLast = --rhs.cend(); - if (lhsFirst->x() > rhsLast->x()) { - return MergePosition::GREATER_THAN; - } - - // Other cases - auto equal = std::equal(lhs.cbegin(), lhs.cend(), rhs.cbegin(), rhs.cend(), - [](const auto &it1, const auto &it2) { - return it1.x() == it2.x() && it1.values() == it2.values(); - }); - return equal ? MergePosition::EQUAL : MergePosition::OVERLAP; -} - } // namespace detail @@ -92,40 +53,30 @@ struct DataSeriesMergeHelper { return; } - // Gets the position of the source in relation to the destination - auto sourcePosition = detail::mergePosition(source, dest); + auto destMin = dest.cbegin()->x(); + auto destMax = (--dest.cend())->x(); + + auto sourceBegin = source.cbegin(); + auto sourceEnd = source.cend(); + auto sourceMin = sourceBegin->x(); + auto sourceMax = (--source.cend())->x(); - switch (sourcePosition) { - case detail::MergePosition::LOWER_THAN: - case detail::MergePosition::GREATER_THAN: { - auto prepend = sourcePosition == detail::MergePosition::LOWER_THAN; - dest.m_XAxisData->add(*source.m_XAxisData, prepend); - dest.m_ValuesData->add(*source.m_ValuesData, prepend); - break; - } - case detail::MergePosition::EQUAL: - // the data series equal each other : no merge made - break; - case detail::MergePosition::OVERLAP: { - // the two data series overlap : merge is made - auto temp = dest.clone(); - if (auto tempSeries = dynamic_cast *>(temp.get())) { - // Makes the merge : - // - Data are sorted by x-axis values - // - If two entries are in the source range and the other range, only one entry - // is retained as result - // - The results are stored directly in the data series - dest.clear(); - std::set_union( - tempSeries->cbegin(), tempSeries->cend(), source.cbegin(), source.cend(), - std::back_inserter(dest), - [](const auto &it1, const auto &it2) { return it1.x() < it2.x(); }); - } - break; - } - default: - Q_ASSERT(false); + // Case : source bounds are inside dest bounds -> no merge is made + if (sourceMin >= destMin && sourceMax <= destMax) { + return; } + + // Default case : + // - prepend to dest the values of source that are lower than min value of dest + // - append to dest the values of source that are greater than max value of dest + auto lowerIt + = std::lower_bound(sourceBegin, sourceEnd, destMin, + [](const auto &it, const auto &val) { return it.x() < val; }); + auto upperIt + = std::upper_bound(lowerIt, sourceEnd, destMax, + [](const auto &val, const auto &it) { return val < it.x(); }); + dest.insert(sourceBegin, lowerIt, true); + dest.insert(upperIt, sourceEnd); } }; diff --git a/core/include/Data/ScalarSeries.h b/core/include/Data/ScalarSeries.h index 1a745e5..82e4ec7 100644 --- a/core/include/Data/ScalarSeries.h +++ b/core/include/Data/ScalarSeries.h @@ -16,7 +16,7 @@ public: * @param xAxisData x-axis data * @param valuesData values data */ - explicit ScalarSeries(QVector xAxisData, QVector valuesData, + explicit ScalarSeries(std::vector xAxisData, std::vector valuesData, const Unit &xAxisUnit, const Unit &valuesUnit); std::unique_ptr clone() const override; diff --git a/core/include/Data/SqpIterator.h b/core/include/Data/SqpIterator.h index dcb0203..aae9315 100644 --- a/core/include/Data/SqpIterator.h +++ b/core/include/Data/SqpIterator.h @@ -52,9 +52,7 @@ public: SqpIterator &operator+=(int offset) { if (offset >= 0) { - while (offset--) { - m_CurrentValue.next(); - } + m_CurrentValue.next(offset); } else { while (offset++) { diff --git a/core/include/Data/VectorSeries.h b/core/include/Data/VectorSeries.h index 99d49cd..c00ed8b 100644 --- a/core/include/Data/VectorSeries.h +++ b/core/include/Data/VectorSeries.h @@ -18,12 +18,12 @@ public: * @param yvaluesData y-values data * @param zvaluesData z-values data */ - explicit VectorSeries(QVector xAxisData, QVector xValuesData, - QVector yValuesData, QVector zValuesData, + explicit VectorSeries(std::vector xAxisData, std::vector xValuesData, + std::vector yValuesData, std::vector zValuesData, const Unit &xAxisUnit, const Unit &valuesUnit); /// Default Ctor - explicit VectorSeries(QVector xAxisData, QVector valuesData, + explicit VectorSeries(std::vector xAxisData, std::vector valuesData, const Unit &xAxisUnit, const Unit &valuesUnit); std::unique_ptr clone() const; diff --git a/core/src/Data/ArrayDataIterator.cpp b/core/src/Data/ArrayDataIterator.cpp index 77734f2..70b47c2 100644 --- a/core/src/Data/ArrayDataIterator.cpp +++ b/core/src/Data/ArrayDataIterator.cpp @@ -36,9 +36,9 @@ ArrayDataIteratorValue ArrayDataIteratorValue::advance(int offset) const return ArrayDataIteratorValue{m_Impl->advance(offset)}; } -void ArrayDataIteratorValue::next() +void ArrayDataIteratorValue::next(int offset) { - m_Impl->next(); + m_Impl->next(offset); } void ArrayDataIteratorValue::prev() diff --git a/core/src/Data/DataSeriesIterator.cpp b/core/src/Data/DataSeriesIterator.cpp index 06a300b..a02ca2d 100644 --- a/core/src/Data/DataSeriesIterator.cpp +++ b/core/src/Data/DataSeriesIterator.cpp @@ -38,9 +38,9 @@ DataSeriesIteratorValue DataSeriesIteratorValue::advance(int offset) const return DataSeriesIteratorValue{m_Impl->advance(offset)}; } -void DataSeriesIteratorValue::next() +void DataSeriesIteratorValue::next(int offset) { - m_Impl->next(); + m_Impl->next(offset); } void DataSeriesIteratorValue::prev() diff --git a/core/src/Data/ScalarSeries.cpp b/core/src/Data/ScalarSeries.cpp index 49bec2e..4dd44f5 100644 --- a/core/src/Data/ScalarSeries.cpp +++ b/core/src/Data/ScalarSeries.cpp @@ -1,6 +1,6 @@ #include -ScalarSeries::ScalarSeries(QVector xAxisData, QVector valuesData, +ScalarSeries::ScalarSeries(std::vector xAxisData, std::vector valuesData, const Unit &xAxisUnit, const Unit &valuesUnit) : DataSeries{std::make_shared >(std::move(xAxisData)), xAxisUnit, std::make_shared >(std::move(valuesData)), valuesUnit} @@ -14,18 +14,18 @@ std::unique_ptr ScalarSeries::clone() const std::shared_ptr ScalarSeries::subDataSeries(const SqpRange &range) { - auto subXAxisData = QVector(); - auto subValuesData = QVector(); + auto subXAxisData = std::vector(); + auto subValuesData = std::vector(); this->lockRead(); { auto bounds = xAxisRange(range.m_TStart, range.m_TEnd); for (auto it = bounds.first; it != bounds.second; ++it) { - subXAxisData.append(it->x()); - subValuesData.append(it->value()); + subXAxisData.push_back(it->x()); + subValuesData.push_back(it->value()); } } this->unlock(); - return std::make_shared(subXAxisData, subValuesData, this->xAxisUnit(), - this->valuesUnit()); + return std::make_shared(std::move(subXAxisData), std::move(subValuesData), + this->xAxisUnit(), this->valuesUnit()); } diff --git a/core/src/Data/VectorSeries.cpp b/core/src/Data/VectorSeries.cpp index b7c9bf7..879d689 100644 --- a/core/src/Data/VectorSeries.cpp +++ b/core/src/Data/VectorSeries.cpp @@ -19,18 +19,22 @@ namespace { * @remarks the three components are consumed * @sa ArrayData */ -QVector flatten(QVector xValues, QVector yValues, QVector zValues) +std::vector flatten(std::vector xValues, std::vector yValues, + std::vector zValues) { if (xValues.size() != yValues.size() || xValues.size() != zValues.size()) { /// @todo ALX : log return {}; } - auto result = QVector{}; + auto result = std::vector(); result.reserve(xValues.size() * 3); - while (!xValues.isEmpty()) { - result.append({xValues.takeFirst(), yValues.takeFirst(), zValues.takeFirst()}); + while (!xValues.empty()) { + result.insert(result.cend(), {xValues.front(), yValues.front(), zValues.front()}); + xValues.erase(xValues.begin()); + yValues.erase(yValues.begin()); + zValues.erase(zValues.begin()); } return result; @@ -38,8 +42,8 @@ QVector flatten(QVector xValues, QVector yValues, QVecto } // namespace -VectorSeries::VectorSeries(QVector xAxisData, QVector xValuesData, - QVector yValuesData, QVector zValuesData, +VectorSeries::VectorSeries(std::vector xAxisData, std::vector xValuesData, + std::vector yValuesData, std::vector zValuesData, const Unit &xAxisUnit, const Unit &valuesUnit) : VectorSeries{std::move(xAxisData), flatten(std::move(xValuesData), std::move(yValuesData), std::move(zValuesData)), @@ -47,7 +51,7 @@ VectorSeries::VectorSeries(QVector xAxisData, QVector xValuesDat { } -VectorSeries::VectorSeries(QVector xAxisData, QVector valuesData, +VectorSeries::VectorSeries(std::vector xAxisData, std::vector valuesData, const Unit &xAxisUnit, const Unit &valuesUnit) : DataSeries{std::make_shared >(std::move(xAxisData)), xAxisUnit, std::make_shared >(std::move(valuesData), 3), valuesUnit} @@ -61,23 +65,24 @@ std::unique_ptr VectorSeries::clone() const std::shared_ptr VectorSeries::subDataSeries(const SqpRange &range) { - auto subXAxisData = QVector(); - auto subXValuesData = QVector(); - auto subYValuesData = QVector(); - auto subZValuesData = QVector(); + auto subXAxisData = std::vector(); + auto subXValuesData = std::vector(); + auto subYValuesData = std::vector(); + auto subZValuesData = std::vector(); this->lockRead(); { auto bounds = xAxisRange(range.m_TStart, range.m_TEnd); for (auto it = bounds.first; it != bounds.second; ++it) { - subXAxisData.append(it->x()); - subXValuesData.append(it->value(0)); - subYValuesData.append(it->value(1)); - subZValuesData.append(it->value(2)); + subXAxisData.push_back(it->x()); + subXValuesData.push_back(it->value(0)); + subYValuesData.push_back(it->value(1)); + subZValuesData.push_back(it->value(2)); } } this->unlock(); - return std::make_shared(subXAxisData, subXValuesData, subYValuesData, - subZValuesData, this->xAxisUnit(), this->valuesUnit()); + return std::make_shared(std::move(subXAxisData), std::move(subXValuesData), + std::move(subYValuesData), std::move(subZValuesData), + this->xAxisUnit(), this->valuesUnit()); } diff --git a/core/tests/Data/TestDataSeries.cpp b/core/tests/Data/TestDataSeries.cpp index 0a9fa4c..3551e87 100644 --- a/core/tests/Data/TestDataSeries.cpp +++ b/core/tests/Data/TestDataSeries.cpp @@ -12,8 +12,10 @@ Q_DECLARE_METATYPE(std::shared_ptr) namespace { -void validateRange(DataSeriesIterator first, DataSeriesIterator last, const QVector &xData, - const QVector &valuesData) +using DataContainer = std::vector; + +void validateRange(DataSeriesIterator first, DataSeriesIterator last, const DataContainer &xData, + const DataContainer &valuesData) { QVERIFY(std::equal(first, last, xData.cbegin(), xData.cend(), [](const auto &it, const auto &expectedX) { return it.x() == expectedX; })); @@ -22,8 +24,8 @@ void validateRange(DataSeriesIterator first, DataSeriesIterator last, const QVec [](const auto &it, const auto &expectedVal) { return it.value() == expectedVal; })); } -void validateRange(DataSeriesIterator first, DataSeriesIterator last, const QVector &xData, - const QVector > &valuesData) +void validateRange(DataSeriesIterator first, DataSeriesIterator last, const DataContainer &xData, + const std::vector &valuesData) { QVERIFY(std::equal(first, last, xData.cbegin(), xData.cend(), [](const auto &it, const auto &expectedX) { return it.x() == expectedX; })); @@ -102,8 +104,8 @@ private: QTest::addColumn("max"); // Expected values after purge - QTest::addColumn >("expectedXAxisData"); - QTest::addColumn > >("expectedValuesData"); + QTest::addColumn("expectedXAxisData"); + QTest::addColumn >("expectedValuesData"); } template @@ -116,8 +118,8 @@ private: dataSeries->purge(min, max); // Validates results - QFETCH(QVector, expectedXAxisData); - QFETCH(QVector >, expectedValuesData); + QFETCH(DataContainer, expectedXAxisData); + QFETCH(std::vector, expectedValuesData); validateRange(dataSeries->cbegin(), dataSeries->cend(), expectedXAxisData, expectedValuesData); @@ -196,67 +198,65 @@ void TestDataSeries::testCtor_data() // ////////////// // // x-axis data - QTest::addColumn >("xAxisData"); + QTest::addColumn("xAxisData"); // values data - QTest::addColumn >("valuesData"); + QTest::addColumn("valuesData"); // expected x-axis data - QTest::addColumn >("expectedXAxisData"); + QTest::addColumn("expectedXAxisData"); // expected values data - QTest::addColumn >("expectedValuesData"); + QTest::addColumn("expectedValuesData"); // ////////// // // Test cases // // ////////// // QTest::newRow("invalidData (different sizes of vectors)") - << QVector{1., 2., 3., 4., 5.} << QVector{100., 200., 300.} - << QVector{} << QVector{}; + << DataContainer{1., 2., 3., 4., 5.} << DataContainer{100., 200., 300.} << DataContainer{} + << DataContainer{}; - QTest::newRow("sortedData") << QVector{1., 2., 3., 4., 5.} - << QVector{100., 200., 300., 400., 500.} - << QVector{1., 2., 3., 4., 5.} - << QVector{100., 200., 300., 400., 500.}; + QTest::newRow("sortedData") << DataContainer{1., 2., 3., 4., 5.} + << DataContainer{100., 200., 300., 400., 500.} + << DataContainer{1., 2., 3., 4., 5.} + << DataContainer{100., 200., 300., 400., 500.}; - QTest::newRow("unsortedData") << QVector{5., 4., 3., 2., 1.} - << QVector{100., 200., 300., 400., 500.} - << QVector{1., 2., 3., 4., 5.} - << QVector{500., 400., 300., 200., 100.}; + QTest::newRow("unsortedData") << DataContainer{5., 4., 3., 2., 1.} + << DataContainer{100., 200., 300., 400., 500.} + << DataContainer{1., 2., 3., 4., 5.} + << DataContainer{500., 400., 300., 200., 100.}; QTest::newRow("unsortedData2") - << QVector{1., 4., 3., 5., 2.} << QVector{100., 200., 300., 400., 500.} - << QVector{1., 2., 3., 4., 5.} << QVector{100., 500., 300., 200., 400.}; + << DataContainer{1., 4., 3., 5., 2.} << DataContainer{100., 200., 300., 400., 500.} + << DataContainer{1., 2., 3., 4., 5.} << DataContainer{100., 500., 300., 200., 400.}; } void TestDataSeries::testCtor() { // Creates series - QFETCH(QVector, xAxisData); - QFETCH(QVector, valuesData); + QFETCH(DataContainer, xAxisData); + QFETCH(DataContainer, valuesData); auto series = std::make_shared(std::move(xAxisData), std::move(valuesData), Unit{}, Unit{}); // Validates results : we check that the data series is sorted on its x-axis data - QFETCH(QVector, expectedXAxisData); - QFETCH(QVector, expectedValuesData); + QFETCH(DataContainer, expectedXAxisData); + QFETCH(DataContainer, expectedValuesData); validateRange(series->cbegin(), series->cend(), expectedXAxisData, expectedValuesData); } namespace { -std::shared_ptr createScalarSeries(QVector xAxisData, - QVector valuesData) +std::shared_ptr createScalarSeries(DataContainer xAxisData, DataContainer valuesData) { return std::make_shared(std::move(xAxisData), std::move(valuesData), Unit{}, Unit{}); } -std::shared_ptr createVectorSeries(QVector xAxisData, - QVector xValuesData, - QVector yValuesData, - QVector zValuesData) +std::shared_ptr createVectorSeries(DataContainer xAxisData, DataContainer xValuesData, + DataContainer yValuesData, + DataContainer zValuesData) { return std::make_shared(std::move(xAxisData), std::move(xValuesData), std::move(yValuesData), std::move(zValuesData), Unit{}, @@ -276,8 +276,8 @@ void TestDataSeries::testMerge_data() QTest::addColumn >("dataSeries2"); // Expected values in the first data series after merge - QTest::addColumn >("expectedXAxisData"); - QTest::addColumn >("expectedValuesData"); + QTest::addColumn("expectedXAxisData"); + QTest::addColumn("expectedValuesData"); // ////////// // // Test cases // @@ -286,26 +286,25 @@ void TestDataSeries::testMerge_data() QTest::newRow("sortedMerge") << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) << createScalarSeries({6., 7., 8., 9., 10.}, {600., 700., 800., 900., 1000.}) - << QVector{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.} - << QVector{100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.}; + << DataContainer{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.} + << DataContainer{100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.}; QTest::newRow("unsortedMerge") << createScalarSeries({6., 7., 8., 9., 10.}, {600., 700., 800., 900., 1000.}) << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) - << QVector{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.} - << QVector{100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.}; + << DataContainer{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.} + << DataContainer{100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.}; - QTest::newRow("unsortedMerge2") - << createScalarSeries({1., 2., 8., 9., 10}, {100., 200., 300., 400., 500.}) - << createScalarSeries({3., 4., 5., 6., 7.}, {600., 700., 800., 900., 1000.}) - << QVector{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.} - << QVector{100., 200., 600., 700., 800., 900., 1000., 300., 400., 500.}; + QTest::newRow("unsortedMerge2 (merge not made because source is in the bounds of dest)") + << createScalarSeries({1., 2., 8., 9., 10}, {100., 200., 800., 900., 1000.}) + << createScalarSeries({3., 4., 5., 6., 7.}, {300., 400., 500., 600., 700.}) + << DataContainer{1., 2., 8., 9., 10.} << DataContainer{100., 200., 800., 900., 1000.}; QTest::newRow("unsortedMerge3") - << createScalarSeries({3., 5., 8., 7., 2}, {100., 200., 300., 400., 500.}) - << createScalarSeries({6., 4., 9., 10., 1.}, {600., 700., 800., 900., 1000.}) - << QVector{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.} - << QVector{1000., 500., 100., 700., 200., 600., 400., 300., 800., 900.}; + << createScalarSeries({3., 4., 5., 7., 8}, {300., 400., 500., 700., 800.}) + << createScalarSeries({1., 2., 3., 7., 10.}, {100., 200., 333., 777., 1000.}) + << DataContainer{1., 2., 3., 4., 5., 7., 8., 10.} + << DataContainer{100., 200., 300., 400., 500., 700., 800., 1000.}; } void TestDataSeries::testMerge() @@ -318,8 +317,8 @@ void TestDataSeries::testMerge() // Validates results : we check that the merge is valid and the data series is sorted on its // x-axis data - QFETCH(QVector, expectedXAxisData); - QFETCH(QVector, expectedValuesData); + QFETCH(DataContainer, expectedXAxisData); + QFETCH(DataContainer, expectedValuesData); validateRange(dataSeries->cbegin(), dataSeries->cend(), expectedXAxisData, expectedValuesData); } @@ -334,24 +333,23 @@ void TestDataSeries::testPurgeScalar_data() QTest::newRow("purgeScalar") << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) - << 2. << 4. << QVector{2., 3., 4.} - << QVector >{{200., 300., 400.}}; + << 2. << 4. << DataContainer{2., 3., 4.} + << std::vector{{200., 300., 400.}}; QTest::newRow("purgeScalar2") << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) - << 0. << 2.5 << QVector{1., 2.} - << QVector >{{100., 200.}}; + << 0. << 2.5 << DataContainer{1., 2.} + << std::vector{{100., 200.}}; QTest::newRow("purgeScalar3") << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) - << 3.5 << 7. << QVector{4., 5.} - << QVector >{{400., 500.}}; + << 3.5 << 7. << DataContainer{4., 5.} + << std::vector{{400., 500.}}; QTest::newRow("purgeScalar4") << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) - << 0. << 7. << QVector{1., 2., 3., 4., 5.} - << QVector >{{100., 200., 300., 400., 500.}}; + << 0. << 7. << DataContainer{1., 2., 3., 4., 5.} + << std::vector{{100., 200., 300., 400., 500.}}; QTest::newRow("purgeScalar5") << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) - << 5.5 << 7. << QVector{} - << QVector >{{}}; + << 5.5 << 7. << DataContainer{} << std::vector{{}}; } void TestDataSeries::testPurgeScalar() @@ -370,8 +368,8 @@ void TestDataSeries::testPurgeVector_data() QTest::newRow("purgeVector") << createVectorSeries({1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.}, {11., 12., 13., 14., 15.}, {16., 17., 18., 19., 20.}) - << 2. << 4. << QVector{2., 3., 4.} - << QVector >{ + << 2. << 4. << DataContainer{2., 3., 4.} + << std::vector{ {7., 8., 9.}, {12., 13., 14.}, {17., 18., 19.}}; } @@ -512,8 +510,8 @@ void TestDataSeries::testXAxisRange_data() QTest::addColumn("max"); // Expected values - QTest::addColumn >("expectedXAxisData"); - QTest::addColumn >("expectedValuesData"); + QTest::addColumn("expectedXAxisData"); + QTest::addColumn("expectedValuesData"); // ////////// // // Test cases // @@ -521,32 +519,32 @@ void TestDataSeries::testXAxisRange_data() QTest::newRow("xAxisRange1") << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) - << -1. << 3.2 << QVector{1., 2., 3.} - << QVector{100., 200., 300.}; + << -1. << 3.2 << DataContainer{1., 2., 3.} + << DataContainer{100., 200., 300.}; QTest::newRow("xAxisRange2") << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) - << 1. << 4. << QVector{1., 2., 3., 4.} - << QVector{100., 200., 300., 400.}; + << 1. << 4. << DataContainer{1., 2., 3., 4.} + << DataContainer{100., 200., 300., 400.}; QTest::newRow("xAxisRange3") << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) - << 1. << 3.9 << QVector{1., 2., 3.} - << QVector{100., 200., 300.}; + << 1. << 3.9 << DataContainer{1., 2., 3.} + << DataContainer{100., 200., 300.}; QTest::newRow("xAxisRange4") << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) - << 0. << 0.9 << QVector{} << QVector{}; + << 0. << 0.9 << DataContainer{} << DataContainer{}; QTest::newRow("xAxisRange5") << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) - << 0. << 1. << QVector{1.} << QVector{100.}; + << 0. << 1. << DataContainer{1.} << DataContainer{100.}; QTest::newRow("xAxisRange6") << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) - << 2.1 << 6. << QVector{3., 4., 5.} - << QVector{300., 400., 500.}; + << 2.1 << 6. << DataContainer{3., 4., 5.} + << DataContainer{300., 400., 500.}; QTest::newRow("xAxisRange7") << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) - << 6. << 9. << QVector{} << QVector{}; + << 6. << 9. << DataContainer{} << DataContainer{}; QTest::newRow("xAxisRange8") << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) - << 5. << 9. << QVector{5.} << QVector{500.}; + << 5. << 9. << DataContainer{5.} << DataContainer{500.}; } void TestDataSeries::testXAxisRange() @@ -555,8 +553,8 @@ void TestDataSeries::testXAxisRange() QFETCH(double, min); QFETCH(double, max); - QFETCH(QVector, expectedXAxisData); - QFETCH(QVector, expectedValuesData); + QFETCH(DataContainer, expectedXAxisData); + QFETCH(DataContainer, expectedValuesData); auto bounds = dataSeries->xAxisRange(min, max); validateRange(bounds.first, bounds.second, expectedXAxisData, expectedValuesData); diff --git a/core/tests/Data/TestOneDimArrayData.cpp b/core/tests/Data/TestOneDimArrayData.cpp index f491a2e..1cbdcb8 100644 --- a/core/tests/Data/TestOneDimArrayData.cpp +++ b/core/tests/Data/TestOneDimArrayData.cpp @@ -4,7 +4,9 @@ namespace { -void verifyArrayData(const ArrayData<1> &arrayData, const QVector &expectedData) +using DataContainer = std::vector; + +void verifyArrayData(const ArrayData<1> &arrayData, const DataContainer &expectedData) { QVERIFY(std::equal( arrayData.cbegin(), arrayData.cend(), expectedData.cbegin(), expectedData.cend(), @@ -44,18 +46,18 @@ private slots: void TestOneDimArrayData::testData_data() { // Test structure - QTest::addColumn >("inputData"); // array's data input - QTest::addColumn >("expectedData"); // expected data + QTest::addColumn("inputData"); // array's data input + QTest::addColumn("expectedData"); // expected data // Test cases - QTest::newRow("data1") << QVector{1., 2., 3., 4., 5.} - << QVector{1., 2., 3., 4., 5.}; + QTest::newRow("data1") << DataContainer{1., 2., 3., 4., 5.} + << DataContainer{1., 2., 3., 4., 5.}; } void TestOneDimArrayData::testData() { - QFETCH(QVector, inputData); - QFETCH(QVector, expectedData); + QFETCH(DataContainer, inputData); + QFETCH(DataContainer, expectedData); ArrayData<1> arrayData{inputData}; verifyArrayData(arrayData, expectedData); @@ -64,26 +66,24 @@ void TestOneDimArrayData::testData() void TestOneDimArrayData::testAdd_data() { // Test structure - QTest::addColumn >("inputData"); // array's data input - QTest::addColumn >("otherData"); // array data's input to merge with - QTest::addColumn("prepend"); // prepend or append merge - QTest::addColumn >("expectedData"); // expected data after merge + QTest::addColumn("inputData"); // array's data input + QTest::addColumn("otherData"); // array data's input to merge with + QTest::addColumn("prepend"); // prepend or append merge + QTest::addColumn("expectedData"); // expected data after merge // Test cases - QTest::newRow("appendMerge") << QVector{1., 2., 3., 4., 5.} - << QVector{6., 7., 8.} << false - << QVector{1., 2., 3., 4., 5., 6., 7., 8.}; - QTest::newRow("prependMerge") << QVector{1., 2., 3., 4., 5.} - << QVector{6., 7., 8.} << true - << QVector{6., 7., 8., 1., 2., 3., 4., 5.}; + QTest::newRow("appendMerge") << DataContainer{1., 2., 3., 4., 5.} << DataContainer{6., 7., 8.} + << false << DataContainer{1., 2., 3., 4., 5., 6., 7., 8.}; + QTest::newRow("prependMerge") << DataContainer{1., 2., 3., 4., 5.} << DataContainer{6., 7., 8.} + << true << DataContainer{6., 7., 8., 1., 2., 3., 4., 5.}; } void TestOneDimArrayData::testAdd() { - QFETCH(QVector, inputData); - QFETCH(QVector, otherData); + QFETCH(DataContainer, inputData); + QFETCH(DataContainer, otherData); QFETCH(bool, prepend); - QFETCH(QVector, expectedData); + QFETCH(DataContainer, expectedData); ArrayData<1> arrayData{inputData}; ArrayData<1> other{otherData}; @@ -95,18 +95,18 @@ void TestOneDimArrayData::testAdd() void TestOneDimArrayData::testAt_data() { // Test structure - QTest::addColumn >("inputData"); // array data's input - QTest::addColumn("index"); // index to retrieve data - QTest::addColumn("expectedData"); // expected data at index + QTest::addColumn("inputData"); // array data's input + QTest::addColumn("index"); // index to retrieve data + QTest::addColumn("expectedData"); // expected data at index // Test cases - QTest::newRow("data1") << QVector{1., 2., 3., 4., 5.} << 0 << 1.; - QTest::newRow("data2") << QVector{1., 2., 3., 4., 5.} << 3 << 4.; + QTest::newRow("data1") << DataContainer{1., 2., 3., 4., 5.} << 0 << 1.; + QTest::newRow("data2") << DataContainer{1., 2., 3., 4., 5.} << 3 << 4.; } void TestOneDimArrayData::testAt() { - QFETCH(QVector, inputData); + QFETCH(DataContainer, inputData); QFETCH(int, index); QFETCH(double, expectedData); @@ -117,34 +117,34 @@ void TestOneDimArrayData::testAt() void TestOneDimArrayData::testClear_data() { // Test structure - QTest::addColumn >("inputData"); // array data's input + QTest::addColumn("inputData"); // array data's input // Test cases - QTest::newRow("data1") << QVector{1., 2., 3., 4., 5.}; + QTest::newRow("data1") << DataContainer{1., 2., 3., 4., 5.}; } void TestOneDimArrayData::testClear() { - QFETCH(QVector, inputData); + QFETCH(DataContainer, inputData); ArrayData<1> arrayData{inputData}; arrayData.clear(); - verifyArrayData(arrayData, QVector{}); + verifyArrayData(arrayData, DataContainer{}); } void TestOneDimArrayData::testSize_data() { // Test structure - QTest::addColumn >("inputData"); // array data's input - QTest::addColumn("expectedSize"); // expected array data size + QTest::addColumn("inputData"); // array data's input + QTest::addColumn("expectedSize"); // expected array data size // Test cases - QTest::newRow("data1") << QVector{1., 2., 3., 4., 5.} << 5; + QTest::newRow("data1") << DataContainer{1., 2., 3., 4., 5.} << 5; } void TestOneDimArrayData::testSize() { - QFETCH(QVector, inputData); + QFETCH(DataContainer, inputData); QFETCH(int, expectedSize); ArrayData<1> arrayData{inputData}; @@ -154,22 +154,22 @@ void TestOneDimArrayData::testSize() void TestOneDimArrayData::testSort_data() { // Test structure - QTest::addColumn >("inputData"); // array data's input + QTest::addColumn("inputData"); // array data's input QTest::addColumn >("sortPermutation"); // permutation used to sort data - QTest::addColumn >("expectedData"); // expected data after sorting + QTest::addColumn("expectedData"); // expected data after sorting // Test cases - QTest::newRow("data1") << QVector{1., 2., 3., 4., 5.} << std::vector{0, 2, 3, 1, 4} - << QVector{1., 3., 4., 2., 5.}; - QTest::newRow("data2") << QVector{1., 2., 3., 4., 5.} << std::vector{4, 1, 2, 3, 0} - << QVector{5., 2., 3., 4., 1.}; + QTest::newRow("data1") << DataContainer{1., 2., 3., 4., 5.} << std::vector{0, 2, 3, 1, 4} + << DataContainer{1., 3., 4., 2., 5.}; + QTest::newRow("data2") << DataContainer{1., 2., 3., 4., 5.} << std::vector{4, 1, 2, 3, 0} + << DataContainer{5., 2., 3., 4., 1.}; } void TestOneDimArrayData::testSort() { - QFETCH(QVector, inputData); + QFETCH(DataContainer, inputData); QFETCH(std::vector, sortPermutation); - QFETCH(QVector, expectedData); + QFETCH(DataContainer, expectedData); ArrayData<1> arrayData{inputData}; auto sortedArrayData = arrayData.sort(sortPermutation); diff --git a/core/tests/Data/TestTwoDimArrayData.cpp b/core/tests/Data/TestTwoDimArrayData.cpp index f884148..d644a47 100644 --- a/core/tests/Data/TestTwoDimArrayData.cpp +++ b/core/tests/Data/TestTwoDimArrayData.cpp @@ -2,31 +2,32 @@ #include #include -using Container = QVector >; -using InputData = QPair, int>; +using DataContainer = std::vector; +using Container = std::vector; +using InputData = QPair; namespace { InputData flatten(const Container &container) { - if (container.isEmpty()) { + if (container.empty()) { return {}; } // We assume here that each component of the container have the same size auto containerSize = container.size(); - auto componentSize = container.first().size(); + auto componentSize = container.front().size(); - auto result = QVector{}; + auto result = DataContainer{}; result.reserve(componentSize * containerSize); for (auto i = 0; i < componentSize; ++i) { for (auto j = 0; j < containerSize; ++j) { - result.append(container.at(j).at(i)); + result.push_back(container.at(j).at(i)); } } - return {result, containerSize}; + return {result, static_cast(containerSize)}; } void verifyArrayData(const ArrayData<2> &arrayData, const Container &expectedData) @@ -175,7 +176,7 @@ void TestTwoDimArrayData::testClear() ArrayData<2> arrayData{inputData.first, inputData.second}; arrayData.clear(); - auto emptyData = Container(inputData.second, QVector{}); + auto emptyData = Container(inputData.second, DataContainer{}); verifyArrayData(arrayData, emptyData); } diff --git a/plugins/amda/src/AmdaResultParser.cpp b/plugins/amda/src/AmdaResultParser.cpp index 73af4a0..e7db277 100644 --- a/plugins/amda/src/AmdaResultParser.cpp +++ b/plugins/amda/src/AmdaResultParser.cpp @@ -194,15 +194,16 @@ std::shared_ptr AmdaResultParser::readTxt(const QString &filePath, case ValueType::SCALAR: Q_ASSERT(results.second.size() == 1); return std::make_shared( - std::move(results.first), std::move(results.second.takeFirst()), xAxisUnit, Unit{}); + std::move(results.first.toStdVector()), + std::move(results.second.takeFirst().toStdVector()), xAxisUnit, Unit{}); case ValueType::VECTOR: { Q_ASSERT(results.second.size() == 3); - auto xValues = results.second.takeFirst(); - auto yValues = results.second.takeFirst(); - auto zValues = results.second.takeFirst(); - return std::make_shared(std::move(results.first), std::move(xValues), - std::move(yValues), std::move(zValues), xAxisUnit, - Unit{}); + auto xValues = results.second.takeFirst().toStdVector(); + auto yValues = results.second.takeFirst().toStdVector(); + auto zValues = results.second.takeFirst().toStdVector(); + return std::make_shared(std::move(results.first.toStdVector()), + std::move(xValues), std::move(yValues), + std::move(zValues), xAxisUnit, Unit{}); } case ValueType::UNKNOWN: // Invalid case diff --git a/plugins/mockplugin/src/CosinusProvider.cpp b/plugins/mockplugin/src/CosinusProvider.cpp index 4781d41..661a78f 100644 --- a/plugins/mockplugin/src/CosinusProvider.cpp +++ b/plugins/mockplugin/src/CosinusProvider.cpp @@ -18,7 +18,7 @@ std::shared_ptr CosinusProvider::retrieveData(QUuid acqIdentifier, auto dataIndex = 0; // Gets the timerange from the parameters - double freq = 1.0; + double freq = 100.0; double start = std::ceil(dataRangeRequested.m_TStart * freq); // 100 htz double end = std::floor(dataRangeRequested.m_TEnd * freq); // 100 htz @@ -30,10 +30,10 @@ std::shared_ptr CosinusProvider::retrieveData(QUuid acqIdentifier, // Generates scalar series containing cosinus values (one value per second) auto dataCount = end - start; - auto xAxisData = QVector{}; + auto xAxisData = std::vector{}; xAxisData.resize(dataCount); - auto valuesData = QVector{}; + auto valuesData = std::vector{}; valuesData.resize(dataCount); int progress = 0; @@ -43,8 +43,8 @@ std::shared_ptr CosinusProvider::retrieveData(QUuid acqIdentifier, if (it != m_VariableToEnableProvider.end() && it.value()) { const auto timeOnFreq = time / freq; - xAxisData.replace(dataIndex, timeOnFreq); - valuesData.replace(dataIndex, std::cos(timeOnFreq)); + xAxisData[dataIndex] = timeOnFreq; + valuesData[dataIndex] = std::cos(timeOnFreq); // progression int currentProgress = (time - start) * 100.0 / progressEnd;