##// END OF EJS Templates
Makes a Data series be sorted (1)
Alexandre Leroux -
r449:9b2f73ab0183
parent child
Show More
@@ -73,14 +73,14 public:
73 73 }
74 74
75 75 /**
76 * @return the data as a vector
76 * @return the data as a vector, as a const reference
77 77 * @remarks this method is only available for a unidimensional ArrayData
78 78 */
79 79 template <int D = Dim, typename = std::enable_if_t<D == 1> >
80 QVector<double> data(double tStart, double tEnd) const noexcept
80 const QVector<double> &cdata() const noexcept
81 81 {
82 82 QReadLocker locker{&m_Lock};
83 return m_Data.at(tStart);
83 return m_Data.at(0);
84 84 }
85 85
86 86 // TODO Comment
@@ -17,7 +17,9 Q_LOGGING_CATEGORY(LOG_DataSeries, "DataSeries")
17 17 /**
18 18 * @brief The DataSeries class is the base (abstract) implementation of IDataSeries.
19 19 *
20 * It proposes to set a dimension for the values ​​data
20 * It proposes to set a dimension for the values ​​data.
21 *
22 * A DataSeries is always sorted on its x-axis data.
21 23 *
22 24 * @tparam Dim The dimension of the values data
23 25 *
@@ -64,7 +66,9 public:
64 66 virtual void unlock() { m_Lock.unlock(); }
65 67
66 68 protected:
67 /// Protected ctor (DataSeries is abstract)
69 /// Protected ctor (DataSeries is abstract). The vectors must have the same size, otherwise a
70 /// DataSeries with no values will be created.
71 /// @remarks data series is automatically sorted on its x-axis data
68 72 explicit DataSeries(std::shared_ptr<ArrayData<1> > xAxisData, const Unit &xAxisUnit,
69 73 std::shared_ptr<ArrayData<Dim> > valuesData, const Unit &valuesUnit)
70 74 : m_XAxisData{xAxisData},
@@ -72,6 +76,15 protected:
72 76 m_ValuesData{valuesData},
73 77 m_ValuesUnit{valuesUnit}
74 78 {
79 if (m_XAxisData->size() != m_ValuesData->size()) {
80 clear();
81 }
82
83 // Sorts data if it's not the case
84 const auto &xAxisCData = m_XAxisData->cdata();
85 if (!std::is_sorted(xAxisCData.cbegin(), xAxisCData.cend())) {
86 sort();
87 }
75 88 }
76 89
77 90 /// Copy ctor
@@ -81,6 +94,8 protected:
81 94 m_ValuesData{std::make_shared<ArrayData<Dim> >(*other.m_ValuesData)},
82 95 m_ValuesUnit{other.m_ValuesUnit}
83 96 {
97 // Since a series is ordered from its construction and is always ordered, it is not
98 // necessary to call the sort method here ('other' is sorted)
84 99 }
85 100
86 101 /// Assignment operator
@@ -96,6 +111,14 protected:
96 111 }
97 112
98 113 private:
114 /**
115 * Sorts data series on its x-axis data
116 */
117 void sort() noexcept
118 {
119 /// @todo ALX
120 }
121
99 122 std::shared_ptr<ArrayData<1> > m_XAxisData;
100 123 Unit m_XAxisUnit;
101 124 std::shared_ptr<ArrayData<Dim> > m_ValuesData;
General Comments 0
You need to be logged in to leave comments. Login now