swift
Loading...
Searching...
No Matches
timestampobjectlist.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#ifndef SWIFT_MISC_TIMESTAMPOBJECTLIST_H
7#define SWIFT_MISC_TIMESTAMPOBJECTLIST_H
8
9#include <algorithm>
10
11#include <QtGlobal>
12
13#include "config/buildconfig.h"
14#include "misc/predicates.h"
16#include "misc/timestampbased.h"
17#include "misc/verify.h"
18
19class QDateTime;
20
21namespace swift::misc
22{
25 {
26 qint64 min;
27 qint64 max;
28 double mean;
29
31 bool isValid() const { return min >= 0 && max >= 0; }
32
34 void reset()
35 {
36 min = -1;
37 max = -1;
38 mean = -1;
39 }
40
43 {
44 return QStringLiteral("Min: %1ms Max: %2ms Mean: %3ms").arg(min).arg(max).arg(mean, 0, 'f', 2);
45 }
46 };
47
50 template <class OBJ, class CONTAINER>
52 {
53 static_assert(std::is_base_of_v<ITimestampBased, OBJ>, "OBJ needs to implement ITimestampBased");
54
55 public:
58 {
59 NoTimestampSortHint,
60 TimestampLatestFirst,
61 TimestampLatestLast
62 };
63
65 CONTAINER findBefore(const QDateTime &dateTime) const { return this->findBefore(dateTime.toMSecsSinceEpoch()); }
66
68 CONTAINER findBefore(qint64 msSinceEpoch) const
69 {
70 return this->container().findBy([&](const OBJ &obj) { return obj.isOlderThan(msSinceEpoch); });
71 }
72
74 OBJ findObjectBeforeOrDefault(qint64 msSinceEpoch) const
75 {
76 const CONTAINER before = this->findBefore(msSinceEpoch);
77 if (before.isEmpty())
78 {
79 return OBJ();
80 }
81 return before.latestObject();
82 }
83
85 CONTAINER findBeforeAndRemove(qint64 msSinceEpoch)
86 {
87 CONTAINER result(findBefore(msSinceEpoch));
88 this->removeBefore(msSinceEpoch);
89 return result;
90 }
91
93 CONTAINER findBeforeNowMinusOffset(qint64 msOffset) const
94 {
95 return this->findBefore(QDateTime::currentMSecsSinceEpoch() - msOffset);
96 }
97
99 CONTAINER findAfter(const QDateTime &dateTime) const { return this->findAfter(dateTime.toMSecsSinceEpoch()); }
100
102 CONTAINER findAfter(qint64 msSinceEpoch) const
103 {
104 return this->container().findBy([&](const OBJ &obj) { return obj.isNewerThan(msSinceEpoch); });
105 }
106
108 CONTAINER findAfterNowMinusOffset(qint64 msOffset) const
109 {
110 return this->findAfter(QDateTime::currentMSecsSinceEpoch() - msOffset);
111 }
112
114 OBJ findObjectAfterOrDefault(qint64 msSinceEpoch) const
115 {
116 const CONTAINER after = this->findAfter(msSinceEpoch);
117 if (after.isEmpty())
118 {
119 return OBJ();
120 }
121 return after.oldestObject();
122 }
123
125 CONTAINER findInvalidTimestamps() const
126 {
127 return this->container().findBy([&](const OBJ &obj) { return !obj.hasValidTimestamp(); });
128 }
129
131 OBJ findClosestTimeDistance(qint64 msSinceEpoch) const
132 {
133 if (this->container().isEmpty())
134 {
135 return OBJ();
136 }
137 const auto closest = std::min_element(this->container().cbegin(), this->container().cend(),
138 [=](const ITimestampBased &a, const ITimestampBased &b) {
139 return qAbs(a.getTimeDifferenceMs(msSinceEpoch)) <
140 qAbs(b.getTimeDifferenceMs(msSinceEpoch));
141 });
142 return *closest;
143 }
144
146 bool hasInvalidTimestamps() const { return this->container().contains(&OBJ::hasValidTimestamp, false); }
147
150 {
151 for (ITimestampBased &tsObj : this->container())
152 {
153 tsObj.setCurrentUtcTime();
154 }
155 }
156
158 void setUtcTime(qint64 msSinceEpoch)
159 {
160 for (ITimestampBased &tsObj : this->container())
161 {
162 tsObj.setMSecsSinceEpoch(msSinceEpoch);
163 }
164 }
165
168 {
169 for (ITimestampBased &tsObj : this->container())
170 {
171 if (tsObj.hasValidTimestamp())
172 {
173 continue;
174 }
175 tsObj.setCurrentUtcTime();
176 }
177 }
178
181 {
182 if (this->container().isEmpty())
183 {
184 return {};
185 }
186 return this->latestObject().getUtcTimestamp();
187 }
188
191 {
192 const QDateTime dt(latestTimestamp());
193 return dt.isValid() ? dt.toMSecsSinceEpoch() : -1;
194 }
195
198 {
199 if (this->container().isEmpty())
200 {
201 return {};
202 }
203 return this->oldestObject().getUtcTimestamp();
204 }
205
208 {
209 const QDateTime dt(oldestTimestamp());
210 return dt.isValid() ? dt.toMSecsSinceEpoch() : -1;
211 }
212
214 OBJ latestObject() const
215 {
216 if (this->container().isEmpty())
217 {
218 return OBJ();
219 }
220 const auto latest =
221 std::max_element(this->container().begin(), this->container().end(), [](const OBJ &a, const OBJ &b) {
222 return a.getMSecsSinceEpoch() < b.getMSecsSinceEpoch();
223 });
224 return *latest;
225 }
226
228 OBJ oldestObject() const
229 {
230 if (this->container().isEmpty())
231 {
232 return OBJ();
233 }
234 const auto oldest =
235 std::min_element(this->container().begin(), this->container().end(), [](const OBJ &a, const OBJ &b) {
236 return a.getMSecsSinceEpoch() < b.getMSecsSinceEpoch();
237 });
238 return *oldest;
239 }
240
242 int removeBefore(const QDateTime &dateTime) { return this->removeBefore(dateTime.toMSecsSinceEpoch()); }
243
245 int removeBefore(qint64 msSinceEpoch)
246 {
247 return this->container().removeIf([&](const OBJ &obj) { return obj.isOlderThan(msSinceEpoch); });
248 }
249
251 int removeOlderThanNowMinusOffset(qint64 offsetMs)
252 {
253 const qint64 epoch = QDateTime::currentMSecsSinceEpoch() - offsetMs;
254 return this->container().removeIf([&](const OBJ &obj) { return obj.isOlderThan(epoch); });
255 }
256
259 {
260 this->container().sortOldestFirst();
261 this->container().reverse();
262 }
263
265 void sortOldestFirst() { this->container().sort(predicates::MemberLess(&OBJ::getMSecsSinceEpoch)); }
266
268 void push_frontKeepLatestFirst(const OBJ &value, bool replaceSameTimestamp = true, int maxElements = -1)
269 {
270 Q_ASSERT_X(maxElements < 0 || maxElements > 1, Q_FUNC_INFO, "Max.value wrong range");
271 CONTAINER &c = this->container();
272 if (replaceSameTimestamp && !c.isEmpty() && c[0].getMSecsSinceEpoch() == value.getMSecsSinceEpoch())
273 {
274 c[0] = value;
275 if (maxElements > 0)
276 {
277 c.truncate(maxElements);
278 }
279 }
280 else
281 {
282 if (maxElements > 0)
283 {
284 c.truncate(maxElements - 1);
285 }
286 const bool needSort = !c.isEmpty() && value.isOlderThan(c.front());
287 c.push_front(value);
288 if (needSort)
289 {
291 }
292 }
293
294 // crosscheck
296 {
297 Q_ASSERT_X(this->isSortedLatestFirst(), Q_FUNC_INFO, "Wrong sort order");
298 }
299 }
300
303 void push_backIncreaseTimestamp(const OBJ &newObject)
304 {
305 if (this->container().isEmpty())
306 {
307 this->container().push_back(newObject);
308 return;
309 }
310 const qint64 newMs = newObject.getMSecsSinceEpoch();
311 const qint64 oldMs = this->container().back().getMSecsSinceEpoch();
312 if (newMs > oldMs)
313 {
314 this->container().push_back(newObject);
315 return;
316 }
317 this->push_backOverrideTimestamp(newObject, oldMs + 1);
318 }
319
321 void push_backOverrideTimestamp(const OBJ &newObject, qint64 newTsMsSinceEpoch)
322 {
323 OBJ newObjectCopy(newObject);
324 newObjectCopy.setMSecsSinceEpoch(newTsMsSinceEpoch);
325 this->container().push_back(newObjectCopy);
326 }
327
329 void setNewTimestampStartingLast(qint64 startTimeStampMs, qint64 deltaTimeMs)
330 {
331 if (this->container().isEmpty())
332 {
333 return;
334 }
335 qint64 currentMs = startTimeStampMs;
336 for (auto it = this->container().rbegin(); it != this->container().rend(); ++it)
337 {
338 it->setMSecsSinceEpoch(currentMs);
339 currentMs += deltaTimeMs;
340 }
341 }
342
344 int replaceIfSameTimestamp(const OBJ &newObject)
345 {
346 int c = 0;
347 for (OBJ &obj : this->container())
348 {
349 if (obj.getMSecsSinceEpoch() == newObject.getMSecsSinceEpoch())
350 {
351 obj = newObject;
352 c++;
353 }
354 }
355 return c;
356 }
357
361 {
362 if (this->container().size() < 2)
363 {
364 return true;
365 }
366 qint64 max = -1;
367 for (const ITimestampBased &obj : this->container())
368 {
369 if (!obj.hasValidTimestamp())
370 {
371 return false;
372 }
373 if (obj.getMSecsSinceEpoch() < max)
374 {
375 return false;
376 }
377 max = obj.getMSecsSinceEpoch();
378 }
379 return true;
380 }
381
385 {
386 if (this->container().size() < 2)
387 {
388 return true;
389 }
390 qint64 min = std::numeric_limits<qint64>::max();
391 for (const ITimestampBased &obj : this->container())
392 {
393 if (!obj.hasValidTimestamp())
394 {
395 return false;
396 }
397 if (obj.getMSecsSinceEpoch() > min)
398 {
399 return false;
400 }
401 min = obj.getMSecsSinceEpoch();
402 }
403 return true;
404 }
405
407 void addMsecs(qint64 msToAdd)
408 {
409 if (msToAdd == 0)
410 {
411 return;
412 }
413 for (ITimestampBased &obj : this->container())
414 {
415 obj.addMsecs(msToAdd);
416 }
417 }
418
421
425 {
427 mmm.reset();
428 const CONTAINER &container = this->container();
429 if (container.size() < 2)
430 {
431 return mmm;
432 }
433
434 // Do not confuse with adjusted sort hint!
435 if (container.m_tsSortHint == NoTimestampSortHint)
436 {
437 CONTAINER copy(container);
438 copy.sortLatestFirst();
439 copy.m_tsSortHint = TimestampLatestFirst;
440 return copy.getTimestampDifferenceMinMaxMean();
441 }
442
443 mmm.max = std::numeric_limits<qint64>::min();
444 mmm.min = std::numeric_limits<qint64>::max();
445 qint64 mean = 0;
446 int c = 0;
447 OBJ last;
448
449 for (const OBJ &object : container)
450 {
451 if (c > 0)
452 {
453 const ITimestampBased &l = last;
454 const ITimestampBased &o = object;
455 const qint64 diff = l.getAbsTimeDifferenceMs(o);
456 mmm.max = std::max(diff, mmm.max);
457 mmm.min = std::min(diff, mmm.min);
458 mean += diff;
459 }
460 c++;
461 last = object;
462 }
463
464 mmm.mean = mean / c;
465 return mmm;
466 }
467
468 protected:
471
473 const CONTAINER &container() const { return static_cast<const CONTAINER &>(*this); }
474
476 CONTAINER &container() { return static_cast<CONTAINER &>(*this); }
477
478 HintTimestampSort m_tsSortHint = NoTimestampSortHint;
479 };
480
483 template <class OBJ, class CONTAINER>
485 {
486 static_assert(std::is_base_of_v<ITimestampWithOffsetBased, OBJ>, "OBJ needs to implement ITimestampBased");
487
488 public:
491 {
492 NoAdjustedTimestampSortHint,
493 AdjustedTimestampLatestFirst
494 };
495
498 {
499 this->container().sortAdjustedOldestFirst();
500 this->container().reverse();
501 }
502
505 {
506 CONTAINER copy(this->container());
507 copy.sortAdjustedLatestFirst();
508 return copy;
509 }
510
512 CONTAINER getLatestAdjustedTwoObjects(bool alreadySortedLatestFirst = false) const
513 {
514 if (this->container().size() < 2)
515 {
516 return CONTAINER();
517 }
518 CONTAINER copy(alreadySortedLatestFirst ? this->container() :
520 copy.truncate(2);
521 return copy;
522 }
523
526 {
527 this->container().sort(predicates::MemberLess(&OBJ::getAdjustedMSecsSinceEpoch));
528 }
529
532 {
533 return std::any_of(this->container().begin(), this->container().end(),
534 [](const ITimestampWithOffsetBased &obj) { return obj.getTimeOffsetMs() <= 0; });
535 }
536
539 {
540 return std::any_of(this->container().begin(), this->container().end(),
541 [](const ITimestampWithOffsetBased &obj) { return obj.getTimeOffsetMs() < 0; });
542 }
543
545 void addMsecsToOffset(qint64 msToAdd)
546 {
547 for (ITimestampWithOffsetBased &obj : this->container())
548 {
549 obj.addMsecsToOffsetTime(msToAdd);
550 }
551 }
552
554 void push_frontKeepLatestAdjustedFirst(const OBJ &value, bool replaceSameTimestamp = true, int maxElements = -1)
555 {
556 Q_ASSERT_X(maxElements < 0 || maxElements > 1, Q_FUNC_INFO, "Max.value wrong range");
557 CONTAINER &c = this->container();
558 if (replaceSameTimestamp && !c.isEmpty() && c[0].getMSecsSinceEpoch() == value.getMSecsSinceEpoch())
559 {
560 c[0] = value;
561 if (maxElements > 0)
562 {
563 c.truncate(maxElements);
564 }
565 return;
566 }
567
568 if (maxElements > 0)
569 {
570 c.truncate(maxElements - 1);
571 }
572 const bool needSort = !c.isEmpty() && value.isOlderThanAdjusted(c.front());
573 c.push_front(value);
574 if (needSort)
575 {
577 }
578 }
579
582 void push_frontKeepLatestFirstAdjustOffset(const OBJ &value, bool replaceSameTimestamp = true,
583 int maxElements = -1)
584 {
586 maxElements);
587
588 // now sorted by timestamp
589 // this reflects normally the incoming order
590 // ts
591 // 8: os 2 adj 12 => min os 4
592 // 6: os 2 adj 11 => min os 5
593 // 5: os 5 adj 10
594 // 0: os 5 adj 5
595 CONTAINER &c = this->container();
596 if (c.size() < 2)
597 {
598 return;
599 }
600 ITimestampWithOffsetBased &front = c.front();
601 const ITimestampWithOffsetBased &second = c[1];
602 if (!front.isNewerThanAdjusted(second))
603 {
604 // const qint64 minOs = qMin(front.getTimeOffsetMs(), second.getTimeOffsetMs());
605 const qint64 minReqOs =
606 second.getAdjustedMSecsSinceEpoch() - front.getMSecsSinceEpoch(); // minimal required
607 const qint64 avgOs = (front.getTimeOffsetMs() + second.getTimeOffsetMs()) / 2;
608 const qint64 os = qMax(minReqOs + 1, avgOs); // at least +1, as value must be > (greater)
609 front.setTimeOffsetMs(os);
610 }
611
613 {
614 SWIFT_VERIFY_X(front.isNewerThanAdjusted(second), Q_FUNC_INFO, "Front/second timestamp");
615 SWIFT_VERIFY_X(this->isSortedAdjustedLatestFirst(), Q_FUNC_INFO, "Wrong sort order");
616 }
617 }
618
620 void push_frontKeepLatestFirstIgnoreOverlapping(const OBJ &value, bool replaceSameTimestamp = true,
621 int maxElements = -1)
622 {
623 CONTAINER &c = this->container();
624 if (c.size() > 1)
625 {
626 const ITimestampWithOffsetBased front = c.front();
627 if (value.getAdjustedMSecsSinceEpoch() <= front.getAdjustedMSecsSinceEpoch())
628 {
629 return;
630 }
631 }
633 maxElements);
634 }
635
637 void prefillLatestAdjustedFirst(const OBJ &value, int elements, qint64 deltaTimeMs = -1)
638 {
639 this->container().clear();
640 const qint64 osTime = value.getTimeOffsetMs();
641 const qint64 os = -1 * qAbs(deltaTimeMs < 0 ? osTime : deltaTimeMs);
643 {
644 SWIFT_VERIFY_X(os < 0, Q_FUNC_INFO, "Need negative offset time to prefill time");
645 }
646 this->container().push_front(value);
647 for (int i = 1; i < elements; i++)
648 {
649 OBJ copy(value);
650 copy.addMsecs(os * i);
651 this->container().push_back(copy);
652 }
653 this->setAdjustedSortHint(ITimestampWithOffsetObjectList::AdjustedTimestampLatestFirst);
654 }
655
659 {
660 if (this->container().isEmpty())
661 {
662 return false;
663 }
664 if (this->container().size() < 2)
665 {
666 return true;
667 }
668 qint64 max = -1;
669 for (const ITimestampWithOffsetBased &obj : this->container())
670 {
671 if (!obj.hasValidTimestamp())
672 {
673 return false;
674 }
675 if (obj.getAdjustedMSecsSinceEpoch() < max)
676 {
677 return false;
678 }
679 max = obj.getAdjustedMSecsSinceEpoch();
680 }
681 return true;
682 }
683
687 {
688 if (this->container().size() < 2)
689 {
690 return true;
691 }
692 qint64 min = std::numeric_limits<qint64>::max();
693 for (const ITimestampWithOffsetBased &obj : this->container())
694 {
695 if (!obj.hasValidTimestamp())
696 {
697 return false;
698 }
699 if (obj.getAdjustedMSecsSinceEpoch() > min)
700 {
701 return false;
702 }
703 min = obj.getAdjustedMSecsSinceEpoch();
704 }
705 return true;
706 }
707
709 CONTAINER findAfterAdjusted(qint64 msSinceEpoch) const
710 {
711 return this->container().findBy(
712 [&](const ITimestampWithOffsetBased &obj) { return obj.isNewerThanAdjusted(msSinceEpoch); });
713 }
714
716 OBJ findObjectAfterAdjustedOrDefault(qint64 msSinceEpoch) const
717 {
718 const CONTAINER after = this->findAfterAdjusted(msSinceEpoch);
719 if (after.isEmpty())
720 {
721 return OBJ();
722 }
723 return after.oldestAdjustedObject();
724 }
725
727 CONTAINER findBeforeAdjusted(qint64 msSinceEpoch) const
728 {
729 return this->container().findBy(
730 [&](const ITimestampWithOffsetBased &obj) { return obj.isOlderThanAdjusted(msSinceEpoch); });
731 }
732
734 OBJ findObjectBeforeAdjustedOrDefault(qint64 msSinceEpoch) const
735 {
736 const CONTAINER before = this->findBeforeAdjusted(msSinceEpoch);
737 if (before.isEmpty())
738 {
739 return OBJ();
740 }
741 return before.latestAdjustedObject();
742 }
743
745 OBJ findClosestTimeDistanceAdjusted(qint64 msSinceEpoch) const
746 {
747 if (this->container().isEmpty())
748 {
749 return OBJ();
750 }
751 const auto closest =
752 std::min_element(this->container().cbegin(), this->container().cend(),
754 return qAbs(a.getAdjustedTimeDifferenceMs(msSinceEpoch)) <
755 qAbs(b.getAdjustedTimeDifferenceMs(msSinceEpoch));
756 });
757 return *closest;
758 }
759
762 {
763 if (this->container().isEmpty())
764 {
765 return OBJ();
766 }
767 if (this->container().m_tsAdjustedSortHint == AdjustedTimestampLatestFirst)
768 {
769 return this->container().front();
770 }
771 const auto latest =
772 std::max_element(this->container().begin(), this->container().end(), [](const OBJ &a, const OBJ &b) {
773 return a.getAdjustedMSecsSinceEpoch() < b.getAdjustedMSecsSinceEpoch();
774 });
775 return *latest;
776 }
777
780 {
781 if (this->container().isEmpty())
782 {
783 return OBJ();
784 }
785 if (this->container().m_tsAdjustedSortHint == AdjustedTimestampLatestFirst)
786 {
787 return this->container().back();
788 }
789 const auto oldest =
790 std::min_element(this->container().begin(), this->container().end(), [](const OBJ &a, const OBJ &b) {
791 return a.getAdjustedMSecsSinceEpoch() < b.getAdjustedMSecsSinceEpoch();
792 });
793 return *oldest;
794 }
795
798 {
799 if (this->container().isEmpty())
800 {
801 return {};
802 }
803 return this->latestAdjustedObject().getUtcTimestamp();
804 }
805
808 {
809 if (this->container().isEmpty())
810 {
811 return {};
812 }
813 return this->oldestAdjustedObject().getUtcTimestamp();
814 }
815
818 {
819 if (this->container().isEmpty())
820 {
821 return -1;
822 }
823 const QDateTime dt(this->latestAdjustedTimestamp());
824 return dt.isValid() ? dt.toMSecsSinceEpoch() : -1;
825 }
826
829 {
830 if (this->container().isEmpty())
831 {
832 return -1;
833 }
835 return dt.isValid() ? dt.toMSecsSinceEpoch() : -1;
836 }
837
839 void setAdjustedSortHint(HintAdjustedTimestampSort hint) { this->container().m_tsAdjustedSortHint = hint; }
840
844 {
846 mmm.reset();
847 const CONTAINER &container = this->container();
848 if (container.size() < 1)
849 {
850 return mmm;
851 }
852
853 mmm.max = std::numeric_limits<qint64>::min();
854 mmm.min = std::numeric_limits<qint64>::max();
855 qint64 mean = 0;
856 int c = 0;
857
858 for (const ITimestampWithOffsetBased &object : container)
859 {
860 if (!object.hasNonZeroOffsetTime())
861 {
862 continue;
863 }
864 const qint64 os = object.getTimeOffsetMs();
865 mmm.max = std::max(os, mmm.max);
866 mmm.min = std::min(os, mmm.min);
867 mean += os;
868 c++;
869 }
870
871 if (c > 0)
872 {
873 mmm.mean = mean / c;
874 }
875 return mmm;
876 }
877
878 protected:
881
882 HintAdjustedTimestampSort m_tsAdjustedSortHint = NoAdjustedTimestampSortHint;
883 };
884} // namespace swift::misc
885
886#endif // SWIFT_MISC_TIMESTAMPOBJECTLIST_H
static bool isLocalDeveloperDebugBuild()
Local build for developers.
Entity with timestamp.
qint64 getMSecsSinceEpoch() const
Timestamp as ms value.
qint64 getTimeDifferenceMs(qint64 compareTime) const
Time difference in ms.
qint64 getAbsTimeDifferenceMs(qint64 compareTime) const
Time difference in ms.
OBJ findObjectBeforeOrDefault(qint64 msSinceEpoch) const
Object before timestamp or default (older).
qint64 latestTimestampMsecsSinceEpoch() const
Latest timestamp.
QDateTime latestTimestamp() const
Latest timestamp.
void push_backOverrideTimestamp(const OBJ &newObject, qint64 newTsMsSinceEpoch)
Push back, but set new timestamp.
void setSortHint(HintTimestampSort hint)
Set the hint.
HintTimestampSort m_tsSortHint
sort hint
void sortOldestFirst()
Sort by timestamp.
OBJ oldestObject() const
Latest object.
int removeBefore(qint64 msSinceEpoch)
Remove objects with timestamp before dateTime.
CONTAINER findBeforeNowMinusOffset(qint64 msOffset) const
List of objects before now - offset.
int replaceIfSameTimestamp(const OBJ &newObject)
Replace if an object has the same timestamp.
CONTAINER findAfter(const QDateTime &dateTime) const
List of objects after dateTime (newer).
void addMsecs(qint64 msToAdd)
Adds a time to all values.
qint64 oldestTimestampMsecsSinceEpoch() const
Oldest timestamp.
CONTAINER findBeforeAndRemove(qint64 msSinceEpoch)
Get objects before msSinceEpoch and remove those.
MillisecondsMinMaxMean getTimestampDifferenceMinMaxMean() const
Difference of timestamp values.
CONTAINER findAfter(qint64 msSinceEpoch) const
List of objects after msSinceEpoch (newer).
ITimestampObjectList()=default
Constructor.
void setCurrentUtcTime()
Set all timestamps to now.
OBJ findObjectAfterOrDefault(qint64 msSinceEpoch) const
List of objects after msSinceEpoch (newer).
void setInvalidTimestampsToCurrentUtcTime()
Set invalid timestamps to now.
OBJ latestObject() const
Latest object.
void sortLatestFirst()
Sort by timestamp.
const CONTAINER & container() const
Container.
HintTimestampSort
Hint if the list is sorted.
void push_backIncreaseTimestamp(const OBJ &newObject)
Push back and increase the timestamp at least by +1ms if equal to last element.
int removeBefore(const QDateTime &dateTime)
Remove objects with timestamp before dateTime.
int removeOlderThanNowMinusOffset(qint64 offsetMs)
Remove objects older than seconds.
bool isSortedLatestLast() const
Is completely sorted: latest last.
void push_frontKeepLatestFirst(const OBJ &value, bool replaceSameTimestamp=true, int maxElements=-1)
Insert as first element by keeping maxElements and the latest first.
QDateTime oldestTimestamp() const
Oldest timestamp.
CONTAINER findBefore(const QDateTime &dateTime) const
List of objects before dateTime (older).
CONTAINER findBefore(qint64 msSinceEpoch) const
List of objects before msSinceEpoch (older).
bool hasInvalidTimestamps() const
Has invalid timestamp.
void setUtcTime(qint64 msSinceEpoch)
Set all timestamps to given time.
CONTAINER findInvalidTimestamps() const
Objects without valid timestamp.
bool isSortedLatestFirst() const
Is completely sorted: latest last.
void setNewTimestampStartingLast(qint64 startTimeStampMs, qint64 deltaTimeMs)
Set new timestamps starting with the last element.
CONTAINER findAfterNowMinusOffset(qint64 msOffset) const
List of objects before now - offset.
OBJ findClosestTimeDistance(qint64 msSinceEpoch) const
Find closest (or default).
qint64 getAdjustedMSecsSinceEpoch() const
Timestamp with offset added for interpolation.
qint64 getTimeOffsetMs() const
Milliseconds to add to timestamp for interpolation.
bool isNewerThanAdjusted(const ITimestampWithOffsetBased &otherTimestampObj) const
Is this newer than other?
bool isOlderThanAdjusted(const ITimestampWithOffsetBased &otherTimestampObj) const
Is this older than other?
qint64 getAdjustedTimeDifferenceMs(qint64 compareTime) const
Time difference in ms (this -> compare).
void setTimeOffsetMs(qint64 offset)
Milliseconds to add to timestamp for interpolation.
OBJ findClosestTimeDistanceAdjusted(qint64 msSinceEpoch) const
Closest adjusted time difference.
bool containsZeroOrNegativeOffsetTime() const
Any negative or zero offset time?
CONTAINER getLatestAdjustedTwoObjects(bool alreadySortedLatestFirst=false) const
Get the latest 2 values.
QDateTime oldestAdjustedTimestamp() const
Oldest adjusted timestamp.
bool isSortedAdjustedLatestFirst() const
Is completely sorted: latest last.
OBJ findObjectBeforeAdjustedOrDefault(qint64 msSinceEpoch) const
Object before timestamp (older).
void setAdjustedSortHint(HintAdjustedTimestampSort hint)
Set the hint.
CONTAINER findBeforeAdjusted(qint64 msSinceEpoch) const
List of objects before msSinceEpoch (older).
OBJ latestAdjustedObject() const
Latest adjusted object.
bool isSortedAdjustedLatestLast() const
Is completely sorted: latest last.
MillisecondsMinMaxMean getOffsetMinMaxMean() const
Difference of timestamp values.
void addMsecsToOffset(qint64 msToAdd)
Adds a time to all offset values.
void push_frontKeepLatestAdjustedFirst(const OBJ &value, bool replaceSameTimestamp=true, int maxElements=-1)
Insert as first element by keeping maxElements and the latest first.
qint64 oldestAdjustedTimestampMsecsSinceEpoch() const
Oldest adjusted timestamp.
void sortAdjustedLatestFirst()
Sort by adjusted timestamp.
bool containsNegativeOffsetTime() const
Any negative offset time?
CONTAINER getSortedAdjustedLatestFirst() const
As sorted copy.
void prefillLatestAdjustedFirst(const OBJ &value, int elements, qint64 deltaTimeMs=-1)
Prefill with elements.
QDateTime latestAdjustedTimestamp() const
Latest adjusted timestamp.
OBJ oldestAdjustedObject() const
Oldest adjusted object.
void push_frontKeepLatestFirstAdjustOffset(const OBJ &value, bool replaceSameTimestamp=true, int maxElements=-1)
Insert as first element by keeping maxElements and the latest first.
HintAdjustedTimestampSort m_tsAdjustedSortHint
sort hint
void push_frontKeepLatestFirstIgnoreOverlapping(const OBJ &value, bool replaceSameTimestamp=true, int maxElements=-1)
Add value, but ignore overlapping (past) values.
qint64 latestAdjustedTimestampMsecsSinceEpoch() const
Latest adjusted timestamp.
CONTAINER findAfterAdjusted(qint64 msSinceEpoch) const
List of objects after msSinceEpoch (newer).
OBJ findObjectAfterAdjustedOrDefault(qint64 msSinceEpoch) const
List of objects after msSinceEpoch (newer).
ITimestampWithOffsetObjectList()=default
Constructor.
void sortAdjustedOldestFirst()
Sort by adjusted timestamp.
auto MemberLess(Ts... vs)
Predicate which compares the return values of some member functions of two objects.
Definition predicates.h:43
Free functions in swift::misc.
T::const_iterator begin(const LockFreeReader< T > &reader)
Non-member begin() and end() for so LockFree containers can be used in ranged for loops.
Definition lockfree.h:258
T::const_iterator end(const LockFreeReader< T > &reader)
Non-member begin() and end() for so LockFree containers can be used in ranged for loops.
Definition lockfree.h:264
qint64 currentMSecsSinceEpoch()
bool isValid() const const
qint64 toMSecsSinceEpoch() const const
QString arg(Args &&... args) const const
Milliseconds minimum/maximum/mean.
#define SWIFT_VERIFY_X(COND, WHERE, WHAT)
A weaker kind of assert.
Definition verify.h:26