##// END OF EJS Templates
Creates general iterator for ArrayData
Alexandre Leroux -
r640:294b109a0563
parent child
Show More
@@ -0,0 +1,56
1 #ifndef SCIQLOP_ARRAYDATAITERATOR_H
2 #define SCIQLOP_ARRAYDATAITERATOR_H
3
4 #include "CoreGlobal.h"
5 #include "Data/SqpIterator.h"
6
7 #include <memory>
8
9 /**
10 * @brief The ArrayDataIteratorValue class represents the current value of an array data iterator.
11 * It offers standard access methods for the data in the series (at(), first()), but it is up to
12 * each array data to define its own implementation of how to retrieve this data (one-dim or two-dim
13 * array), by implementing the ArrayDataIteratorValue::Impl interface
14 * @sa ArrayDataIterator
15 */
16 class SCIQLOP_CORE_EXPORT ArrayDataIteratorValue {
17 public:
18 struct Impl {
19 virtual ~Impl() noexcept = default;
20 virtual std::unique_ptr<Impl> clone() const = 0;
21 virtual bool equals(const Impl &other) const = 0;
22 virtual void next() = 0;
23 virtual void prev() = 0;
24 virtual double at(int componentIndex) const = 0;
25 virtual double first() const = 0;
26 virtual double min() const = 0;
27 virtual double max() const = 0;
28 };
29
30 explicit ArrayDataIteratorValue(std::unique_ptr<Impl> impl);
31 ArrayDataIteratorValue(const ArrayDataIteratorValue &other);
32 ArrayDataIteratorValue(ArrayDataIteratorValue &&other) = default;
33 ArrayDataIteratorValue &operator=(ArrayDataIteratorValue other);
34
35 bool equals(const ArrayDataIteratorValue &other) const;
36
37 /// Advances to the next value
38 void next();
39 /// Moves back to the previous value
40 void prev();
41 /// Gets value of a specified component
42 double at(int componentIndex) const;
43 /// Gets value of first component
44 double first() const;
45 /// Gets min value among all components
46 double min() const;
47 /// Gets max value among all components
48 double max() const;
49
50 private:
51 std::unique_ptr<Impl> m_Impl;
52 };
53
54 using ArrayDataIterator = SqpIterator<ArrayDataIteratorValue>;
55
56 #endif // SCIQLOP_ARRAYDATAITERATOR_H
@@ -0,0 +1,52
1 #include "Data/ArrayDataIterator.h"
2
3 ArrayDataIteratorValue::ArrayDataIteratorValue(std::unique_ptr<ArrayDataIteratorValue::Impl> impl)
4 : m_Impl{std::move(impl)}
5 {
6 }
7
8 ArrayDataIteratorValue::ArrayDataIteratorValue(const ArrayDataIteratorValue &other)
9 : m_Impl{other.m_Impl->clone()}
10 {
11 }
12
13 ArrayDataIteratorValue &ArrayDataIteratorValue::operator=(ArrayDataIteratorValue other)
14 {
15 std::swap(m_Impl, other.m_Impl);
16 return *this;
17 }
18
19 bool ArrayDataIteratorValue::equals(const ArrayDataIteratorValue &other) const
20 {
21 return m_Impl->equals(*other.m_Impl);
22 }
23
24 void ArrayDataIteratorValue::next()
25 {
26 m_Impl->next();
27 }
28
29 void ArrayDataIteratorValue::prev()
30 {
31 m_Impl->prev();
32 }
33
34 double ArrayDataIteratorValue::at(int componentIndex) const
35 {
36 return m_Impl->at(componentIndex);
37 }
38
39 double ArrayDataIteratorValue::first() const
40 {
41 return m_Impl->first();
42 }
43
44 double ArrayDataIteratorValue::min() const
45 {
46 return m_Impl->min();
47 }
48
49 double ArrayDataIteratorValue::max() const
50 {
51 return m_Impl->max();
52 }
General Comments 0
You need to be logged in to leave comments. Login now