From 34ec67ab5cd87657089298346b8e289c778d9744 2017-08-31 10:28:47 From: Alexandre Leroux Date: 2017-08-31 10:28:47 Subject: [PATCH] Implements purge() method for DataSeries --- diff --git a/core/include/Data/DataSeries.h b/core/include/Data/DataSeries.h index b82e7d9..ea2d962 100644 --- a/core/include/Data/DataSeries.h +++ b/core/include/Data/DataSeries.h @@ -163,6 +163,21 @@ public: dataSeries->unlock(); } + void purge(double min, double max) override + { + if (min > max) { + std::swap(min, max); + } + + lockWrite(); + + auto it = std::remove_if( + begin(), end(), [min, max](const auto &it) { return it.x() < min || it.x() > max; }); + erase(it, end()); + + unlock(); + } + // ///////// // // Iterators // // ///////// // diff --git a/core/include/Data/IDataSeries.h b/core/include/Data/IDataSeries.h index 8414af8..aea7206 100644 --- a/core/include/Data/IDataSeries.h +++ b/core/include/Data/IDataSeries.h @@ -57,6 +57,9 @@ public: virtual Unit valuesUnit() const = 0; virtual void merge(IDataSeries *dataSeries) = 0; + /// Removes from data series all entries whose value on the x-axis is not between min and max + virtual void purge(double min, double max) = 0; + /// @todo Review the name and signature of this method virtual std::shared_ptr subDataSeries(const SqpRange &range) = 0;