diff --git a/include/etl/type_def.h b/include/etl/type_def.h index 55e54c94b..7cb5c246c 100644 --- a/include/etl/type_def.h +++ b/include/etl/type_def.h @@ -35,274 +35,274 @@ SOFTWARE. namespace etl { -#define ETL_TYPEDEF(T, name) \ - class name##_tag; \ - typedef etl::type_def name - - //************************************************************************* - /// A template type to define strong typedefs. - /// Usage: - ///\code - /// // Short form. - /// ETL_TYPEDEF(int, mytype); - /// - /// // Long form. - /// class mytype_t_tag; - /// typedef etl::type_def mytype_t_tag; - ///\endcode - //************************************************************************* - template - class type_def - { - public: - typedef TValue value_type; - typedef TIdType id_type; - - //********************************************************************* - ETL_CONSTEXPR type_def() - : value(TValue()) - { - } - - //********************************************************************* - ETL_CONSTEXPR type_def(TValue value_) - : value(value_) - { - } - - //********************************************************************* - ETL_CONSTEXPR type_def(const type_def& other) - : value(other.value) - { - } - - //********************************************************************* - ETL_CONSTEXPR operator TValue() const - { - return value; - } - - //********************************************************************* - ETL_CONSTEXPR14 type_def& operator++() - { - ++value; - return *this; - } - - //********************************************************************* - ETL_CONSTEXPR14 type_def operator++(int) - { - type_def temp(*this); - type_def::operator++(); - return temp; - } - - //********************************************************************* - ETL_CONSTEXPR14 type_def& operator--() - { - --value; - return *this; - } - - //********************************************************************* - ETL_CONSTEXPR14 type_def operator--(int) - { - type_def temp(*this); - type_def::operator--(); - return temp; - } - - //********************************************************************* - ETL_CONSTEXPR14 type_def& operator+=(TValue rhs) - { - value += rhs; - return *this; - } - - //********************************************************************* - ETL_CONSTEXPR14 type_def& operator+=(const type_def& rhs) - { - value += rhs.value; - return *this; - } - - //********************************************************************* - ETL_CONSTEXPR14 type_def& operator-=(TValue rhs) - { - value -= rhs; - return *this; - } - - //********************************************************************* - ETL_CONSTEXPR14 type_def& operator-=(const type_def& rhs) - { - value -= rhs.value; - return *this; - } - - //********************************************************************* - ETL_CONSTEXPR14 type_def& operator*=(TValue rhs) - { - value *= rhs; - return *this; - } - - //********************************************************************* - ETL_CONSTEXPR14 type_def& operator*=(const type_def& rhs) - { - value *= rhs.value; - return *this; - } - - //********************************************************************* - ETL_CONSTEXPR14 type_def& operator/=(TValue rhs) - { - value /= rhs; - return *this; - } - - //********************************************************************* - ETL_CONSTEXPR14 type_def& operator/=(const type_def& rhs) - { - value /= rhs.value; - return *this; - } - - //********************************************************************* - ETL_CONSTEXPR14 type_def& operator%=(TValue rhs) - { - value %= rhs; - return *this; - } - - //********************************************************************* - ETL_CONSTEXPR14 type_def& operator%=(const type_def& rhs) - { - value %= rhs.value; - return *this; - } - - //********************************************************************* - ETL_CONSTEXPR14 type_def& operator&=(TValue rhs) - { - value &= rhs; - return *this; - } - - //********************************************************************* - ETL_CONSTEXPR14 type_def& operator&=(const type_def& rhs) - { - value &= rhs.value; - return *this; - } - - //********************************************************************* - ETL_CONSTEXPR14 type_def& operator|=(TValue rhs) - { - value |= rhs; - return *this; - } - - //********************************************************************* - ETL_CONSTEXPR14 type_def& operator|=(const type_def& rhs) - { - value |= rhs.value; - return *this; - } - - //********************************************************************* - ETL_CONSTEXPR14 type_def& operator^=(TValue rhs) - { - value ^= rhs; - return *this; - } - - //********************************************************************* - ETL_CONSTEXPR14 type_def& operator^=(const type_def& rhs) - { - value ^= rhs.value; - return *this; - } - - //********************************************************************* - ETL_CONSTEXPR14 type_def& operator<<=(TValue rhs) - { - value <<= rhs; - return *this; - } - - //********************************************************************* - ETL_CONSTEXPR14 type_def& operator>>=(TValue rhs) - { - value >>= rhs; - return *this; - } - - //********************************************************************* - ETL_CONSTEXPR14 type_def& operator=(TValue rhs) - { - value = rhs; - return *this; - } - - //********************************************************************* - ETL_CONSTEXPR14 type_def& operator=(const type_def& rhs) - { - value = rhs.value; - return *this; - } - - //********************************************************************* - ETL_CONSTEXPR14 TValue& get() - { - return value; - } - - //********************************************************************* - ETL_CONSTEXPR14 const TValue& get() const - { - return value; - } - - //********************************************************************* - friend ETL_CONSTEXPR bool operator<(const type_def& lhs, const type_def& rhs) - { - return lhs.value < rhs.value; - } - - //********************************************************************* - friend ETL_CONSTEXPR bool operator<=(const type_def& lhs, const type_def& rhs) - { - return lhs.value <= rhs.value; - } - - //********************************************************************* - friend ETL_CONSTEXPR bool operator>(const type_def& lhs, const type_def& rhs) - { - return lhs.value > rhs.value; - } - - //********************************************************************* - friend ETL_CONSTEXPR bool operator>=(const type_def& lhs, const type_def& rhs) - { - return lhs.value >= rhs.value; - } - - //********************************************************************* - friend ETL_CONSTEXPR bool operator==(const type_def& lhs, const type_def& rhs) - { - return lhs.value == rhs.value; - } - - //********************************************************************* - friend ETL_CONSTEXPR bool operator!=(const type_def& lhs, const type_def& rhs) - { - return lhs.value != rhs.value; - } - - private: - TValue value; - }; -} // namespace etl + #define ETL_TYPEDEF(T, name) class name##_tag; typedef etl::type_def name + + //************************************************************************* + /// A template type to define strong typedefs. + /// Usage: + ///\code + /// // Short form. + /// ETL_TYPEDEF(int, mytype); + /// + /// // Long form. + /// class mytype_t_tag; + /// typedef etl::type_def mytype_t_tag; + ///\endcode + //************************************************************************* + template + class type_def + { + public: + + typedef TValue value_type; + typedef TIdType id_type; + + //********************************************************************* + ETL_CONSTEXPR type_def() + : value(TValue()) + { + } + + //********************************************************************* + ETL_CONSTEXPR type_def(TValue value_) + : value(value_) + { + } + + //********************************************************************* + ETL_CONSTEXPR type_def(const type_def& other) + : value(other.value) + { + } + + //********************************************************************* + ETL_CONSTEXPR operator TValue() const + { + return value; + } + + //********************************************************************* + ETL_CONSTEXPR14 type_def& operator ++() + { + ++value; + return *this; + } + + //********************************************************************* + ETL_CONSTEXPR14 type_def operator ++(int) + { + type_def temp(*this); + type_def::operator ++(); + return temp; + } + + //********************************************************************* + ETL_CONSTEXPR14 type_def& operator --() + { + --value; + return *this; + } + + //********************************************************************* + ETL_CONSTEXPR14 type_def operator --(int) + { + type_def temp(*this); + type_def::operator --(); + return temp; + } + + //********************************************************************* + ETL_CONSTEXPR14 type_def& operator +=(TValue rhs) + { + value += rhs; + return *this; + } + + //********************************************************************* + ETL_CONSTEXPR14 type_def& operator +=(const type_def& rhs) + { + value += rhs.value; + return *this; + } + + //********************************************************************* + ETL_CONSTEXPR14 type_def& operator -=(TValue rhs) + { + value -= rhs; + return *this; + } + + //********************************************************************* + ETL_CONSTEXPR14 type_def& operator -=(const type_def& rhs) + { + value -= rhs.value; + return *this; + } + + //********************************************************************* + ETL_CONSTEXPR14 type_def& operator *=(TValue rhs) + { + value *= rhs; + return *this; + } + + //********************************************************************* + ETL_CONSTEXPR14 type_def& operator *=(const type_def& rhs) + { + value *= rhs.value; + return *this; + } + + //********************************************************************* + ETL_CONSTEXPR14 type_def& operator /=(TValue rhs) + { + value /= rhs; + return *this; + } + + //********************************************************************* + ETL_CONSTEXPR14 type_def& operator /=(const type_def& rhs) + { + value /= rhs.value; + return *this; + } + + //********************************************************************* + ETL_CONSTEXPR14 type_def& operator %=(TValue rhs) + { + value %= rhs; + return *this; + } + + //********************************************************************* + ETL_CONSTEXPR14 type_def& operator %=(const type_def& rhs) + { + value %= rhs.value; + return *this; + } + + //********************************************************************* + ETL_CONSTEXPR14 type_def& operator &=(TValue rhs) + { + value &= rhs; + return *this; + } + + //********************************************************************* + ETL_CONSTEXPR14 type_def& operator &=(const type_def& rhs) + { + value &= rhs.value; + return *this; + } + + //********************************************************************* + ETL_CONSTEXPR14 type_def& operator |=(TValue rhs) + { + value |= rhs; + return *this; + } + + //********************************************************************* + ETL_CONSTEXPR14 type_def& operator |=(const type_def& rhs) + { + value |= rhs.value; + return *this; + } + + //********************************************************************* + ETL_CONSTEXPR14 type_def& operator ^=(TValue rhs) + { + value ^= rhs; + return *this; + } + + //********************************************************************* + ETL_CONSTEXPR14 type_def& operator ^=(const type_def& rhs) + { + value ^= rhs.value; + return *this; + } + + //********************************************************************* + ETL_CONSTEXPR14 type_def& operator <<=(TValue rhs) + { + value <<= rhs; + return *this; + } + + //********************************************************************* + ETL_CONSTEXPR14 type_def& operator >>=(TValue rhs) + { + value >>= rhs; + return *this; + } + + //********************************************************************* + ETL_CONSTEXPR14 type_def& operator =(TValue rhs) + { + value = rhs; + return *this; + } + + //********************************************************************* + ETL_CONSTEXPR14 type_def& operator =(const type_def& rhs) + { + value = rhs.value; + return *this; + } + + //********************************************************************* + ETL_CONSTEXPR14 TValue& get() + { + return value; + } + + //********************************************************************* + ETL_CONSTEXPR14 const TValue& get() const + { + return value; + } + + //********************************************************************* + friend ETL_CONSTEXPR bool operator <(const type_def& lhs, const type_def& rhs) + { + return lhs.value < rhs.value; + } + + //********************************************************************* + friend ETL_CONSTEXPR bool operator <=(const type_def& lhs, const type_def& rhs) + { + return lhs.value <= rhs.value; + } + + //********************************************************************* + friend ETL_CONSTEXPR bool operator >(const type_def& lhs, const type_def& rhs) + { + return lhs.value > rhs.value; + } + + //********************************************************************* + friend ETL_CONSTEXPR bool operator >=(const type_def& lhs, const type_def& rhs) + { + return lhs.value >= rhs.value; + } + + //********************************************************************* + friend ETL_CONSTEXPR bool operator ==(const type_def& lhs, const type_def& rhs) + { + return lhs.value == rhs.value; + } + + //********************************************************************* + friend ETL_CONSTEXPR bool operator !=(const type_def& lhs, const type_def& rhs) + { + return lhs.value != rhs.value; + } + + private: + + TValue value; + }; +} #endif