mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-15 01:05: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;
|
return m_timeOffsetMs != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ITimestampWithOffsetBased::addMsecsToOffsetTime(qint64 msToAdd)
|
||||||
|
{
|
||||||
|
m_timeOffsetMs += msToAdd;
|
||||||
|
}
|
||||||
|
|
||||||
QString ITimestampWithOffsetBased::getTimeOffsetWithUnit() const
|
QString ITimestampWithOffsetBased::getTimeOffsetWithUnit() const
|
||||||
{
|
{
|
||||||
static const QString os("%1ms");
|
static const QString os("%1ms");
|
||||||
|
|||||||
@@ -167,6 +167,9 @@ namespace BlackMisc
|
|||||||
//! Having a valid offset time
|
//! Having a valid offset time
|
||||||
bool hasNonZeroOffsetTime() const;
|
bool hasNonZeroOffsetTime() const;
|
||||||
|
|
||||||
|
//! Adds a value to offset time
|
||||||
|
void addMsecsToOffsetTime(qint64 msToAdd);
|
||||||
|
|
||||||
//! Offset with unit
|
//! Offset with unit
|
||||||
QString getTimeOffsetWithUnit() const;
|
QString getTimeOffsetWithUnit() const;
|
||||||
|
|
||||||
|
|||||||
@@ -261,7 +261,6 @@ namespace BlackMisc
|
|||||||
if (!obj.hasValidTimestamp()) { return false; }
|
if (!obj.hasValidTimestamp()) { return false; }
|
||||||
if (obj.getMSecsSinceEpoch() < max) { return false; }
|
if (obj.getMSecsSinceEpoch() < max) { return false; }
|
||||||
max = obj.getMSecsSinceEpoch();
|
max = obj.getMSecsSinceEpoch();
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -276,11 +275,20 @@ namespace BlackMisc
|
|||||||
if (!obj.hasValidTimestamp()) { return false; }
|
if (!obj.hasValidTimestamp()) { return false; }
|
||||||
if (obj.getMSecsSinceEpoch() > min) { return false; }
|
if (obj.getMSecsSinceEpoch() > min) { return false; }
|
||||||
min = obj.getMSecsSinceEpoch();
|
min = obj.getMSecsSinceEpoch();
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
return true;
|
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>
|
template <class OBJ, class CONTAINER>
|
||||||
void ITimestampWithOffsetObjectList<OBJ, CONTAINER>::sortAdjustedLatestFirst()
|
void ITimestampWithOffsetObjectList<OBJ, CONTAINER>::sortAdjustedLatestFirst()
|
||||||
{
|
{
|
||||||
@@ -314,6 +322,15 @@ namespace BlackMisc
|
|||||||
return false;
|
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>
|
template<class OBJ, class CONTAINER>
|
||||||
ITimestampWithOffsetObjectList<OBJ, CONTAINER>::ITimestampWithOffsetObjectList() : ITimestampObjectList<OBJ, CONTAINER>()
|
ITimestampWithOffsetObjectList<OBJ, CONTAINER>::ITimestampWithOffsetObjectList() : ITimestampObjectList<OBJ, CONTAINER>()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -106,6 +106,9 @@ namespace BlackMisc
|
|||||||
//! \remark all object must have a valid timestamp
|
//! \remark all object must have a valid timestamp
|
||||||
bool isSortedLatestFirst() const;
|
bool isSortedLatestFirst() const;
|
||||||
|
|
||||||
|
//! Adds a time to all values
|
||||||
|
void addMsecs(qint64 msToAdd);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! Constructor
|
//! Constructor
|
||||||
ITimestampObjectList();
|
ITimestampObjectList();
|
||||||
@@ -134,6 +137,9 @@ namespace BlackMisc
|
|||||||
//! Any negative offset time?
|
//! Any negative offset time?
|
||||||
bool containsNegativeOffsetTime() const;
|
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
|
//! Insert as first element by keeping maxElements and the latest first
|
||||||
void push_frontKeepLatestAdjustedFirst(const OBJ &value, int maxElements = -1);
|
void push_frontKeepLatestAdjustedFirst(const OBJ &value, int maxElements = -1);
|
||||||
|
|
||||||
@@ -152,7 +158,7 @@ namespace BlackMisc
|
|||||||
//! Closest adjusted time difference
|
//! Closest adjusted time difference
|
||||||
OBJ findClosestTimeDistanceAdjusted(qint64 msSinceEpoch) const;
|
OBJ findClosestTimeDistanceAdjusted(qint64 msSinceEpoch) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! Constructor
|
//! Constructor
|
||||||
ITimestampWithOffsetObjectList();
|
ITimestampWithOffsetObjectList();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user