@@ -21,84 +21,70 inline const QLoggingCategory &LOG_DataSeries() | |||||
21 | return category; |
|
21 | return category; | |
22 | } |
|
22 | } | |
23 |
|
23 | |||
24 | /** |
|
|||
25 | * @brief The DataSeries class is the base (abstract) implementation of IDataSeries. |
|
|||
26 | * |
|
|||
27 | * It proposes to set a dimension for the values data. |
|
|||
28 | * |
|
|||
29 | * A DataSeries is always sorted on its x-axis data. |
|
|||
30 | * |
|
|||
31 | * @tparam Dim The dimension of the values data |
|
|||
32 | * |
|
|||
33 | */ |
|
|||
34 | template <int Dim> |
|
24 | template <int Dim> | |
35 | class SCIQLOP_CORE_EXPORT DataSeries : public IDataSeries { |
|
25 | class DataSeries; | |
36 | public: |
|
26 | ||
37 | class IteratorValue { |
|
27 | namespace dataseries_detail { | |
|
28 | ||||
|
29 | template <int Dim> | |||
|
30 | class IteratorValue : public DataSeriesIteratorValue::Impl { | |||
38 |
|
|
31 | public: | |
39 |
|
|
32 | explicit IteratorValue(const DataSeries<Dim> &dataSeries, bool begin) | |
40 |
|
|
33 | : m_XIt(begin ? dataSeries.xAxisData()->cbegin() : dataSeries.xAxisData()->cend()), | |
41 |
|
|
34 | m_ValuesIt(begin ? dataSeries.valuesData()->cbegin() | |
42 |
|
|
35 | : dataSeries.valuesData()->cend()) | |
43 |
|
|
36 | { | |
44 |
|
|
37 | } | |
|
38 | IteratorValue(const IteratorValue &other) = default; | |||
45 |
|
39 | |||
46 | double x() const { return m_XIt->at(0); } |
|
40 | std::unique_ptr<DataSeriesIteratorValue::Impl> clone() const override | |
47 | double value() const { return m_ValuesIt->at(0); } |
|
|||
48 | double value(int componentIndex) const { return m_ValuesIt->at(componentIndex); } |
|
|||
49 |
|
||||
50 | void next() |
|
|||
51 |
|
|
41 | { | |
52 | ++m_XIt; |
|
42 | return std::make_unique<IteratorValue<Dim> >(*this); | |
53 | ++m_ValuesIt; |
|
|||
54 |
|
|
43 | } | |
55 |
|
44 | |||
56 |
|
|
45 | bool equals(const DataSeriesIteratorValue::Impl &other) const override try { | |
57 | { |
|
46 | const auto &otherImpl = dynamic_cast<const IteratorValue &>(other); | |
58 |
|
|
47 | return std::tie(m_XIt, m_ValuesIt) == std::tie(otherImpl.m_XIt, otherImpl.m_ValuesIt); | |
|
48 | } | |||
|
49 | catch (const std::bad_cast &) { | |||
|
50 | return false; | |||
59 |
|
|
51 | } | |
60 |
|
52 | |||
61 | private: |
|
53 | void next() override | |
62 | ArrayData<1>::Iterator m_XIt; |
|
|||
63 | typename ArrayData<Dim>::Iterator m_ValuesIt; |
|
|||
64 | }; |
|
|||
65 |
|
||||
66 | class Iterator { |
|
|||
67 | public: |
|
|||
68 | using iterator_category = std::forward_iterator_tag; |
|
|||
69 | using value_type = const IteratorValue; |
|
|||
70 | using difference_type = std::ptrdiff_t; |
|
|||
71 | using pointer = value_type *; |
|
|||
72 | using reference = value_type &; |
|
|||
73 |
|
||||
74 | Iterator(const DataSeries &dataSeries, bool begin) : m_CurrentValue{dataSeries, begin} {} |
|
|||
75 | virtual ~Iterator() noexcept = default; |
|
|||
76 | Iterator(const Iterator &) = default; |
|
|||
77 | Iterator(Iterator &&) = default; |
|
|||
78 | Iterator &operator=(const Iterator &) = default; |
|
|||
79 | Iterator &operator=(Iterator &&) = default; |
|
|||
80 |
|
||||
81 | Iterator &operator++() |
|
|||
82 |
|
|
54 | { | |
83 | m_CurrentValue.next(); |
|
55 | ++m_XIt; | |
84 | return *this; |
|
56 | ++m_ValuesIt; | |
85 |
|
|
57 | } | |
86 |
|
58 | |||
87 | pointer operator->() const { return &m_CurrentValue; } |
|
59 | void prev() override | |
88 |
|
||||
89 | reference operator*() const { return m_CurrentValue; } |
|
|||
90 |
|
||||
91 | bool operator==(const Iterator &other) const |
|
|||
92 |
|
|
60 | { | |
93 | return m_CurrentValue == other.m_CurrentValue; |
|
61 | --m_XIt; | |
|
62 | --m_ValuesIt; | |||
94 |
|
|
63 | } | |
95 |
|
64 | |||
96 | bool operator!=(const Iterator &other) const { return !(*this == other); } |
|
65 | double x() const override { return m_XIt->at(0); } | |
|
66 | double value() const override { return m_ValuesIt->at(0); } | |||
|
67 | double value(int componentIndex) const override { return m_ValuesIt->at(componentIndex); } | |||
97 |
|
68 | |||
98 |
|
|
69 | private: | |
99 | IteratorValue m_CurrentValue; |
|
70 | ArrayData<1>::Iterator m_XIt; | |
|
71 | typename ArrayData<Dim>::Iterator m_ValuesIt; | |||
100 | }; |
|
72 | }; | |
|
73 | } // namespace dataseries_detail | |||
101 |
|
74 | |||
|
75 | /** | |||
|
76 | * @brief The DataSeries class is the base (abstract) implementation of IDataSeries. | |||
|
77 | * | |||
|
78 | * It proposes to set a dimension for the values data. | |||
|
79 | * | |||
|
80 | * A DataSeries is always sorted on its x-axis data. | |||
|
81 | * | |||
|
82 | * @tparam Dim The dimension of the values data | |||
|
83 | * | |||
|
84 | */ | |||
|
85 | template <int Dim> | |||
|
86 | class SCIQLOP_CORE_EXPORT DataSeries : public IDataSeries { | |||
|
87 | public: | |||
102 | /// @sa IDataSeries::xAxisData() |
|
88 | /// @sa IDataSeries::xAxisData() | |
103 | std::shared_ptr<ArrayData<1> > xAxisData() override { return m_XAxisData; } |
|
89 | std::shared_ptr<ArrayData<1> > xAxisData() override { return m_XAxisData; } | |
104 | const std::shared_ptr<ArrayData<1> > xAxisData() const { return m_XAxisData; } |
|
90 | const std::shared_ptr<ArrayData<1> > xAxisData() const { return m_XAxisData; } | |
@@ -193,9 +179,17 public: | |||||
193 | // Iterators // |
|
179 | // Iterators // | |
194 | // ///////// // |
|
180 | // ///////// // | |
195 |
|
181 | |||
196 |
Iterator cbegin() const |
|
182 | DataSeriesIterator cbegin() const override | |
|
183 | { | |||
|
184 | return DataSeriesIterator{DataSeriesIteratorValue{ | |||
|
185 | std::make_unique<dataseries_detail::IteratorValue<Dim> >(*this, true)}}; | |||
|
186 | } | |||
197 |
|
187 | |||
198 | Iterator cend() const { return Iterator{*this, false}; } |
|
188 | DataSeriesIterator cend() const override | |
|
189 | { | |||
|
190 | return DataSeriesIterator{DataSeriesIteratorValue{ | |||
|
191 | std::make_unique<dataseries_detail::IteratorValue<Dim> >(*this, false)}}; | |||
|
192 | } | |||
199 |
|
193 | |||
200 | std::pair<Iterator, Iterator> subData(double min, double max) const |
|
194 | std::pair<Iterator, Iterator> subData(double min, double max) const | |
201 | { |
|
195 | { |
General Comments 0
You need to be logged in to leave comments.
Login now