##// END OF EJS Templates
Makes a Data series be sorted (1)
Alexandre Leroux -
r415: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 * @remarks this method is only available for a unidimensional ArrayData
77 * @remarks this method is only available for a unidimensional ArrayData
78 */
78 */
79 template <int D = Dim, typename = std::enable_if_t<D == 1> >
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 QReadLocker locker{&m_Lock};
82 QReadLocker locker{&m_Lock};
83 return m_Data.at(tStart);
83 return m_Data.at(0);
84 }
84 }
85
85
86 // TODO Comment
86 // TODO Comment
@@ -17,7 +17,9 Q_LOGGING_CATEGORY(LOG_DataSeries, "DataSeries")
17 /**
17 /**
18 * @brief The DataSeries class is the base (abstract) implementation of IDataSeries.
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 * @tparam Dim The dimension of the values data
24 * @tparam Dim The dimension of the values data
23 *
25 *
@@ -64,7 +66,9 public:
64 virtual void unlock() { m_Lock.unlock(); }
66 virtual void unlock() { m_Lock.unlock(); }
65
67
66 protected:
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 explicit DataSeries(std::shared_ptr<ArrayData<1> > xAxisData, const Unit &xAxisUnit,
72 explicit DataSeries(std::shared_ptr<ArrayData<1> > xAxisData, const Unit &xAxisUnit,
69 std::shared_ptr<ArrayData<Dim> > valuesData, const Unit &valuesUnit)
73 std::shared_ptr<ArrayData<Dim> > valuesData, const Unit &valuesUnit)
70 : m_XAxisData{xAxisData},
74 : m_XAxisData{xAxisData},
@@ -72,6 +76,15 protected:
72 m_ValuesData{valuesData},
76 m_ValuesData{valuesData},
73 m_ValuesUnit{valuesUnit}
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 }
note

Since m_ValuesData isn't sorted, how can we keep the correspondance at iteration between x and val ?

75 }
88 }
76
89
77 /// Copy ctor
90 /// Copy ctor
@@ -81,6 +94,8 protected:
81 m_ValuesData{std::make_shared<ArrayData<Dim> >(*other.m_ValuesData)},
94 m_ValuesData{std::make_shared<ArrayData<Dim> >(*other.m_ValuesData)},
82 m_ValuesUnit{other.m_ValuesUnit}
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 /// Assignment operator
101 /// Assignment operator
@@ -96,6 +111,14 protected:
96 }
111 }
97
112
98 private:
113 private:
114 /**
115 * Sorts data series on its x-axis data
116 */
117 void sort() noexcept
118 {
119 /// @todo ALX
120 }
121
99 std::shared_ptr<ArrayData<1> > m_XAxisData;
122 std::shared_ptr<ArrayData<1> > m_XAxisData;
100 Unit m_XAxisUnit;
123 Unit m_XAxisUnit;
101 std::shared_ptr<ArrayData<Dim> > m_ValuesData;
124 std::shared_ptr<ArrayData<Dim> > m_ValuesData;
General Comments 0
You need to be logged in to leave comments. Login now