##// END OF EJS Templates
Uses new iterator in DataSeries.cpp...
Alexandre Leroux -
r558:96f73c42ec59
parent child
Show More
@@ -21,6 +21,57 inline const QLoggingCategory &LOG_DataSeries()
21 return category;
21 return category;
22 }
22 }
23
23
24 template <int Dim>
25 class DataSeries;
26
27 namespace dataseries_detail {
28
29 template <int Dim>
30 class IteratorValue : public DataSeriesIteratorValue::Impl {
31 public:
32 explicit IteratorValue(const DataSeries<Dim> &dataSeries, bool begin)
33 : m_XIt(begin ? dataSeries.xAxisData()->cbegin() : dataSeries.xAxisData()->cend()),
34 m_ValuesIt(begin ? dataSeries.valuesData()->cbegin()
35 : dataSeries.valuesData()->cend())
36 {
37 }
38 IteratorValue(const IteratorValue &other) = default;
39
40 std::unique_ptr<DataSeriesIteratorValue::Impl> clone() const override
41 {
42 return std::make_unique<IteratorValue<Dim> >(*this);
43 }
44
45 bool equals(const DataSeriesIteratorValue::Impl &other) const override try {
46 const auto &otherImpl = dynamic_cast<const IteratorValue &>(other);
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;
51 }
52
53 void next() override
54 {
55 ++m_XIt;
56 ++m_ValuesIt;
57 }
58
59 void prev() override
60 {
61 --m_XIt;
62 --m_ValuesIt;
63 }
64
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); }
68
69 private:
70 ArrayData<1>::Iterator m_XIt;
71 typename ArrayData<Dim>::Iterator m_ValuesIt;
72 };
73 } // namespace dataseries_detail
74
24 /**
75 /**
25 * @brief The DataSeries class is the base (abstract) implementation of IDataSeries.
76 * @brief The DataSeries class is the base (abstract) implementation of IDataSeries.
26 *
77 *
@@ -34,71 +85,6 inline const QLoggingCategory &LOG_DataSeries()
34 template <int Dim>
85 template <int Dim>
35 class SCIQLOP_CORE_EXPORT DataSeries : public IDataSeries {
86 class SCIQLOP_CORE_EXPORT DataSeries : public IDataSeries {
36 public:
87 public:
37 class IteratorValue {
38 public:
39 explicit IteratorValue(const DataSeries &dataSeries, bool begin)
40 : m_XIt(begin ? dataSeries.xAxisData()->cbegin() : dataSeries.xAxisData()->cend()),
41 m_ValuesIt(begin ? dataSeries.valuesData()->cbegin()
42 : dataSeries.valuesData()->cend())
43 {
44 }
45
46 double x() const { return m_XIt->at(0); }
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 {
52 ++m_XIt;
53 ++m_ValuesIt;
54 }
55
56 bool operator==(const IteratorValue &other) const
57 {
58 return std::tie(m_XIt, m_ValuesIt) == std::tie(other.m_XIt, other.m_ValuesIt);
59 }
60
61 private:
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 {
83 m_CurrentValue.next();
84 return *this;
85 }
86
87 pointer operator->() const { return &m_CurrentValue; }
88
89 reference operator*() const { return m_CurrentValue; }
90
91 bool operator==(const Iterator &other) const
92 {
93 return m_CurrentValue == other.m_CurrentValue;
94 }
95
96 bool operator!=(const Iterator &other) const { return !(*this == other); }
97
98 private:
99 IteratorValue m_CurrentValue;
100 };
101
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 { return Iterator{*this, true}; }
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