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_SPEED_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_SPEED_EXPLICIT_CONVERSION_ explicit 46 : : #else 47 : : /*! 48 : : * \brief Enable/Disable explicit conversion. Currently set to "implicit conversion allowed". 49 : : */ 50 : : #define _AD_PHYSICS_SPEED_EXPLICIT_CONVERSION_ 51 : : #endif 52 : : 53 : : /*! 54 : : * \brief Forward declaration of SpeedSquared 55 : : * 56 : : * Since Speed is defined explicitly as a physical type we have to consider this 57 : : * within operations. Therefore this squared type is defined. 58 : : */ 59 : : class SpeedSquared; 60 : : 61 : : /*! 62 : : * \brief DataType Speed 63 : : * 64 : : * The rate of change of an object's position with respect to time. The speed of an object is the magnitude of its 65 : : * velocity. 66 : : * The unit is: MeterPerSecond 67 : : */ 68 : : class Speed 69 : : { 70 : : public: 71 : : /*! 72 : : * \brief constant defining the minimum valid Speed value (used in isValid()) 73 : : */ 74 : : static const double cMinValue; 75 : : 76 : : /*! 77 : : * \brief constant defining the maximum valid Speed value (used in isValid()) 78 : : */ 79 : : static const double cMaxValue; 80 : : 81 : : /*! 82 : : * \brief constant defining the assumed Speed value accuracy 83 : : * (used in comparison operator==(), operator!=()) 84 : : */ 85 : : static const double cPrecisionValue; 86 : : 87 : : /*! 88 : : * \brief default constructor 89 : : * 90 : : * The default value of Speed is: 91 : : * std::numeric_limits<double>::quiet_NaN() 92 : : */ 93 : 115 : Speed() 94 : 115 : : mSpeed(std::numeric_limits<double>::quiet_NaN()) 95 : : { 96 : 115 : } 97 : : 98 : : /*! 99 : : * \brief standard constructor 100 : : * 101 : : * \note \ref \_AD_PHYSICS_SPEED_EXPLICIT_CONVERSION\_ defines, if only an explicit conversion is allowed. 102 : : */ 103 : 431 : _AD_PHYSICS_SPEED_EXPLICIT_CONVERSION_ Speed(double const iSpeed) 104 : 431 : : mSpeed(iSpeed) 105 : : { 106 : 431 : } 107 : : 108 : : /*! 109 : : * \brief standard copy constructor 110 : : */ 111 : : Speed(const Speed &other) = default; 112 : : 113 : : /*! 114 : : * \brief standard move constructor 115 : : */ 116 : : Speed(Speed &&other) = default; 117 : : 118 : : /** 119 : : * \brief standard assignment operator 120 : : * 121 : : * \param[in] other Other Speed 122 : : * 123 : : * \returns Reference to this Speed. 124 : : */ 125 : : Speed &operator=(const Speed &other) = default; 126 : : 127 : : /** 128 : : * \brief standard move operator 129 : : * 130 : : * \param[in] other Other Speed 131 : : * 132 : : * \returns Reference to this Speed. 133 : : */ 134 : : Speed &operator=(Speed &&other) = default; 135 : : 136 : : /** 137 : : * \brief standard comparison operator 138 : : * 139 : : * \param[in] other Other Speed 140 : : * 141 : : * \returns \c true if both Speed are valid and can be taken as numerically equal 142 : : */ 143 : 126 : bool operator==(const Speed &other) const 144 : : { 145 : 126 : ensureValid(); 146 : 124 : other.ensureValid(); 147 : 122 : return std::fabs(mSpeed - other.mSpeed) < cPrecisionValue; 148 : : } 149 : : 150 : : /** 151 : : * \brief standard comparison operator 152 : : * 153 : : * \param[in] other Other Speed. 154 : : * 155 : : * \returns \c true if one of the Speed is not valid or they can be taken as numerically different 156 : : */ 157 : 11 : bool operator!=(const Speed &other) const 158 : : { 159 : 11 : return !operator==(other); 160 : : } 161 : : 162 : : /** 163 : : * \brief standard comparison operator 164 : : * 165 : : * \param[in] other Other Speed. 166 : : * 167 : : * \returns \c true if both Speed are valid and 168 : : * this Speed is strictly numerically greater than other. 169 : : * \note the precision of Speed is considered 170 : : */ 171 : 5 : bool operator>(const Speed &other) const 172 : : { 173 : 5 : ensureValid(); 174 : 4 : other.ensureValid(); 175 [ + + + + ]: 3 : return (mSpeed > other.mSpeed) && operator!=(other); 176 : : } 177 : : 178 : : /** 179 : : * \brief standard comparison operator 180 : : * 181 : : * \param[in] other Other Speed. 182 : : * 183 : : * \returns \c true if both Speed are valid and 184 : : * this Speed is strictly numerically smaller than other. 185 : : * \note the precision of Speed is considered 186 : : */ 187 : 5 : bool operator<(const Speed &other) const 188 : : { 189 : 5 : ensureValid(); 190 : 4 : other.ensureValid(); 191 [ + + + + ]: 3 : return (mSpeed < other.mSpeed) && operator!=(other); 192 : : } 193 : : 194 : : /** 195 : : * \brief standard comparison operator 196 : : * 197 : : * \param[in] other Other Speed. 198 : : * 199 : : * \returns \c true if both Speed are valid and 200 : : * this Speed is numerically greater than other. 201 : : * \note the precision of Speed is considered 202 : : */ 203 : 7 : bool operator>=(const Speed &other) const 204 : : { 205 : 7 : ensureValid(); 206 : 6 : other.ensureValid(); 207 [ + + + + ]: 5 : return ((mSpeed > other.mSpeed) || operator==(other)); 208 : : } 209 : : 210 : : /** 211 : : * \brief standard comparison operator 212 : : * 213 : : * \param[in] other Other Speed 214 : : * 215 : : * \returns \c true if both Speed are valid and 216 : : * this Speed is numerically smaller than other. 217 : : * \note the precision of Speed is considered 218 : : */ 219 : 160 : bool operator<=(const Speed &other) const 220 : : { 221 : 160 : ensureValid(); 222 : 159 : other.ensureValid(); 223 [ + + + + ]: 158 : return ((mSpeed < other.mSpeed) || operator==(other)); 224 : : } 225 : : 226 : : /** 227 : : * \brief standard arithmetic operator 228 : : * 229 : : * \param[in] other Other Speed 230 : : * 231 : : * \returns Result of arithmetic operation. 232 : : * 233 : : * \note throws a std::out_of_range exception if one of the two operands or the result of 234 : : * the operation is not valid 235 : : */ 236 : 4 : Speed operator+(const Speed &other) const 237 : : { 238 [ + + ]: 4 : ensureValid(); 239 [ + + ]: 3 : other.ensureValid(); 240 : 2 : Speed const result(mSpeed + other.mSpeed); 241 [ + + ]: 2 : result.ensureValid(); 242 : 1 : return result; 243 : : } 244 : : 245 : : /** 246 : : * \brief standard arithmetic operator 247 : : * 248 : : * \param[in] other Other Speed 249 : : * 250 : : * \returns Result of arithmetic operation. 251 : : * 252 : : * \note throws a std::out_of_range exception if one of the two operands or the result of 253 : : * the operation is not valid 254 : : */ 255 : 4 : Speed &operator+=(const Speed &other) 256 : : { 257 : 4 : ensureValid(); 258 : 3 : other.ensureValid(); 259 : 2 : mSpeed += other.mSpeed; 260 : 2 : ensureValid(); 261 : 1 : return *this; 262 : : } 263 : : 264 : : /** 265 : : * \brief standard arithmetic operator 266 : : * 267 : : * \param[in] other Other Speed 268 : : * 269 : : * \returns Result of arithmetic operation. 270 : : * 271 : : * \note throws a std::out_of_range exception if one of the two operands or the result of 272 : : * the operation is not valid 273 : : */ 274 : 4 : Speed operator-(const Speed &other) const 275 : : { 276 [ + + ]: 4 : ensureValid(); 277 [ + + ]: 3 : other.ensureValid(); 278 : 2 : Speed const result(mSpeed - other.mSpeed); 279 [ + + ]: 2 : result.ensureValid(); 280 : 1 : return result; 281 : : } 282 : : 283 : : /** 284 : : * \brief standard arithmetic operator 285 : : * 286 : : * \param[in] other Other Speed 287 : : * 288 : : * \returns Result of arithmetic operation. 289 : : * 290 : : * \note throws a std::out_of_range exception if one of the two operands or the result of 291 : : * the operation is not valid 292 : : */ 293 : 4 : Speed operator-=(const Speed &other) 294 : : { 295 : 4 : ensureValid(); 296 : 3 : other.ensureValid(); 297 : 2 : mSpeed -= other.mSpeed; 298 : 2 : ensureValid(); 299 : 1 : return *this; 300 : : } 301 : : 302 : : /** 303 : : * \brief standard arithmetic operator 304 : : * 305 : : * \param[in] other Other Speed 306 : : * 307 : : * \returns Result of arithmetic operation. 308 : : * 309 : : * \note throws a std::out_of_range exception if one of the two operands or the result of 310 : : * the operation is not valid 311 : : * \note since Speed is a type with physical unit, the multiplication results in the Squared type. 312 : : */ 313 : : SpeedSquared operator*(const Speed &other) const; 314 : : 315 : : /** 316 : : * \brief standard arithmetic operator 317 : : * 318 : : * \param[in] scalar Scalar double value 319 : : * 320 : : * \returns Result of arithmetic operation. 321 : : * 322 : : * \note throws a std::out_of_range exception if \c value or the result of 323 : : * the operation is not valid 324 : : */ 325 : 4 : Speed operator*(const double &scalar) const 326 : : { 327 [ + + ]: 4 : ensureValid(); 328 : 3 : Speed const result(mSpeed * scalar); 329 [ + + ]: 3 : result.ensureValid(); 330 : 2 : return result; 331 : : } 332 : : 333 : : /** 334 : : * \brief standard arithmetic operator 335 : : * 336 : : * \param[in] scalar Scalar double value 337 : : * 338 : : * \returns Result of arithmetic operation. 339 : : * 340 : : * \note throws a std::out_of_range exception if this or the result of 341 : : * the operation is not valid or other is zero 342 : : */ 343 : 5 : Speed operator/(const double &scalar) const 344 : : { 345 : 5 : Speed const scalarSpeed(scalar); 346 [ + + ]: 5 : Speed const result(operator/(scalarSpeed)); 347 [ + + ]: 2 : result.ensureValid(); 348 : 1 : return result; 349 : : } 350 : : 351 : : /** 352 : : * \brief standard arithmetic operator 353 : : * 354 : : * \param[in] other Other Speed 355 : : * 356 : : * \returns Result of arithmetic operation. 357 : : * 358 : : * \note throws a std::out_of_range exception if one of the two operands or the result of 359 : : * the operation is not valid or other is zero 360 : : * \note since Speed is a type with physical unit, the division results in the dimensionless type. 361 : : */ 362 : 9 : double operator/(const Speed &other) const 363 : : { 364 : 9 : ensureValid(); 365 : 7 : other.ensureValidNonZero(); 366 : 3 : double const result = mSpeed / other.mSpeed; 367 : 3 : return result; 368 : : } 369 : : 370 : : /** 371 : : * \brief standard arithmetic operator 372 : : * 373 : : * \returns Result of arithmetic operation. 374 : : * 375 : : * \note throws a std::out_of_range exception if this or the result of 376 : : * the operation is not valid 377 : : */ 378 : 2 : Speed operator-() const 379 : : { 380 [ + + ]: 2 : ensureValid(); 381 : 1 : Speed const result(-mSpeed); 382 : 1 : result.ensureValid(); // LCOV_EXCL_BR_LINE Some types do not throw an exception 383 : 1 : return result; 384 : : } 385 : : 386 : : /*! 387 : : * \brief conversion to base type: double 388 : : * 389 : : * \note the conversion to the base type removes the physical unit. 390 : : * \ref \_AD_PHYSICS_SPEED_EXPLICIT_CONVERSION\_ defines, if only explicit calls are allowed. 391 : : */ 392 : 251 : _AD_PHYSICS_SPEED_EXPLICIT_CONVERSION_ operator double() const 393 : : { 394 : 251 : return mSpeed; 395 : : } 396 : : 397 : : /*! 398 : : * \returns \c true if the Speed in a valid range 399 : : * 400 : : * An Speed value is defined to be valid if: 401 : : * - It is normal or zero (see std::fpclassify()) 402 : : * - \ref cMinValue <= value <= \ref cMaxValue 403 : : */ 404 : 737 : bool isValid() const 405 : : { 406 : 737 : auto const valueClass = std::fpclassify(mSpeed); 407 [ + + + + : 737 : return ((valueClass == FP_NORMAL) || (valueClass == FP_ZERO)) && (cMinValue <= mSpeed) && (mSpeed <= cMaxValue); + + + + ] 408 : : } 409 : : 410 : : /*! 411 : : * \brief ensure that the Speed is valid 412 : : * 413 : : * Throws an std::out_of_range() exception if the Speed 414 : : * in not valid (i.e. isValid() returns false) 415 : : */ 416 : 674 : void ensureValid() const 417 : : { 418 [ + + ]: 674 : if (!isValid()) 419 : : { 420 : 37 : spdlog::info("ensureValid(::ad::physics::Speed)>> {} value out of range", *this); // LCOV_EXCL_BR_LINE 421 : : #if (AD_PHYSICS_SPEED_THROWS_EXCEPTION == 1) 422 : 37 : throw std::out_of_range("Speed value out of range"); // LCOV_EXCL_BR_LINE 423 : : #endif 424 : : } 425 : 637 : } 426 : : 427 : : /*! 428 : : * \brief ensure that the Speed is valid and non zero 429 : : * 430 : : * Throws an std::out_of_range() exception if the Speed 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==(Speed(0.))) // LCOV_EXCL_BR_LINE 437 : : { 438 : 3 : spdlog::info("ensureValid(::ad::physics::Speed)>> {} value is zero", *this); // LCOV_EXCL_BR_LINE 439 : : #if (AD_PHYSICS_SPEED_THROWS_EXCEPTION == 1) 440 : 3 : throw std::out_of_range("Speed value is zero"); // LCOV_EXCL_BR_LINE 441 : : #endif 442 : : } 443 : 3 : } 444 : : 445 : : /*! 446 : : * \brief get minimum valid Speed (i.e. \ref cMinValue) 447 : : */ 448 : 77 : static Speed getMin() 449 : : { 450 : 77 : return Speed(cMinValue); 451 : : } 452 : : 453 : : /*! 454 : : * \brief get maximum valid Speed (i.e. \ref cMaxValue) 455 : : */ 456 : 77 : static Speed getMax() 457 : : { 458 : 77 : return Speed(cMaxValue); 459 : : } 460 : : 461 : : /*! 462 : : * \brief get assumed accuracy of Speed (i.e. \ref cPrecisionValue) 463 : : */ 464 : 3 : static Speed getPrecision() 465 : : { 466 : 3 : return Speed(cPrecisionValue); 467 : : } 468 : : 469 : : private: 470 : : /*! 471 : : * \brief the actual value of the type 472 : : */ 473 : : double mSpeed; 474 : : }; 475 : : 476 : : } // namespace physics 477 : : } // namespace ad 478 : : /** 479 : : * \brief standard arithmetic operator 480 : : * 481 : : * \param[in] other Other Speed as double value 482 : : * \param[in] value Speed 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::Speed operator*(const double &other, ::ad::physics::Speed 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 Speed 501 : : */ 502 : 7 : inline ::ad::physics::Speed fabs(const ::ad::physics::Speed other) 503 : : { 504 : 7 : ::ad::physics::Speed const result(std::fabs(static_cast<double>(other))); 505 : 7 : return result; 506 : : } 507 : : 508 : : /*! 509 : : * \brief specialization of the std::numeric_limits for Speed 510 : : * 511 : : * Derived from std::numeric_limits<double> with overloaded functions: 512 : : * std::numeric_limits<Speed>::lowest() (\see Speed::getMin()) 513 : : * std::numeric_limits<Speed>::max() (\see Speed::getMax()) 514 : : * std::numeric_limits<Speed>::epsilon() (\see Speed::getPrecision()) 515 : : */ 516 : : template <> class numeric_limits<::ad::physics::Speed> : public numeric_limits<double> 517 : : { 518 : : public: 519 : : /*! 520 : : * \see std::numeric_limits::lowest() 521 : : */ 522 : 74 : static inline ::ad::physics::Speed lowest() 523 : : { 524 : 74 : return ::ad::physics::Speed::getMin(); 525 : : } 526 : : /*! 527 : : * \see std::numeric_limits::max() 528 : : */ 529 : 74 : static inline ::ad::physics::Speed max() 530 : : { 531 : 74 : return ::ad::physics::Speed::getMax(); 532 : : } 533 : : 534 : : /*! 535 : : * \see std::numeric_limits::epsilon() 536 : : */ 537 : 1 : static inline ::ad::physics::Speed epsilon() 538 : : { 539 : 1 : return ::ad::physics::Speed::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_SPEED 549 : : #define GEN_GUARD_AD_PHYSICS_SPEED 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 Speed value 564 : : * 565 : : * \returns The stream object. 566 : : * 567 : : */ 568 : 182 : inline std::ostream &operator<<(std::ostream &os, Speed const &_value) 569 : : { 570 : 182 : 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 Speed 579 : : */ 580 : : inline std::string to_string(::ad::physics::Speed const &value) 581 : : { 582 : : return to_string(static_cast<double>(value)); 583 : : } 584 : : } // namespace std 585 : : #endif // GEN_GUARD_AD_PHYSICS_SPEED