| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /** | ||
| 2 | * \file: BasicTypes.hpp | ||
| 3 | * \author mstarch | ||
| 4 | * \brief C++ header for working with basic fprime types | ||
| 5 | * | ||
| 6 | * \copyright | ||
| 7 | * Copyright 2009-2016, by the California Institute of Technology. | ||
| 8 | * ALL RIGHTS RESERVED. United States Government Sponsorship | ||
| 9 | * acknowledged. | ||
| 10 | */ | ||
| 11 | |||
| 12 | #ifndef FW_BASIC_TYPES_HPP | ||
| 13 | #define FW_BASIC_TYPES_HPP | ||
| 14 | |||
| 15 | #include <cstddef> | ||
| 16 | #include <limits> | ||
| 17 | #include <type_traits> | ||
| 18 | // Use C linkage for the basic items | ||
| 19 | extern "C" { | ||
| 20 | #include "Fw/Types/BasicTypes.h" | ||
| 21 | } | ||
| 22 | |||
| 23 | // FW_NUM_ARRAY_ELEMENTS for C++. This has to live outside the extern "C" block | ||
| 24 | // above (C linkage cannot be applied to templates). The plain sizeof macro is | ||
| 25 | // wrong for FPP array types and other non-array types (see #5155), so the C++ | ||
| 26 | // form asserts the argument is a C-style array and then takes its extent. | ||
| 27 | // | ||
| 28 | // numArrayElements is resolved on the type only (via decltype, which does not | ||
| 29 | // evaluate its operand) and takes no runtime argument, so FW_NUM_ARRAY_ELEMENTS | ||
| 30 | // stays a constant expression and is safe on member arrays such as this->member. | ||
| 31 | namespace Fw { | ||
| 32 | namespace BasicTypes { | ||
| 33 | |||
| 34 | template <typename T> | ||
| 35 | 3 | constexpr std::size_t numArrayElements() { | |
| 36 | static_assert(std::is_array<T>::value, "FW_NUM_ARRAY_ELEMENTS may only be used on a primitive (C-style) array"); | ||
| 37 | 3 | return std::extent<T>::value; | |
| 38 | } | ||
| 39 | |||
| 40 | } // namespace BasicTypes | ||
| 41 | } // namespace Fw | ||
| 42 | |||
| 43 | #define FW_NUM_ARRAY_ELEMENTS(a) \ | ||
| 44 | (::Fw::BasicTypes::numArrayElements<decltype(a)>()) //!< number of elements in a C-style array | ||
| 45 | |||
| 46 | // IEEE compliance checks must occur in C++ code | ||
| 47 | #if !defined(SKIP_FLOAT_IEEE_754_COMPLIANCE) || !SKIP_FLOAT_IEEE_754_COMPLIANCE | ||
| 48 | static_assert((std::numeric_limits<float>::is_iec559 == true) && (std::numeric_limits<float>::radix == 2) && | ||
| 49 | (std::numeric_limits<float>::digits == 24) && (std::numeric_limits<float>::max_exponent == 128), | ||
| 50 | "The 32-bit floating point type does not conform to the IEEE-754 standard."); | ||
| 51 | static_assert((std::numeric_limits<double>::is_iec559 == true) && (std::numeric_limits<double>::radix == 2) && | ||
| 52 | (std::numeric_limits<double>::digits == 53) && (std::numeric_limits<double>::max_exponent == 1024), | ||
| 53 | "The 64-bit floating point type does not conform to the IEEE-754 standard."); | ||
| 54 | #endif | ||
| 55 | #endif // End FW_BASIC_TYPES_HPP | ||
| 56 |