Ref T259, Ref T243 timestamp utility functions

This commit is contained in:
Klaus Basan
2018-03-04 22:26:11 +01:00
parent c061091bd2
commit 7beab371a1
3 changed files with 35 additions and 1 deletions

View File

@@ -102,6 +102,17 @@ namespace BlackMisc
});
}
template<class OBJ, class CONTAINER>
OBJ ITimestampObjectList<OBJ, CONTAINER>::findClosestTimeDistance(qint64 msSinceEpoch) const
{
if (this->container().isEmpty()) { return OBJ(); }
const auto closest = std::min_element(this->container().cbegin(), this->container().cend(), [ = ](const ITimestampBased & a, const ITimestampBased & b)
{
return qAbs(a.getTimeDifferenceMs(msSinceEpoch)) < qAbs(b.getTimeDifferenceMs(msSinceEpoch));
});
return *closest;
}
template <class OBJ, class CONTAINER>
bool ITimestampObjectList<OBJ, CONTAINER>::hasInvalidTimestamps() const
{
@@ -377,6 +388,17 @@ namespace BlackMisc
return true;
}
template<class OBJ, class CONTAINER>
OBJ ITimestampWithOffsetObjectList<OBJ, CONTAINER>::findClosestTimeDistanceAdjusted(qint64 msSinceEpoch) const
{
if (this->container().isEmpty()) { return OBJ(); }
const auto closest = std::min_element(this->container().cbegin(), this->container().cend(), [ = ](const ITimestampWithOffsetBased & a, const ITimestampWithOffsetBased & b)
{
return qAbs(a.getAdjustedTimeDifferenceMs(msSinceEpoch)) < qAbs(b.getAdjustedTimeDifferenceMs(msSinceEpoch));
});
return *closest;
}
// see here for the reason of thess forward instantiations
// https://isocpp.org/wiki/faq/templates#separate-template-fn-defn-from-decl
//! \cond PRIVATE