Branch data Line data Source code
1 : : /* 2 : : * ----------------- BEGIN LICENSE BLOCK --------------------------------- 3 : : * 4 : : * Copyright (C) 2018-2020 Intel Corporation 5 : : * 6 : : * SPDX-License-Identifier: MIT 7 : : * 8 : : * ----------------- END LICENSE BLOCK ----------------------------------- 9 : : */ 10 : : 11 : : /** 12 : : * Generated file 13 : : * @file 14 : : * 15 : : * Generator Version : 11.0.0-1997 16 : : */ 17 : : 18 : : #pragma once 19 : : 20 : : #include <cmath> 21 : : #include <iostream> 22 : : #include <limits> 23 : : #include <sstream> 24 : : #include <stdexcept> 25 : : #include "spdlog/fmt/ostr.h" 26 : : #include "spdlog/spdlog.h" 27 : : /*! 28 : : * @brief namespace ad 29 : : */ 30 : : namespace ad { 31 : : /*! 32 : : * @brief namespace physics 33 : : */ 34 : : namespace physics { 35 : : 36 : : /*! 37 : : * \brief Define to indicate whether throwing exceptions is enabled 38 : : */ 39 : : #define AD_PHYSICS_DURATION_THROWS_EXCEPTION 1 40 : : 41 : : #if SAFE_DATATYPES_EXPLICIT_CONVERSION 42 : : /*! 43 : : * \brief Enable/Disable explicit conversion. Currently set to "only explicit conversion". 44 : : */ 45 : : #define _AD_PHYSICS_DURATION_EXPLICIT_CONVERSION_ explicit 46 : : #else 47 : : /*! 48 : : * \brief Enable/Disable explicit conversion. Currently set to "implicit conversion allowed". 49 : : */ 50 : : #define _AD_PHYSICS_DURATION_EXPLICIT_CONVERSION_ 51 : : #endif 52 : : 53 : : /*! 54 : : * \brief Forward declaration of DurationSquared 55 : : * 56 : : * Since Duration is defined explicitly as a physical type we have to consider this 57 : : * within operations. Therefore this squared type is defined. 58 : : */ 59 : : class DurationSquared; 60 : : 61 : : /*! 62 : : * \brief DataType Duration 63 : : * 64 : : * A duration represents a time interval. 65 : : * The unit is: Second 66 : : */ 67 : : class Duration 68 : : { 69 : : public: 70 : : /*! 71 : : * \brief constant defining the minimum valid Duration value (used in isValid()) 72 : : */ 73 : : static const double cMinValue; 74 : : 75 : : /*! 76 : : * \brief constant defining the maximum valid Duration value (used in isValid()) 77 : : */ 78 : : static const double cMaxValue; 79 : : 80 : : /*! 81 : : * \brief constant defining the assumed Duration value accuracy 82 : : * (used in comparison operator==(), operator!=()) 83 : : */ 84 : : static const double cPrecisionValue; 85 : : 86 : : /*! 87 : : * \brief default constructor 88 : : * 89 : : * The default value of Duration is: 90 : : * std::numeric_limits<double>::quiet_NaN() 91 : : */ 92 : 14 : Duration() 93 : 14 : : mDuration(std::numeric_limits<double>::quiet_NaN()) 94 : : { 95 : 14 : } 96 : : 97 : : /*! 98 : : * \brief standard constructor 99 : : * 100 : : * \note \ref \_AD_PHYSICS_DURATION_EXPLICIT_CONVERSION\_ defines, if only an explicit conversion is allowed. 101 : : */ 102 : 121 : _AD_PHYSICS_DURATION_EXPLICIT_CONVERSION_ Duration(double const iDuration) 103 : 121 : : mDuration(iDuration) 104 : : { 105 : 121 : } 106 : : 107 : : /*! 108 : : * \brief standard copy constructor 109 : : */ 110 : : Duration(const Duration &other) = default; 111 : : 112 : : /*! 113 : : * \brief standard move constructor 114 : : */ 115 : : Duration(Duration &&other) = default; 116 : : 117 : : /** 118 : : * \brief standard assignment operator 119 : : * 120 : : * \param[in] other Other Duration 121 : : * 122 : : * \returns Reference to this Duration. 123 : : */ 124 : : Duration &operator=(const Duration &other) = default; 125 : : 126 : : /** 127 : : * \brief standard move operator 128 : : * 129 : : * \param[in] other Other Duration 130 : : * 131 : : * \returns Reference to this Duration. 132 : : */ 133 : : Duration &operator=(Duration &&other) = default; 134 : : 135 : : /** 136 : : * \brief standard comparison operator 137 : : * 138 : : * \param[in] other Other Duration 139 : : * 140 : : * \returns \c true if both Duration are valid and can be taken as numerically equal 141 : : */ 142 : 40 : bool operator==(const Duration &other) const 143 : : { 144 : 40 : ensureValid(); 145 : 38 : other.ensureValid(); 146 : 36 : return std::fabs(mDuration - other.mDuration) < cPrecisionValue; 147 : : } 148 : : 149 : : /** 150 : : * \brief standard comparison operator 151 : : * 152 : : * \param[in] other Other Duration. 153 : : * 154 : : * \returns \c true if one of the Duration is not valid or they can be taken as numerically different 155 : : */ 156 : 11 : bool operator!=(const Duration &other) const 157 : : { 158 : 11 : return !operator==(other); 159 : : } 160 : : 161 : : /** 162 : : * \brief standard comparison operator 163 : : * 164 : : * \param[in] other Other Duration. 165 : : * 166 : : * \returns \c true if both Duration are valid and 167 : : * this Duration is strictly numerically greater than other. 168 : : * \note the precision of Duration is considered 169 : : */ 170 : 5 : bool operator>(const Duration &other) const 171 : : { 172 : 5 : ensureValid(); 173 : 4 : other.ensureValid(); 174 [ + + + + ]: 3 : return (mDuration > other.mDuration) && operator!=(other); 175 : : } 176 : : 177 : : /** 178 : : * \brief standard comparison operator 179 : : * 180 : : * \param[in] other Other Duration. 181 : : * 182 : : * \returns \c true if both Duration are valid and 183 : : * this Duration is strictly numerically smaller than other. 184 : : * \note the precision of Duration is considered 185 : : */ 186 : 5 : bool operator<(const Duration &other) const 187 : : { 188 : 5 : ensureValid(); 189 : 4 : other.ensureValid(); 190 [ + + + + ]: 3 : return (mDuration < other.mDuration) && operator!=(other); 191 : : } 192 : : 193 : : /** 194 : : * \brief standard comparison operator 195 : : * 196 : : * \param[in] other Other Duration. 197 : : * 198 : : * \returns \c true if both Duration are valid and 199 : : * this Duration is numerically greater than other. 200 : : * \note the precision of Duration is considered 201 : : */ 202 : 7 : bool operator>=(const Duration &other) const 203 : : { 204 : 7 : ensureValid(); 205 : 6 : other.ensureValid(); 206 [ + + + + ]: 5 : return ((mDuration > other.mDuration) || operator==(other)); 207 : : } 208 : : 209 : : /** 210 : : * \brief standard comparison operator 211 : : * 212 : : * \param[in] other Other Duration 213 : : * 214 : : * \returns \c true if both Duration are valid and 215 : : * this Duration is numerically smaller than other. 216 : : * \note the precision of Duration is considered 217 : : */ 218 : 32 : bool operator<=(const Duration &other) const 219 : : { 220 : 32 : ensureValid(); 221 : 31 : other.ensureValid(); 222 [ + + + + ]: 30 : return ((mDuration < other.mDuration) || operator==(other)); 223 : : } 224 : : 225 : : /** 226 : : * \brief standard arithmetic operator 227 : : * 228 : : * \param[in] other Other Duration 229 : : * 230 : : * \returns Result of arithmetic operation. 231 : : * 232 : : * \note throws a std::out_of_range exception if one of the two operands or the result of 233 : : * the operation is not valid 234 : : */ 235 : 4 : Duration operator+(const Duration &other) const 236 : : { 237 [ + + ]: 4 : ensureValid(); 238 [ + + ]: 3 : other.ensureValid(); 239 : 2 : Duration const result(mDuration + other.mDuration); 240 [ + + ]: 2 : result.ensureValid(); 241 : 1 : return result; 242 : : } 243 : : 244 : : /** 245 : : * \brief standard arithmetic operator 246 : : * 247 : : * \param[in] other Other Duration 248 : : * 249 : : * \returns Result of arithmetic operation. 250 : : * 251 : : * \note throws a std::out_of_range exception if one of the two operands or the result of 252 : : * the operation is not valid 253 : : */ 254 : 4 : Duration &operator+=(const Duration &other) 255 : : { 256 : 4 : ensureValid(); 257 : 3 : other.ensureValid(); 258 : 2 : mDuration += other.mDuration; 259 : 2 : ensureValid(); 260 : 1 : return *this; 261 : : } 262 : : 263 : : /** 264 : : * \brief standard arithmetic operator 265 : : * 266 : : * \param[in] other Other Duration 267 : : * 268 : : * \returns Result of arithmetic operation. 269 : : * 270 : : * \note throws a std::out_of_range exception if one of the two operands or the result of 271 : : * the operation is not valid 272 : : */ 273 : 4 : Duration operator-(const Duration &other) const 274 : : { 275 [ + + ]: 4 : ensureValid(); 276 [ + + ]: 3 : other.ensureValid(); 277 : 2 : Duration const result(mDuration - other.mDuration); 278 [ + + ]: 2 : result.ensureValid(); 279 : 1 : return result; 280 : : } 281 : : 282 : : /** 283 : : * \brief standard arithmetic operator 284 : : * 285 : : * \param[in] other Other Duration 286 : : * 287 : : * \returns Result of arithmetic operation. 288 : : * 289 : : * \note throws a std::out_of_range exception if one of the two operands or the result of 290 : : * the operation is not valid 291 : : */ 292 : 4 : Duration operator-=(const Duration &other) 293 : : { 294 : 4 : ensureValid(); 295 : 3 : other.ensureValid(); 296 : 2 : mDuration -= other.mDuration; 297 : 2 : ensureValid(); 298 : 1 : return *this; 299 : : } 300 : : 301 : : /** 302 : : * \brief standard arithmetic operator 303 : : * 304 : : * \param[in] other Other Duration 305 : : * 306 : : * \returns Result of arithmetic operation. 307 : : * 308 : : * \note throws a std::out_of_range exception if one of the two operands or the result of 309 : : * the operation is not valid 310 : : * \note since Duration is a type with physical unit, the multiplication results in the Squared type. 311 : : */ 312 : : DurationSquared operator*(const Duration &other) const; 313 : : 314 : : /** 315 : : * \brief standard arithmetic operator 316 : : * 317 : : * \param[in] scalar Scalar double value 318 : : * 319 : : * \returns Result of arithmetic operation. 320 : : * 321 : : * \note throws a std::out_of_range exception if \c value or the result of 322 : : * the operation is not valid 323 : : */ 324 : 4 : Duration operator*(const double &scalar) const 325 : : { 326 [ + + ]: 4 : ensureValid(); 327 : 3 : Duration const result(mDuration * scalar); 328 [ + + ]: 3 : result.ensureValid(); 329 : 2 : return result; 330 : : } 331 : : 332 : : /** 333 : : * \brief standard arithmetic operator 334 : : * 335 : : * \param[in] scalar Scalar double value 336 : : * 337 : : * \returns Result of arithmetic operation. 338 : : * 339 : : * \note throws a std::out_of_range exception if this or the result of 340 : : * the operation is not valid or other is zero 341 : : */ 342 : 5 : Duration operator/(const double &scalar) const 343 : : { 344 : 5 : Duration const scalarDuration(scalar); 345 [ + + ]: 5 : Duration const result(operator/(scalarDuration)); 346 [ + + ]: 2 : result.ensureValid(); 347 : 1 : return result; 348 : : } 349 : : 350 : : /** 351 : : * \brief standard arithmetic operator 352 : : * 353 : : * \param[in] other Other Duration 354 : : * 355 : : * \returns Result of arithmetic operation. 356 : : * 357 : : * \note throws a std::out_of_range exception if one of the two operands or the result of 358 : : * the operation is not valid or other is zero 359 : : * \note since Duration is a type with physical unit, the division results in the dimensionless type. 360 : : */ 361 : 9 : double operator/(const Duration &other) const 362 : : { 363 : 9 : ensureValid(); 364 : 7 : other.ensureValidNonZero(); 365 : 3 : double const result = mDuration / other.mDuration; 366 : 3 : return result; 367 : : } 368 : : 369 : : /** 370 : : * \brief standard arithmetic operator 371 : : * 372 : : * \returns Result of arithmetic operation. 373 : : * 374 : : * \note throws a std::out_of_range exception if this or the result of 375 : : * the operation is not valid 376 : : */ 377 : 2 : Duration operator-() const 378 : : { 379 [ + + ]: 2 : ensureValid(); 380 : 1 : Duration const result(-mDuration); 381 : 1 : result.ensureValid(); // LCOV_EXCL_BR_LINE Some types do not throw an exception 382 : 1 : return result; 383 : : } 384 : : 385 : : /*! 386 : : * \brief conversion to base type: double 387 : : * 388 : : * \note the conversion to the base type removes the physical unit. 389 : : * \ref \_AD_PHYSICS_DURATION_EXPLICIT_CONVERSION\_ defines, if only explicit calls are allowed. 390 : : */ 391 : 133 : _AD_PHYSICS_DURATION_EXPLICIT_CONVERSION_ operator double() const 392 : : { 393 : 133 : return mDuration; 394 : : } 395 : : 396 : : /*! 397 : : * \returns \c true if the Duration in a valid range 398 : : * 399 : : * An Duration value is defined to be valid if: 400 : : * - It is normal or zero (see std::fpclassify()) 401 : : * - \ref cMinValue <= value <= \ref cMaxValue 402 : : */ 403 : 274 : bool isValid() const 404 : : { 405 : 274 : auto const valueClass = std::fpclassify(mDuration); 406 [ + + + + ]: 274 : return ((valueClass == FP_NORMAL) || (valueClass == FP_ZERO)) && (cMinValue <= mDuration) 407 [ + + + + ]: 548 : && (mDuration <= cMaxValue); 408 : : } 409 : : 410 : : /*! 411 : : * \brief ensure that the Duration is valid 412 : : * 413 : : * Throws an std::out_of_range() exception if the Duration 414 : : * in not valid (i.e. isValid() returns false) 415 : : */ 416 : 246 : void ensureValid() const 417 : : { 418 [ + + ]: 246 : if (!isValid()) 419 : : { 420 : 37 : spdlog::info("ensureValid(::ad::physics::Duration)>> {} value out of range", *this); // LCOV_EXCL_BR_LINE 421 : : #if (AD_PHYSICS_DURATION_THROWS_EXCEPTION == 1) 422 : 37 : throw std::out_of_range("Duration value out of range"); // LCOV_EXCL_BR_LINE 423 : : #endif 424 : : } 425 : 209 : } 426 : : 427 : : /*! 428 : : * \brief ensure that the Duration is valid and non zero 429 : : * 430 : : * Throws an std::out_of_range() exception if the Duration 431 : : * in not valid or zero (i.e. isValid() returns false) 432 : : */ 433 : 9 : void ensureValidNonZero() const 434 : : { 435 : 9 : ensureValid(); 436 : 6 : if (operator==(Duration(0.))) // LCOV_EXCL_BR_LINE 437 : : { 438 : 3 : spdlog::info("ensureValid(::ad::physics::Duration)>> {} value is zero", *this); // LCOV_EXCL_BR_LINE 439 : : #if (AD_PHYSICS_DURATION_THROWS_EXCEPTION == 1) 440 : 3 : throw std::out_of_range("Duration value is zero"); // LCOV_EXCL_BR_LINE 441 : : #endif 442 : : } 443 : 3 : } 444 : : 445 : : /*! 446 : : * \brief get minimum valid Duration (i.e. \ref cMinValue) 447 : : */ 448 : 15 : static Duration getMin() 449 : : { 450 : 15 : return Duration(cMinValue); 451 : : } 452 : : 453 : : /*! 454 : : * \brief get maximum valid Duration (i.e. \ref cMaxValue) 455 : : */ 456 : 15 : static Duration getMax() 457 : : { 458 : 15 : return Duration(cMaxValue); 459 : : } 460 : : 461 : : /*! 462 : : * \brief get assumed accuracy of Duration (i.e. \ref cPrecisionValue) 463 : : */ 464 : 3 : static Duration getPrecision() 465 : : { 466 : 3 : return Duration(cPrecisionValue); 467 : : } 468 : : 469 : : private: 470 : : /*! 471 : : * \brief the actual value of the type 472 : : */ 473 : : double mDuration; 474 : : }; 475 : : 476 : : } // namespace physics 477 : : } // namespace ad 478 : : /** 479 : : * \brief standard arithmetic operator 480 : : * 481 : : * \param[in] other Other Duration as double value 482 : : * \param[in] value Duration value 483 : : * 484 : : * \returns Result of arithmetic operation. 485 : : * 486 : : * \note throws a std::out_of_range exception if \c value or the result of 487 : : * the operation is not valid 488 : : */ 489 : 1 : inline ::ad::physics::Duration operator*(const double &other, ::ad::physics::Duration const &value) 490 : : { 491 : 1 : return value.operator*(other); 492 : : } 493 : : 494 : : /*! 495 : : * \brief namespace std 496 : : */ 497 : : namespace std { 498 : : 499 : : /*! 500 : : * \brief overload of the std::fabs for Duration 501 : : */ 502 : 7 : inline ::ad::physics::Duration fabs(const ::ad::physics::Duration other) 503 : : { 504 : 7 : ::ad::physics::Duration const result(std::fabs(static_cast<double>(other))); 505 : 7 : return result; 506 : : } 507 : : 508 : : /*! 509 : : * \brief specialization of the std::numeric_limits for Duration 510 : : * 511 : : * Derived from std::numeric_limits<double> with overloaded functions: 512 : : * std::numeric_limits<Duration>::lowest() (\see Duration::getMin()) 513 : : * std::numeric_limits<Duration>::max() (\see Duration::getMax()) 514 : : * std::numeric_limits<Duration>::epsilon() (\see Duration::getPrecision()) 515 : : */ 516 : : template <> class numeric_limits<::ad::physics::Duration> : public numeric_limits<double> 517 : : { 518 : : public: 519 : : /*! 520 : : * \see std::numeric_limits::lowest() 521 : : */ 522 : 12 : static inline ::ad::physics::Duration lowest() 523 : : { 524 : 12 : return ::ad::physics::Duration::getMin(); 525 : : } 526 : : /*! 527 : : * \see std::numeric_limits::max() 528 : : */ 529 : 12 : static inline ::ad::physics::Duration max() 530 : : { 531 : 12 : return ::ad::physics::Duration::getMax(); 532 : : } 533 : : 534 : : /*! 535 : : * \see std::numeric_limits::epsilon() 536 : : */ 537 : 1 : static inline ::ad::physics::Duration epsilon() 538 : : { 539 : 1 : return ::ad::physics::Duration::getPrecision(); 540 : : } 541 : : }; 542 : : 543 : : } // namespace std 544 : : 545 : : /*! 546 : : * \brief protect the definition of functions from duplicates by typedef usage within other data types 547 : : */ 548 : : #ifndef GEN_GUARD_AD_PHYSICS_DURATION 549 : : #define GEN_GUARD_AD_PHYSICS_DURATION 550 : : /*! 551 : : * @brief namespace ad 552 : : */ 553 : : namespace ad { 554 : : /*! 555 : : * @brief namespace physics 556 : : */ 557 : : namespace physics { 558 : : 559 : : /** 560 : : * \brief standard ostream operator 561 : : * 562 : : * \param[in] os The output stream to write to 563 : : * \param[in] _value Duration value 564 : : * 565 : : * \returns The stream object. 566 : : * 567 : : */ 568 : 64 : inline std::ostream &operator<<(std::ostream &os, Duration const &_value) 569 : : { 570 : 64 : return os << double(_value); 571 : : } 572 : : 573 : : } // namespace physics 574 : : } // namespace ad 575 : : 576 : : namespace std { 577 : : /*! 578 : : * \brief overload of the std::to_string for Duration 579 : : */ 580 : : inline std::string to_string(::ad::physics::Duration const &value) 581 : : { 582 : : return to_string(static_cast<double>(value)); 583 : : } 584 : : } // namespace std 585 : : #endif // GEN_GUARD_AD_PHYSICS_DURATION