From 328efd1b7baf137b15fa4a645b7250e6a4334196 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Mon, 8 Dec 2014 20:18:47 +0000 Subject: [PATCH] Change alignment class name --- variant.h | 94 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 58 insertions(+), 36 deletions(-) diff --git a/variant.h b/variant.h index 1dfe9a50..8acc5b66 100644 --- a/variant.h +++ b/variant.h @@ -29,7 +29,7 @@ SOFTWARE. #ifndef __ETL_VARIANT__ #define __ETL_VARIANT__ -#include +#include #include "array.h" #include "largest.h" @@ -37,7 +37,11 @@ SOFTWARE. #include "type_traits.h" #include "integral_limits.h" #include "static_assert.h" -#include "aligned_variable.h" +#include "alignment.h" + +#if defined(COMPILER_KEIL) + #pragma diag_suppress 940 +#endif //***************************************************************************** ///\defgroup variant variant @@ -80,7 +84,7 @@ namespace etl { public: variant_incorrect_type_exception() - : variant_exception("Unsupported type") + : variant_exception("variant: unsupported type") { } }; @@ -94,7 +98,7 @@ namespace etl { public: variant_invalid_type_id_exception() - : variant_exception("Invalid type id") + : variant_exception("variant: invalid type id") { } }; @@ -110,7 +114,7 @@ namespace etl typename T5 = __private_variant__::no_type<5>, typename T6 = __private_variant__::no_type<6>, typename T7 = __private_variant__::no_type<7>, - typename T8 = __private_variant__::no_type<8>> + typename T8 = __private_variant__::no_type<8> > class variant { private: @@ -437,9 +441,10 @@ namespace etl case 6: return reinterpret_cast(*p_data); case 7: return reinterpret_cast(*p_data); default: -#ifdef ETL_USE_EXCEPTIONS +#ifdef ETL_THROW_EXCEPTIONS throw variant_invalid_type_id_exception(); #endif + break; } } @@ -456,9 +461,10 @@ namespace etl case 6: return reinterpret_cast(*p_data); case 7: return reinterpret_cast(*p_data); default: -#ifdef ETL_USE_EXCEPTIONS +#ifdef ETL_THROW_EXCEPTIONS throw variant_invalid_type_id_exception(); #endif + break; } } }; @@ -483,9 +489,10 @@ namespace etl case 5: return reinterpret_cast(*p_data); case 6: return reinterpret_cast(*p_data); default: -#ifdef ETL_USE_EXCEPTIONS +#ifdef ETL_THROW_EXCEPTIONS throw variant_invalid_type_id_exception(); -#endif +#endif + break; } } @@ -501,9 +508,10 @@ namespace etl case 5: return reinterpret_cast(*p_data); case 6: return reinterpret_cast(*p_data); default: -#ifdef ETL_USE_EXCEPTIONS +#ifdef ETL_THROW_EXCEPTIONS throw variant_invalid_type_id_exception(); #endif + break; } } }; @@ -527,9 +535,10 @@ namespace etl case 4: return reinterpret_cast(*p_data); case 5: return reinterpret_cast(*p_data); default: -#ifdef ETL_USE_EXCEPTIONS +#ifdef ETL_THROW_EXCEPTIONS throw variant_invalid_type_id_exception(); #endif + break; } } @@ -544,9 +553,10 @@ namespace etl case 4: return reinterpret_cast(*p_data); case 5: return reinterpret_cast(*p_data); default: -#ifdef ETL_USE_EXCEPTIONS +#ifdef ETL_THROW_EXCEPTIONS throw variant_invalid_type_id_exception(); #endif + break; } } }; @@ -569,9 +579,10 @@ namespace etl case 3: return reinterpret_cast(*p_data); case 4: return reinterpret_cast(*p_data); default: -#ifdef ETL_USE_EXCEPTIONS +#ifdef ETL_THROW_EXCEPTIONS throw variant_invalid_type_id_exception(); #endif + break; } } @@ -585,9 +596,10 @@ namespace etl case 3: return reinterpret_cast(*p_data); case 4: return reinterpret_cast(*p_data); default: -#ifdef ETL_USE_EXCEPTIONS +#ifdef ETL_THROW_EXCEPTIONS throw variant_invalid_type_id_exception(); #endif + break; } } }; @@ -609,9 +621,10 @@ namespace etl case 2: return reinterpret_cast(*p_data); case 3: return reinterpret_cast(*p_data); default: -#ifdef ETL_USE_EXCEPTIONS +#ifdef ETL_THROW_EXCEPTIONS throw variant_invalid_type_id_exception(); #endif + break; } } @@ -624,9 +637,10 @@ namespace etl case 2: return reinterpret_cast(*p_data); case 3: return reinterpret_cast(*p_data); default: -#ifdef ETL_USE_EXCEPTIONS +#ifdef ETL_THROW_EXCEPTIONS throw variant_invalid_type_id_exception(); #endif + break; } } }; @@ -647,9 +661,10 @@ namespace etl case 1: return reinterpret_cast(*p_data); case 2: return reinterpret_cast(*p_data); default: -#ifdef ETL_USE_EXCEPTIONS +#ifdef ETL_THROW_EXCEPTIONS throw variant_invalid_type_id_exception(); #endif + break; } } @@ -661,9 +676,10 @@ namespace etl case 1: return reinterpret_cast(*p_data); case 2: return reinterpret_cast(*p_data); default: -#ifdef ETL_USE_EXCEPTIONS +#ifdef ETL_THROW_EXCEPTIONS throw variant_invalid_type_id_exception(); #endif + break; } } }; @@ -683,9 +699,10 @@ namespace etl case 0: return reinterpret_cast(*p_data); case 1: return reinterpret_cast(*p_data); default: -#ifdef ETL_USE_EXCEPTIONS +#ifdef ETL_THROW_EXCEPTIONS throw variant_invalid_type_id_exception(); #endif + break; } } @@ -696,9 +713,10 @@ namespace etl case 0: return reinterpret_cast(*p_data); case 1: return reinterpret_cast(*p_data); default: -#ifdef ETL_USE_EXCEPTIONS +#ifdef ETL_THROW_EXCEPTIONS throw variant_invalid_type_id_exception(); #endif + break; } } }; @@ -717,9 +735,10 @@ namespace etl { case 0: return reinterpret_cast(*p_data); default: -#ifdef ETL_USE_EXCEPTIONS +#ifdef ETL_THROW_EXCEPTIONS throw variant_invalid_type_id_exception(); #endif + break; } } @@ -729,9 +748,10 @@ namespace etl { case 0: return reinterpret_cast(*p_data); default: -#ifdef ETL_USE_EXCEPTIONS +#ifdef ETL_THROW_EXCEPTIONS throw variant_invalid_type_id_exception(); #endif + break; } } }; @@ -757,7 +777,7 @@ namespace etl template variant(T value) { - static_assert(Type_Is_Supported::value, "Unsupported type"); + STATIC_ASSERT(Type_Is_Supported::value, "Unsupported type"); new(&data.value[0]) T(value); type_id = Type_Id_Lookup::type_id; @@ -780,7 +800,7 @@ namespace etl template variant& operator =(typename parameter_type::type value) { - static_assert(Type_Is_Supported::value, "Unsupported type"); + STATIC_ASSERT(Type_Is_Supported::value, "Unsupported type"); new(&data.value[0]) T(value); type_id = Type_Id_Lookup::type_id; @@ -792,7 +812,7 @@ namespace etl /// For variants with the same type declarations. ///\return true if the types are the same, otherwise false. //*************************************************************************** - inline bool is_same_type(const variant& other) const + bool is_same_type(const variant& other) const { return type_id == other.type_id; } @@ -818,9 +838,10 @@ namespace etl case 6: is_same_type = type_id == Type_Id_Lookup::type_id; break; case 7: is_same_type = type_id == Type_Id_Lookup::type_id; break; default: -#if ETL_USE_EXCEPTIONS +#ifdef ETL_THROW_EXCEPTIONS throw variant_invalid_type_id_exception(); #endif + break; } return is_same_type; @@ -843,9 +864,10 @@ namespace etl case 6: reader.read(reinterpret_cast(*&data.value[0])); break; case 7: reader.read(reinterpret_cast(*&data.value[0])); break; default: -#if ETL_USE_EXCEPTIONS +#ifdef ETL_THROW_EXCEPTIONS throw variant_invalid_type_id_exception(); #endif + break; } } @@ -853,7 +875,7 @@ namespace etl /// Checks whether a valid value is currently stored. ///\return true if the value is valid, otherwise false. //*************************************************************************** - inline bool is_valid() const + bool is_valid() const { return type_id != UNSUPPORTED_TYPE_ID; } @@ -863,7 +885,7 @@ namespace etl ///\return true if it is the specified type, otherwise false. //*************************************************************************** template - inline bool is_type() const + bool is_type() const { return type_id == Type_Id_Lookup::type_id; } @@ -871,7 +893,7 @@ namespace etl //*************************************************************************** /// Clears the value to 'no valid stored value'. //*************************************************************************** - inline void clear() + void clear() { type_id = UNSUPPORTED_TYPE_ID; } @@ -884,9 +906,9 @@ namespace etl template T& get() { - static_assert(Type_Is_Supported::value, "Unsupported type"); + STATIC_ASSERT(Type_Is_Supported::value, "Unsupported type"); -#if ETL_USE_EXCEPTIONS +#ifdef ETL_THROW_EXCEPTIONS if (!is_type()) { throw variant_incorrect_type_exception(); @@ -904,9 +926,9 @@ namespace etl template const T& get() const { - static_assert(Type_Is_Supported::value, "Unsupported type"); + STATIC_ASSERT(Type_Is_Supported::value, "Unsupported type"); -#if ETL_USE_EXCEPTIONS +#ifdef ETL_THROW_EXCEPTIONS if (!is_type()) { throw variant_incorrect_type_exception(); @@ -953,7 +975,7 @@ namespace etl ///\return true if the type is supported, otherwise false. //*************************************************************************** template - inline static bool is_supported_type() + static bool is_supported_type() { return Type_Is_Supported::value; } @@ -982,7 +1004,7 @@ namespace etl /// The internal storage. /// Aligned on a suitable boundary, which should be good for all types. //*************************************************************************** - aligned_variable, ALIGNMENT> data; + align_at, ALIGNMENT> data; //*************************************************************************** /// The id of the current stored type.