@@ -93,6 +93,15 public: | |||||
93 | return std::make_unique<IteratorValue<Dim, IsConst> >(*this); |
|
93 | return std::make_unique<IteratorValue<Dim, IsConst> >(*this); | |
94 | } |
|
94 | } | |
95 |
|
95 | |||
|
96 | int distance(const ArrayDataIteratorValue::Impl &other) const override try { | |||
|
97 | /// @todo ALX : validate | |||
|
98 | const auto &otherImpl = dynamic_cast<const IteratorValue &>(other); | |||
|
99 | return std::distance(otherImpl.m_It, m_It) / m_NbComponents; | |||
|
100 | } | |||
|
101 | catch (const std::bad_cast &) { | |||
|
102 | return 0; | |||
|
103 | } | |||
|
104 | ||||
96 | bool equals(const ArrayDataIteratorValue::Impl &other) const override try { |
|
105 | bool equals(const ArrayDataIteratorValue::Impl &other) const override try { | |
97 | const auto &otherImpl = dynamic_cast<const IteratorValue &>(other); |
|
106 | const auto &otherImpl = dynamic_cast<const IteratorValue &>(other); | |
98 | return std::tie(m_It, m_NbComponents) == std::tie(otherImpl.m_It, otherImpl.m_NbComponents); |
|
107 | return std::tie(m_It, m_NbComponents) == std::tie(otherImpl.m_It, otherImpl.m_NbComponents); | |
@@ -101,6 +110,23 public: | |||||
101 | return false; |
|
110 | return false; | |
102 | } |
|
111 | } | |
103 |
|
112 | |||
|
113 | bool lowerThan(const ArrayDataIteratorValue::Impl &other) const override try { | |||
|
114 | const auto &otherImpl = dynamic_cast<const IteratorValue &>(other); | |||
|
115 | return m_It < otherImpl.m_It; | |||
|
116 | } | |||
|
117 | catch (const std::bad_cast &) { | |||
|
118 | return false; | |||
|
119 | } | |||
|
120 | ||||
|
121 | std::unique_ptr<ArrayDataIteratorValue::Impl> advance(int offset) const override | |||
|
122 | { | |||
|
123 | auto result = clone(); | |||
|
124 | while (offset--) { | |||
|
125 | result->next(); | |||
|
126 | } | |||
|
127 | return result; | |||
|
128 | } | |||
|
129 | ||||
104 | void next() override { std::advance(m_It, m_NbComponents); } |
|
130 | void next() override { std::advance(m_It, m_NbComponents); } | |
105 | void prev() override { std::advance(m_It, -m_NbComponents); } |
|
131 | void prev() override { std::advance(m_It, -m_NbComponents); } | |
106 |
|
132 |
@@ -19,7 +19,10 public: | |||||
19 | struct Impl { |
|
19 | struct Impl { | |
20 | virtual ~Impl() noexcept = default; |
|
20 | virtual ~Impl() noexcept = default; | |
21 | virtual std::unique_ptr<Impl> clone() const = 0; |
|
21 | virtual std::unique_ptr<Impl> clone() const = 0; | |
|
22 | virtual int distance(const Impl &other) const = 0; | |||
22 | virtual bool equals(const Impl &other) const = 0; |
|
23 | virtual bool equals(const Impl &other) const = 0; | |
|
24 | virtual bool lowerThan(const Impl &other) const = 0; | |||
|
25 | virtual std::unique_ptr<Impl> advance(int offset) const = 0; | |||
23 | virtual void next() = 0; |
|
26 | virtual void next() = 0; | |
24 | virtual void prev() = 0; |
|
27 | virtual void prev() = 0; | |
25 | virtual double at(int componentIndex) const = 0; |
|
28 | virtual double at(int componentIndex) const = 0; | |
@@ -35,8 +38,11 public: | |||||
35 | ArrayDataIteratorValue(const ArrayDataIteratorValue &other); |
|
38 | ArrayDataIteratorValue(const ArrayDataIteratorValue &other); | |
36 | ArrayDataIteratorValue &operator=(ArrayDataIteratorValue other); |
|
39 | ArrayDataIteratorValue &operator=(ArrayDataIteratorValue other); | |
37 |
|
40 | |||
|
41 | int distance(const ArrayDataIteratorValue &other) const; | |||
38 | bool equals(const ArrayDataIteratorValue &other) const; |
|
42 | bool equals(const ArrayDataIteratorValue &other) const; | |
|
43 | bool lowerThan(const ArrayDataIteratorValue &other) const; | |||
39 |
|
44 | |||
|
45 | ArrayDataIteratorValue advance(int offset) const; | |||
40 | /// Advances to the next value |
|
46 | /// Advances to the next value | |
41 | void next(); |
|
47 | void next(); | |
42 | /// Moves back to the previous value |
|
48 | /// Moves back to the previous value |
@@ -54,6 +54,14 public: | |||||
54 | return std::make_unique<IteratorValue<Dim, IsConst> >(*this); |
|
54 | return std::make_unique<IteratorValue<Dim, IsConst> >(*this); | |
55 | } |
|
55 | } | |
56 |
|
56 | |||
|
57 | int distance(const DataSeriesIteratorValue::Impl &other) const override try { | |||
|
58 | const auto &otherImpl = dynamic_cast<const IteratorValue &>(other); | |||
|
59 | return m_XIt->distance(*otherImpl.m_XIt); | |||
|
60 | } | |||
|
61 | catch (const std::bad_cast &) { | |||
|
62 | return 0; | |||
|
63 | } | |||
|
64 | ||||
57 | bool equals(const DataSeriesIteratorValue::Impl &other) const override try { |
|
65 | bool equals(const DataSeriesIteratorValue::Impl &other) const override try { | |
58 | const auto &otherImpl = dynamic_cast<const IteratorValue &>(other); |
|
66 | const auto &otherImpl = dynamic_cast<const IteratorValue &>(other); | |
59 | return std::tie(m_XIt, m_ValuesIt) == std::tie(otherImpl.m_XIt, otherImpl.m_ValuesIt); |
|
67 | return std::tie(m_XIt, m_ValuesIt) == std::tie(otherImpl.m_XIt, otherImpl.m_ValuesIt); | |
@@ -62,6 +70,23 public: | |||||
62 | return false; |
|
70 | return false; | |
63 | } |
|
71 | } | |
64 |
|
72 | |||
|
73 | bool lowerThan(const DataSeriesIteratorValue::Impl &other) const override try { | |||
|
74 | const auto &otherImpl = dynamic_cast<const IteratorValue &>(other); | |||
|
75 | return m_XIt->lowerThan(*otherImpl.m_XIt); | |||
|
76 | } | |||
|
77 | catch (const std::bad_cast &) { | |||
|
78 | return false; | |||
|
79 | } | |||
|
80 | ||||
|
81 | std::unique_ptr<DataSeriesIteratorValue::Impl> advance(int offset) const override | |||
|
82 | { | |||
|
83 | auto result = clone(); | |||
|
84 | while (offset--) { | |||
|
85 | result->next(); | |||
|
86 | } | |||
|
87 | return result; | |||
|
88 | } | |||
|
89 | ||||
65 | void next() override |
|
90 | void next() override | |
66 | { |
|
91 | { | |
67 | ++m_XIt; |
|
92 | ++m_XIt; | |
@@ -165,17 +190,28 public: | |||||
165 |
|
190 | |||
166 | void purge(double min, double max) override |
|
191 | void purge(double min, double max) override | |
167 | { |
|
192 | { | |
|
193 | // Nothing to purge if series is empty | |||
|
194 | if (isEmpty()) { | |||
|
195 | return; | |||
|
196 | } | |||
|
197 | ||||
168 | if (min > max) { |
|
198 | if (min > max) { | |
169 | std::swap(min, max); |
|
199 | std::swap(min, max); | |
170 | } |
|
200 | } | |
171 |
|
201 | |||
172 | lockWrite(); |
|
202 | // Nothing to purge if series min/max are inside purge range | |
173 |
|
203 | auto xMin = cbegin()->x(); | ||
174 | auto it = std::remove_if( |
|
204 | auto xMax = (--cend())->x(); | |
175 | begin(), end(), [min, max](const auto &it) { return it.x() < min || it.x() > max; }); |
|
205 | if (xMin >= min && xMax <= max) { | |
176 | erase(it, end()); |
|
206 | return; | |
|
207 | } | |||
177 |
|
208 | |||
178 | unlock(); |
|
209 | auto lowerIt = std::lower_bound( | |
|
210 | begin(), end(), min, [](const auto &it, const auto &val) { return it.x() < val; }); | |||
|
211 | erase(begin(), lowerIt); | |||
|
212 | auto upperIt = std::upper_bound( | |||
|
213 | begin(), end(), max, [](const auto &val, const auto &it) { return val < it.x(); }); | |||
|
214 | erase(upperIt, end()); | |||
179 | } |
|
215 | } | |
180 |
|
216 | |||
181 | // ///////// // |
|
217 | // ///////// // |
@@ -20,7 +20,10 public: | |||||
20 | struct Impl { |
|
20 | struct Impl { | |
21 | virtual ~Impl() noexcept = default; |
|
21 | virtual ~Impl() noexcept = default; | |
22 | virtual std::unique_ptr<Impl> clone() const = 0; |
|
22 | virtual std::unique_ptr<Impl> clone() const = 0; | |
|
23 | virtual int distance(const Impl &other) const = 0; | |||
23 | virtual bool equals(const Impl &other) const = 0; |
|
24 | virtual bool equals(const Impl &other) const = 0; | |
|
25 | virtual bool lowerThan(const Impl &other) const = 0; | |||
|
26 | virtual std::unique_ptr<Impl> advance(int offset) const = 0; | |||
24 | virtual void next() = 0; |
|
27 | virtual void next() = 0; | |
25 | virtual void prev() = 0; |
|
28 | virtual void prev() = 0; | |
26 | virtual double x() const = 0; |
|
29 | virtual double x() const = 0; | |
@@ -37,8 +40,11 public: | |||||
37 | DataSeriesIteratorValue(const DataSeriesIteratorValue &other); |
|
40 | DataSeriesIteratorValue(const DataSeriesIteratorValue &other); | |
38 | DataSeriesIteratorValue &operator=(DataSeriesIteratorValue other); |
|
41 | DataSeriesIteratorValue &operator=(DataSeriesIteratorValue other); | |
39 |
|
42 | |||
|
43 | int distance(const DataSeriesIteratorValue &other) const; | |||
40 | bool equals(const DataSeriesIteratorValue &other) const; |
|
44 | bool equals(const DataSeriesIteratorValue &other) const; | |
|
45 | bool lowerThan(const DataSeriesIteratorValue &other) const; | |||
41 |
|
46 | |||
|
47 | DataSeriesIteratorValue advance(int offset) const; | |||
42 | /// Advances to the next value |
|
48 | /// Advances to the next value | |
43 | void next(); |
|
49 | void next(); | |
44 | /// Moves back to the previous value |
|
50 | /// Moves back to the previous value |
@@ -12,7 +12,7 | |||||
12 | template <typename T> |
|
12 | template <typename T> | |
13 | class SCIQLOP_CORE_EXPORT SqpIterator { |
|
13 | class SCIQLOP_CORE_EXPORT SqpIterator { | |
14 | public: |
|
14 | public: | |
15 |
using iterator_category = std:: |
|
15 | using iterator_category = std::random_access_iterator_tag; | |
16 | using value_type = const T; |
|
16 | using value_type = const T; | |
17 | using difference_type = std::ptrdiff_t; |
|
17 | using difference_type = std::ptrdiff_t; | |
18 | using pointer = value_type *; |
|
18 | using pointer = value_type *; | |
@@ -36,16 +36,72 public: | |||||
36 | return *this; |
|
36 | return *this; | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
|
39 | SqpIterator operator++(int)const | |||
|
40 | { | |||
|
41 | auto result = *this; | |||
|
42 | this->operator++(); | |||
|
43 | return result; | |||
|
44 | } | |||
|
45 | SqpIterator operator--(int)const | |||
|
46 | { | |||
|
47 | auto result = *this; | |||
|
48 | this->operator--(); | |||
|
49 | return result; | |||
|
50 | } | |||
|
51 | ||||
|
52 | SqpIterator &operator+=(int offset) | |||
|
53 | { | |||
|
54 | if (offset >= 0) { | |||
|
55 | while (offset--) { | |||
|
56 | m_CurrentValue.next(); | |||
|
57 | } | |||
|
58 | } | |||
|
59 | else { | |||
|
60 | while (offset++) { | |||
|
61 | m_CurrentValue.prev(); | |||
|
62 | } | |||
|
63 | } | |||
|
64 | ||||
|
65 | return *this; | |||
|
66 | } | |||
|
67 | SqpIterator &operator-=(int offset) { return *this += -offset; } | |||
|
68 | ||||
|
69 | SqpIterator operator+(int offset) const | |||
|
70 | { | |||
|
71 | auto result = *this; | |||
|
72 | result += offset; | |||
|
73 | return result; | |||
|
74 | } | |||
|
75 | SqpIterator operator-(int offset) const | |||
|
76 | { | |||
|
77 | auto result = *this; | |||
|
78 | result -= offset; | |||
|
79 | return result; | |||
|
80 | } | |||
|
81 | ||||
|
82 | int operator-(const SqpIterator &other) const | |||
|
83 | { | |||
|
84 | return m_CurrentValue.distance(other.m_CurrentValue); | |||
|
85 | } | |||
|
86 | ||||
39 | const T *operator->() const { return &m_CurrentValue; } |
|
87 | const T *operator->() const { return &m_CurrentValue; } | |
40 | const T &operator*() const { return m_CurrentValue; } |
|
88 | const T &operator*() const { return m_CurrentValue; } | |
41 | T *operator->() { return &m_CurrentValue; } |
|
89 | T *operator->() { return &m_CurrentValue; } | |
42 | T &operator*() { return m_CurrentValue; } |
|
90 | T &operator*() { return m_CurrentValue; } | |
|
91 | T &operator[](int offset) const { return m_CurrentValue.advance(offset); } | |||
43 |
|
92 | |||
44 | bool operator==(const SqpIterator &other) const |
|
93 | bool operator==(const SqpIterator &other) const | |
45 | { |
|
94 | { | |
46 | return m_CurrentValue.equals(other.m_CurrentValue); |
|
95 | return m_CurrentValue.equals(other.m_CurrentValue); | |
47 | } |
|
96 | } | |
48 | bool operator!=(const SqpIterator &other) const { return !(*this == other); } |
|
97 | bool operator!=(const SqpIterator &other) const { return !(*this == other); } | |
|
98 | bool operator>(const SqpIterator &other) const { return other.m_CurrentValue.lowerThan(*this); } | |||
|
99 | bool operator<(const SqpIterator &other) const | |||
|
100 | { | |||
|
101 | return m_CurrentValue.lowerThan(other.m_CurrentValue); | |||
|
102 | } | |||
|
103 | bool operator>=(const SqpIterator &other) const { return !(*this < other); } | |||
|
104 | bool operator<=(const SqpIterator &other) const { return !(*this > other); } | |||
49 |
|
105 | |||
50 | private: |
|
106 | private: | |
51 | T m_CurrentValue; |
|
107 | T m_CurrentValue; |
@@ -16,11 +16,26 ArrayDataIteratorValue &ArrayDataIteratorValue::operator=(ArrayDataIteratorValue | |||||
16 | return *this; |
|
16 | return *this; | |
17 | } |
|
17 | } | |
18 |
|
18 | |||
|
19 | int ArrayDataIteratorValue::distance(const ArrayDataIteratorValue &other) const | |||
|
20 | { | |||
|
21 | return m_Impl->distance(*other.m_Impl); | |||
|
22 | } | |||
|
23 | ||||
19 | bool ArrayDataIteratorValue::equals(const ArrayDataIteratorValue &other) const |
|
24 | bool ArrayDataIteratorValue::equals(const ArrayDataIteratorValue &other) const | |
20 | { |
|
25 | { | |
21 | return m_Impl->equals(*other.m_Impl); |
|
26 | return m_Impl->equals(*other.m_Impl); | |
22 | } |
|
27 | } | |
23 |
|
28 | |||
|
29 | bool ArrayDataIteratorValue::lowerThan(const ArrayDataIteratorValue &other) const | |||
|
30 | { | |||
|
31 | return m_Impl->lowerThan(*other.m_Impl); | |||
|
32 | } | |||
|
33 | ||||
|
34 | ArrayDataIteratorValue ArrayDataIteratorValue::advance(int offset) const | |||
|
35 | { | |||
|
36 | return ArrayDataIteratorValue{m_Impl->advance(offset)}; | |||
|
37 | } | |||
|
38 | ||||
24 | void ArrayDataIteratorValue::next() |
|
39 | void ArrayDataIteratorValue::next() | |
25 | { |
|
40 | { | |
26 | m_Impl->next(); |
|
41 | m_Impl->next(); |
@@ -17,11 +17,27 DataSeriesIteratorValue &DataSeriesIteratorValue::operator=(DataSeriesIteratorVa | |||||
17 | return *this; |
|
17 | return *this; | |
18 | } |
|
18 | } | |
19 |
|
19 | |||
|
20 | int DataSeriesIteratorValue::distance(const DataSeriesIteratorValue &other) const | |||
|
21 | { | |||
|
22 | auto dist = m_Impl->distance(*other.m_Impl); | |||
|
23 | return m_Impl->distance(*other.m_Impl); | |||
|
24 | } | |||
|
25 | ||||
20 | bool DataSeriesIteratorValue::equals(const DataSeriesIteratorValue &other) const |
|
26 | bool DataSeriesIteratorValue::equals(const DataSeriesIteratorValue &other) const | |
21 | { |
|
27 | { | |
22 | return m_Impl->equals(*other.m_Impl); |
|
28 | return m_Impl->equals(*other.m_Impl); | |
23 | } |
|
29 | } | |
24 |
|
30 | |||
|
31 | bool DataSeriesIteratorValue::lowerThan(const DataSeriesIteratorValue &other) const | |||
|
32 | { | |||
|
33 | return m_Impl->lowerThan(*other.m_Impl); | |||
|
34 | } | |||
|
35 | ||||
|
36 | DataSeriesIteratorValue DataSeriesIteratorValue::advance(int offset) const | |||
|
37 | { | |||
|
38 | return DataSeriesIteratorValue{m_Impl->advance(offset)}; | |||
|
39 | } | |||
|
40 | ||||
25 | void DataSeriesIteratorValue::next() |
|
41 | void DataSeriesIteratorValue::next() | |
26 | { |
|
42 | { | |
27 | m_Impl->next(); |
|
43 | m_Impl->next(); |
@@ -31,12 +31,12 DataSeries\.h:\d+:.*IPSIS_S06.*found: (IC) | |||||
31 | DataSeries\.h:\d+:.*IPSIS_S06.*found: (IsConst) |
|
31 | DataSeries\.h:\d+:.*IPSIS_S06.*found: (IsConst) | |
32 |
|
32 | |||
33 | # Ignore false positive relative to iterators |
|
33 | # Ignore false positive relative to iterators | |
34 |
SqpIterator\.h:\d+:.*IPSIS_S04_VARIABLE.*found: ( |
|
34 | SqpIterator\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (random_access_iterator_tag) | |
35 | SqpIterator\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (T) |
|
35 | SqpIterator\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (T) | |
36 | SqpIterator\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (ptrdiff_t) |
|
36 | SqpIterator\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (ptrdiff_t) | |
37 | SqpIterator\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (value_type) |
|
37 | SqpIterator\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (value_type) | |
38 | SqpIterator\.h:\d+:.*IPSIS_S06.*found: (iterator_category) |
|
38 | SqpIterator\.h:\d+:.*IPSIS_S06.*found: (iterator_category) | |
39 |
SqpIterator\.h:\d+:.*IPSIS_S06.*found: ( |
|
39 | SqpIterator\.h:\d+:.*IPSIS_S06.*found: (random_access_iterator_tag) | |
40 | SqpIterator\.h:\d+:.*IPSIS_S06.*found: (value_type) |
|
40 | SqpIterator\.h:\d+:.*IPSIS_S06.*found: (value_type) | |
41 | SqpIterator\.h:\d+:.*IPSIS_S06.*found: (T) |
|
41 | SqpIterator\.h:\d+:.*IPSIS_S06.*found: (T) | |
42 | SqpIterator\.h:\d+:.*IPSIS_S06.*found: (difference_type) |
|
42 | SqpIterator\.h:\d+:.*IPSIS_S06.*found: (difference_type) |
General Comments 0
You need to be logged in to leave comments.
Login now