deCONZ C++ API v2.6.1
Loading...
Searching...
No Matches
timeref.h
1#ifndef DECONZ_TIMEREF_H
2#define DECONZ_TIMEREF_H
3
4/*
5 * Copyright (c) 2012-2023 dresden elektronik ingenieurtechnik gmbh.
6 * All rights reserved.
7 *
8 * The software in this package is published under the terms of the BSD
9 * style license a copy of which has been included with this distribution in
10 * the LICENSE.txt file.
11 *
12 */
13
14#include <stdint.h>
15#include "deconz/declspec.h"
16
17
18namespace deCONZ {
19
20
22{
23 SteadyTimeRef() : ref(0) {}
24 SteadyTimeRef(int64_t r_) : ref(r_) {}
25 int64_t ref = 0;
26};
27
29{
30 SystemTimeRef() : ref() {}
31 SystemTimeRef(int64_t r_) : ref(r_) {}
32 int64_t ref = 0;
33};
34
36struct TimeMs
37{
38 int64_t val = 0;
39};
40
43{
44 int64_t val = 0;
45};
46
48int64_t DECONZ_DLLSPEC msecSinceEpoch();
49
55SystemTimeRef DECONZ_DLLSPEC systemTimeRef() noexcept;
56
61SteadyTimeRef DECONZ_DLLSPEC steadyTimeRef() noexcept;
62
63inline bool DECONZ_DLLSPEC isValid(SteadyTimeRef t) { return t.ref != 0; }
64inline bool DECONZ_DLLSPEC isValid(SystemTimeRef t) { return t.ref != 0; }
65
66inline bool DECONZ_DLLSPEC operator<(SystemTimeRef a, SystemTimeRef b) { return a.ref < b.ref; }
67
68inline bool DECONZ_DLLSPEC operator==(SteadyTimeRef a, SteadyTimeRef b) { return a.ref == b.ref; }
69inline bool DECONZ_DLLSPEC operator!=(SteadyTimeRef a, SteadyTimeRef b) { return a.ref != b.ref; }
70inline bool DECONZ_DLLSPEC operator<(SteadyTimeRef a, SteadyTimeRef b) { return a.ref < b.ref; }
71inline bool DECONZ_DLLSPEC operator<=(SteadyTimeRef a, SteadyTimeRef b) { return a.ref <= b.ref; }
72
73inline TimeMs DECONZ_DLLSPEC operator-(SteadyTimeRef a, SteadyTimeRef b) { TimeMs res; res.val = a.ref - b.ref; return res; }
74inline SteadyTimeRef DECONZ_DLLSPEC operator+(SteadyTimeRef a, TimeMs t) { return SteadyTimeRef{a.ref + t.val}; }
75inline SteadyTimeRef DECONZ_DLLSPEC operator+(SteadyTimeRef a, TimeSeconds t) { return SteadyTimeRef{a.ref + t.val * 1000}; }
76
77inline bool DECONZ_DLLSPEC operator<(TimeMs a, TimeMs b) { return a.val < b.val; }
78inline bool DECONZ_DLLSPEC operator<(TimeSeconds a, TimeSeconds b) { return a.val < b.val; }
79inline bool DECONZ_DLLSPEC operator<(TimeSeconds a, TimeMs b) { return a.val * 1000 < b.val; }
80inline bool DECONZ_DLLSPEC operator<(TimeMs a, TimeSeconds b) { return a.val < b.val * 1000; }
81
82inline TimeSeconds DECONZ_DLLSPEC operator*(TimeSeconds a, int factor) { TimeSeconds res; res.val = a.val * factor; return res; }
83inline TimeMs DECONZ_DLLSPEC operator*(TimeMs a, int factor) { TimeMs res; res.val = a.val * factor; return res; }
84
85} // namespace deCONZ
86
87#endif // DECONZ_TIMEREF_H
The deCONZ namespace.
Definition aps.cpp:19
int64_t DECONZ_DLLSPEC msecSinceEpoch()
Returnes milliseconds since Epoch.
Definition timeref.cpp:17
SystemTimeRef DECONZ_DLLSPEC systemTimeRef() noexcept
Returnes a time point reference in system time as milliseconds since Epoch.
Definition timeref.cpp:31
SteadyTimeRef DECONZ_DLLSPEC steadyTimeRef() noexcept
Returnes a time point reference in milliseconds which is monotonic increasing.
Definition timeref.cpp:23
Definition timeref.h:22
Definition timeref.h:29
Strong typed milliseconds.
Definition timeref.h:37
Strong typed seconds.
Definition timeref.h:43