##// END OF EJS Templates
Removed forgotten files form previous impl of VC, fixed wrong submodules...
Removed forgotten files form previous impl of VC, fixed wrong submodules init (was always erasing changes :( ) Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>

File last commit:

r29:ab4890d233e8
r31:dec007be0b03
Show More
Variable.cpp
214 lines | 6.0 KiB | text/x-c | CppLexer
Some refactoring on Variable class...
r15 #include <optional>
#include <QMutex>
#include <QReadWriteLock>
#include <QThread>
First init from SciQLop Core module...
r0 #include "Variable/Variable.h"
#include <Data/IDataSeries.h>
#include <Data/DateTimeRange.h>
Basic serial variable creation and update...
r2 #include <Common/debug.h>
First init from SciQLop Core module...
r0
Q_LOGGING_CATEGORY(LOG_Variable, "Variable")
/**
* Searches in metadata for a value that can be converted to DataSeriesType
* @param metadata the metadata where to search
* @return the value converted to a DataSeriesType if it was found, UNKNOWN type otherwise
* @sa DataSeriesType
*/
Made Variable data update atomic ease thread safety and avoid mixing...
r16 static DataSeriesType findDataSeriesType(const QVariantHash &metadata)
First init from SciQLop Core module...
r0 {
auto dataSeriesType = DataSeriesType::UNKNOWN;
// Go through the metadata and stop at the first value that could be converted to DataSeriesType
for (auto it = metadata.cbegin(), end = metadata.cend();
it != end && dataSeriesType == DataSeriesType::UNKNOWN; ++it) {
dataSeriesType = DataSeriesTypeUtils::fromString(it.value().toString());
}
return dataSeriesType;
}
Some refactoring on Variable class...
r15 #define VP_PROPERTY(property,getter,setter,type) \
type getter() noexcept\
{\
QReadLocker lock{&m_Lock};\
return property;\
}\
void setter(const type& getter) noexcept\
{\
QWriteLocker lock{&m_Lock};\
property = getter;\
}\
type property;\
#define V_FW_GETTER_SETTER(getter,setter, type)\
type Variable::getter() const noexcept \
{\
return impl->getter();\
}\
void Variable::setter(const type& getter) noexcept \
{\
impl->setter(getter);\
Removed useless function in Variable class...
r29 emit updated();\
Some refactoring on Variable class...
r15 }\
First init from SciQLop Core module...
r0 struct Variable::VariablePrivate {
explicit VariablePrivate(const QString &name, const QVariantHash &metadata)
: m_Name{name},
m_Range{INVALID_RANGE},
m_CacheRange{INVALID_RANGE},
m_Metadata{metadata},
m_DataSeries{nullptr},
m_RealRange{INVALID_RANGE},
m_NbPoints{0},
m_Type{findDataSeriesType(m_Metadata)}
{
}
VariablePrivate(const VariablePrivate &other)
: m_Name{other.m_Name},
m_Range{other.m_Range},
m_CacheRange{other.m_CacheRange},
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_Type{findDataSeriesType(m_Metadata)}
{
}
void lockRead() { m_Lock.lockForRead(); }
void lockWrite() { m_Lock.lockForWrite(); }
void unlock() { m_Lock.unlock(); }
void purgeDataSeries()
{
if (m_DataSeries) {
m_DataSeries->purge(m_CacheRange.m_TStart, m_CacheRange.m_TEnd);
}
updateRealRange();
updateNbPoints();
}
Made Variable data update atomic ease thread safety and avoid mixing...
r16 void mergeDataSeries(const std::vector<IDataSeries*>& dataseries)
{
QWriteLocker lock{&m_Lock};
for(auto ds:dataseries)
{
if(m_DataSeries)
m_DataSeries->merge(ds);
else
m_DataSeries = ds->clone();
}
}
First init from SciQLop Core module...
r0 void updateNbPoints() { m_NbPoints = m_DataSeries ? m_DataSeries->nbPoints() : 0; }
/// Updates real range according to current variable range and data series
void updateRealRange()
{
if (m_DataSeries) {
Made Variable data update atomic ease thread safety and avoid mixing...
r16 auto lock = m_DataSeries->getReadLock();
First init from SciQLop Core module...
r0 auto end = m_DataSeries->cend();
auto minXAxisIt = m_DataSeries->minXAxisData(m_Range.m_TStart);
auto maxXAxisIt = m_DataSeries->maxXAxisData(m_Range.m_TEnd);
Made Variable data update atomic ease thread safety and avoid mixing...
r16 if(minXAxisIt != end && maxXAxisIt != end && minXAxisIt->x() <= maxXAxisIt->x())
m_RealRange = DateTimeRange{minXAxisIt->x(), maxXAxisIt->x()};
else
m_RealRange = std::nullopt;
First init from SciQLop Core module...
r0 }
else {
Some refactoring on Variable class...
r15 m_RealRange = std::nullopt;
First init from SciQLop Core module...
r0 }
}
Some refactoring on Variable class...
r15 VP_PROPERTY(m_Name, name, setName, QString)
VP_PROPERTY(m_Range, range, setRange, DateTimeRange)
VP_PROPERTY(m_CacheRange, cacheRange, setCacheRange, DateTimeRange)
VP_PROPERTY(m_Metadata, metadata, setMetadata, QVariantHash)
VP_PROPERTY(m_DataSeries, dataSeries, setDataSeries, std::shared_ptr<IDataSeries>)
VP_PROPERTY(m_RealRange, realRange, setRealRange, std::optional<DateTimeRange>)
VariableController2 tests refactoring...
r3 unsigned int m_NbPoints;
Some refactoring on Variable class...
r15 VP_PROPERTY(m_Type, type, setType, DataSeriesType)
First init from SciQLop Core module...
r0 QReadWriteLock m_Lock;
};
Variable::Variable(const QString &name, const QVariantHash &metadata)
Basic serial variable creation and update...
r2 : impl{spimpl::make_unique_impl<VariablePrivate>(name, metadata)},
_uuid{QUuid::createUuid()}
First init from SciQLop Core module...
r0 {
}
Variable::Variable(const Variable &other)
Basic serial variable creation and update...
r2 : impl{spimpl::make_unique_impl<VariablePrivate>(*other.impl)},
_uuid{QUuid::createUuid()} //is a clone but must have a != uuid
First init from SciQLop Core module...
r0 {
}
std::shared_ptr<Variable> Variable::clone() const
{
return std::make_shared<Variable>(*this);
}
Some refactoring on Variable class...
r15 V_FW_GETTER_SETTER(name,setName,QString)
First init from SciQLop Core module...
r0
DateTimeRange Variable::range() const noexcept
{
Some refactoring on Variable class...
r15 return impl->range();
First init from SciQLop Core module...
r0 }
Many fixes plus implemented var synchronization...
r9 void Variable::setRange(const DateTimeRange &range, bool notify) noexcept
First init from SciQLop Core module...
r0 {
Some refactoring on Variable class...
r15 impl->setRange(range);
First init from SciQLop Core module...
r0 impl->updateRealRange();
Many fixes plus implemented var synchronization...
r9 if(notify)
emit this->updated();
First init from SciQLop Core module...
r0 }
Some refactoring on Variable class...
r15 V_FW_GETTER_SETTER(cacheRange, setCacheRange, DateTimeRange)
First init from SciQLop Core module...
r0
VariableController2 tests refactoring...
r3 unsigned int Variable::nbPoints() const noexcept
First init from SciQLop Core module...
r0 {
return impl->m_NbPoints;
}
Some refactoring on Variable class...
r15 std::optional<DateTimeRange> Variable::realRange() const noexcept
First init from SciQLop Core module...
r0 {
Some refactoring on Variable class...
r15 return impl->realRange();
First init from SciQLop Core module...
r0 }
Made Variable data update atomic ease thread safety and avoid mixing...
r16 void Variable::updateData(const std::vector<IDataSeries *> &dataSeries, const DateTimeRange &newRange, const DateTimeRange &newCacheRange, bool notify)
Basic serial variable creation and update...
r2 {
Made Variable data update atomic ease thread safety and avoid mixing...
r16 {
QWriteLocker lock{&m_lock};
impl->mergeDataSeries(dataSeries);
impl->setRange(newRange);
impl->setCacheRange(newCacheRange);
impl->purgeDataSeries();
Basic serial variable creation and update...
r2 }
Many fixes plus implemented var synchronization...
r9 if(notify)
Made Variable data update atomic ease thread safety and avoid mixing...
r16 emit updated();
Basic serial variable creation and update...
r2 }
First init from SciQLop Core module...
r0
std::shared_ptr<IDataSeries> Variable::dataSeries() const noexcept
{
Some refactoring on Variable class...
r15 return impl->dataSeries();
First init from SciQLop Core module...
r0 }
DataSeriesType Variable::type() const noexcept
{
Some refactoring on Variable class...
r15 return impl->type();
First init from SciQLop Core module...
r0 }
QVariantHash Variable::metadata() const noexcept
{
impl->lockRead();
auto metadata = impl->m_Metadata;
impl->unlock();
return metadata;
}