##// END OF EJS Templates
Reads variable's metadata to retrieve the type of data series (scalar, vector, spectrogram)
Alexandre Leroux -
r1279:88939ef97b8f
parent child
Show More
@@ -1,89 +1,93
1 #ifndef SCIQLOP_VARIABLE_H
1 #ifndef SCIQLOP_VARIABLE_H
2 #define SCIQLOP_VARIABLE_H
2 #define SCIQLOP_VARIABLE_H
3
3
4 #include "CoreGlobal.h"
4 #include "CoreGlobal.h"
5
5
6 #include <Data/DataSeriesIterator.h>
6 #include <Data/DataSeriesIterator.h>
7 #include <Data/DataSeriesType.h>
7 #include <Data/SqpRange.h>
8 #include <Data/SqpRange.h>
8
9
9 #include <QLoggingCategory>
10 #include <QLoggingCategory>
10 #include <QObject>
11 #include <QObject>
11
12
12 #include <Common/MetaTypes.h>
13 #include <Common/MetaTypes.h>
13 #include <Common/spimpl.h>
14 #include <Common/spimpl.h>
14
15
15 Q_DECLARE_LOGGING_CATEGORY(LOG_Variable)
16 Q_DECLARE_LOGGING_CATEGORY(LOG_Variable)
16
17
17 class IDataSeries;
18 class IDataSeries;
18 class QString;
19 class QString;
19
20
20 /**
21 /**
21 * @brief The Variable class represents a variable in SciQlop.
22 * @brief The Variable class represents a variable in SciQlop.
22 */
23 */
23 class SCIQLOP_CORE_EXPORT Variable : public QObject {
24 class SCIQLOP_CORE_EXPORT Variable : public QObject {
24
25
25 Q_OBJECT
26 Q_OBJECT
26
27
27 public:
28 public:
28 explicit Variable(const QString &name, const QVariantHash &metadata = {});
29 explicit Variable(const QString &name, const QVariantHash &metadata = {});
29
30
30 /// Copy ctor
31 /// Copy ctor
31 explicit Variable(const Variable &other);
32 explicit Variable(const Variable &other);
32
33
33 std::shared_ptr<Variable> clone() const;
34 std::shared_ptr<Variable> clone() const;
34
35
35 QString name() const noexcept;
36 QString name() const noexcept;
36 void setName(const QString &name) noexcept;
37 void setName(const QString &name) noexcept;
37 SqpRange range() const noexcept;
38 SqpRange range() const noexcept;
38 void setRange(const SqpRange &range) noexcept;
39 void setRange(const SqpRange &range) noexcept;
39 SqpRange cacheRange() const noexcept;
40 SqpRange cacheRange() const noexcept;
40 void setCacheRange(const SqpRange &cacheRange) noexcept;
41 void setCacheRange(const SqpRange &cacheRange) noexcept;
41
42
42 /// @return the number of points hold by the variable. The number of points is updated each time
43 /// @return the number of points hold by the variable. The number of points is updated each time
43 /// the data series changes
44 /// the data series changes
44 int nbPoints() const noexcept;
45 int nbPoints() const noexcept;
45
46
46 /// Returns the real range of the variable, i.e. the min and max x-axis values of the data
47 /// Returns the real range of the variable, i.e. the min and max x-axis values of the data
47 /// series between the range of the variable. The real range is updated each time the variable
48 /// series between the range of the variable. The real range is updated each time the variable
48 /// range or the data series changed
49 /// range or the data series changed
49 /// @return the real range, invalid range if the data series is null or empty
50 /// @return the real range, invalid range if the data series is null or empty
50 /// @sa setDataSeries()
51 /// @sa setDataSeries()
51 /// @sa setRange()
52 /// @sa setRange()
52 SqpRange realRange() const noexcept;
53 SqpRange realRange() const noexcept;
53
54
54 /// @return the data of the variable, nullptr if there is no data
55 /// @return the data of the variable, nullptr if there is no data
55 std::shared_ptr<IDataSeries> dataSeries() const noexcept;
56 std::shared_ptr<IDataSeries> dataSeries() const noexcept;
56
57
58 /// @return the type of data that the variable holds
59 DataSeriesType type() const noexcept;
60
57 QVariantHash metadata() const noexcept;
61 QVariantHash metadata() const noexcept;
58
62
59 bool contains(const SqpRange &range) const noexcept;
63 bool contains(const SqpRange &range) const noexcept;
60 bool intersect(const SqpRange &range) const noexcept;
64 bool intersect(const SqpRange &range) const noexcept;
61 bool isInside(const SqpRange &range) const noexcept;
65 bool isInside(const SqpRange &range) const noexcept;
62
66
63 bool cacheContains(const SqpRange &range) const noexcept;
67 bool cacheContains(const SqpRange &range) const noexcept;
64 bool cacheIntersect(const SqpRange &range) const noexcept;
68 bool cacheIntersect(const SqpRange &range) const noexcept;
65 bool cacheIsInside(const SqpRange &range) const noexcept;
69 bool cacheIsInside(const SqpRange &range) const noexcept;
66
70
67 QVector<SqpRange> provideNotInCacheRangeList(const SqpRange &range) const noexcept;
71 QVector<SqpRange> provideNotInCacheRangeList(const SqpRange &range) const noexcept;
68 QVector<SqpRange> provideInCacheRangeList(const SqpRange &range) const noexcept;
72 QVector<SqpRange> provideInCacheRangeList(const SqpRange &range) const noexcept;
69 void mergeDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
73 void mergeDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
70
74
71 static QVector<SqpRange> provideNotInCacheRangeList(const SqpRange &oldRange,
75 static QVector<SqpRange> provideNotInCacheRangeList(const SqpRange &oldRange,
72 const SqpRange &nextRange);
76 const SqpRange &nextRange);
73
77
74 static QVector<SqpRange> provideInCacheRangeList(const SqpRange &oldRange,
78 static QVector<SqpRange> provideInCacheRangeList(const SqpRange &oldRange,
75 const SqpRange &nextRange);
79 const SqpRange &nextRange);
76
80
77 signals:
81 signals:
78 void updated();
82 void updated();
79
83
80 private:
84 private:
81 class VariablePrivate;
85 class VariablePrivate;
82 spimpl::unique_impl_ptr<VariablePrivate> impl;
86 spimpl::unique_impl_ptr<VariablePrivate> impl;
83 };
87 };
84
88
85 // Required for using shared_ptr in signals/slots
89 // Required for using shared_ptr in signals/slots
86 SCIQLOP_REGISTER_META_TYPE(VARIABLE_PTR_REGISTRY, std::shared_ptr<Variable>)
90 SCIQLOP_REGISTER_META_TYPE(VARIABLE_PTR_REGISTRY, std::shared_ptr<Variable>)
87 SCIQLOP_REGISTER_META_TYPE(VARIABLE_PTR_VECTOR_REGISTRY, QVector<std::shared_ptr<Variable> >)
91 SCIQLOP_REGISTER_META_TYPE(VARIABLE_PTR_VECTOR_REGISTRY, QVector<std::shared_ptr<Variable> >)
88
92
89 #endif // SCIQLOP_VARIABLE_H
93 #endif // SCIQLOP_VARIABLE_H
@@ -1,388 +1,423
1 #include "Variable/Variable.h"
1 #include "Variable/Variable.h"
2
2
3 #include <Data/IDataSeries.h>
3 #include <Data/IDataSeries.h>
4 #include <Data/SqpRange.h>
4 #include <Data/SqpRange.h>
5
5
6 #include <QMutex>
6 #include <QMutex>
7 #include <QReadWriteLock>
7 #include <QReadWriteLock>
8 #include <QThread>
8 #include <QThread>
9
9
10 Q_LOGGING_CATEGORY(LOG_Variable, "Variable")
10 Q_LOGGING_CATEGORY(LOG_Variable, "Variable")
11
11
12 namespace {
13
14 /**
15 * Searches in metadata for a value that can be converted to DataSeriesType
16 * @param metadata the metadata where to search
17 * @return the value converted to a DataSeriesType if it was found, UNKNOWN type otherwise
18 * @sa DataSeriesType
19 */
20 DataSeriesType findDataSeriesType(const QVariantHash &metadata)
21 {
22 auto dataSeriesType = DataSeriesType::UNKNOWN;
23
24 // Go through the metadata and stop at the first value that could be converted to DataSeriesType
25 for (auto it = metadata.cbegin(), end = metadata.cend();
26 it != end && dataSeriesType == DataSeriesType::UNKNOWN; ++it) {
27 dataSeriesType = DataSeriesTypeUtils::fromString(it.value().toString());
28 }
29
30 return dataSeriesType;
31 }
32
33 } // namespace
34
12 struct Variable::VariablePrivate {
35 struct Variable::VariablePrivate {
13 explicit VariablePrivate(const QString &name, const QVariantHash &metadata)
36 explicit VariablePrivate(const QString &name, const QVariantHash &metadata)
14 : m_Name{name},
37 : m_Name{name},
15 m_Range{INVALID_RANGE},
38 m_Range{INVALID_RANGE},
16 m_CacheRange{INVALID_RANGE},
39 m_CacheRange{INVALID_RANGE},
17 m_Metadata{metadata},
40 m_Metadata{metadata},
18 m_DataSeries{nullptr},
41 m_DataSeries{nullptr},
19 m_RealRange{INVALID_RANGE},
42 m_RealRange{INVALID_RANGE},
20 m_NbPoints{0}
43 m_NbPoints{0},
44 m_Type{findDataSeriesType(m_Metadata)}
21 {
45 {
22 }
46 }
23
47
24 VariablePrivate(const VariablePrivate &other)
48 VariablePrivate(const VariablePrivate &other)
25 : m_Name{other.m_Name},
49 : m_Name{other.m_Name},
26 m_Range{other.m_Range},
50 m_Range{other.m_Range},
27 m_CacheRange{other.m_CacheRange},
51 m_CacheRange{other.m_CacheRange},
28 m_Metadata{other.m_Metadata},
52 m_Metadata{other.m_Metadata},
29 m_DataSeries{other.m_DataSeries != nullptr ? other.m_DataSeries->clone() : nullptr},
53 m_DataSeries{other.m_DataSeries != nullptr ? other.m_DataSeries->clone() : nullptr},
30 m_RealRange{other.m_RealRange},
54 m_RealRange{other.m_RealRange},
31 m_NbPoints{other.m_NbPoints}
55 m_NbPoints{other.m_NbPoints},
56 m_Type{findDataSeriesType(m_Metadata)}
32 {
57 {
33 }
58 }
34
59
35 void lockRead() { m_Lock.lockForRead(); }
60 void lockRead() { m_Lock.lockForRead(); }
36 void lockWrite() { m_Lock.lockForWrite(); }
61 void lockWrite() { m_Lock.lockForWrite(); }
37 void unlock() { m_Lock.unlock(); }
62 void unlock() { m_Lock.unlock(); }
38
63
39 void purgeDataSeries()
64 void purgeDataSeries()
40 {
65 {
41 if (m_DataSeries) {
66 if (m_DataSeries) {
42 m_DataSeries->purge(m_CacheRange.m_TStart, m_CacheRange.m_TEnd);
67 m_DataSeries->purge(m_CacheRange.m_TStart, m_CacheRange.m_TEnd);
43 }
68 }
44 updateRealRange();
69 updateRealRange();
45 updateNbPoints();
70 updateNbPoints();
46 }
71 }
47
72
48 void updateNbPoints() { m_NbPoints = m_DataSeries ? m_DataSeries->nbPoints() : 0; }
73 void updateNbPoints() { m_NbPoints = m_DataSeries ? m_DataSeries->nbPoints() : 0; }
49
74
50 /// Updates real range according to current variable range and data series
75 /// Updates real range according to current variable range and data series
51 void updateRealRange()
76 void updateRealRange()
52 {
77 {
53 if (m_DataSeries) {
78 if (m_DataSeries) {
54 m_DataSeries->lockRead();
79 m_DataSeries->lockRead();
55 auto end = m_DataSeries->cend();
80 auto end = m_DataSeries->cend();
56 auto minXAxisIt = m_DataSeries->minXAxisData(m_Range.m_TStart);
81 auto minXAxisIt = m_DataSeries->minXAxisData(m_Range.m_TStart);
57 auto maxXAxisIt = m_DataSeries->maxXAxisData(m_Range.m_TEnd);
82 auto maxXAxisIt = m_DataSeries->maxXAxisData(m_Range.m_TEnd);
58
83
59 m_RealRange
84 m_RealRange
60 = (minXAxisIt != end && maxXAxisIt != end && minXAxisIt->x() <= maxXAxisIt->x())
85 = (minXAxisIt != end && maxXAxisIt != end && minXAxisIt->x() <= maxXAxisIt->x())
61 ? SqpRange{minXAxisIt->x(), maxXAxisIt->x()}
86 ? SqpRange{minXAxisIt->x(), maxXAxisIt->x()}
62 : INVALID_RANGE;
87 : INVALID_RANGE;
63 m_DataSeries->unlock();
88 m_DataSeries->unlock();
64 }
89 }
65 else {
90 else {
66 m_RealRange = INVALID_RANGE;
91 m_RealRange = INVALID_RANGE;
67 }
92 }
68 }
93 }
69
94
70 QString m_Name;
95 QString m_Name;
71
96
72 SqpRange m_Range;
97 SqpRange m_Range;
73 SqpRange m_CacheRange;
98 SqpRange m_CacheRange;
74 QVariantHash m_Metadata;
99 QVariantHash m_Metadata;
75 std::shared_ptr<IDataSeries> m_DataSeries;
100 std::shared_ptr<IDataSeries> m_DataSeries;
76 SqpRange m_RealRange;
101 SqpRange m_RealRange;
77 int m_NbPoints;
102 int m_NbPoints;
103 DataSeriesType m_Type;
78
104
79 QReadWriteLock m_Lock;
105 QReadWriteLock m_Lock;
80 };
106 };
81
107
82 Variable::Variable(const QString &name, const QVariantHash &metadata)
108 Variable::Variable(const QString &name, const QVariantHash &metadata)
83 : impl{spimpl::make_unique_impl<VariablePrivate>(name, metadata)}
109 : impl{spimpl::make_unique_impl<VariablePrivate>(name, metadata)}
84 {
110 {
85 }
111 }
86
112
87 Variable::Variable(const Variable &other)
113 Variable::Variable(const Variable &other)
88 : impl{spimpl::make_unique_impl<VariablePrivate>(*other.impl)}
114 : impl{spimpl::make_unique_impl<VariablePrivate>(*other.impl)}
89 {
115 {
90 }
116 }
91
117
92 std::shared_ptr<Variable> Variable::clone() const
118 std::shared_ptr<Variable> Variable::clone() const
93 {
119 {
94 return std::make_shared<Variable>(*this);
120 return std::make_shared<Variable>(*this);
95 }
121 }
96
122
97 QString Variable::name() const noexcept
123 QString Variable::name() const noexcept
98 {
124 {
99 impl->lockRead();
125 impl->lockRead();
100 auto name = impl->m_Name;
126 auto name = impl->m_Name;
101 impl->unlock();
127 impl->unlock();
102 return name;
128 return name;
103 }
129 }
104
130
105 void Variable::setName(const QString &name) noexcept
131 void Variable::setName(const QString &name) noexcept
106 {
132 {
107 impl->lockWrite();
133 impl->lockWrite();
108 impl->m_Name = name;
134 impl->m_Name = name;
109 impl->unlock();
135 impl->unlock();
110 }
136 }
111
137
112 SqpRange Variable::range() const noexcept
138 SqpRange Variable::range() const noexcept
113 {
139 {
114 impl->lockRead();
140 impl->lockRead();
115 auto range = impl->m_Range;
141 auto range = impl->m_Range;
116 impl->unlock();
142 impl->unlock();
117 return range;
143 return range;
118 }
144 }
119
145
120 void Variable::setRange(const SqpRange &range) noexcept
146 void Variable::setRange(const SqpRange &range) noexcept
121 {
147 {
122 impl->lockWrite();
148 impl->lockWrite();
123 impl->m_Range = range;
149 impl->m_Range = range;
124 impl->updateRealRange();
150 impl->updateRealRange();
125 impl->unlock();
151 impl->unlock();
126 }
152 }
127
153
128 SqpRange Variable::cacheRange() const noexcept
154 SqpRange Variable::cacheRange() const noexcept
129 {
155 {
130 impl->lockRead();
156 impl->lockRead();
131 auto cacheRange = impl->m_CacheRange;
157 auto cacheRange = impl->m_CacheRange;
132 impl->unlock();
158 impl->unlock();
133 return cacheRange;
159 return cacheRange;
134 }
160 }
135
161
136 void Variable::setCacheRange(const SqpRange &cacheRange) noexcept
162 void Variable::setCacheRange(const SqpRange &cacheRange) noexcept
137 {
163 {
138 impl->lockWrite();
164 impl->lockWrite();
139 if (cacheRange != impl->m_CacheRange) {
165 if (cacheRange != impl->m_CacheRange) {
140 impl->m_CacheRange = cacheRange;
166 impl->m_CacheRange = cacheRange;
141 }
167 }
142 impl->unlock();
168 impl->unlock();
143 }
169 }
144
170
145 int Variable::nbPoints() const noexcept
171 int Variable::nbPoints() const noexcept
146 {
172 {
147 return impl->m_NbPoints;
173 return impl->m_NbPoints;
148 }
174 }
149
175
150 SqpRange Variable::realRange() const noexcept
176 SqpRange Variable::realRange() const noexcept
151 {
177 {
152 return impl->m_RealRange;
178 return impl->m_RealRange;
153 }
179 }
154
180
155 void Variable::mergeDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept
181 void Variable::mergeDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept
156 {
182 {
157 qCDebug(LOG_Variable()) << "TORM Variable::mergeDataSeries"
183 qCDebug(LOG_Variable()) << "TORM Variable::mergeDataSeries"
158 << QThread::currentThread()->objectName();
184 << QThread::currentThread()->objectName();
159 if (!dataSeries) {
185 if (!dataSeries) {
160 /// @todo ALX : log
186 /// @todo ALX : log
161 return;
187 return;
162 }
188 }
163
189
164 // Add or merge the data
190 // Add or merge the data
165 impl->lockWrite();
191 impl->lockWrite();
166 if (!impl->m_DataSeries) {
192 if (!impl->m_DataSeries) {
167 impl->m_DataSeries = dataSeries->clone();
193 impl->m_DataSeries = dataSeries->clone();
168 }
194 }
169 else {
195 else {
170 impl->m_DataSeries->merge(dataSeries.get());
196 impl->m_DataSeries->merge(dataSeries.get());
171 }
197 }
172 impl->purgeDataSeries();
198 impl->purgeDataSeries();
173 impl->unlock();
199 impl->unlock();
174 }
200 }
175
201
176
202
177 std::shared_ptr<IDataSeries> Variable::dataSeries() const noexcept
203 std::shared_ptr<IDataSeries> Variable::dataSeries() const noexcept
178 {
204 {
179 impl->lockRead();
205 impl->lockRead();
180 auto dataSeries = impl->m_DataSeries;
206 auto dataSeries = impl->m_DataSeries;
181 impl->unlock();
207 impl->unlock();
182
208
183 return dataSeries;
209 return dataSeries;
184 }
210 }
185
211
212 DataSeriesType Variable::type() const noexcept
213 {
214 impl->lockRead();
215 auto type = impl->m_Type;
216 impl->unlock();
217
218 return type;
219 }
220
186 QVariantHash Variable::metadata() const noexcept
221 QVariantHash Variable::metadata() const noexcept
187 {
222 {
188 impl->lockRead();
223 impl->lockRead();
189 auto metadata = impl->m_Metadata;
224 auto metadata = impl->m_Metadata;
190 impl->unlock();
225 impl->unlock();
191 return metadata;
226 return metadata;
192 }
227 }
193
228
194 bool Variable::contains(const SqpRange &range) const noexcept
229 bool Variable::contains(const SqpRange &range) const noexcept
195 {
230 {
196 impl->lockRead();
231 impl->lockRead();
197 auto res = impl->m_Range.contains(range);
232 auto res = impl->m_Range.contains(range);
198 impl->unlock();
233 impl->unlock();
199 return res;
234 return res;
200 }
235 }
201
236
202 bool Variable::intersect(const SqpRange &range) const noexcept
237 bool Variable::intersect(const SqpRange &range) const noexcept
203 {
238 {
204
239
205 impl->lockRead();
240 impl->lockRead();
206 auto res = impl->m_Range.intersect(range);
241 auto res = impl->m_Range.intersect(range);
207 impl->unlock();
242 impl->unlock();
208 return res;
243 return res;
209 }
244 }
210
245
211 bool Variable::isInside(const SqpRange &range) const noexcept
246 bool Variable::isInside(const SqpRange &range) const noexcept
212 {
247 {
213 impl->lockRead();
248 impl->lockRead();
214 auto res = range.contains(SqpRange{impl->m_Range.m_TStart, impl->m_Range.m_TEnd});
249 auto res = range.contains(SqpRange{impl->m_Range.m_TStart, impl->m_Range.m_TEnd});
215 impl->unlock();
250 impl->unlock();
216 return res;
251 return res;
217 }
252 }
218
253
219 bool Variable::cacheContains(const SqpRange &range) const noexcept
254 bool Variable::cacheContains(const SqpRange &range) const noexcept
220 {
255 {
221 impl->lockRead();
256 impl->lockRead();
222 auto res = impl->m_CacheRange.contains(range);
257 auto res = impl->m_CacheRange.contains(range);
223 impl->unlock();
258 impl->unlock();
224 return res;
259 return res;
225 }
260 }
226
261
227 bool Variable::cacheIntersect(const SqpRange &range) const noexcept
262 bool Variable::cacheIntersect(const SqpRange &range) const noexcept
228 {
263 {
229 impl->lockRead();
264 impl->lockRead();
230 auto res = impl->m_CacheRange.intersect(range);
265 auto res = impl->m_CacheRange.intersect(range);
231 impl->unlock();
266 impl->unlock();
232 return res;
267 return res;
233 }
268 }
234
269
235 bool Variable::cacheIsInside(const SqpRange &range) const noexcept
270 bool Variable::cacheIsInside(const SqpRange &range) const noexcept
236 {
271 {
237 impl->lockRead();
272 impl->lockRead();
238 auto res = range.contains(SqpRange{impl->m_CacheRange.m_TStart, impl->m_CacheRange.m_TEnd});
273 auto res = range.contains(SqpRange{impl->m_CacheRange.m_TStart, impl->m_CacheRange.m_TEnd});
239 impl->unlock();
274 impl->unlock();
240 return res;
275 return res;
241 }
276 }
242
277
243
278
244 QVector<SqpRange> Variable::provideNotInCacheRangeList(const SqpRange &range) const noexcept
279 QVector<SqpRange> Variable::provideNotInCacheRangeList(const SqpRange &range) const noexcept
245 {
280 {
246 // This code assume that cach in contigue. Can return 0, 1 or 2 SqpRange
281 // This code assume that cach in contigue. Can return 0, 1 or 2 SqpRange
247 auto notInCache = QVector<SqpRange>{};
282 auto notInCache = QVector<SqpRange>{};
248 if (impl->m_CacheRange != INVALID_RANGE) {
283 if (impl->m_CacheRange != INVALID_RANGE) {
249
284
250 if (!this->cacheContains(range)) {
285 if (!this->cacheContains(range)) {
251 if (range.m_TEnd <= impl->m_CacheRange.m_TStart
286 if (range.m_TEnd <= impl->m_CacheRange.m_TStart
252 || range.m_TStart >= impl->m_CacheRange.m_TEnd) {
287 || range.m_TStart >= impl->m_CacheRange.m_TEnd) {
253 notInCache << range;
288 notInCache << range;
254 }
289 }
255 else if (range.m_TStart < impl->m_CacheRange.m_TStart
290 else if (range.m_TStart < impl->m_CacheRange.m_TStart
256 && range.m_TEnd <= impl->m_CacheRange.m_TEnd) {
291 && range.m_TEnd <= impl->m_CacheRange.m_TEnd) {
257 notInCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TStart};
292 notInCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TStart};
258 }
293 }
259 else if (range.m_TStart < impl->m_CacheRange.m_TStart
294 else if (range.m_TStart < impl->m_CacheRange.m_TStart
260 && range.m_TEnd > impl->m_CacheRange.m_TEnd) {
295 && range.m_TEnd > impl->m_CacheRange.m_TEnd) {
261 notInCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TStart}
296 notInCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TStart}
262 << SqpRange{impl->m_CacheRange.m_TEnd, range.m_TEnd};
297 << SqpRange{impl->m_CacheRange.m_TEnd, range.m_TEnd};
263 }
298 }
264 else if (range.m_TStart < impl->m_CacheRange.m_TEnd) {
299 else if (range.m_TStart < impl->m_CacheRange.m_TEnd) {
265 notInCache << SqpRange{impl->m_CacheRange.m_TEnd, range.m_TEnd};
300 notInCache << SqpRange{impl->m_CacheRange.m_TEnd, range.m_TEnd};
266 }
301 }
267 else {
302 else {
268 qCCritical(LOG_Variable()) << tr("Detection of unknown case.")
303 qCCritical(LOG_Variable()) << tr("Detection of unknown case.")
269 << QThread::currentThread();
304 << QThread::currentThread();
270 }
305 }
271 }
306 }
272 }
307 }
273 else {
308 else {
274 notInCache << range;
309 notInCache << range;
275 }
310 }
276
311
277 return notInCache;
312 return notInCache;
278 }
313 }
279
314
280 QVector<SqpRange> Variable::provideInCacheRangeList(const SqpRange &range) const noexcept
315 QVector<SqpRange> Variable::provideInCacheRangeList(const SqpRange &range) const noexcept
281 {
316 {
282 // This code assume that cach in contigue. Can return 0 or 1 SqpRange
317 // This code assume that cach in contigue. Can return 0 or 1 SqpRange
283
318
284 auto inCache = QVector<SqpRange>{};
319 auto inCache = QVector<SqpRange>{};
285
320
286 if (impl->m_CacheRange != INVALID_RANGE) {
321 if (impl->m_CacheRange != INVALID_RANGE) {
287
322
288 if (this->cacheIntersect(range)) {
323 if (this->cacheIntersect(range)) {
289 if (range.m_TStart <= impl->m_CacheRange.m_TStart
324 if (range.m_TStart <= impl->m_CacheRange.m_TStart
290 && range.m_TEnd >= impl->m_CacheRange.m_TStart
325 && range.m_TEnd >= impl->m_CacheRange.m_TStart
291 && range.m_TEnd < impl->m_CacheRange.m_TEnd) {
326 && range.m_TEnd < impl->m_CacheRange.m_TEnd) {
292 inCache << SqpRange{impl->m_CacheRange.m_TStart, range.m_TEnd};
327 inCache << SqpRange{impl->m_CacheRange.m_TStart, range.m_TEnd};
293 }
328 }
294
329
295 else if (range.m_TStart >= impl->m_CacheRange.m_TStart
330 else if (range.m_TStart >= impl->m_CacheRange.m_TStart
296 && range.m_TEnd <= impl->m_CacheRange.m_TEnd) {
331 && range.m_TEnd <= impl->m_CacheRange.m_TEnd) {
297 inCache << range;
332 inCache << range;
298 }
333 }
299 else if (range.m_TStart > impl->m_CacheRange.m_TStart
334 else if (range.m_TStart > impl->m_CacheRange.m_TStart
300 && range.m_TEnd > impl->m_CacheRange.m_TEnd) {
335 && range.m_TEnd > impl->m_CacheRange.m_TEnd) {
301 inCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TEnd};
336 inCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TEnd};
302 }
337 }
303 else if (range.m_TStart <= impl->m_CacheRange.m_TStart
338 else if (range.m_TStart <= impl->m_CacheRange.m_TStart
304 && range.m_TEnd >= impl->m_CacheRange.m_TEnd) {
339 && range.m_TEnd >= impl->m_CacheRange.m_TEnd) {
305 inCache << impl->m_CacheRange;
340 inCache << impl->m_CacheRange;
306 }
341 }
307 else {
342 else {
308 qCCritical(LOG_Variable()) << tr("Detection of unknown case.")
343 qCCritical(LOG_Variable()) << tr("Detection of unknown case.")
309 << QThread::currentThread();
344 << QThread::currentThread();
310 }
345 }
311 }
346 }
312 }
347 }
313
348
314 return inCache;
349 return inCache;
315 }
350 }
316
351
317
352
318 QVector<SqpRange> Variable::provideNotInCacheRangeList(const SqpRange &oldRange,
353 QVector<SqpRange> Variable::provideNotInCacheRangeList(const SqpRange &oldRange,
319 const SqpRange &nextRange)
354 const SqpRange &nextRange)
320 {
355 {
321
356
322 // This code assume that cach in contigue. Can return 0, 1 or 2 SqpRange
357 // This code assume that cach in contigue. Can return 0, 1 or 2 SqpRange
323 auto notInCache = QVector<SqpRange>{};
358 auto notInCache = QVector<SqpRange>{};
324 if (oldRange != INVALID_RANGE) {
359 if (oldRange != INVALID_RANGE) {
325
360
326 if (!oldRange.contains(nextRange)) {
361 if (!oldRange.contains(nextRange)) {
327 if (nextRange.m_TEnd <= oldRange.m_TStart || nextRange.m_TStart >= oldRange.m_TEnd) {
362 if (nextRange.m_TEnd <= oldRange.m_TStart || nextRange.m_TStart >= oldRange.m_TEnd) {
328 notInCache << nextRange;
363 notInCache << nextRange;
329 }
364 }
330 else if (nextRange.m_TStart < oldRange.m_TStart
365 else if (nextRange.m_TStart < oldRange.m_TStart
331 && nextRange.m_TEnd <= oldRange.m_TEnd) {
366 && nextRange.m_TEnd <= oldRange.m_TEnd) {
332 notInCache << SqpRange{nextRange.m_TStart, oldRange.m_TStart};
367 notInCache << SqpRange{nextRange.m_TStart, oldRange.m_TStart};
333 }
368 }
334 else if (nextRange.m_TStart < oldRange.m_TStart && nextRange.m_TEnd > oldRange.m_TEnd) {
369 else if (nextRange.m_TStart < oldRange.m_TStart && nextRange.m_TEnd > oldRange.m_TEnd) {
335 notInCache << SqpRange{nextRange.m_TStart, oldRange.m_TStart}
370 notInCache << SqpRange{nextRange.m_TStart, oldRange.m_TStart}
336 << SqpRange{oldRange.m_TEnd, nextRange.m_TEnd};
371 << SqpRange{oldRange.m_TEnd, nextRange.m_TEnd};
337 }
372 }
338 else if (nextRange.m_TStart < oldRange.m_TEnd) {
373 else if (nextRange.m_TStart < oldRange.m_TEnd) {
339 notInCache << SqpRange{oldRange.m_TEnd, nextRange.m_TEnd};
374 notInCache << SqpRange{oldRange.m_TEnd, nextRange.m_TEnd};
340 }
375 }
341 else {
376 else {
342 qCCritical(LOG_Variable()) << tr("Detection of unknown case.")
377 qCCritical(LOG_Variable()) << tr("Detection of unknown case.")
343 << QThread::currentThread();
378 << QThread::currentThread();
344 }
379 }
345 }
380 }
346 }
381 }
347 else {
382 else {
348 notInCache << nextRange;
383 notInCache << nextRange;
349 }
384 }
350
385
351 return notInCache;
386 return notInCache;
352 }
387 }
353
388
354 QVector<SqpRange> Variable::provideInCacheRangeList(const SqpRange &oldRange,
389 QVector<SqpRange> Variable::provideInCacheRangeList(const SqpRange &oldRange,
355 const SqpRange &nextRange)
390 const SqpRange &nextRange)
356 {
391 {
357 // This code assume that cach is contigue. Can return 0 or 1 SqpRange
392 // This code assume that cach is contigue. Can return 0 or 1 SqpRange
358
393
359 auto inCache = QVector<SqpRange>{};
394 auto inCache = QVector<SqpRange>{};
360
395
361 if (oldRange != INVALID_RANGE) {
396 if (oldRange != INVALID_RANGE) {
362
397
363 if (oldRange.intersect(nextRange)) {
398 if (oldRange.intersect(nextRange)) {
364 if (nextRange.m_TStart <= oldRange.m_TStart && nextRange.m_TEnd >= oldRange.m_TStart
399 if (nextRange.m_TStart <= oldRange.m_TStart && nextRange.m_TEnd >= oldRange.m_TStart
365 && nextRange.m_TEnd < oldRange.m_TEnd) {
400 && nextRange.m_TEnd < oldRange.m_TEnd) {
366 inCache << SqpRange{oldRange.m_TStart, nextRange.m_TEnd};
401 inCache << SqpRange{oldRange.m_TStart, nextRange.m_TEnd};
367 }
402 }
368
403
369 else if (nextRange.m_TStart >= oldRange.m_TStart
404 else if (nextRange.m_TStart >= oldRange.m_TStart
370 && nextRange.m_TEnd <= oldRange.m_TEnd) {
405 && nextRange.m_TEnd <= oldRange.m_TEnd) {
371 inCache << nextRange;
406 inCache << nextRange;
372 }
407 }
373 else if (nextRange.m_TStart > oldRange.m_TStart && nextRange.m_TEnd > oldRange.m_TEnd) {
408 else if (nextRange.m_TStart > oldRange.m_TStart && nextRange.m_TEnd > oldRange.m_TEnd) {
374 inCache << SqpRange{nextRange.m_TStart, oldRange.m_TEnd};
409 inCache << SqpRange{nextRange.m_TStart, oldRange.m_TEnd};
375 }
410 }
376 else if (nextRange.m_TStart <= oldRange.m_TStart
411 else if (nextRange.m_TStart <= oldRange.m_TStart
377 && nextRange.m_TEnd >= oldRange.m_TEnd) {
412 && nextRange.m_TEnd >= oldRange.m_TEnd) {
378 inCache << oldRange;
413 inCache << oldRange;
379 }
414 }
380 else {
415 else {
381 qCCritical(LOG_Variable()) << tr("Detection of unknown case.")
416 qCCritical(LOG_Variable()) << tr("Detection of unknown case.")
382 << QThread::currentThread();
417 << QThread::currentThread();
383 }
418 }
384 }
419 }
385 }
420 }
386
421
387 return inCache;
422 return inCache;
388 }
423 }
General Comments 0
You need to be logged in to leave comments. Login now