mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-03 15:45:46 +08:00
Ref T515, allow to override the timestamps
Rational: Sometime we want to keep a certain order of status messages, and this can be achieved "by that trick"
This commit is contained in:
committed by
Mat Sutcliffe
parent
407aaba746
commit
e3da559c5e
@@ -294,6 +294,44 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
template<class OBJ, class CONTAINER>
|
||||
void ITimestampObjectList<OBJ, CONTAINER>::push_backIncreaseTimestamp(const OBJ &newObject)
|
||||
{
|
||||
if (this->container().isEmpty())
|
||||
{
|
||||
this->container().push_back(newObject);
|
||||
return;
|
||||
}
|
||||
const qint64 newMs = newObject.getMSecsSinceEpoch();
|
||||
const qint64 oldMs = this->container().back().getMSecsSinceEpoch();
|
||||
if (newMs > oldMs)
|
||||
{
|
||||
this->container().push_back(newObject);
|
||||
return;
|
||||
}
|
||||
this->push_backOverrideTimestamp(newObject, oldMs + 1);
|
||||
}
|
||||
|
||||
template<class OBJ, class CONTAINER>
|
||||
void ITimestampObjectList<OBJ, CONTAINER>::push_backOverrideTimestamp(const OBJ &newObject, qint64 newTsMsSinceEpoch)
|
||||
{
|
||||
OBJ newObjectCopy(newObject);
|
||||
newObjectCopy.setMSecsSinceEpoch(newTsMsSinceEpoch);
|
||||
this->container().push_back(newObjectCopy);
|
||||
}
|
||||
|
||||
template<class OBJ, class CONTAINER>
|
||||
void ITimestampObjectList<OBJ, CONTAINER>::setNewTimestampStartingLast(qint64 startTimeStampMs, qint64 deltaTimeMs)
|
||||
{
|
||||
if (this->container().isEmpty()) { return; }
|
||||
qint64 currentMs = startTimeStampMs;
|
||||
for (auto it = this->container().rbegin(); it != this->container().rend(); ++it)
|
||||
{
|
||||
it->setMSecsSinceEpoch(currentMs);
|
||||
currentMs += deltaTimeMs;
|
||||
}
|
||||
}
|
||||
|
||||
template<class OBJ, class CONTAINER>
|
||||
int ITimestampObjectList<OBJ, CONTAINER>::replaceIfSameTimestamp(const OBJ &newObject)
|
||||
{
|
||||
|
||||
@@ -132,6 +132,16 @@ namespace BlackMisc
|
||||
//! Insert as first element by keeping maxElements and the latest first
|
||||
void push_frontKeepLatestFirst(const OBJ &value, bool replaceSameTimestamp = true, int maxElements = -1);
|
||||
|
||||
//! Push back and increase the timestamp at least by +1ms if equal to last element
|
||||
//! \remark if the timestamp is already greater it does not modifcation
|
||||
void push_backIncreaseTimestamp(const OBJ &newObject);
|
||||
|
||||
//! Push back, but set new timestamp
|
||||
void push_backOverrideTimestamp(const OBJ &newObject, qint64 newTsMsSinceEpoch);
|
||||
|
||||
//! Set new timestamps starting with the last element
|
||||
void setNewTimestampStartingLast(qint64 startTimeStampMs, qint64 deltaTimeMs);
|
||||
|
||||
//! Replace if an object has the same timestamp
|
||||
int replaceIfSameTimestamp(const OBJ &newObject);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user