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_DISTANCE_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_DISTANCE_EXPLICIT_CONVERSION_ explicit 46 : : #else 47 : : /*! 48 : : * \brief Enable/Disable explicit conversion. Currently set to "implicit conversion allowed". 49 : : */ 50 : : #define _AD_PHYSICS_DISTANCE_EXPLICIT_CONVERSION_ 51 : : #endif 52 : : 53 : : /*! 54 : : * \brief Forward declaration of DistanceSquared 55 : : * 56 : : * Since Distance is defined explicitly as a physical type we have to consider this 57 : : * within operations. Therefore this squared type is defined. 58 : : */ 59 : : class DistanceSquared; 60 : : 61 : : /*! 62 : : * \brief DataType Distance 63 : : * 64 : : * The length of a specific path traveled between two points. 65 : : * The unit is: Meter 66 : : */ 67 : : class Distance 68 : : { 69 : : public: 70 : : /*! 71 : : * \brief constant defining the minimum valid Distance value (used in isValid()) 72 : : */ 73 : : static const double cMinValue; 74 : : 75 : : /*! 76 : : * \brief constant defining the maximum valid Distance value (used in isValid()) 77 : : */ 78 : : static const double cMaxValue; 79 : : 80 : : /*! 81 : : * \brief constant defining the assumed Distance 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 Distance is: 90 : : * std::numeric_limits<double>::quiet_NaN() 91 : : */ 92 : 326 : Distance() 93 : 326 : : mDistance(std::numeric_limits<double>::quiet_NaN()) 94 : : { 95 : 326 : } 96 : : 97 : : /*! 98 : : * \brief standard constructor 99 : : * 100 : : * \note \ref \_AD_PHYSICS_DISTANCE_EXPLICIT_CONVERSION\_ defines, if only an explicit conversion is allowed. 101 : : */ 102 : 690 : _AD_PHYSICS_DISTANCE_EXPLICIT_CONVERSION_ Distance(double const iDistance) 103 : 690 : : mDistance(iDistance) 104 : : { 105 : 690 : } 106 : : 107 : : /*! 108 : : * \brief standard copy constructor 109 : : */ 110 : : Distance(const Distance &other) = default; 111 : : 112 : : /*! 113 : : * \brief standard move constructor 114 : : */ 115 : : Distance(Distance &&other) = default; 116 : : 117 : : /** 118 : : * \brief standard assignment operator 119 : : * 120 : : * \param[in] other Other Distance 121 : : * 122 : : * \returns Reference to this Distance. 123 : : */ 124 : : Distance &operator=(const Distance &other) = default; 125 : : 126 : : /** 127 : : * \brief standard move operator 128 : : * 129 : : * \param[in] other Other Distance 130 : : * 131 : : * \returns Reference to this Distance. 132 : : */ 133 : : Distance &operator=(Distance &&other) = default; 134 : : 135 : : /** 136 : : * \brief standard comparison operator 137 : : * 138 : : * \param[in] other Other Distance 139 : : * 140 : : * \returns \c true if both Distance are valid and can be taken as numerically equal 141 : : */ 142 : 237 : bool operator==(const Distance &other) const 143 : : { 144 : 237 : ensureValid(); 145 : 235 : other.ensureValid(); 146 : 233 : return std::fabs(mDistance - other.mDistance) < cPrecisionValue; 147 : : } 148 : : 149 : : /** 150 : : * \brief standard comparison operator 151 : : * 152 : : * \param[in] other Other Distance. 153 : : * 154 : : * \returns \c true if one of the Distance is not valid or they can be taken as numerically different 155 : : */ 156 : 11 : bool operator!=(const Distance &other) const 157 : : { 158 : 11 : return !operator==(other); 159 : : } 160 : : 161 : : /** 162 : : * \brief standard comparison operator 163 : : * 164 : : * \param[in] other Other Distance. 165 : : * 166 : : * \returns \c true if both Distance are valid and 167 : : * this Distance is strictly numerically greater than other. 168 : : * \note the precision of Distance is considered 169 : : */ 170 : 5 : bool operator>(const Distance &other) const 171 : : { 172 : 5 : ensureValid(); 173 : 4 : other.ensureValid(); 174 [ + + + + ]: 3 : return (mDistance > other.mDistance) && operator!=(other); 175 : : } 176 : : 177 : : /** 178 : : * \brief standard comparison operator 179 : : * 180 : : * \param[in] other Other Distance. 181 : : * 182 : : * \returns \c true if both Distance are valid and 183 : : * this Distance is strictly numerically smaller than other. 184 : : * \note the precision of Distance is considered 185 : : */ 186 : 5 : bool operator<(const Distance &other) const 187 : : { 188 : 5 : ensureValid(); 189 : 4 : other.ensureValid(); 190 [ + + + + ]: 3 : return (mDistance < other.mDistance) && operator!=(other); 191 : : } 192 : : 193 : : /** 194 : : * \brief standard comparison operator 195 : : * 196 : : * \param[in] other Other Distance. 197 : : * 198 : : * \returns \c true if both Distance are valid and 199 : : * this Distance is numerically greater than other. 200 : : * \note the precision of Distance is considered 201 : : */ 202 : 7 : bool operator>=(const Distance &other) const 203 : : { 204 : 7 : ensureValid(); 205 : 6 : other.ensureValid(); 206 [ + + + + ]: 5 : return ((mDistance > other.mDistance) || operator==(other)); 207 : : } 208 : : 209 : : /** 210 : : * \brief standard comparison operator 211 : : * 212 : : * \param[in] other Other Distance 213 : : * 214 : : * \returns \c true if both Distance are valid and 215 : : * this Distance is numerically smaller than other. 216 : : * \note the precision of Distance is considered 217 : : */ 218 : 228 : bool operator<=(const Distance &other) const 219 : : { 220 : 228 : ensureValid(); 221 : 227 : other.ensureValid(); 222 [ + + + + ]: 226 : return ((mDistance < other.mDistance) || operator==(other)); 223 : : } 224 : : 225 : : /** 226 : : * \brief standard arithmetic operator 227 : : * 228 : : * \param[in] other Other Distance 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 : Distance operator+(const Distance &other) const 236 : : { 237 [ + + ]: 4 : ensureValid(); 238 [ + + ]: 3 : other.ensureValid(); 239 : 2 : Distance const result(mDistance + other.mDistance); 240 [ + + ]: 2 : result.ensureValid(); 241 : 1 : return result; 242 : : } 243 : : 244 : : /** 245 : : * \brief standard arithmetic operator 246 : : * 247 : : * \param[in] other Other Distance 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 : Distance &operator+=(const Distance &other) 255 : : { 256 : 4 : ensureValid(); 257 : 3 : other.ensureValid(); 258 : 2 : mDistance += other.mDistance; 259 : 2 : ensureValid(); 260 : 1 : return *this; 261 : : } 262 : : 263 : : /** 264 : : * \brief standard arithmetic operator 265 : : * 266 : : * \param[in] other Other Distance 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 : Distance operator-(const Distance &other) const 274 : : { 275 [ + + ]: 4 : ensureValid(); 276 [ + + ]: 3 : other.ensureValid(); 277 : 2 : Distance const result(mDistance - other.mDistance); 278 [ + + ]: 2 : result.ensureValid(); 279 : 1 : return result; 280 : : } 281 : : 282 : : /** 283 : : * \brief standard arithmetic operator 284 : : * 285 : : * \param[in] other Other Distance 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 : Distance operator-=(const Distance &other) 293 : : { 294 : 4 : ensureValid(); 295 : 3 : other.ensureValid(); 296 : 2 : mDistance -= other.mDistance; 297 : 2 : ensureValid(); 298 : 1 : return *this; 299 : : } 300 : : 301 : : /** 302 : : * \brief standard arithmetic operator 303 : : * 304 : : * \param[in] other Other Distance 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 Distance is a type with physical unit, the multiplication results in the Squared type. 311 : : */ 312 : : DistanceSquared operator*(const Distance &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 : Distance operator*(const double &scalar) const 325 : : { 326 [ + + ]: 4 : ensureValid(); 327 : 3 : Distance const result(mDistance * 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 : Distance operator/(const double &scalar) const 343 : : { 344 : 5 : Distance const scalarDistance(scalar); 345 [ + + ]: 5 : Distance const result(operator/(scalarDistance)); 346 [ + + ]: 2 : result.ensureValid(); 347 : 1 : return result; 348 : : } 349 : : 350 : : /** 351 : : * \brief standard arithmetic operator 352 : : * 353 : : * \param[in] other Other Distance 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 Distance is a type with physical unit, the division results in the dimensionless type. 360 : : */ 361 : 9 : double operator/(const Distance &other) const 362 : : { 363 : 9 : ensureValid(); 364 : 7 : other.ensureValidNonZero(); 365 : 3 : double const result = mDistance / other.mDistance; 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 : Distance operator-() const 378 : : { 379 [ + + ]: 2 : ensureValid(); 380 : 1 : Distance const result(-mDistance); 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_DISTANCE_EXPLICIT_CONVERSION\_ defines, if only explicit calls are allowed. 390 : : */ 391 : 413 : _AD_PHYSICS_DISTANCE_EXPLICIT_CONVERSION_ operator double() const 392 : : { 393 : 413 : return mDistance; 394 : : } 395 : : 396 : : /*! 397 : : * \returns \c true if the Distance in a valid range 398 : : * 399 : : * An Distance value is defined to be valid if: 400 : : * - It is normal or zero (see std::fpclassify()) 401 : : * - \ref cMinValue <= value <= \ref cMaxValue 402 : : */ 403 : 1148 : bool isValid() const 404 : : { 405 : 1148 : auto const valueClass = std::fpclassify(mDistance); 406 [ + + + + ]: 1148 : return ((valueClass == FP_NORMAL) || (valueClass == FP_ZERO)) && (cMinValue <= mDistance) 407 [ + + + + ]: 2296 : && (mDistance <= cMaxValue); 408 : : } 409 : : 410 : : /*! 411 : : * \brief ensure that the Distance is valid 412 : : * 413 : : * Throws an std::out_of_range() exception if the Distance 414 : : * in not valid (i.e. isValid() returns false) 415 : : */ 416 : 1032 : void ensureValid() const 417 : : { 418 [ + + ]: 1032 : if (!isValid()) 419 : : { 420 : 37 : spdlog::info("ensureValid(::ad::physics::Distance)>> {} value out of range", *this); // LCOV_EXCL_BR_LINE 421 : : #if (AD_PHYSICS_DISTANCE_THROWS_EXCEPTION == 1) 422 : 37 : throw std::out_of_range("Distance value out of range"); // LCOV_EXCL_BR_LINE 423 : : #endif 424 : : } 425 : 995 : } 426 : : 427 : : /*! 428 : : * \brief ensure that the Distance is valid and non zero 429 : : * 430 : : * Throws an std::out_of_range() exception if the Distance 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==(Distance(0.))) // LCOV_EXCL_BR_LINE 437 : : { 438 : 3 : spdlog::info("ensureValid(::ad::physics::Distance)>> {} value is zero", *this); // LCOV_EXCL_BR_LINE 439 : : #if (AD_PHYSICS_DISTANCE_THROWS_EXCEPTION == 1) 440 : 3 : throw std::out_of_range("Distance value is zero"); // LCOV_EXCL_BR_LINE 441 : : #endif 442 : : } 443 : 3 : } 444 : : 445 : : /*! 446 : : * \brief get minimum valid Distance (i.e. \ref cMinValue) 447 : : */ 448 : 130 : static Distance getMin() 449 : : { 450 : 130 : return Distance(cMinValue); 451 : : } 452 : : 453 : : /*! 454 : : * \brief get maximum valid Distance (i.e. \ref cMaxValue) 455 : : */ 456 : 130 : static Distance getMax() 457 : : { 458 : 130 : return Distance(cMaxValue); 459 : : } 460 : : 461 : : /*! 462 : : * \brief get assumed accuracy of Distance (i.e. \ref cPrecisionValue) 463 : : */ 464 : 3 : static Distance getPrecision() 465 : : { 466 : 3 : return Distance(cPrecisionValue); 467 : : } 468 : : 469 : : private: 470 : : /*! 471 : : * \brief the actual value of the type 472 : : */ 473 : : double mDistance; 474 : : }; 475 : : 476 : : } // namespace physics 477 : : } // namespace ad 478 : : /** 479 : : * \brief standard arithmetic operator 480 : : * 481 : : * \param[in] other Other Distance as double value 482 : : * \param[in] value Distance 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::Distance operator*(const double &other, ::ad::physics::Distance 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 Distance 501 : : */ 502 : 7 : inline ::ad::physics::Distance fabs(const ::ad::physics::Distance other) 503 : : { 504 : 7 : ::ad::physics::Distance const result(std::fabs(static_cast<double>(other))); 505 : 7 : return result; 506 : : } 507 : : 508 : : /*! 509 : : * \brief specialization of the std::numeric_limits for Distance 510 : : * 511 : : * Derived from std::numeric_limits<double> with overloaded functions: 512 : : * std::numeric_limits<Distance>::lowest() (\see Distance::getMin()) 513 : : * std::numeric_limits<Distance>::max() (\see Distance::getMax()) 514 : : * std::numeric_limits<Distance>::epsilon() (\see Distance::getPrecision()) 515 : : */ 516 : : template <> class numeric_limits<::ad::physics::Distance> : public numeric_limits<double> 517 : : { 518 : : public: 519 : : /*! 520 : : * \see std::numeric_limits::lowest() 521 : : */ 522 : 127 : static inline ::ad::physics::Distance lowest() 523 : : { 524 : 127 : return ::ad::physics::Distance::getMin(); 525 : : } 526 : : /*! 527 : : * \see std::numeric_limits::max() 528 : : */ 529 : 127 : static inline ::ad::physics::Distance max() 530 : : { 531 : 127 : return ::ad::physics::Distance::getMax(); 532 : : } 533 : : 534 : : /*! 535 : : * \see std::numeric_limits::epsilon() 536 : : */ 537 : 1 : static inline ::ad::physics::Distance epsilon() 538 : : { 539 : 1 : return ::ad::physics::Distance::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_DISTANCE 549 : : #define GEN_GUARD_AD_PHYSICS_DISTANCE 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 Distance value 564 : : * 565 : : * \returns The stream object. 566 : : * 567 : : */ 568 : 344 : inline std::ostream &operator<<(std::ostream &os, Distance const &_value) 569 : : { 570 : 344 : 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 Distance 579 : : */ 580 : : inline std::string to_string(::ad::physics::Distance const &value) 581 : : { 582 : : return to_string(static_cast<double>(value)); 583 : : } 584 : : } // namespace std 585 : : #endif // GEN_GUARD_AD_PHYSICS_DISTANCE