diff --git a/core/include/Variable/Variable.h b/core/include/Variable/Variable.h index bf30f18..47a668e 100644 --- a/core/include/Variable/Variable.h +++ b/core/include/Variable/Variable.h @@ -12,6 +12,8 @@ #include #include +#include + Q_DECLARE_LOGGING_CATEGORY(LOG_Variable) class IDataSeries; @@ -39,6 +41,10 @@ public: SqpRange cacheRange() const noexcept; void setCacheRange(const SqpRange &cacheRange) noexcept; + /// @return the properties associated to the current state of the variable + StateData stateData() const noexcept; + void setState(std::unique_ptr state) noexcept; + /// @return the number of points hold by the variable. The number of points is updated each time /// the data series changes int nbPoints() const noexcept; diff --git a/core/src/Variable/Variable.cpp b/core/src/Variable/Variable.cpp index 5e56d4b..3d29462 100644 --- a/core/src/Variable/Variable.cpp +++ b/core/src/Variable/Variable.cpp @@ -17,7 +17,9 @@ struct Variable::VariablePrivate { m_Metadata{metadata}, m_DataSeries{nullptr}, m_RealRange{INVALID_RANGE}, - m_NbPoints{0} + m_NbPoints{0}, + m_State{std::make_unique()} + { } @@ -28,7 +30,9 @@ struct Variable::VariablePrivate { m_Metadata{other.m_Metadata}, m_DataSeries{other.m_DataSeries != nullptr ? other.m_DataSeries->clone() : nullptr}, m_RealRange{other.m_RealRange}, - m_NbPoints{other.m_NbPoints} + m_NbPoints{other.m_NbPoints}, + m_State{other.m_State->clone()} + { } @@ -75,6 +79,7 @@ struct Variable::VariablePrivate { std::shared_ptr m_DataSeries; SqpRange m_RealRange; int m_NbPoints; + std::unique_ptr m_State; QReadWriteLock m_Lock; }; @@ -143,6 +148,24 @@ void Variable::setCacheRange(const SqpRange &cacheRange) noexcept impl->unlock(); } +StateData Variable::stateData() const noexcept +{ + impl->lockRead(); + Q_ASSERT(impl->m_State != nullptr); + auto stateData = impl->m_State->data(); + impl->unlock(); + + return stateData; +} + +void Variable::setState(std::unique_ptr state) noexcept +{ + Q_ASSERT(state != nullptr); + impl->lockWrite(); + impl->m_State = std::move(state); + impl->unlock(); +} + int Variable::nbPoints() const noexcept { return impl->m_NbPoints;