From 9423975d81b361adf0cdf14fab917e3e3dcafc1b 2017-06-23 14:24:27 From: mperrinel Date: 2017-06-23 14:24:27 Subject: [PATCH] Create a variable notify the variable cache parameter --- diff --git a/core/include/Variable/VariableCacheController.h b/core/include/Variable/VariableCacheController.h new file mode 100644 index 0000000..1a037d3 --- /dev/null +++ b/core/include/Variable/VariableCacheController.h @@ -0,0 +1,26 @@ +#ifndef SCIQLOP_VARIABLECACHECONTROLLER_H +#define SCIQLOP_VARIABLECACHECONTROLLER_H + +#include + +#include + +#include + +class Variable; + +/// This class aims to store in the cash all of the dateTime already requested to the variable. +class VariableCacheController : public QObject { + Q_OBJECT +public: + explicit VariableCacheController(QObject *parent = 0); + + + void addDateTime(std::shared_ptr variable, const SqpDateTime &dateTime); + +private: + class VariableCacheControllerPrivate; + spimpl::unique_impl_ptr impl; +}; + +#endif // SCIQLOP_VARIABLECACHECONTROLLER_H diff --git a/core/src/Variable/VariableCacheController.cpp b/core/src/Variable/VariableCacheController.cpp new file mode 100644 index 0000000..1db6df5 --- /dev/null +++ b/core/src/Variable/VariableCacheController.cpp @@ -0,0 +1,25 @@ +#include "Variable/VariableCacheController.h" + +#include "Variable/Variable.h" +#include + +struct VariableCacheController::VariableCacheControllerPrivate { + + std::unordered_map, std::list > + m_VariableToSqpDateTimeListMap; +}; + + +VariableCacheController::VariableCacheController(QObject *parent) + : QObject(parent), impl{spimpl::make_unique_impl()} +{ +} + +void VariableCacheController::addDateTime(std::shared_ptr variable, + const SqpDateTime &dateTime) +{ + if (variable) { + // TODO: squeeze the map to let it only some SqpDateTime without intersection + impl->m_VariableToSqpDateTimeListMap[variable].push_back(dateTime); + } +} diff --git a/core/src/Variable/VariableController.cpp b/core/src/Variable/VariableController.cpp index ccd7a5c..78102c6 100644 --- a/core/src/Variable/VariableController.cpp +++ b/core/src/Variable/VariableController.cpp @@ -1,3 +1,4 @@ +#include #include #include @@ -10,6 +11,8 @@ #include #include +#include + Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") namespace { @@ -28,7 +31,9 @@ std::unique_ptr generateDefaultDataSeries(const IDataProvider &prov struct VariableController::VariableControllerPrivate { explicit VariableControllerPrivate(VariableController *parent) - : m_WorkingMutex{}, m_VariableModel{new VariableModel{parent}} + : m_WorkingMutex{}, + m_VariableModel{new VariableModel{parent}}, + m_VariableCacheController{std::make_unique()} { } @@ -36,7 +41,9 @@ struct VariableController::VariableControllerPrivate { /// Variable model. The VariableController has the ownership VariableModel *m_VariableModel; + TimeController *m_TimeController{nullptr}; + std::unique_ptr m_VariableCacheController; }; VariableController::VariableController(QObject *parent) @@ -86,8 +93,14 @@ void VariableController::createVariable(const QString &name, /// it will be retained later /// - default data are generated for the variable, without taking into account the timerange set /// in sciqlop + auto dateTime = impl->m_TimeController->dateTime(); if (auto newVariable = impl->m_VariableModel->createVariable( - name, generateDefaultDataSeries(*provider, impl->m_TimeController->dateTime()))) { + name, generateDefaultDataSeries(*provider, dateTime))) { + + // store in cache + impl->m_VariableCacheController->addDateTime(newVariable, dateTime); + + // notify the creation emit variableCreated(newVariable); } }