mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 04:25:35 +08:00
Ref T259, Ref T243 utility functions for timestamp based classes
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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>()
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user