@@ -58,6 +58,67 struct Sort<1> { | |||
|
58 | 58 | template <int Dim> |
|
59 | 59 | class ArrayData { |
|
60 | 60 | public: |
|
61 | class IteratorValue { | |
|
62 | public: | |
|
63 | explicit IteratorValue(const DataContainer &container, bool begin) : m_Its{} | |
|
64 | { | |
|
65 | for (auto i = 0; i < container.size(); ++i) { | |
|
66 | m_Its.push_back(begin ? container.at(i).cbegin() : container.at(i).cend()); | |
|
67 | } | |
|
68 | } | |
|
69 | ||
|
70 | double at(int index) const { return *m_Its.at(index); } | |
|
71 | double first() const { return *m_Its.front(); } | |
|
72 | ||
|
73 | void next() | |
|
74 | { | |
|
75 | for (auto &it : m_Its) { | |
|
76 | ++it; | |
|
77 | } | |
|
78 | } | |
|
79 | ||
|
80 | bool operator==(const IteratorValue &other) const { return m_Its == other.m_Its; } | |
|
81 | ||
|
82 | private: | |
|
83 | std::vector<DataContainer::value_type::const_iterator> m_Its; | |
|
84 | }; | |
|
85 | ||
|
86 | class Iterator { | |
|
87 | public: | |
|
88 | using iterator_category = std::forward_iterator_tag; | |
|
89 | using value_type = const IteratorValue; | |
|
90 | using difference_type = std::ptrdiff_t; | |
|
91 | using pointer = value_type *; | |
|
92 | using reference = value_type &; | |
|
93 | ||
|
94 | Iterator(const DataContainer &container, bool begin) : m_CurrentValue{container, begin} {} | |
|
95 | ||
|
96 | virtual ~Iterator() noexcept = default; | |
|
97 | Iterator(const Iterator &) = default; | |
|
98 | Iterator(Iterator &&) = default; | |
|
99 | Iterator &operator=(const Iterator &) = default; | |
|
100 | Iterator &operator=(Iterator &&) = default; | |
|
101 | ||
|
102 | Iterator &operator++() | |
|
103 | { | |
|
104 | m_CurrentValue.next(); | |
|
105 | return *this; | |
|
106 | } | |
|
107 | ||
|
108 | pointer operator->() const { return &m_CurrentValue; } | |
|
109 | reference operator*() const { return m_CurrentValue; } | |
|
110 | ||
|
111 | bool operator==(const Iterator &other) const | |
|
112 | { | |
|
113 | return m_CurrentValue == other.m_CurrentValue; | |
|
114 | } | |
|
115 | ||
|
116 | bool operator!=(const Iterator &other) const { return !(*this == other); } | |
|
117 | ||
|
118 | private: | |
|
119 | IteratorValue m_CurrentValue; | |
|
120 | }; | |
|
121 | ||
|
61 | 122 | // ///// // |
|
62 | 123 | // Ctors // |
|
63 | 124 | // ///// // |
@@ -184,6 +245,13 public: | |||
|
184 | 245 | return arraydata_detail::Sort<Dim>::sort(m_Data, sortPermutation); |
|
185 | 246 | } |
|
186 | 247 | |
|
248 | // ///////// // | |
|
249 | // Iterators // | |
|
250 | // ///////// // | |
|
251 | ||
|
252 | Iterator cbegin() const { return Iterator{m_Data, true}; } | |
|
253 | Iterator cend() const { return Iterator{m_Data, false}; } | |
|
254 | ||
|
187 | 255 | // ///////////// // |
|
188 | 256 | // 1-dim methods // |
|
189 | 257 | // ///////////// // |
@@ -29,6 +29,71 Q_LOGGING_CATEGORY(LOG_DataSeries, "DataSeries") | |||
|
29 | 29 | template <int Dim> |
|
30 | 30 | class DataSeries : public IDataSeries { |
|
31 | 31 | public: |
|
32 | class IteratorValue { | |
|
33 | public: | |
|
34 | explicit IteratorValue(const DataSeries &dataSeries, bool begin) | |
|
35 | : m_XIt(begin ? dataSeries.xAxisData()->cbegin() : dataSeries.xAxisData()->cend()), | |
|
36 | m_ValuesIt(begin ? dataSeries.valuesData()->cbegin() | |
|
37 | : dataSeries.valuesData()->cend()) | |
|
38 | { | |
|
39 | } | |
|
40 | ||
|
41 | double x() const { return m_XIt->at(0); } | |
|
42 | double value() const { return m_ValuesIt->at(0); } | |
|
43 | double value(int componentIndex) const { return m_ValuesIt->at(componentIndex); } | |
|
44 | ||
|
45 | void next() | |
|
46 | { | |
|
47 | ++m_XIt; | |
|
48 | ++m_ValuesIt; | |
|
49 | } | |
|
50 | ||
|
51 | bool operator==(const IteratorValue &other) const | |
|
52 | { | |
|
53 | return std::tie(m_XIt, m_ValuesIt) == std::tie(other.m_XIt, other.m_ValuesIt); | |
|
54 | } | |
|
55 | ||
|
56 | private: | |
|
57 | ArrayData<1>::Iterator m_XIt; | |
|
58 | typename ArrayData<Dim>::Iterator m_ValuesIt; | |
|
59 | }; | |
|
60 | ||
|
61 | class Iterator { | |
|
62 | public: | |
|
63 | using iterator_category = std::forward_iterator_tag; | |
|
64 | using value_type = const IteratorValue; | |
|
65 | using difference_type = std::ptrdiff_t; | |
|
66 | using pointer = value_type *; | |
|
67 | using reference = value_type &; | |
|
68 | ||
|
69 | Iterator(const DataSeries &dataSeries, bool begin) : m_CurrentValue{dataSeries, begin} {} | |
|
70 | virtual ~Iterator() noexcept = default; | |
|
71 | Iterator(const Iterator &) = default; | |
|
72 | Iterator(Iterator &&) = default; | |
|
73 | Iterator &operator=(const Iterator &) = default; | |
|
74 | Iterator &operator=(Iterator &&) = default; | |
|
75 | ||
|
76 | Iterator &operator++() | |
|
77 | { | |
|
78 | m_CurrentValue.next(); | |
|
79 | return *this; | |
|
80 | } | |
|
81 | ||
|
82 | pointer operator->() const { return &m_CurrentValue; } | |
|
83 | ||
|
84 | reference operator*() const { return m_CurrentValue; } | |
|
85 | ||
|
86 | bool operator==(const Iterator &other) const | |
|
87 | { | |
|
88 | return m_CurrentValue == other.m_CurrentValue; | |
|
89 | } | |
|
90 | ||
|
91 | bool operator!=(const Iterator &other) const { return !(*this == other); } | |
|
92 | ||
|
93 | private: | |
|
94 | IteratorValue m_CurrentValue; | |
|
95 | }; | |
|
96 | ||
|
32 | 97 | /// @sa IDataSeries::xAxisData() |
|
33 | 98 | std::shared_ptr<ArrayData<1> > xAxisData() override { return m_XAxisData; } |
|
34 | 99 | const std::shared_ptr<ArrayData<1> > xAxisData() const { return m_XAxisData; } |
@@ -119,6 +184,39 public: | |||
|
119 | 184 | dataSeries->unlock(); |
|
120 | 185 | } |
|
121 | 186 | |
|
187 | // ///////// // | |
|
188 | // Iterators // | |
|
189 | // ///////// // | |
|
190 | ||
|
191 | Iterator cbegin() const { return Iterator{*this, true}; } | |
|
192 | ||
|
193 | Iterator cend() const { return Iterator{*this, false}; } | |
|
194 | ||
|
195 | std::pair<Iterator, Iterator> subData(double min, double max) const | |
|
196 | { | |
|
197 | if (min > max) { | |
|
198 | std::swap(min, max); | |
|
199 | } | |
|
200 | ||
|
201 | auto begin = cbegin(); | |
|
202 | auto end = cend(); | |
|
203 | ||
|
204 | auto lowerIt | |
|
205 | = std::lower_bound(begin, end, min, [](const auto &itValue, const auto &value) { | |
|
206 | return itValue.x() == value; | |
|
207 | }); | |
|
208 | auto upperIt | |
|
209 | = std::upper_bound(begin, end, max, [](const auto &value, const auto &itValue) { | |
|
210 | return itValue.x() == value; | |
|
211 | }); | |
|
212 | ||
|
213 | return std::make_pair(lowerIt, upperIt); | |
|
214 | } | |
|
215 | ||
|
216 | // /////// // | |
|
217 | // Mutexes // | |
|
218 | // /////// // | |
|
219 | ||
|
122 | 220 | virtual void lockRead() { m_Lock.lockForRead(); } |
|
123 | 221 | virtual void lockWrite() { m_Lock.lockForWrite(); } |
|
124 | 222 | virtual void unlock() { m_Lock.unlock(); } |
@@ -56,7 +56,8 public: | |||
|
56 | 56 | virtual Unit valuesUnit() const = 0; |
|
57 | 57 | |
|
58 | 58 | virtual void merge(IDataSeries *dataSeries) = 0; |
|
59 | virtual std::shared_ptr<IDataSeries> subData(const SqpRange &range) = 0; | |
|
59 | /// @todo Review the name and signature of this method | |
|
60 | virtual std::shared_ptr<IDataSeries> subDataSeries(const SqpRange &range) = 0; | |
|
60 | 61 | |
|
61 | 62 | virtual std::unique_ptr<IDataSeries> clone() const = 0; |
|
62 | 63 | virtual SqpRange range() const = 0; |
@@ -21,7 +21,7 public: | |||
|
21 | 21 | |
|
22 | 22 | std::unique_ptr<IDataSeries> clone() const override; |
|
23 | 23 | |
|
24 | std::shared_ptr<IDataSeries> subData(const SqpRange &range) override; | |
|
24 | std::shared_ptr<IDataSeries> subDataSeries(const SqpRange &range) override; | |
|
25 | 25 | }; |
|
26 | 26 | |
|
27 | 27 | #endif // SCIQLOP_SCALARSERIES_H |
@@ -12,7 +12,7 std::unique_ptr<IDataSeries> ScalarSeries::clone() const | |||
|
12 | 12 | return std::make_unique<ScalarSeries>(*this); |
|
13 | 13 | } |
|
14 | 14 | |
|
15 | std::shared_ptr<IDataSeries> ScalarSeries::subData(const SqpRange &range) | |
|
15 | std::shared_ptr<IDataSeries> ScalarSeries::subDataSeries(const SqpRange &range) | |
|
16 | 16 | { |
|
17 | 17 | auto subXAxisData = QVector<double>(); |
|
18 | 18 | auto subValuesData = QVector<double>(); |
@@ -107,7 +107,7 void Variable::mergeDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept | |||
|
107 | 107 | impl->unlock(); |
|
108 | 108 | |
|
109 | 109 | // sub the data |
|
110 | auto subData = this->dataSeries()->subData(this->cacheRange()); | |
|
110 | auto subData = this->dataSeries()->subDataSeries(this->cacheRange()); | |
|
111 | 111 | qCDebug(LOG_Variable()) << "TORM: Variable::mergeDataSeries sub" << subData->range(); |
|
112 | 112 | this->setDataSeries(subData); |
|
113 | 113 | qCDebug(LOG_Variable()) << "TORM: Variable::mergeDataSeries set" << this->dataSeries()->range(); |
@@ -481,7 +481,7 void VariableController::VariableControllerPrivate::processRequest(std::shared_p | |||
|
481 | 481 | else { |
|
482 | 482 | var->setRange(rangeRequested); |
|
483 | 483 | var->setCacheRange(varRangesRequested.second); |
|
484 | var->setDataSeries(var->dataSeries()->subData(varRangesRequested.second)); | |
|
484 | var->setDataSeries(var->dataSeries()->subDataSeries(varRangesRequested.second)); | |
|
485 | 485 | emit var->updated(); |
|
486 | 486 | } |
|
487 | 487 | } |
@@ -11,6 +11,32 ArrayData\.h:\d+:.*IPSIS_S06.*found: (D) | |||
|
11 | 11 | ArrayData\.h:\d+:.*IPSIS_S06.*found: (Dim) |
|
12 | 12 | DataSeries\.h:\d+:.*IPSIS_S04_VARIABLE.* |
|
13 | 13 | |
|
14 | # Ignore false positive relative to iterators | |
|
15 | ArrayData\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (forward_iterator_tag) | |
|
16 | ArrayData\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (IteratorValue) | |
|
17 | ArrayData\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (ptrdiff_t) | |
|
18 | ArrayData\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (value_type) | |
|
19 | ArrayData\.h:\d+:.*IPSIS_S05.* | |
|
20 | ArrayData\.h:\d+:.*IPSIS_S06.*found: (iterator_category) | |
|
21 | ArrayData\.h:\d+:.*IPSIS_S06.*found: (forward_iterator_tag) | |
|
22 | ArrayData\.h:\d+:.*IPSIS_S06.*found: (value_type) | |
|
23 | ArrayData\.h:\d+:.*IPSIS_S06.*found: (IteratorValue) | |
|
24 | ArrayData\.h:\d+:.*IPSIS_S06.*found: (difference_type) | |
|
25 | ArrayData\.h:\d+:.*IPSIS_S06.*found: (ptrdiff_t) | |
|
26 | ArrayData\.h:\d+:.*IPSIS_S06.*found: (pointer) | |
|
27 | ArrayData\.h:\d+:.*IPSIS_S06.*found: (reference) | |
|
28 | ArrayData\.h:\d+:.*IPSIS_S06.*found: (value_type) | |
|
29 | DataSeries\.h:\d+:.*IPSIS_S05.* | |
|
30 | DataSeries\.h:\d+:.*IPSIS_S06.*found: (iterator_category) | |
|
31 | DataSeries\.h:\d+:.*IPSIS_S06.*found: (forward_iterator_tag) | |
|
32 | DataSeries\.h:\d+:.*IPSIS_S06.*found: (value_type) | |
|
33 | DataSeries\.h:\d+:.*IPSIS_S06.*found: (IteratorValue) | |
|
34 | DataSeries\.h:\d+:.*IPSIS_S06.*found: (difference_type) | |
|
35 | DataSeries\.h:\d+:.*IPSIS_S06.*found: (ptrdiff_t) | |
|
36 | DataSeries\.h:\d+:.*IPSIS_S06.*found: (pointer) | |
|
37 | DataSeries\.h:\d+:.*IPSIS_S06.*found: (reference) | |
|
38 | DataSeries\.h:\d+:.*IPSIS_S06.*found: (value_type) | |
|
39 | ||
|
14 | 40 | # Ignore false positive relative to an alias |
|
15 | 41 | DataSourceItemAction\.h:\d+:.*IPSIS_S06.*found: (ExecuteFunction) |
|
16 | 42 |
General Comments 0
You need to be logged in to leave comments.
Login now