diff --git a/core/include/Variable/VariableCacheStrategy.h b/core/include/Variable/VariableCacheStrategy.h index da94ff4..54d401a 100644 --- a/core/include/Variable/VariableCacheStrategy.h +++ b/core/include/Variable/VariableCacheStrategy.h @@ -18,23 +18,14 @@ Q_DECLARE_LOGGING_CATEGORY(LOG_VariableCacheStrategy) class Variable; -/** - * Possible types of zoom operation - */ -enum class CacheStrategy { FixedTolerance, TwoThreashold }; - /// This class aims to hande the cache strategy. -class SCIQLOP_CORE_EXPORT VariableCacheStrategy : public QObject { - Q_OBJECT -public: - explicit VariableCacheStrategy(QObject *parent = 0); - - std::pair computeStrategyRanges(const SqpRange &vRange, - const SqpRange &rangeRequested); +class SCIQLOP_CORE_EXPORT VariableCacheStrategy { -private: - class VariableCacheStrategyPrivate; - spimpl::unique_impl_ptr impl; +public: + virtual std::pair computeRange(const SqpRange &vRange, + const SqpRange &rangeRequested) + = 0; }; + #endif // SCIQLOP_VARIABLECACHESTRATEGY_H diff --git a/core/include/Variable/VariableCacheStrategyFactory.h b/core/include/Variable/VariableCacheStrategyFactory.h new file mode 100644 index 0000000..a7ec00c --- /dev/null +++ b/core/include/Variable/VariableCacheStrategyFactory.h @@ -0,0 +1,44 @@ +#ifndef SCIQLOP_VARIABLECACHESTRATEGYFACTORY_H +#define SCIQLOP_VARIABLECACHESTRATEGYFACTORY_H + + +#include +#include + +#include "VariableCacheStrategy.h" +#include "VariableSingleThresholdCacheStrategy.h" + +#include +#include + +Q_LOGGING_CATEGORY(LOG_VariableCacheStrategyFactory, "VariableCacheStrategyFactory") + +enum class CacheStrategy { SingleThreshold, TwoThreashold }; + +class VariableCacheStrategyFactory { + + using cacheStratPtr = std::unique_ptr; + +public: + static cacheStratPtr createCacheStrategy(CacheStrategy specificStrategy) + { + switch (specificStrategy) { + case CacheStrategy::SingleThreshold: { + return std::unique_ptr{ + new VariableSingleThresholdCacheStrategy{}}; + break; + } + case CacheStrategy::TwoThreashold: { + qCCritical(LOG_VariableCacheStrategyFactory()) + << QObject::tr("cache strategy not implemented yet"); + break; + } + default: + qCCritical(LOG_VariableCacheStrategyFactory()) + << QObject::tr("Unknown cache strategy"); + } + } +}; + + +#endif // VARIABLECACHESTRATEGYFACTORY_H diff --git a/core/include/Variable/VariableSingleThresholdCacheStrategy.h b/core/include/Variable/VariableSingleThresholdCacheStrategy.h new file mode 100644 index 0000000..66be152 --- /dev/null +++ b/core/include/Variable/VariableSingleThresholdCacheStrategy.h @@ -0,0 +1,32 @@ +#ifndef SCIQLOP_VARIABLESINGLETHRESHOLDCACHESTRATEGY_H +#define SCIQLOP_VARIABLESINGLETHRESHOLDCACHESTRATEGY_H + +#include "Settings/SqpSettingsDefs.h" +#include "VariableCacheStrategy.h" + + +/// This class aims to hande the cache strategy. +class SCIQLOP_CORE_EXPORT VariableSingleThresholdCacheStrategy : public VariableCacheStrategy { +public: + VariableSingleThresholdCacheStrategy() = default; + + std::pair computeRange(const SqpRange &vRange, + const SqpRange &rangeRequested) override + { + + auto varRanges = std::pair{}; + + auto toleranceFactor = SqpSettings::toleranceValue( + GENERAL_TOLERANCE_AT_UPDATE_KEY, GENERAL_TOLERANCE_AT_UPDATE_DEFAULT_VALUE); + auto tolerance = toleranceFactor * (rangeRequested.m_TEnd - rangeRequested.m_TStart); + + varRanges.first = rangeRequested; + varRanges.second + = SqpRange{rangeRequested.m_TStart - tolerance, rangeRequested.m_TEnd + tolerance}; + + return varRanges; + } +}; + + +#endif // SCIQLOP_VARIABLESINGLETHRESHOLDCACHESTRATEGY_H diff --git a/core/src/Data/VectorSeries.cpp b/core/src/Data/VectorSeries.cpp index 3043f7c..ab86bad 100644 --- a/core/src/Data/VectorSeries.cpp +++ b/core/src/Data/VectorSeries.cpp @@ -33,7 +33,7 @@ std::vector flatten(std::vector xValues, std::vector yVa result.push_back(xValues[i]); result.push_back(yValues[i]); result.push_back(zValues[i]); - } + } return result; } diff --git a/core/src/Variable/VariableCacheStrategy.cpp b/core/src/Variable/VariableCacheStrategy.cpp deleted file mode 100644 index 962c5b6..0000000 --- a/core/src/Variable/VariableCacheStrategy.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "Variable/VariableCacheStrategy.h" - -#include "Settings/SqpSettingsDefs.h" - -#include "Variable/Variable.h" -#include "Variable/VariableController.h" - -Q_LOGGING_CATEGORY(LOG_VariableCacheStrategy, "VariableCacheStrategy") - -struct VariableCacheStrategy::VariableCacheStrategyPrivate { - VariableCacheStrategyPrivate() : m_CacheStrategy{CacheStrategy::FixedTolerance} {} - - CacheStrategy m_CacheStrategy; -}; - - -VariableCacheStrategy::VariableCacheStrategy(QObject *parent) - : QObject{parent}, impl{spimpl::make_unique_impl()} -{ -} - -std::pair -VariableCacheStrategy::computeStrategyRanges(const SqpRange &vRange, const SqpRange &rangeRequested) -{ - - auto varRanges = std::pair{}; - - auto toleranceFactor = SqpSettings::toleranceValue(GENERAL_TOLERANCE_AT_UPDATE_KEY, - GENERAL_TOLERANCE_AT_UPDATE_DEFAULT_VALUE); - auto tolerance = toleranceFactor * (rangeRequested.m_TEnd - rangeRequested.m_TStart); - - switch (impl->m_CacheStrategy) { - case CacheStrategy::FixedTolerance: { - varRanges.first = rangeRequested; - varRanges.second - = SqpRange{rangeRequested.m_TStart - tolerance, rangeRequested.m_TEnd + tolerance}; - break; - } - - case CacheStrategy::TwoThreashold: { - // TODO Implement - break; - } - default: - qCCritical(LOG_VariableCacheStrategy()) - << tr("Impossible to use compute the cache range with an unknow cache strategy"); - // No action - break; - } - - return varRanges; -} diff --git a/core/src/Variable/VariableController.cpp b/core/src/Variable/VariableController.cpp index 32a44b3..6fa1b1e 100644 --- a/core/src/Variable/VariableController.cpp +++ b/core/src/Variable/VariableController.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -79,7 +80,9 @@ struct VariableController::VariableControllerPrivate { : m_WorkingMutex{}, m_VariableModel{new VariableModel{parent}}, m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}}, - m_VariableCacheStrategy{std::make_unique()}, + // m_VariableCacheStrategy{std::make_unique()}, + m_VariableCacheStrategy{VariableCacheStrategyFactory::createCacheStrategy( + CacheStrategy::SingleThreshold)}, m_VariableAcquisitionWorker{std::make_unique()}, q{parent} { @@ -573,7 +576,7 @@ void VariableController::VariableControllerPrivate::processRequest(std::shared_p auto varId = m_VariableToIdentifierMap.at(var); auto varStrategyRangesRequested - = m_VariableCacheStrategy->computeStrategyRanges(var->range(), rangeRequested); + = m_VariableCacheStrategy->computeRange(var->range(), rangeRequested); auto notInCacheRangeList = QVector{varStrategyRangesRequested.second}; auto inCacheRangeList = QVector{}; diff --git a/core/tests/Variable/TestVariableSync.cpp b/core/tests/Variable/TestVariableSync.cpp new file mode 100644 index 0000000..61daa00 --- /dev/null +++ b/core/tests/Variable/TestVariableSync.cpp @@ -0,0 +1,310 @@ +#include +#include + +#include + +#include +#include +#include +#include