From fd7b1e0d9c9e5d45f24ee68b9a998f0e4c1192cd Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 10 Mar 2018 17:56:53 +0100 Subject: [PATCH] Ref T259, Ref T243 utility functions for timestamp based classes --- src/blackmisc/timestampbased.cpp | 5 +++++ src/blackmisc/timestampbased.h | 3 +++ src/blackmisc/timestampobjectlist.cpp | 21 +++++++++++++++++++-- src/blackmisc/timestampobjectlist.h | 8 +++++++- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/blackmisc/timestampbased.cpp b/src/blackmisc/timestampbased.cpp index f8e9cf039..419bd5d5c 100644 --- a/src/blackmisc/timestampbased.cpp +++ b/src/blackmisc/timestampbased.cpp @@ -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"); diff --git a/src/blackmisc/timestampbased.h b/src/blackmisc/timestampbased.h index b16537f63..02740849c 100644 --- a/src/blackmisc/timestampbased.h +++ b/src/blackmisc/timestampbased.h @@ -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; diff --git a/src/blackmisc/timestampobjectlist.cpp b/src/blackmisc/timestampobjectlist.cpp index 99b71afd9..9f108c1d1 100644 --- a/src/blackmisc/timestampobjectlist.cpp +++ b/src/blackmisc/timestampobjectlist.cpp @@ -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 + void ITimestampObjectList::addMsecs(qint64 msToAdd) + { + if (msToAdd == 0) { return; } + for (ITimestampBased &obj : this->container()) + { + obj.addMsecs(msToAdd); + } + } + template void ITimestampWithOffsetObjectList::sortAdjustedLatestFirst() { @@ -314,6 +322,15 @@ namespace BlackMisc return false; } + template + void ITimestampWithOffsetObjectList::addMsecsToOffset(qint64 msToAdd) + { + for (ITimestampWithOffsetBased &obj : this->container()) + { + obj.addMsecsToOffsetTime(msToAdd); + } + } + template ITimestampWithOffsetObjectList::ITimestampWithOffsetObjectList() : ITimestampObjectList() { diff --git a/src/blackmisc/timestampobjectlist.h b/src/blackmisc/timestampobjectlist.h index 0acccbe09..f3fb26a6e 100644 --- a/src/blackmisc/timestampobjectlist.h +++ b/src/blackmisc/timestampobjectlist.h @@ -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(); };