diff --git a/src/blackmisc/timestampobjectlist.cpp b/src/blackmisc/timestampobjectlist.cpp index 7e48fc3bc..df6d5235e 100644 --- a/src/blackmisc/timestampobjectlist.cpp +++ b/src/blackmisc/timestampobjectlist.cpp @@ -294,6 +294,44 @@ namespace BlackMisc } } + template + void ITimestampObjectList::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 + void ITimestampObjectList::push_backOverrideTimestamp(const OBJ &newObject, qint64 newTsMsSinceEpoch) + { + OBJ newObjectCopy(newObject); + newObjectCopy.setMSecsSinceEpoch(newTsMsSinceEpoch); + this->container().push_back(newObjectCopy); + } + + template + void ITimestampObjectList::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 int ITimestampObjectList::replaceIfSameTimestamp(const OBJ &newObject) { diff --git a/src/blackmisc/timestampobjectlist.h b/src/blackmisc/timestampobjectlist.h index 54b5e89ed..05bb28386 100644 --- a/src/blackmisc/timestampobjectlist.h +++ b/src/blackmisc/timestampobjectlist.h @@ -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);