ADTF  3.14.3
repo/src/libraries/base/include/adtfbase/chrono.h
Go to the documentation of this file.
1 
7 #pragma once
8 #include <adtf_utils.h>
9 #include <chrono>
10 
11 namespace adtf
12 {
13 namespace base
14 {
15 namespace flash
16 {
17 
20 {
21  int64_t nCount;
22 
23  tNanoSeconds():
24  nCount(0)
25  {
26  }
27 
28  tNanoSeconds(const tNanoSeconds&) = default;
29  tNanoSeconds(tNanoSeconds&&) = default;
30 
31  tNanoSeconds& operator=(const tNanoSeconds&) = default;
32  tNanoSeconds& operator=(tNanoSeconds&&) = default;
33 
34  explicit tNanoSeconds(int64_t nCount):
35  nCount(nCount)
36  {
37  }
38 
39  template<typename Representation, typename Period>
40  inline tNanoSeconds(const std::chrono::duration<Representation, Period>& oDuration):
41  nCount(std::chrono::duration_cast<std::chrono::nanoseconds>(oDuration).count())
42  {
43  }
44 
45  tNanoSeconds& operator+=(const tNanoSeconds& tmDuration)
46  {
47  nCount += tmDuration.nCount;
48  return *this;
49  }
50 
51  tNanoSeconds& operator-=(const tNanoSeconds& tmDuration)
52  {
53  nCount -= tmDuration.nCount;
54  return *this;
55  }
56 
57  tNanoSeconds& operator*=(const int64_t& nFactor)
58  {
59  nCount *= nFactor;
60  return *this;
61  }
62 
63  tNanoSeconds& operator/=(const int64_t& nDivisor)
64  {
65  nCount /= nDivisor;
66  return *this;
67  }
68 
69  tNanoSeconds& operator%=(const int64_t& nDivisor)
70  {
71  nCount %= nDivisor;
72  return *this;
73  }
74 
75  inline operator std::chrono::nanoseconds() const
76  {
77  return std::chrono::nanoseconds(nCount);
78  }
79 };
80 
81 inline bool operator<(const tNanoSeconds& tmA, const tNanoSeconds& tmB)
82 {
83  return tmA.nCount < tmB.nCount;
84 }
85 
86 inline bool operator>(const tNanoSeconds& tmA, const tNanoSeconds& tmB)
87 {
88  return tmA.nCount > tmB.nCount;
89 }
90 
91 inline bool operator<=(const tNanoSeconds& tmA, const tNanoSeconds& tmB)
92 {
93  return tmA.nCount <= tmB.nCount;
94 }
95 
96 inline bool operator>=(const tNanoSeconds& tmA, const tNanoSeconds& tmB)
97 {
98  return tmA.nCount >= tmB.nCount;
99 }
100 
101 inline bool operator==(const tNanoSeconds& tmA, const tNanoSeconds& tmB)
102 {
103  return tmA.nCount == tmB.nCount;
104 }
105 
106 inline bool operator!=(const tNanoSeconds& tmA, const tNanoSeconds& tmB)
107 {
108  return tmA.nCount != tmB.nCount;
109 }
110 
111 inline tNanoSeconds operator+(const tNanoSeconds& tmA, const tNanoSeconds& tmB)
112 {
113  return tNanoSeconds{tmA.nCount + tmB.nCount};
114 }
115 
116 inline tNanoSeconds operator-(const tNanoSeconds& tmA, const tNanoSeconds& tmB)
117 {
118  return tNanoSeconds{tmA.nCount - tmB.nCount};
119 }
120 
121 inline tNanoSeconds operator*(const tNanoSeconds& tmDuration, const int64_t& nFactor)
122 {
123  return tNanoSeconds{tmDuration.nCount * nFactor};
124 }
125 
126 inline tNanoSeconds operator*(const int64_t& nFactor, const tNanoSeconds& tmDuration)
127 {
128  return tNanoSeconds{nFactor * tmDuration.nCount};
129 }
130 
131 inline tNanoSeconds operator/(const tNanoSeconds& tmDuration, const int64_t& tmB)
132 {
133  return tNanoSeconds{tmDuration.nCount / tmB};
134 }
135 
136 inline int64_t operator/(const tNanoSeconds& tmA, const tNanoSeconds& tmB)
137 {
138  return tmA.nCount / tmB.nCount;
139 }
140 
141 namespace detail
142 {
143  template<typename T>
144  struct always_false : std::false_type {};
145 }
146 
147 template <typename DestinationTimeStamp, typename SourceTimeStamp>
148 DestinationTimeStamp duration_cast(const SourceTimeStamp& /*tmSource*/)
149 {
150  static_assert(detail::always_false<DestinationTimeStamp>::value, "unsupported duration cast");
151  return DestinationTimeStamp();
152 }
153 
154 template <>
155 inline tTimeStamp duration_cast(const tNanoSeconds& tmSource)
156 {
157  return tmSource.nCount / 1000;
158 }
159 
160 template <>
161 inline tNanoSeconds duration_cast(const tTimeStamp& tmSource)
162 {
163  return tNanoSeconds{tmSource * 1000};
164 }
165 
166 template <>
167 inline std::chrono::nanoseconds duration_cast(const tNanoSeconds& tmSource)
168 {
169  return tmSource;
170 }
171 
172 template <>
173 inline tNanoSeconds duration_cast(const std::chrono::nanoseconds& tmSource)
174 {
175  return tmSource;
176 }
177 
178 template <>
179 inline tTimeStamp duration_cast(const std::chrono::nanoseconds& tmSource)
180 {
181  return tmSource.count() / 1000;
182 }
183 
184 }
185 
186 using flash::tNanoSeconds;
187 using flash::duration_cast;
188 
189 }
190 }
Copyright © Audi Electronics Venture GmbH.
bool operator!=(const forward_iterator< T > &oLHS, const forward_iterator< T > &oRHS) noexcept
Inequality operator for forward_iterator.
bool operator==(const forward_iterator< T > &oLHS, const forward_iterator< T > &oRHS) noexcept
Equality operator for forward_iterator.
Namespace for entire ADTF SDK.

Copyright © Audi Electronics Venture GmbH. All rights reserved. (Generated on Thu Jun 9 2022 by doxygen 1.9.1)