@@ -1,40 +1,40 | |||
|
1 | 1 | #ifndef SCIQLOP_VARIABLECACHESTRATEGY_H |
|
2 | 2 | #define SCIQLOP_VARIABLECACHESTRATEGY_H |
|
3 | 3 | |
|
4 | 4 | #include "CoreGlobal.h" |
|
5 | 5 | |
|
6 | 6 | #include <QLoggingCategory> |
|
7 | 7 | #include <QObject> |
|
8 | 8 | |
|
9 | 9 | #include <Data/SqpRange.h> |
|
10 | 10 | |
|
11 | 11 | #include <QLoggingCategory> |
|
12 | 12 | |
|
13 | 13 | #include <Common/spimpl.h> |
|
14 | 14 | #include <utility> |
|
15 | 15 | |
|
16 | 16 | |
|
17 | 17 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableCacheStrategy) |
|
18 | 18 | |
|
19 | 19 | class Variable; |
|
20 | 20 | |
|
21 | 21 | /** |
|
22 | 22 | * Possible types of zoom operation |
|
23 | 23 | */ |
|
24 | 24 | enum class CacheStrategy { FixedTolerance, TwoThreashold }; |
|
25 | 25 | |
|
26 | 26 | /// This class aims to hande the cache strategy. |
|
27 | 27 | class SCIQLOP_CORE_EXPORT VariableCacheStrategy : public QObject { |
|
28 | 28 | Q_OBJECT |
|
29 | 29 | public: |
|
30 | 30 | explicit VariableCacheStrategy(QObject *parent = 0); |
|
31 | 31 | |
|
32 |
std::pair<SqpRange, SqpRange> compute |
|
|
33 | const SqpRange &rangeRequested); | |
|
32 | std::pair<SqpRange, SqpRange> computeStrategyRanges(const SqpRange &vRange, | |
|
33 | const SqpRange &rangeRequested); | |
|
34 | 34 | |
|
35 | 35 | private: |
|
36 | 36 | class VariableCacheStrategyPrivate; |
|
37 | 37 | spimpl::unique_impl_ptr<VariableCacheStrategyPrivate> impl; |
|
38 | 38 | }; |
|
39 | 39 | |
|
40 | 40 | #endif // SCIQLOP_VARIABLECACHESTRATEGY_H |
@@ -1,52 +1,52 | |||
|
1 | 1 | #include "Variable/VariableCacheStrategy.h" |
|
2 | 2 | |
|
3 | 3 | #include "Settings/SqpSettingsDefs.h" |
|
4 | 4 | |
|
5 | 5 | #include "Variable/Variable.h" |
|
6 | 6 | #include "Variable/VariableController.h" |
|
7 | 7 | |
|
8 | 8 | Q_LOGGING_CATEGORY(LOG_VariableCacheStrategy, "VariableCacheStrategy") |
|
9 | 9 | |
|
10 | 10 | struct VariableCacheStrategy::VariableCacheStrategyPrivate { |
|
11 | 11 | VariableCacheStrategyPrivate() : m_CacheStrategy{CacheStrategy::FixedTolerance} {} |
|
12 | 12 | |
|
13 | 13 | CacheStrategy m_CacheStrategy; |
|
14 | 14 | }; |
|
15 | 15 | |
|
16 | 16 | |
|
17 | 17 | VariableCacheStrategy::VariableCacheStrategy(QObject *parent) |
|
18 | 18 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableCacheStrategyPrivate>()} |
|
19 | 19 | { |
|
20 | 20 | } |
|
21 | 21 | |
|
22 | 22 | std::pair<SqpRange, SqpRange> |
|
23 |
VariableCacheStrategy::compute |
|
|
23 | VariableCacheStrategy::computeStrategyRanges(const SqpRange &vRange, const SqpRange &rangeRequested) | |
|
24 | 24 | { |
|
25 | 25 | |
|
26 | 26 | auto varRanges = std::pair<SqpRange, SqpRange>{}; |
|
27 | 27 | |
|
28 | 28 | auto toleranceFactor = SqpSettings::toleranceValue(GENERAL_TOLERANCE_AT_UPDATE_KEY, |
|
29 | 29 | GENERAL_TOLERANCE_AT_UPDATE_DEFAULT_VALUE); |
|
30 | 30 | auto tolerance = toleranceFactor * (rangeRequested.m_TEnd - rangeRequested.m_TStart); |
|
31 | 31 | |
|
32 | 32 | switch (impl->m_CacheStrategy) { |
|
33 | 33 | case CacheStrategy::FixedTolerance: { |
|
34 | 34 | varRanges.first = rangeRequested; |
|
35 | 35 | varRanges.second |
|
36 | 36 | = SqpRange{rangeRequested.m_TStart - tolerance, rangeRequested.m_TEnd + tolerance}; |
|
37 | 37 | break; |
|
38 | 38 | } |
|
39 | 39 | |
|
40 | 40 | case CacheStrategy::TwoThreashold: { |
|
41 | 41 | // TODO Implement |
|
42 | 42 | break; |
|
43 | 43 | } |
|
44 | 44 | default: |
|
45 | 45 | qCCritical(LOG_VariableCacheStrategy()) |
|
46 | 46 | << tr("Impossible to use compute the cache range with an unknow cache strategy"); |
|
47 | 47 | // No action |
|
48 | 48 | break; |
|
49 | 49 | } |
|
50 | 50 | |
|
51 | 51 | return varRanges; |
|
52 | 52 | } |
General Comments 0
You need to be logged in to leave comments.
Login now