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