Skip to content

Commit 5f4dd12

Browse files
Merge pull request #1830 from ithier/iox-1394-fix-duration-warnings
iox-#1394 Fix axivion warnings in duration class
2 parents 0e4faa0 + cb4d8cf commit 5f4dd12

File tree

4 files changed

+341
-127
lines changed

4 files changed

+341
-127
lines changed

iceoryx_hoofs/include/iceoryx_hoofs/internal/units/duration.hpp

+88-36
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,31 @@ class Duration;
4343
namespace duration_literals
4444
{
4545
/// @brief Constructs a new Duration object from nanoseconds
46+
// AXIVION Next Line AutosarC++19_03-A3.9.1 : Use of unsigned long long int in user-defined literals is enforced by the standard
4647
constexpr Duration operator"" _ns(unsigned long long int value) noexcept;
4748

4849
/// @brief Constructs a new Duration object from microseconds
50+
// AXIVION Next Line AutosarC++19_03-A3.9.1 : Use of unsigned long long int in user-defined literals is enforced by the standard
4951
constexpr Duration operator"" _us(unsigned long long int value) noexcept;
5052

5153
/// @brief Constructs a new Duration object from milliseconds
54+
// AXIVION Next Line AutosarC++19_03-A3.9.1 : Use of unsigned long long int in user-defined literals is enforced by the standard
5255
constexpr Duration operator"" _ms(unsigned long long int value) noexcept;
5356

5457
/// @brief Constructs a new Duration object from seconds
58+
// AXIVION Next Line AutosarC++19_03-A3.9.1 : Use of unsigned long long int in user-defined literals is enforced by the standard
5559
constexpr Duration operator"" _s(unsigned long long int value) noexcept;
5660

5761
/// @brief Constructs a new Duration object from minutes
62+
// AXIVION Next Line AutosarC++19_03-A3.9.1 : Use of unsigned long long int in user-defined literals is enforced by the standard
5863
constexpr Duration operator"" _m(unsigned long long int value) noexcept;
5964

6065
/// @brief Constructs a new Duration object from hours
66+
// AXIVION Next Line AutosarC++19_03-A3.9.1 : Use of unsigned long long int in user-defined literals is enforced by the standard
6167
constexpr Duration operator"" _h(unsigned long long int value) noexcept;
6268

6369
/// @brief Constructs a new Duration object from days
70+
// AXIVION Next Line AutosarC++19_03-A3.9.1 : Use of unsigned long long int in user-defined literals is enforced by the standard
6471
constexpr Duration operator"" _d(unsigned long long int value) noexcept;
6572
} // namespace duration_literals
6673

@@ -148,67 +155,47 @@ class Duration
148155

149156
/// @brief Construct a Duration object from timeval
150157
/// @param[in] value as timeval
158+
// AXIVION Next Line AutosarC++19_03-A8.4.7 : Argument is larger than two words
151159
constexpr explicit Duration(const struct timeval& value) noexcept;
152160

153161
/// @brief Construct a Duration object from timespec
154162
/// @param[in] value as timespec
163+
// AXIVION Next Line AutosarC++19_03-A8.4.7 : Argument is larger than two words
155164
constexpr explicit Duration(const struct timespec& value) noexcept;
156165

157166
/// @brief Construct a Duration object from itimerspec
158167
/// @param[in] value as itimerspec
159168
/// @note only it_interval from the itimerspec is used
169+
// AXIVION Next Line AutosarC++19_03-A8.4.7 : Argument is larger than two words
160170
constexpr explicit Duration(const struct itimerspec& value) noexcept;
161171

162172
/// @brief Construct a Duration object from std::chrono::milliseconds
163173
/// @param[in] value as milliseconds
164174
/// @attention Since negative durations are not allowed, the duration will be clamped to 0
165-
constexpr explicit Duration(const std::chrono::milliseconds& value) noexcept;
175+
constexpr explicit Duration(const std::chrono::milliseconds value) noexcept;
166176

167177
/// @brief Construct a Duration object from std::chrono::nanoseconds
168178
/// @param[in] value as nanoseconds
169179
/// @attention Since negative durations are not allowed, the duration will be clamped to 0
170-
constexpr explicit Duration(const std::chrono::nanoseconds& value) noexcept;
180+
constexpr explicit Duration(const std::chrono::nanoseconds value) noexcept;
171181

172182
/// @brief Assigns a std::chrono::milliseconds to an duration object
173183
/// @param[in] rhs is the right hand side of the assignment
174184
/// @return a reference to the Duration object with the assigned millisecond value
175185
/// @attention Since negative durations are not allowed, the duration will be clamped to 0
176-
Duration& operator=(const std::chrono::milliseconds& rhs) noexcept;
186+
Duration& operator=(const std::chrono::milliseconds rhs) noexcept;
177187

178188
// END CONSTRUCTORS AND ASSIGNMENT
179189

180190
// BEGIN COMPARISON
181-
182-
/// @brief Equal to operator
183-
/// @param[in] rhs is the right hand side of the comparison
184-
/// @return true if duration equal to rhs
185-
constexpr bool operator==(const Duration& rhs) const noexcept;
186-
187-
/// @brief Not equal to operator
188-
/// @param[in] rhs is the right hand side of the comparison
189-
/// @return true if duration not equal to rhs
190-
constexpr bool operator!=(const Duration& rhs) const noexcept;
191-
192-
/// @brief Less than operator
193-
/// @param[in] rhs is the right hand side of the comparison
194-
/// @return true if duration is less than rhs
195-
constexpr bool operator<(const Duration& rhs) const noexcept;
196-
197-
/// @brief Less than or equal to operator
198-
/// @param[in] rhs is the right hand side of the comparison
199-
/// @return true if duration is less than or equal to rhs
200-
constexpr bool operator<=(const Duration& rhs) const noexcept;
201-
202-
/// @brief Greater than operator
203-
/// @param[in] rhs is the right hand side of the comparison
204-
/// @return true if duration is greater than rhs
205-
constexpr bool operator>(const Duration& rhs) const noexcept;
206-
207-
/// @brief Greater than or equal to operator
208-
/// @param[in] rhs is the right hand side of the comparison
209-
/// @return true if duration is greater than or equal to rhs
210-
constexpr bool operator>=(const Duration& rhs) const noexcept;
211-
191+
// AXIVION DISABLE STYLE AutosarC++19_03-A8.4.7 : Each argument is larger than two words
192+
friend constexpr bool operator==(const Duration& lhs, const Duration& rhs) noexcept;
193+
friend constexpr bool operator!=(const Duration& lhs, const Duration& rhs) noexcept;
194+
friend constexpr bool operator<(const Duration& lhs, const Duration& rhs) noexcept;
195+
friend constexpr bool operator<=(const Duration& lhs, const Duration& rhs) noexcept;
196+
friend constexpr bool operator>(const Duration& lhs, const Duration& rhs) noexcept;
197+
friend constexpr bool operator>=(const Duration& lhs, const Duration& rhs) noexcept;
198+
// AXIVION ENABLE STYLE AutosarC++19_03-A8.4.7
212199
// END COMPARISON
213200

214201
// BEGIN ARITHMETIC
@@ -217,15 +204,32 @@ class Duration
217204
/// saturates to Duration::max().
218205
/// @param[in] rhs is the second summand
219206
/// @return a new Duration object
207+
// AXIVION Next Line AutosarC++19_03-A8.4.7 : Argument is larger than two words
220208
constexpr Duration operator+(const Duration& rhs) const noexcept;
221209

210+
/// @brief Creates Duration object by addition. On overflow duration
211+
/// saturates to Duration::max().
212+
/// @param[in] rhs is the second summand
213+
/// @return a new Duration object
214+
// AXIVION Next Line AutosarC++19_03-A8.4.7 : Argument is larger than two words
215+
constexpr Duration& operator+=(const Duration& rhs) noexcept;
216+
222217
/// @brief Creates Duration object by subtraction. On underflow duration
223218
/// saturates to Duration::zero().
224219
/// @param[in] rhs is the subtrahend
225220
/// @return a new Duration object
226221
/// @attention Since negative durations are not allowed, the duration will be clamped to 0
222+
// AXIVION Next Line AutosarC++19_03-A8.4.7 : Each argument is larger than two words
227223
constexpr Duration operator-(const Duration& rhs) const noexcept;
228224

225+
/// @brief Creates Duration object by subtraction. On underflow duration
226+
/// saturates to Duration::zero().
227+
/// @param[in] rhs is the subtrahend
228+
/// @return a new Duration object
229+
/// @attention Since negative durations are not allowed, the duration will be clamped to 0
230+
// AXIVION Next Line AutosarC++19_03-A8.4.7 : Argument is larger than two words
231+
constexpr Duration& operator-=(const Duration& rhs) noexcept;
232+
229233
/// @brief Creates Duration object by multiplication.
230234
/// @tparam T is an arithmetic type for the multiplicator
231235
/// @param[in] rhs is the multiplicator
@@ -276,7 +280,7 @@ class Duration
276280
constexpr uint64_t toDays() const noexcept;
277281

278282
/// @brief converts duration in a timespec c struct
279-
struct timespec timespec(const TimeSpecReference& reference = TimeSpecReference::None) const noexcept;
283+
struct timespec timespec(const TimeSpecReference reference = TimeSpecReference::None) const noexcept;
280284

281285
/// @brief converts duration in a timeval c struct
282286
/// timeval::tv_sec = seconds since the Epoch (01.01.1970)
@@ -285,17 +289,21 @@ class Duration
285289

286290
// END CONVERSION
287291

292+
// AXIVION DISABLE STYLE AutosarC++19_03-A3.9.1 : Use of unsigned long long int in user-defined literals is enforced by the standard
288293
friend constexpr Duration duration_literals::operator"" _ns(unsigned long long int value) noexcept;
289294
friend constexpr Duration duration_literals::operator"" _us(unsigned long long int value) noexcept;
290295
friend constexpr Duration duration_literals::operator"" _ms(unsigned long long int value) noexcept;
291296
friend constexpr Duration duration_literals::operator"" _s(unsigned long long int value) noexcept;
292297
friend constexpr Duration duration_literals::operator"" _m(unsigned long long int value) noexcept;
293298
friend constexpr Duration duration_literals::operator"" _h(unsigned long long int value) noexcept;
294299
friend constexpr Duration duration_literals::operator"" _d(unsigned long long int value) noexcept;
300+
// AXIVION ENABLE STYLE AutosarC++19_03-A3.9.1
295301

302+
// AXIVION Next Construct AutosarC++19_03-A8.4.7 : Argument is larger than two words
296303
template <typename T>
297304
friend constexpr Duration operator*(const T& lhs, const Duration& rhs) noexcept;
298305

306+
// AXIVION Next Line AutosarC++19_03-A8.4.7 : Argument is larger than two words
299307
friend std::ostream& operator<<(std::ostream& stream, const Duration& t) noexcept;
300308
friend iox::log::LogStream& operator<<(iox::log::LogStream& stream, const Duration t) noexcept;
301309

@@ -326,7 +334,7 @@ class Duration
326334

327335
private:
328336
template <typename T>
329-
static constexpr unsigned long long int positiveValueOrClampToZero(const T value) noexcept;
337+
static constexpr uint64_t positiveValueOrClampToZero(const T value) noexcept;
330338

331339
template <typename T>
332340
constexpr Duration fromFloatingPointSeconds(const T floatingPointSeconds) const noexcept;
@@ -351,12 +359,56 @@ class Duration
351359
/// @param[in] rhs is the multiplicant
352360
/// @return a new Duration object
353361
/// @attention Since negative durations are not allowed, the duration will be clamped to 0
362+
// AXIVION Next Construct AutosarC++19_03-A8.4.7 : Each argument is larger than two words
354363
template <typename T>
355364
constexpr Duration operator*(const T& lhs, const Duration& rhs) noexcept;
356365

357366
/// @brief stream operator for the Duration class
367+
// AXIVION Next Line AutosarC++19_03-A8.4.7 : Argument is larger than two words
358368
std::ostream& operator<<(std::ostream& stream, const Duration& t) noexcept;
359369

370+
/// @brief Equal to operator
371+
/// @param[in] lhs is the left hand side of the comparison
372+
/// @param[in] rhs is the right hand side of the comparison
373+
/// @return true if duration equal to rhs
374+
// AXIVION Next Line AutosarC++19_03-A8.4.7 : Each argument is larger than two words
375+
constexpr bool operator==(const Duration& lhs, const Duration& rhs) noexcept;
376+
377+
/// @brief Not equal to operator
378+
/// @param[in] lhs is the left hand side of the comparison
379+
/// @param[in] rhs is the right hand side of the comparison
380+
/// @return true if duration not equal to rhs
381+
// AXIVION Next Line AutosarC++19_03-A8.4.7 : Each argument is larger than two words
382+
constexpr bool operator!=(const Duration& lhs, const Duration& rhs) noexcept;
383+
384+
/// @brief Less than operator
385+
/// @param[in] lhs is the left hand side of the comparison
386+
/// @param[in] rhs is the right hand side of the comparison
387+
/// @return true if duration is less than rhs
388+
// AXIVION Next Line AutosarC++19_03-A8.4.7 : Each argument is larger than two words
389+
constexpr bool operator<(const Duration& lhs, const Duration& rhs) noexcept;
390+
391+
/// @brief Greater than operator
392+
/// @param[in] lhs is the left hand side of the comparison
393+
/// @param[in] rhs is the right hand side of the comparison
394+
/// @return true if duration is greater than rhs
395+
// AXIVION Next Line AutosarC++19_03-A8.4.7 : Each argument is larger than two words
396+
constexpr bool operator>(const Duration& lhs, const Duration& rhs) noexcept;
397+
398+
/// @brief Less than or equal to operator
399+
/// @param[in] lhs is the left hand side of the comparison
400+
/// @param[in] rhs is the right hand side of the comparison
401+
/// @return true if duration is less than or equal to rhs
402+
// AXIVION Next Line AutosarC++19_03-A8.4.7 : Each argument is larger than two words
403+
constexpr bool operator<=(const Duration& lhs, const Duration& rhs) noexcept;
404+
405+
/// @brief Greater than or equal to operator
406+
/// @param[in] lhs is the left hand side of the comparison
407+
/// @param[in] rhs is the right hand side of the comparison
408+
/// @return true if duration is greater than or equal to rhs
409+
// AXIVION Next Line AutosarC++19_03-A8.4.7 : Each argument is larger than two words
410+
constexpr bool operator>=(const Duration& lhs, const Duration& rhs) noexcept;
411+
360412
} // namespace units
361413
} // namespace iox
362414

0 commit comments

Comments
 (0)