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