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