##// END OF EJS Templates
Updates DataSeriesIterator to make an iterator general to SciQlop
Alexandre Leroux -
r639:ec7e67b5ba15
parent child
Show More
@@ -0,0 +1,54
1 #ifndef SCIQLOP_SQPITERATOR_H
2 #define SCIQLOP_SQPITERATOR_H
3
4 #include "CoreGlobal.h"
5
6 /**
7 * @brief The SqpIterator class represents an iterator used in SciQlop. It defines all operators
8 * needed for a standard forward iterator
9 * @tparam T the type of object handled in iterator
10 * @sa http://www.cplusplus.com/reference/iterator/
11 */
12 template <typename T>
13 class SCIQLOP_CORE_EXPORT SqpIterator {
14 public:
15 using iterator_category = std::forward_iterator_tag;
16 using value_type = const T;
17 using difference_type = std::ptrdiff_t;
18 using pointer = value_type *;
19 using reference = value_type &;
20
21 explicit SqpIterator(T value) : m_CurrentValue{std::move(value)} {}
22
23 virtual ~SqpIterator() noexcept = default;
24 SqpIterator(const SqpIterator &) = default;
25 SqpIterator(SqpIterator &&) = default;
26 SqpIterator &operator=(const SqpIterator &) = default;
27 SqpIterator &operator=(SqpIterator &&) = default;
28
29 SqpIterator &operator++()
30 {
31 m_CurrentValue.next();
32 return *this;
33 }
34
35 SqpIterator &operator--()
36 {
37 m_CurrentValue.prev();
38 return *this;
39 }
40
41 pointer operator->() const { return &m_CurrentValue; }
42 reference operator*() const { return m_CurrentValue; }
43
44 bool operator==(const SqpIterator &other) const
45 {
46 return m_CurrentValue.equals(other.m_CurrentValue);
47 }
48 bool operator!=(const SqpIterator &other) const { return !(*this == other); }
49
50 private:
51 T m_CurrentValue;
52 };
53
54 #endif // SCIQLOP_SQPITERATOR_H
@@ -1,88 +1,60
1 #ifndef SCIQLOP_DATASERIESITERATOR_H
1 #ifndef SCIQLOP_DATASERIESITERATOR_H
2 #define SCIQLOP_DATASERIESITERATOR_H
2 #define SCIQLOP_DATASERIESITERATOR_H
3
3
4 #include "CoreGlobal.h"
4 #include "CoreGlobal.h"
5 #include "Data/SqpIterator.h"
5
6
6 #include <memory>
7 #include <memory>
7
8
8 /**
9 /**
9 * @brief The DataSeriesIteratorValue class represents the current value of a data series iterator.
10 * @brief The DataSeriesIteratorValue class represents the current value of a data series iterator.
10 * It offers standard access methods for the data in the series (x-axis, values), but it is up to
11 * It offers standard access methods for the data in the series (x-axis, values), but it is up to
11 * each series to define its own implementation of how to retrieve this data, by implementing the
12 * each series to define its own implementation of how to retrieve this data, by implementing the
12 * DataSeriesIteratorValue::Impl interface
13 * DataSeriesIteratorValue::Impl interface
13 *
14 *
14 * @sa DataSeriesIterator
15 * @sa DataSeriesIterator
15 */
16 */
16 class SCIQLOP_CORE_EXPORT DataSeriesIteratorValue {
17 class SCIQLOP_CORE_EXPORT DataSeriesIteratorValue {
17 public:
18 public:
18 struct Impl {
19 struct Impl {
19 virtual ~Impl() noexcept = default;
20 virtual ~Impl() noexcept = default;
20 virtual std::unique_ptr<Impl> clone() const = 0;
21 virtual std::unique_ptr<Impl> clone() const = 0;
21 virtual bool equals(const Impl &other) const = 0;
22 virtual bool equals(const Impl &other) const = 0;
22 virtual void next() = 0;
23 virtual void next() = 0;
23 virtual void prev() = 0;
24 virtual void prev() = 0;
24 virtual double x() const = 0;
25 virtual double x() const = 0;
25 virtual double value() const = 0;
26 virtual double value() const = 0;
26 virtual double value(int componentIndex) const = 0;
27 virtual double value(int componentIndex) const = 0;
27 virtual double minValue() const = 0;
28 virtual double minValue() const = 0;
28 virtual double maxValue() const = 0;
29 virtual double maxValue() const = 0;
29 };
30 };
30
31
31 explicit DataSeriesIteratorValue(std::unique_ptr<Impl> impl);
32 explicit DataSeriesIteratorValue(std::unique_ptr<Impl> impl);
32 DataSeriesIteratorValue(const DataSeriesIteratorValue &other);
33 DataSeriesIteratorValue(const DataSeriesIteratorValue &other);
33 DataSeriesIteratorValue(DataSeriesIteratorValue &&other) = default;
34 DataSeriesIteratorValue(DataSeriesIteratorValue &&other) = default;
34 DataSeriesIteratorValue &operator=(DataSeriesIteratorValue other);
35 DataSeriesIteratorValue &operator=(DataSeriesIteratorValue other);
35
36
36 bool equals(const DataSeriesIteratorValue &other) const;
37 bool equals(const DataSeriesIteratorValue &other) const;
37
38
38 /// Advances to the next value
39 /// Advances to the next value
39 void next();
40 void next();
40 /// Moves back to the previous value
41 /// Moves back to the previous value
41 void prev();
42 void prev();
42 /// Gets x-axis data
43 /// Gets x-axis data
43 double x() const;
44 double x() const;
44 /// Gets value data
45 /// Gets value data
45 double value() const;
46 double value() const;
46 /// Gets value data depending on an index
47 /// Gets value data depending on an index
47 double value(int componentIndex) const;
48 double value(int componentIndex) const;
48 /// Gets min of all values data
49 /// Gets min of all values data
49 double minValue() const;
50 double minValue() const;
50 /// Gets max of all values data
51 /// Gets max of all values data
51 double maxValue() const;
52 double maxValue() const;
52
53
53 private:
54 private:
54 std::unique_ptr<Impl> m_Impl;
55 std::unique_ptr<Impl> m_Impl;
55 };
56 };
56
57
57 /**
58 using DataSeriesIterator = SqpIterator<DataSeriesIteratorValue>;
58 * @brief The DataSeriesIterator class represents an iterator used for data series. It defines all
59 * operators needed for a standard forward iterator
60 * @sa http://www.cplusplus.com/reference/iterator/
61 */
62 class SCIQLOP_CORE_EXPORT DataSeriesIterator {
63 public:
64 using iterator_category = std::forward_iterator_tag;
65 using value_type = const DataSeriesIteratorValue;
66 using difference_type = std::ptrdiff_t;
67 using pointer = value_type *;
68 using reference = value_type &;
69
70 explicit DataSeriesIterator(DataSeriesIteratorValue value);
71 virtual ~DataSeriesIterator() noexcept = default;
72 DataSeriesIterator(const DataSeriesIterator &) = default;
73 DataSeriesIterator(DataSeriesIterator &&) = default;
74 DataSeriesIterator &operator=(const DataSeriesIterator &) = default;
75 DataSeriesIterator &operator=(DataSeriesIterator &&) = default;
76
77 DataSeriesIterator &operator++();
78 DataSeriesIterator &operator--();
79 pointer operator->() const { return &m_CurrentValue; }
80 reference operator*() const { return m_CurrentValue; }
81 bool operator==(const DataSeriesIterator &other) const;
82 bool operator!=(const DataSeriesIterator &other) const;
83
84 private:
85 DataSeriesIteratorValue m_CurrentValue;
86 };
87
59
88 #endif // SCIQLOP_DATASERIESITERATOR_H
60 #endif // SCIQLOP_DATASERIESITERATOR_H
@@ -1,85 +1,58
1 #include "Data/DataSeriesIterator.h"
1 #include "Data/DataSeriesIterator.h"
2
2
3 DataSeriesIteratorValue::DataSeriesIteratorValue(
3 DataSeriesIteratorValue::DataSeriesIteratorValue(
4 std::unique_ptr<DataSeriesIteratorValue::Impl> impl)
4 std::unique_ptr<DataSeriesIteratorValue::Impl> impl)
5 : m_Impl{std::move(impl)}
5 : m_Impl{std::move(impl)}
6 {
6 {
7 }
7 }
8
8
9 DataSeriesIteratorValue::DataSeriesIteratorValue(const DataSeriesIteratorValue &other)
9 DataSeriesIteratorValue::DataSeriesIteratorValue(const DataSeriesIteratorValue &other)
10 : m_Impl{other.m_Impl->clone()}
10 : m_Impl{other.m_Impl->clone()}
11 {
11 {
12 }
12 }
13
13
14 DataSeriesIteratorValue &DataSeriesIteratorValue::operator=(DataSeriesIteratorValue other)
14 DataSeriesIteratorValue &DataSeriesIteratorValue::operator=(DataSeriesIteratorValue other)
15 {
15 {
16 std::swap(m_Impl, other.m_Impl);
16 std::swap(m_Impl, other.m_Impl);
17 return *this;
17 return *this;
18 }
18 }
19
19
20 bool DataSeriesIteratorValue::equals(const DataSeriesIteratorValue &other) const
20 bool DataSeriesIteratorValue::equals(const DataSeriesIteratorValue &other) const
21 {
21 {
22 return m_Impl->equals(*other.m_Impl);
22 return m_Impl->equals(*other.m_Impl);
23 }
23 }
24
24
25 void DataSeriesIteratorValue::next()
25 void DataSeriesIteratorValue::next()
26 {
26 {
27 m_Impl->next();
27 m_Impl->next();
28 }
28 }
29
29
30 void DataSeriesIteratorValue::prev()
30 void DataSeriesIteratorValue::prev()
31 {
31 {
32 m_Impl->prev();
32 m_Impl->prev();
33 }
33 }
34
34
35 double DataSeriesIteratorValue::x() const
35 double DataSeriesIteratorValue::x() const
36 {
36 {
37 return m_Impl->x();
37 return m_Impl->x();
38 }
38 }
39
39
40 double DataSeriesIteratorValue::value() const
40 double DataSeriesIteratorValue::value() const
41 {
41 {
42 return m_Impl->value();
42 return m_Impl->value();
43 }
43 }
44
44
45 double DataSeriesIteratorValue::value(int componentIndex) const
45 double DataSeriesIteratorValue::value(int componentIndex) const
46 {
46 {
47 return m_Impl->value(componentIndex);
47 return m_Impl->value(componentIndex);
48 }
48 }
49
49
50 double DataSeriesIteratorValue::minValue() const
50 double DataSeriesIteratorValue::minValue() const
51 {
51 {
52 return m_Impl->minValue();
52 return m_Impl->minValue();
53 }
53 }
54
54
55 double DataSeriesIteratorValue::maxValue() const
55 double DataSeriesIteratorValue::maxValue() const
56 {
56 {
57 return m_Impl->maxValue();
57 return m_Impl->maxValue();
58 }
58 }
59
60 DataSeriesIterator::DataSeriesIterator(DataSeriesIteratorValue value)
61 : m_CurrentValue{std::move(value)}
62 {
63 }
64
65 DataSeriesIterator &DataSeriesIterator::operator++()
66 {
67 m_CurrentValue.next();
68 return *this;
69 }
70
71 DataSeriesIterator &DataSeriesIterator::operator--()
72 {
73 m_CurrentValue.prev();
74 return *this;
75 }
76
77 bool DataSeriesIterator::operator==(const DataSeriesIterator &other) const
78 {
79 return m_CurrentValue.equals(other.m_CurrentValue);
80 }
81
82 bool DataSeriesIterator::operator!=(const DataSeriesIterator &other) const
83 {
84 return !(*this == other);
85 }
General Comments 0
You need to be logged in to leave comments. Login now