Ref T259, Ref T243 utility functions for timestamp based classes

This commit is contained in:
Klaus Basan
2018-03-10 17:56:53 +01:00
parent ad71a67a44
commit fd7b1e0d9c
4 changed files with 34 additions and 3 deletions

View File

@@ -315,6 +315,11 @@ namespace BlackMisc
return m_timeOffsetMs != 0;
}
void ITimestampWithOffsetBased::addMsecsToOffsetTime(qint64 msToAdd)
{
m_timeOffsetMs += msToAdd;
}
QString ITimestampWithOffsetBased::getTimeOffsetWithUnit() const
{
static const QString os("%1ms");

View File

@@ -167,6 +167,9 @@ namespace BlackMisc
//! Having a valid offset time
bool hasNonZeroOffsetTime() const;
//! Adds a value to offset time
void addMsecsToOffsetTime(qint64 msToAdd);
//! Offset with unit
QString getTimeOffsetWithUnit() const;

View File

@@ -261,7 +261,6 @@ namespace BlackMisc
if (!obj.hasValidTimestamp()) { return false; }
if (obj.getMSecsSinceEpoch() < max) { return false; }
max = obj.getMSecsSinceEpoch();
continue;
}
return true;
}
@@ -276,11 +275,20 @@ namespace BlackMisc
if (!obj.hasValidTimestamp()) { return false; }
if (obj.getMSecsSinceEpoch() > min) { return false; }
min = obj.getMSecsSinceEpoch();
continue;
}
return true;
}
template<class OBJ, class CONTAINER>
void ITimestampObjectList<OBJ, CONTAINER>::addMsecs(qint64 msToAdd)
{
if (msToAdd == 0) { return; }
for (ITimestampBased &obj : this->container())
{
obj.addMsecs(msToAdd);
}
}
template <class OBJ, class CONTAINER>
void ITimestampWithOffsetObjectList<OBJ, CONTAINER>::sortAdjustedLatestFirst()
{
@@ -314,6 +322,15 @@ namespace BlackMisc
return false;
}
template<class OBJ, class CONTAINER>
void ITimestampWithOffsetObjectList<OBJ, CONTAINER>::addMsecsToOffset(qint64 msToAdd)
{
for (ITimestampWithOffsetBased &obj : this->container())
{
obj.addMsecsToOffsetTime(msToAdd);
}
}
template<class OBJ, class CONTAINER>
ITimestampWithOffsetObjectList<OBJ, CONTAINER>::ITimestampWithOffsetObjectList() : ITimestampObjectList<OBJ, CONTAINER>()
{

View File

@@ -106,6 +106,9 @@ namespace BlackMisc
//! \remark all object must have a valid timestamp
bool isSortedLatestFirst() const;
//! Adds a time to all values
void addMsecs(qint64 msToAdd);
protected:
//! Constructor
ITimestampObjectList();
@@ -134,6 +137,9 @@ namespace BlackMisc
//! Any negative offset time?
bool containsNegativeOffsetTime() const;
//! Adds a time to all offset values
void addMsecsToOffset(qint64 msToAdd);
//! Insert as first element by keeping maxElements and the latest first
void push_frontKeepLatestAdjustedFirst(const OBJ &value, int maxElements = -1);
@@ -152,7 +158,7 @@ namespace BlackMisc
//! Closest adjusted time difference
OBJ findClosestTimeDistanceAdjusted(qint64 msSinceEpoch) const;
protected:
protected:
//! Constructor
ITimestampWithOffsetObjectList();
};