Variable.cpp
169 lines
| 4.6 KiB
| text/x-c
|
CppLexer
Alexandre Leroux
|
r151 | #include "Variable/Variable.h" | ||
Alexandre Leroux
|
r152 | #include <Data/IDataSeries.h> | ||
r471 | #include <Data/SqpRange.h> | |||
r210 | ||||
r336 | #include <QReadWriteLock> | |||
#include <QThread> | ||||
r210 | Q_LOGGING_CATEGORY(LOG_Variable, "Variable") | |||
Alexandre Leroux
|
r152 | |||
Alexandre Leroux
|
r151 | struct Variable::VariablePrivate { | ||
r471 | explicit VariablePrivate(const QString &name, const SqpRange &dateTime, | |||
Alexandre Leroux
|
r373 | const QVariantHash &metadata) | ||
r488 | : m_Name{name}, m_Range{dateTime}, m_Metadata{metadata}, m_DataSeries{nullptr} | |||
Alexandre Leroux
|
r151 | { | ||
} | ||||
QString m_Name; | ||||
r210 | ||||
r488 | SqpRange m_Range; | |||
SqpRange m_CacheRange; | ||||
Alexandre Leroux
|
r373 | QVariantHash m_Metadata; | ||
Alexandre Leroux
|
r152 | std::unique_ptr<IDataSeries> m_DataSeries; | ||
Alexandre Leroux
|
r151 | }; | ||
r471 | Variable::Variable(const QString &name, const SqpRange &dateTime, const QVariantHash &metadata) | |||
Alexandre Leroux
|
r373 | : impl{spimpl::make_unique_impl<VariablePrivate>(name, dateTime, metadata)} | ||
Alexandre Leroux
|
r151 | { | ||
} | ||||
QString Variable::name() const noexcept | ||||
{ | ||||
return impl->m_Name; | ||||
} | ||||
r488 | SqpRange Variable::range() const noexcept | |||
r219 | { | |||
r488 | return impl->m_Range; | |||
r219 | } | |||
r488 | void Variable::setRange(const SqpRange &range) noexcept | |||
r241 | { | |||
r488 | impl->m_Range = range; | |||
} | ||||
SqpRange Variable::cacheRange() const noexcept | ||||
{ | ||||
return impl->m_CacheRange; | ||||
} | ||||
void Variable::setCacheRange(const SqpRange &cacheRange) noexcept | ||||
{ | ||||
impl->m_CacheRange = cacheRange; | ||||
r241 | } | |||
Alexandre Leroux
|
r287 | void Variable::setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept | ||
Alexandre Leroux
|
r152 | { | ||
r339 | qCDebug(LOG_Variable()) << "Variable::setDataSeries" << QThread::currentThread()->objectName(); | |||
Alexandre Leroux
|
r287 | if (!dataSeries) { | ||
/// @todo ALX : log | ||||
return; | ||||
Alexandre Leroux
|
r152 | } | ||
r219 | ||||
r494 | impl->m_DataSeries = dataSeries->clone(); | |||
// // Inits the data series of the variable | ||||
// if (!impl->m_DataSeries) { | ||||
// impl->m_DataSeries = dataSeries->clone(); | ||||
// } | ||||
// else { | ||||
// impl->m_DataSeries->merge(dataSeries.get()); | ||||
// } | ||||
} | ||||
void Variable::mergeDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept | ||||
{ | ||||
qCDebug(LOG_Variable()) << "Variable::setDataSeries" << QThread::currentThread()->objectName(); | ||||
if (!dataSeries) { | ||||
/// @todo ALX : log | ||||
return; | ||||
} | ||||
// Add or merge the data | ||||
Alexandre Leroux
|
r287 | // Inits the data series of the variable | ||
if (!impl->m_DataSeries) { | ||||
impl->m_DataSeries = dataSeries->clone(); | ||||
} | ||||
else { | ||||
r219 | impl->m_DataSeries->merge(dataSeries.get()); | |||
} | ||||
r494 | ||||
// sub the data | ||||
auto subData = this->dataSeries()->subData(this->cacheRange()); | ||||
qCCritical(LOG_Variable()) << "TORM: Variable::mergeDataSeries sub" << subData->range(); | ||||
this->setDataSeries(subData); | ||||
qCCritical(LOG_Variable()) << "TORM: Variable::mergeDataSeries set" | ||||
<< this->dataSeries()->range(); | ||||
Alexandre Leroux
|
r152 | } | ||
Alexandre Leroux
|
r169 | |||
IDataSeries *Variable::dataSeries() const noexcept | ||||
{ | ||||
return impl->m_DataSeries.get(); | ||||
} | ||||
r210 | ||||
Alexandre Leroux
|
r373 | QVariantHash Variable::metadata() const noexcept | ||
{ | ||||
return impl->m_Metadata; | ||||
} | ||||
r488 | bool Variable::contains(const SqpRange &range) const noexcept | |||
r210 | { | |||
r488 | return impl->m_Range.contains(range); | |||
r210 | } | |||
r240 | ||||
r488 | bool Variable::intersect(const SqpRange &range) const noexcept | |||
r240 | { | |||
r488 | return impl->m_Range.intersect(range); | |||
r240 | } | |||
r293 | ||||
r488 | bool Variable::isInside(const SqpRange &range) const noexcept | |||
r293 | { | |||
r488 | return range.contains(SqpRange{impl->m_Range.m_TStart, impl->m_Range.m_TEnd}); | |||
} | ||||
bool Variable::cacheContains(const SqpRange &range) const noexcept | ||||
{ | ||||
return impl->m_CacheRange.contains(range); | ||||
} | ||||
bool Variable::cacheIntersect(const SqpRange &range) const noexcept | ||||
{ | ||||
return impl->m_CacheRange.intersect(range); | ||||
} | ||||
bool Variable::cacheIsInside(const SqpRange &range) const noexcept | ||||
{ | ||||
return range.contains(SqpRange{impl->m_CacheRange.m_TStart, impl->m_CacheRange.m_TEnd}); | ||||
} | ||||
QVector<SqpRange> Variable::provideNotInCacheRangeList(const SqpRange &range) | ||||
{ | ||||
auto notInCache = QVector<SqpRange>{}; | ||||
if (!this->cacheContains(range)) { | ||||
if (range.m_TEnd <= impl->m_CacheRange.m_TStart | ||||
|| range.m_TStart >= impl->m_CacheRange.m_TEnd) { | ||||
notInCache << range; | ||||
} | ||||
else if (range.m_TStart < impl->m_CacheRange.m_TStart | ||||
&& range.m_TEnd <= impl->m_CacheRange.m_TEnd) { | ||||
notInCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TStart}; | ||||
} | ||||
else if (range.m_TStart < impl->m_CacheRange.m_TStart | ||||
&& range.m_TEnd > impl->m_CacheRange.m_TEnd) { | ||||
notInCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TStart} | ||||
r494 | << SqpRange{impl->m_CacheRange.m_TEnd, range.m_TEnd}; | |||
r488 | } | |||
else if (range.m_TStart < impl->m_CacheRange.m_TEnd) { | ||||
r494 | notInCache << SqpRange{impl->m_CacheRange.m_TEnd, range.m_TEnd}; | |||
r488 | } | |||
else { | ||||
qCCritical(LOG_Variable()) << tr("Detection of unknown case.") | ||||
<< QThread::currentThread(); | ||||
} | ||||
} | ||||
return notInCache; | ||||
r293 | } | |||