@@ -0,0 +1,188 | |||||
|
1 | #include <Variable/Variable.h> | |||
|
2 | ||||
|
3 | #include <QObject> | |||
|
4 | #include <QtTest> | |||
|
5 | ||||
|
6 | #include <memory> | |||
|
7 | ||||
|
8 | class TestVariable : public QObject { | |||
|
9 | Q_OBJECT | |||
|
10 | ||||
|
11 | private slots: | |||
|
12 | void testNotInCacheRangeList(); | |||
|
13 | ||||
|
14 | void testInCacheRangeList(); | |||
|
15 | }; | |||
|
16 | ||||
|
17 | ||||
|
18 | void TestVariable::testNotInCacheRangeList() | |||
|
19 | { | |||
|
20 | auto varRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; | |||
|
21 | auto varRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 40, 0}}; | |||
|
22 | ||||
|
23 | auto sqpR = SqpRange{static_cast<double>(varRS.toMSecsSinceEpoch()), | |||
|
24 | static_cast<double>(varRE.toMSecsSinceEpoch())}; | |||
|
25 | ||||
|
26 | auto varCRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}}; | |||
|
27 | auto varCRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; | |||
|
28 | auto sqpCR = SqpRange{static_cast<double>(varCRS.toMSecsSinceEpoch()), | |||
|
29 | static_cast<double>(varCRE.toMSecsSinceEpoch())}; | |||
|
30 | ||||
|
31 | Variable var{"Var test", sqpR}; | |||
|
32 | var.setCacheRange(sqpCR); | |||
|
33 | ||||
|
34 | // 1: [ts,te] < varTS | |||
|
35 | auto ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |||
|
36 | auto te = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; | |||
|
37 | auto sqp = SqpRange{static_cast<double>(ts.toMSecsSinceEpoch()), | |||
|
38 | static_cast<double>(te.toMSecsSinceEpoch())}; | |||
|
39 | ||||
|
40 | auto notInCach = var.provideNotInCacheRangeList(sqp); | |||
|
41 | ||||
|
42 | QCOMPARE(notInCach.size(), 1); | |||
|
43 | ||||
|
44 | auto notInCachRange = notInCach.first(); | |||
|
45 | ||||
|
46 | QCOMPARE(notInCachRange.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |||
|
47 | QCOMPARE(notInCachRange.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |||
|
48 | ||||
|
49 | // 2: ts < varTS < te < varTE | |||
|
50 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |||
|
51 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; | |||
|
52 | sqp = SqpRange{static_cast<double>(ts.toMSecsSinceEpoch()), | |||
|
53 | static_cast<double>(te.toMSecsSinceEpoch())}; | |||
|
54 | notInCach = var.provideNotInCacheRangeList(sqp); | |||
|
55 | QCOMPARE(notInCach.size(), 1); | |||
|
56 | notInCachRange = notInCach.first(); | |||
|
57 | QCOMPARE(notInCachRange.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |||
|
58 | QCOMPARE(notInCachRange.m_TEnd, static_cast<double>(varCRS.toMSecsSinceEpoch())); | |||
|
59 | ||||
|
60 | // 3: varTS < ts < te < varTE | |||
|
61 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; | |||
|
62 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; | |||
|
63 | sqp = SqpRange{static_cast<double>(ts.toMSecsSinceEpoch()), | |||
|
64 | static_cast<double>(te.toMSecsSinceEpoch())}; | |||
|
65 | notInCach = var.provideNotInCacheRangeList(sqp); | |||
|
66 | QCOMPARE(notInCach.size(), 0); | |||
|
67 | ||||
|
68 | ||||
|
69 | // 4: varTS < ts < varTE < te | |||
|
70 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; | |||
|
71 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |||
|
72 | sqp = SqpRange{static_cast<double>(ts.toMSecsSinceEpoch()), | |||
|
73 | static_cast<double>(te.toMSecsSinceEpoch())}; | |||
|
74 | notInCach = var.provideNotInCacheRangeList(sqp); | |||
|
75 | QCOMPARE(notInCach.size(), 1); | |||
|
76 | notInCachRange = notInCach.first(); | |||
|
77 | QCOMPARE(notInCachRange.m_TStart, static_cast<double>(varCRE.toMSecsSinceEpoch())); | |||
|
78 | QCOMPARE(notInCachRange.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |||
|
79 | ||||
|
80 | // 5: varTS < varTE < ts < te | |||
|
81 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 20, 0}}; | |||
|
82 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |||
|
83 | sqp = SqpRange{static_cast<double>(ts.toMSecsSinceEpoch()), | |||
|
84 | static_cast<double>(te.toMSecsSinceEpoch())}; | |||
|
85 | notInCach = var.provideNotInCacheRangeList(sqp); | |||
|
86 | QCOMPARE(notInCach.size(), 1); | |||
|
87 | notInCachRange = notInCach.first(); | |||
|
88 | QCOMPARE(notInCachRange.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |||
|
89 | QCOMPARE(notInCachRange.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |||
|
90 | ||||
|
91 | // 6: ts <varTS < varTE < te | |||
|
92 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; | |||
|
93 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |||
|
94 | sqp = SqpRange{static_cast<double>(ts.toMSecsSinceEpoch()), | |||
|
95 | static_cast<double>(te.toMSecsSinceEpoch())}; | |||
|
96 | notInCach = var.provideNotInCacheRangeList(sqp); | |||
|
97 | QCOMPARE(notInCach.size(), 2); | |||
|
98 | notInCachRange = notInCach.first(); | |||
|
99 | QCOMPARE(notInCachRange.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |||
|
100 | QCOMPARE(notInCachRange.m_TEnd, static_cast<double>(varCRS.toMSecsSinceEpoch())); | |||
|
101 | notInCachRange = notInCach[1]; | |||
|
102 | QCOMPARE(notInCachRange.m_TStart, static_cast<double>(varCRE.toMSecsSinceEpoch())); | |||
|
103 | QCOMPARE(notInCachRange.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |||
|
104 | } | |||
|
105 | ||||
|
106 | ||||
|
107 | void TestVariable::testInCacheRangeList() | |||
|
108 | { | |||
|
109 | auto varRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; | |||
|
110 | auto varRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 40, 0}}; | |||
|
111 | ||||
|
112 | auto sqpR = SqpRange{static_cast<double>(varRS.toMSecsSinceEpoch()), | |||
|
113 | static_cast<double>(varRE.toMSecsSinceEpoch())}; | |||
|
114 | ||||
|
115 | auto varCRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}}; | |||
|
116 | auto varCRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; | |||
|
117 | auto sqpCR = SqpRange{static_cast<double>(varCRS.toMSecsSinceEpoch()), | |||
|
118 | static_cast<double>(varCRE.toMSecsSinceEpoch())}; | |||
|
119 | ||||
|
120 | Variable var{"Var test", sqpR}; | |||
|
121 | var.setCacheRange(sqpCR); | |||
|
122 | ||||
|
123 | // 1: [ts,te] < varTS | |||
|
124 | auto ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |||
|
125 | auto te = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; | |||
|
126 | auto sqp = SqpRange{static_cast<double>(ts.toMSecsSinceEpoch()), | |||
|
127 | static_cast<double>(te.toMSecsSinceEpoch())}; | |||
|
128 | ||||
|
129 | auto notInCach = var.provideInCacheRangeList(sqp); | |||
|
130 | ||||
|
131 | QCOMPARE(notInCach.size(), 0); | |||
|
132 | ||||
|
133 | // 2: ts < varTS < te < varTE | |||
|
134 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |||
|
135 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; | |||
|
136 | sqp = SqpRange{static_cast<double>(ts.toMSecsSinceEpoch()), | |||
|
137 | static_cast<double>(te.toMSecsSinceEpoch())}; | |||
|
138 | notInCach = var.provideInCacheRangeList(sqp); | |||
|
139 | QCOMPARE(notInCach.size(), 1); | |||
|
140 | auto notInCachRange = notInCach.first(); | |||
|
141 | QCOMPARE(notInCachRange.m_TStart, static_cast<double>(varCRS.toMSecsSinceEpoch())); | |||
|
142 | QCOMPARE(notInCachRange.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |||
|
143 | ||||
|
144 | // 3: varTS < ts < te < varTE | |||
|
145 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; | |||
|
146 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; | |||
|
147 | sqp = SqpRange{static_cast<double>(ts.toMSecsSinceEpoch()), | |||
|
148 | static_cast<double>(te.toMSecsSinceEpoch())}; | |||
|
149 | notInCach = var.provideInCacheRangeList(sqp); | |||
|
150 | QCOMPARE(notInCach.size(), 1); | |||
|
151 | notInCachRange = notInCach.first(); | |||
|
152 | QCOMPARE(notInCachRange.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |||
|
153 | QCOMPARE(notInCachRange.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |||
|
154 | ||||
|
155 | // 4: varTS < ts < varTE < te | |||
|
156 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 20, 0}}; | |||
|
157 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |||
|
158 | sqp = SqpRange{static_cast<double>(ts.toMSecsSinceEpoch()), | |||
|
159 | static_cast<double>(te.toMSecsSinceEpoch())}; | |||
|
160 | notInCach = var.provideInCacheRangeList(sqp); | |||
|
161 | QCOMPARE(notInCach.size(), 1); | |||
|
162 | notInCachRange = notInCach.first(); | |||
|
163 | QCOMPARE(notInCachRange.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |||
|
164 | QCOMPARE(notInCachRange.m_TEnd, static_cast<double>(varCRE.toMSecsSinceEpoch())); | |||
|
165 | ||||
|
166 | // 5: varTS < varTE < ts < te | |||
|
167 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 20, 0}}; | |||
|
168 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |||
|
169 | sqp = SqpRange{static_cast<double>(ts.toMSecsSinceEpoch()), | |||
|
170 | static_cast<double>(te.toMSecsSinceEpoch())}; | |||
|
171 | notInCach = var.provideInCacheRangeList(sqp); | |||
|
172 | QCOMPARE(notInCach.size(), 0); | |||
|
173 | ||||
|
174 | // 6: ts <varTS < varTE < te | |||
|
175 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; | |||
|
176 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |||
|
177 | sqp = SqpRange{static_cast<double>(ts.toMSecsSinceEpoch()), | |||
|
178 | static_cast<double>(te.toMSecsSinceEpoch())}; | |||
|
179 | notInCach = var.provideInCacheRangeList(sqp); | |||
|
180 | QCOMPARE(notInCach.size(), 1); | |||
|
181 | notInCachRange = notInCach.first(); | |||
|
182 | QCOMPARE(notInCachRange.m_TStart, static_cast<double>(varCRS.toMSecsSinceEpoch())); | |||
|
183 | QCOMPARE(notInCachRange.m_TEnd, static_cast<double>(varCRE.toMSecsSinceEpoch())); | |||
|
184 | } | |||
|
185 | ||||
|
186 | ||||
|
187 | QTEST_MAIN(TestVariable) | |||
|
188 | #include "TestVariable.moc" |
@@ -1,243 +1,248 | |||||
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 | struct Variable::VariablePrivate { |
|
12 | struct Variable::VariablePrivate { | |
13 | explicit VariablePrivate(const QString &name, const SqpRange &dateTime, |
|
13 | explicit VariablePrivate(const QString &name, const SqpRange &dateTime, | |
14 | const QVariantHash &metadata) |
|
14 | const QVariantHash &metadata) | |
15 | : m_Name{name}, m_Range{dateTime}, m_Metadata{metadata}, m_DataSeries{nullptr} |
|
15 | : m_Name{name}, m_Range{dateTime}, m_Metadata{metadata}, m_DataSeries{nullptr} | |
16 | { |
|
16 | { | |
17 | } |
|
17 | } | |
18 |
|
18 | |||
19 | void lockRead() { m_Lock.lockForRead(); } |
|
19 | void lockRead() { m_Lock.lockForRead(); } | |
20 | void lockWrite() { m_Lock.lockForWrite(); } |
|
20 | void lockWrite() { m_Lock.lockForWrite(); } | |
21 | void unlock() { m_Lock.unlock(); } |
|
21 | void unlock() { m_Lock.unlock(); } | |
22 |
|
22 | |||
23 | QString m_Name; |
|
23 | QString m_Name; | |
24 |
|
24 | |||
25 | SqpRange m_Range; |
|
25 | SqpRange m_Range; | |
26 | SqpRange m_CacheRange; |
|
26 | SqpRange m_CacheRange; | |
27 | QVariantHash m_Metadata; |
|
27 | QVariantHash m_Metadata; | |
28 | std::shared_ptr<IDataSeries> m_DataSeries; |
|
28 | std::shared_ptr<IDataSeries> m_DataSeries; | |
29 |
|
29 | |||
30 | QReadWriteLock m_Lock; |
|
30 | QReadWriteLock m_Lock; | |
31 | }; |
|
31 | }; | |
32 |
|
32 | |||
33 | Variable::Variable(const QString &name, const SqpRange &dateTime, const QVariantHash &metadata) |
|
33 | Variable::Variable(const QString &name, const SqpRange &dateTime, const QVariantHash &metadata) | |
34 | : impl{spimpl::make_unique_impl<VariablePrivate>(name, dateTime, metadata)} |
|
34 | : impl{spimpl::make_unique_impl<VariablePrivate>(name, dateTime, metadata)} | |
35 | { |
|
35 | { | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | QString Variable::name() const noexcept |
|
38 | QString Variable::name() const noexcept | |
39 | { |
|
39 | { | |
40 | impl->lockRead(); |
|
40 | impl->lockRead(); | |
41 | auto name = impl->m_Name; |
|
41 | auto name = impl->m_Name; | |
42 | impl->unlock(); |
|
42 | impl->unlock(); | |
43 | return name; |
|
43 | return name; | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | SqpRange Variable::range() const noexcept |
|
46 | SqpRange Variable::range() const noexcept | |
47 | { |
|
47 | { | |
48 | impl->lockRead(); |
|
48 | impl->lockRead(); | |
49 | auto range = impl->m_Range; |
|
49 | auto range = impl->m_Range; | |
50 | impl->unlock(); |
|
50 | impl->unlock(); | |
51 | return range; |
|
51 | return range; | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 | void Variable::setRange(const SqpRange &range) noexcept |
|
54 | void Variable::setRange(const SqpRange &range) noexcept | |
55 | { |
|
55 | { | |
56 | impl->lockWrite(); |
|
56 | impl->lockWrite(); | |
57 | impl->m_Range = range; |
|
57 | impl->m_Range = range; | |
58 | impl->unlock(); |
|
58 | impl->unlock(); | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | SqpRange Variable::cacheRange() const noexcept |
|
61 | SqpRange Variable::cacheRange() const noexcept | |
62 | { |
|
62 | { | |
63 | impl->lockRead(); |
|
63 | impl->lockRead(); | |
64 | auto cacheRange = impl->m_CacheRange; |
|
64 | auto cacheRange = impl->m_CacheRange; | |
65 | impl->unlock(); |
|
65 | impl->unlock(); | |
66 | return cacheRange; |
|
66 | return cacheRange; | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | void Variable::setCacheRange(const SqpRange &cacheRange) noexcept |
|
69 | void Variable::setCacheRange(const SqpRange &cacheRange) noexcept | |
70 | { |
|
70 | { | |
71 | impl->lockWrite(); |
|
71 | impl->lockWrite(); | |
72 | impl->m_CacheRange = cacheRange; |
|
72 | impl->m_CacheRange = cacheRange; | |
73 | impl->unlock(); |
|
73 | impl->unlock(); | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | void Variable::setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept |
|
76 | void Variable::setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept | |
77 | { |
|
77 | { | |
78 | qCDebug(LOG_Variable()) << "TORM Variable::setDataSeries" |
|
78 | qCDebug(LOG_Variable()) << "TORM Variable::setDataSeries" | |
79 | << QThread::currentThread()->objectName(); |
|
79 | << QThread::currentThread()->objectName(); | |
80 | if (!dataSeries) { |
|
80 | if (!dataSeries) { | |
81 | /// @todo ALX : log |
|
81 | /// @todo ALX : log | |
82 | return; |
|
82 | return; | |
83 | } |
|
83 | } | |
84 | impl->lockWrite(); |
|
84 | impl->lockWrite(); | |
85 | impl->m_DataSeries = dataSeries->clone(); |
|
85 | impl->m_DataSeries = dataSeries->clone(); | |
86 | impl->unlock(); |
|
86 | impl->unlock(); | |
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | void Variable::mergeDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept |
|
89 | void Variable::mergeDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept | |
90 | { |
|
90 | { | |
91 | qCDebug(LOG_Variable()) << "TORM Variable::mergeDataSeries" |
|
91 | qCDebug(LOG_Variable()) << "TORM Variable::mergeDataSeries" | |
92 | << QThread::currentThread()->objectName(); |
|
92 | << QThread::currentThread()->objectName(); | |
93 | if (!dataSeries) { |
|
93 | if (!dataSeries) { | |
94 | /// @todo ALX : log |
|
94 | /// @todo ALX : log | |
95 | return; |
|
95 | return; | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 | // Add or merge the data |
|
98 | // Add or merge the data | |
99 | // Inits the data series of the variable |
|
99 | // Inits the data series of the variable | |
100 | impl->lockWrite(); |
|
100 | impl->lockWrite(); | |
101 | if (!impl->m_DataSeries) { |
|
101 | if (!impl->m_DataSeries) { | |
102 | impl->m_DataSeries = dataSeries->clone(); |
|
102 | impl->m_DataSeries = dataSeries->clone(); | |
103 | } |
|
103 | } | |
104 | else { |
|
104 | else { | |
105 | impl->m_DataSeries->merge(dataSeries.get()); |
|
105 | impl->m_DataSeries->merge(dataSeries.get()); | |
106 | } |
|
106 | } | |
107 | impl->unlock(); |
|
107 | impl->unlock(); | |
108 |
|
108 | |||
109 | // sub the data |
|
109 | // sub the data | |
110 | auto subData = this->dataSeries()->subDataSeries(this->cacheRange()); |
|
110 | auto subData = this->dataSeries()->subDataSeries(this->cacheRange()); | |
111 | qCDebug(LOG_Variable()) << "TORM: Variable::mergeDataSeries sub" << subData->range(); |
|
111 | qCDebug(LOG_Variable()) << "TORM: Variable::mergeDataSeries sub" << subData->range(); | |
112 | this->setDataSeries(subData); |
|
112 | this->setDataSeries(subData); | |
113 | qCDebug(LOG_Variable()) << "TORM: Variable::mergeDataSeries set" << this->dataSeries()->range(); |
|
113 | qCDebug(LOG_Variable()) << "TORM: Variable::mergeDataSeries set" << this->dataSeries()->range(); | |
114 | } |
|
114 | } | |
115 |
|
115 | |||
116 | std::shared_ptr<IDataSeries> Variable::dataSeries() const noexcept |
|
116 | std::shared_ptr<IDataSeries> Variable::dataSeries() const noexcept | |
117 | { |
|
117 | { | |
118 | impl->lockRead(); |
|
118 | impl->lockRead(); | |
119 | auto dataSeries = impl->m_DataSeries; |
|
119 | auto dataSeries = impl->m_DataSeries; | |
120 | impl->unlock(); |
|
120 | impl->unlock(); | |
121 |
|
121 | |||
122 | return dataSeries; |
|
122 | return dataSeries; | |
123 | } |
|
123 | } | |
124 |
|
124 | |||
125 | QVariantHash Variable::metadata() const noexcept |
|
125 | QVariantHash Variable::metadata() const noexcept | |
126 | { |
|
126 | { | |
127 | impl->lockRead(); |
|
127 | impl->lockRead(); | |
128 | auto metadata = impl->m_Metadata; |
|
128 | auto metadata = impl->m_Metadata; | |
129 | impl->unlock(); |
|
129 | impl->unlock(); | |
130 | return metadata; |
|
130 | return metadata; | |
131 | } |
|
131 | } | |
132 |
|
132 | |||
133 | bool Variable::contains(const SqpRange &range) const noexcept |
|
133 | bool Variable::contains(const SqpRange &range) const noexcept | |
134 | { |
|
134 | { | |
135 | impl->lockRead(); |
|
135 | impl->lockRead(); | |
136 | auto res = impl->m_Range.contains(range); |
|
136 | auto res = impl->m_Range.contains(range); | |
137 | impl->unlock(); |
|
137 | impl->unlock(); | |
138 | return res; |
|
138 | return res; | |
139 | } |
|
139 | } | |
140 |
|
140 | |||
141 | bool Variable::intersect(const SqpRange &range) const noexcept |
|
141 | bool Variable::intersect(const SqpRange &range) const noexcept | |
142 | { |
|
142 | { | |
143 |
|
143 | |||
144 | impl->lockRead(); |
|
144 | impl->lockRead(); | |
145 | auto res = impl->m_Range.intersect(range); |
|
145 | auto res = impl->m_Range.intersect(range); | |
146 | impl->unlock(); |
|
146 | impl->unlock(); | |
147 | return res; |
|
147 | return res; | |
148 | } |
|
148 | } | |
149 |
|
149 | |||
150 | bool Variable::isInside(const SqpRange &range) const noexcept |
|
150 | bool Variable::isInside(const SqpRange &range) const noexcept | |
151 | { |
|
151 | { | |
152 | impl->lockRead(); |
|
152 | impl->lockRead(); | |
153 | auto res = range.contains(SqpRange{impl->m_Range.m_TStart, impl->m_Range.m_TEnd}); |
|
153 | auto res = range.contains(SqpRange{impl->m_Range.m_TStart, impl->m_Range.m_TEnd}); | |
154 | impl->unlock(); |
|
154 | impl->unlock(); | |
155 | return res; |
|
155 | return res; | |
156 | } |
|
156 | } | |
157 |
|
157 | |||
158 | bool Variable::cacheContains(const SqpRange &range) const noexcept |
|
158 | bool Variable::cacheContains(const SqpRange &range) const noexcept | |
159 | { |
|
159 | { | |
160 | impl->lockRead(); |
|
160 | impl->lockRead(); | |
161 | auto res = impl->m_CacheRange.contains(range); |
|
161 | auto res = impl->m_CacheRange.contains(range); | |
162 | impl->unlock(); |
|
162 | impl->unlock(); | |
163 | return res; |
|
163 | return res; | |
164 | } |
|
164 | } | |
165 |
|
165 | |||
166 | bool Variable::cacheIntersect(const SqpRange &range) const noexcept |
|
166 | bool Variable::cacheIntersect(const SqpRange &range) const noexcept | |
167 | { |
|
167 | { | |
168 | impl->lockRead(); |
|
168 | impl->lockRead(); | |
169 | auto res = impl->m_CacheRange.intersect(range); |
|
169 | auto res = impl->m_CacheRange.intersect(range); | |
170 | impl->unlock(); |
|
170 | impl->unlock(); | |
171 | return res; |
|
171 | return res; | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 | bool Variable::cacheIsInside(const SqpRange &range) const noexcept |
|
174 | bool Variable::cacheIsInside(const SqpRange &range) const noexcept | |
175 | { |
|
175 | { | |
176 | impl->lockRead(); |
|
176 | impl->lockRead(); | |
177 | auto res = range.contains(SqpRange{impl->m_CacheRange.m_TStart, impl->m_CacheRange.m_TEnd}); |
|
177 | auto res = range.contains(SqpRange{impl->m_CacheRange.m_TStart, impl->m_CacheRange.m_TEnd}); | |
178 | impl->unlock(); |
|
178 | impl->unlock(); | |
179 | return res; |
|
179 | return res; | |
180 | } |
|
180 | } | |
181 |
|
181 | |||
182 |
|
182 | |||
183 | QVector<SqpRange> Variable::provideNotInCacheRangeList(const SqpRange &range) const noexcept |
|
183 | QVector<SqpRange> Variable::provideNotInCacheRangeList(const SqpRange &range) const noexcept | |
184 | { |
|
184 | { | |
185 | // This code assume that cach in contigue. Can return 0, 1 or 2 SqpRange |
|
185 | // This code assume that cach in contigue. Can return 0, 1 or 2 SqpRange | |
186 |
|
186 | |||
187 | auto notInCache = QVector<SqpRange>{}; |
|
187 | auto notInCache = QVector<SqpRange>{}; | |
188 |
|
188 | |||
189 | if (!this->cacheContains(range)) { |
|
189 | if (!this->cacheContains(range)) { | |
190 | if (range.m_TEnd <= impl->m_CacheRange.m_TStart |
|
190 | if (range.m_TEnd <= impl->m_CacheRange.m_TStart | |
191 | || range.m_TStart >= impl->m_CacheRange.m_TEnd) { |
|
191 | || range.m_TStart >= impl->m_CacheRange.m_TEnd) { | |
192 | notInCache << range; |
|
192 | notInCache << range; | |
193 | } |
|
193 | } | |
194 | else if (range.m_TStart < impl->m_CacheRange.m_TStart |
|
194 | else if (range.m_TStart < impl->m_CacheRange.m_TStart | |
195 | && range.m_TEnd <= impl->m_CacheRange.m_TEnd) { |
|
195 | && range.m_TEnd <= impl->m_CacheRange.m_TEnd) { | |
196 | notInCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TStart}; |
|
196 | notInCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TStart}; | |
197 | } |
|
197 | } | |
198 | else if (range.m_TStart < impl->m_CacheRange.m_TStart |
|
198 | else if (range.m_TStart < impl->m_CacheRange.m_TStart | |
199 | && range.m_TEnd > impl->m_CacheRange.m_TEnd) { |
|
199 | && range.m_TEnd > impl->m_CacheRange.m_TEnd) { | |
200 | notInCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TStart} |
|
200 | notInCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TStart} | |
201 | << SqpRange{impl->m_CacheRange.m_TEnd, range.m_TEnd}; |
|
201 | << SqpRange{impl->m_CacheRange.m_TEnd, range.m_TEnd}; | |
202 | } |
|
202 | } | |
203 | else if (range.m_TStart < impl->m_CacheRange.m_TEnd) { |
|
203 | else if (range.m_TStart < impl->m_CacheRange.m_TEnd) { | |
204 | notInCache << SqpRange{impl->m_CacheRange.m_TEnd, range.m_TEnd}; |
|
204 | notInCache << SqpRange{impl->m_CacheRange.m_TEnd, range.m_TEnd}; | |
205 | } |
|
205 | } | |
206 | else { |
|
206 | else { | |
207 | qCCritical(LOG_Variable()) << tr("Detection of unknown case.") |
|
207 | qCCritical(LOG_Variable()) << tr("Detection of unknown case.") | |
208 | << QThread::currentThread(); |
|
208 | << QThread::currentThread(); | |
209 | } |
|
209 | } | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | return notInCache; |
|
212 | return notInCache; | |
213 | } |
|
213 | } | |
214 |
|
214 | |||
215 | QVector<SqpRange> Variable::provideInCacheRangeList(const SqpRange &range) const noexcept |
|
215 | QVector<SqpRange> Variable::provideInCacheRangeList(const SqpRange &range) const noexcept | |
216 | { |
|
216 | { | |
217 | // This code assume that cach in contigue. Can return 0 or 1 SqpRange |
|
217 | // This code assume that cach in contigue. Can return 0 or 1 SqpRange | |
218 |
|
218 | |||
219 | auto inCache = QVector<SqpRange>{}; |
|
219 | auto inCache = QVector<SqpRange>{}; | |
220 |
|
220 | |||
221 |
|
221 | |||
222 |
if (this-> |
|
222 | if (this->intersect(range)) { | |
223 |
if (range.m_TStart <= impl->m_CacheRange.m_T |
|
223 | if (range.m_TStart <= impl->m_CacheRange.m_TStart | |
224 |
&& range.m_TEnd >= impl->m_CacheRange.m_T |
|
224 | && range.m_TEnd >= impl->m_CacheRange.m_TStart | |
225 |
|
|
225 | && range.m_TEnd < impl->m_CacheRange.m_TEnd) { | |
|
226 | inCache << SqpRange{impl->m_CacheRange.m_TStart, range.m_TEnd}; | |||
226 | } |
|
227 | } | |
227 |
|
228 | |||
228 | else if (range.m_TStart >= impl->m_CacheRange.m_TStart |
|
229 | else if (range.m_TStart >= impl->m_CacheRange.m_TStart | |
229 | && range.m_TEnd < impl->m_CacheRange.m_TEnd) { |
|
230 | && range.m_TEnd <= impl->m_CacheRange.m_TEnd) { | |
230 | inCache << range; |
|
231 | inCache << range; | |
231 | } |
|
232 | } | |
232 |
else if (range.m_TStart |
|
233 | else if (range.m_TStart > impl->m_CacheRange.m_TStart | |
233 |
&& range.m_TEnd > |
|
234 | && range.m_TEnd > impl->m_CacheRange.m_TEnd) { | |
234 |
inCache << SqpRange{impl->m_CacheRange. |
|
235 | inCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TEnd}; | |
|
236 | } | |||
|
237 | else if (range.m_TStart <= impl->m_CacheRange.m_TStart | |||
|
238 | && range.m_TEnd >= impl->m_CacheRange.m_TEnd) { | |||
|
239 | inCache << impl->m_CacheRange; | |||
235 | } |
|
240 | } | |
236 | else { |
|
241 | else { | |
237 | qCCritical(LOG_Variable()) << tr("Detection of unknown case.") |
|
242 | qCCritical(LOG_Variable()) << tr("Detection of unknown case.") | |
238 | << QThread::currentThread(); |
|
243 | << QThread::currentThread(); | |
239 | } |
|
244 | } | |
240 | } |
|
245 | } | |
241 |
|
246 | |||
242 | return inCache; |
|
247 | return inCache; | |
243 | } |
|
248 | } |
General Comments 0
You need to be logged in to leave comments.
Login now