##// END OF EJS Templates
Adapts SqpIterator to make non-const iterators
Alexandre Leroux -
r626:09db2d1144f0
parent child
Show More
@@ -39,19 +39,49 struct Sort<1> {
39 39 }
40 40 };
41 41
42 template <int Dim, bool IsConst>
43 class IteratorValue;
44
45 template <int Dim, bool IsConst>
46 struct IteratorValueBuilder {
47 };
48
49 template <int Dim>
50 struct IteratorValueBuilder<Dim, true> {
51 using DataContainerIterator = DataContainer::const_iterator;
52 };
53
42 54 template <int Dim>
55 struct IteratorValueBuilder<Dim, false> {
56 using DataContainerIterator = DataContainer::iterator;
57 };
58
59 template <int Dim, bool IsConst>
43 60 class IteratorValue : public ArrayDataIteratorValue::Impl {
44 61 public:
62 friend class ArrayData<Dim>;
63 friend class IteratorValueBuilder<Dim, IsConst>;
64
65 using DataContainerIterator =
66 typename IteratorValueBuilder<Dim, IsConst>::DataContainerIterator;
67
68 template <bool IC = IsConst, typename = std::enable_if_t<IC == true> >
45 69 explicit IteratorValue(const DataContainer &container, int nbComponents, bool begin)
46 70 : m_It{begin ? container.cbegin() : container.cend()}, m_NbComponents{nbComponents}
47 71 {
48 72 }
49 73
74 template <bool IC = IsConst, typename = std::enable_if_t<IC == false> >
75 explicit IteratorValue(DataContainer &container, int nbComponents, bool begin)
76 : m_It{begin ? container.begin() : container.end()}, m_NbComponents{nbComponents}
77 {
78 }
79
50 80 IteratorValue(const IteratorValue &other) = default;
51 81
52 82 std::unique_ptr<ArrayDataIteratorValue::Impl> clone() const override
53 83 {
54 return std::make_unique<IteratorValue<Dim> >(*this);
84 return std::make_unique<IteratorValue<Dim, IsConst> >(*this);
55 85 }
56 86
57 87 bool equals(const ArrayDataIteratorValue::Impl &other) const override try {
@@ -98,7 +128,7 public:
98 128 }
99 129
100 130 private:
101 DataContainer::const_iterator m_It;
131 DataContainerIterator m_It;
102 132 int m_NbComponents;
103 133 };
104 134
@@ -223,15 +253,31 public:
223 253 // Iterators //
224 254 // ///////// //
225 255
256 ArrayDataIterator begin()
257 {
258 return ArrayDataIterator{
259 ArrayDataIteratorValue{std::make_unique<arraydata_detail::IteratorValue<Dim, false> >(
260 m_Data, m_NbComponents, true)}};
261 }
262
263 ArrayDataIterator end()
264 {
265 return ArrayDataIterator{
266 ArrayDataIteratorValue{std::make_unique<arraydata_detail::IteratorValue<Dim, false> >(
267 m_Data, m_NbComponents, false)}};
268 }
269
226 270 ArrayDataIterator cbegin() const
227 271 {
228 return ArrayDataIterator{ArrayDataIteratorValue{
229 std::make_unique<arraydata_detail::IteratorValue<Dim> >(m_Data, m_NbComponents, true)}};
272 return ArrayDataIterator{
273 ArrayDataIteratorValue{std::make_unique<arraydata_detail::IteratorValue<Dim, true> >(
274 m_Data, m_NbComponents, true)}};
230 275 }
276
231 277 ArrayDataIterator cend() const
232 278 {
233 279 return ArrayDataIterator{
234 ArrayDataIteratorValue{std::make_unique<arraydata_detail::IteratorValue<Dim> >(
280 ArrayDataIteratorValue{std::make_unique<arraydata_detail::IteratorValue<Dim, true> >(
235 281 m_Data, m_NbComponents, false)}};
236 282 }
237 283
@@ -27,20 +27,31 class DataSeries;
27 27
28 28 namespace dataseries_detail {
29 29
30 template <int Dim>
30 template <int Dim, bool IsConst>
31 31 class IteratorValue : public DataSeriesIteratorValue::Impl {
32 32 public:
33 friend class DataSeries<Dim>;
34
35 template <bool IC = IsConst, typename = std::enable_if_t<IC == false> >
36 explicit IteratorValue(DataSeries<Dim> &dataSeries, bool begin)
37 : m_XIt(begin ? dataSeries.xAxisData()->begin() : dataSeries.xAxisData()->end()),
38 m_ValuesIt(begin ? dataSeries.valuesData()->begin() : dataSeries.valuesData()->end())
39 {
40 }
41
42 template <bool IC = IsConst, typename = std::enable_if_t<IC == true> >
33 43 explicit IteratorValue(const DataSeries<Dim> &dataSeries, bool begin)
34 44 : m_XIt(begin ? dataSeries.xAxisData()->cbegin() : dataSeries.xAxisData()->cend()),
35 45 m_ValuesIt(begin ? dataSeries.valuesData()->cbegin()
36 46 : dataSeries.valuesData()->cend())
37 47 {
38 48 }
49
39 50 IteratorValue(const IteratorValue &other) = default;
40 51
41 52 std::unique_ptr<DataSeriesIteratorValue::Impl> clone() const override
42 53 {
43 return std::make_unique<IteratorValue<Dim> >(*this);
54 return std::make_unique<IteratorValue<Dim, IsConst> >(*this);
44 55 }
45 56
46 57 bool equals(const DataSeriesIteratorValue::Impl &other) const override try {
@@ -149,16 +160,28 public:
149 160 // Iterators //
150 161 // ///////// //
151 162
163 DataSeriesIterator begin() override
164 {
165 return DataSeriesIterator{DataSeriesIteratorValue{
166 std::make_unique<dataseries_detail::IteratorValue<Dim, false> >(*this, true)}};
167 }
168
169 DataSeriesIterator end() override
170 {
171 return DataSeriesIterator{DataSeriesIteratorValue{
172 std::make_unique<dataseries_detail::IteratorValue<Dim, false> >(*this, false)}};
173 }
174
152 175 DataSeriesIterator cbegin() const override
153 176 {
154 177 return DataSeriesIterator{DataSeriesIteratorValue{
155 std::make_unique<dataseries_detail::IteratorValue<Dim> >(*this, true)}};
178 std::make_unique<dataseries_detail::IteratorValue<Dim, true> >(*this, true)}};
156 179 }
157 180
158 181 DataSeriesIterator cend() const override
159 182 {
160 183 return DataSeriesIterator{DataSeriesIteratorValue{
161 std::make_unique<dataseries_detail::IteratorValue<Dim> >(*this, false)}};
184 std::make_unique<dataseries_detail::IteratorValue<Dim, true> >(*this, false)}};
162 185 }
163 186
164 187 /// @sa IDataSeries::minXAxisData()
@@ -69,6 +69,8 public:
69 69
70 70 virtual DataSeriesIterator cbegin() const = 0;
71 71 virtual DataSeriesIterator cend() const = 0;
72 virtual DataSeriesIterator begin() = 0;
73 virtual DataSeriesIterator end() = 0;
72 74
73 75 /// @return the iterator to the first entry of the data series whose x-axis data is greater than
74 76 /// or equal to the value passed in parameter, or the end iterator if there is no matching value
@@ -38,8 +38,10 public:
38 38 return *this;
39 39 }
40 40
41 pointer operator->() const { return &m_CurrentValue; }
42 reference operator*() const { return m_CurrentValue; }
41 const T *operator->() const { return &m_CurrentValue; }
42 const T &operator*() const { return m_CurrentValue; }
43 T *operator->() { return &m_CurrentValue; }
44 T &operator*() { return m_CurrentValue; }
43 45
44 46 bool operator==(const SqpIterator &other) const
45 47 {
General Comments 0
You need to be logged in to leave comments. Login now