/*---------------------------------------------------------------------------* Project: Horizon File: util_SizedEnum.h Copyright (C) Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Rev: 27772 $ *---------------------------------------------------------------------------*/ #ifndef NN_UTIL_UTIL_SIZEDENUM_H_ #define NN_UTIL_UTIL_SIZEDENUM_H_ #include #include #ifdef __cplusplus namespace nn { namespace util { //--------------------------------------------------------------------------- //! :category Utility class template. //! //! @tparam StorageT Type to use for storing the enum value. //! @tparam EnumT Enumeration type of the target //! //! @brief Class template for handling enumerated types with a fixed size. //! //! With this class, you can use enum values of explicit size. //! //! The EnumT type enumerated type is stored to a StorageT type variable for handling. //--------------------------------------------------------------------------- template class SizedEnum { private: typedef SizedEnum Self; // NN_STATIC_ASSERT(sizeof(EnumT) <= sizeof(StorageT)); private: StorageT m_EnumValue; public: //--------------------------------------------------------------------------- //! @brief Instantiates an object. //! //! Constructor that does no initialization. //--------------------------------------------------------------------------- SizedEnum() {} //--------------------------------------------------------------------------- //! @brief //! //! Constructor that initializes using the specified initial value. //! //! @param[in] e Default instance values. //--------------------------------------------------------------------------- SizedEnum(EnumT e) { Set(e); } //--------------------------------------------------------------------------- //! @brief The type conversion operator for the enumeration type. //! //! It can directly read EnumT type values. //--------------------------------------------------------------------------- operator EnumT() const { return Get(); } //--------------------------------------------------------------------------- //! @brief Assignment operator for assigning an enumerated type. //! //! With the assignment operator, you can directly assign an EnumT type value. //! //! @param[in] e New values to set. //! //! @return Returns a reference to self. //--------------------------------------------------------------------------- Self& operator =(EnumT e) { Set(e); return *this; } //--------------------------------------------------------------------------- //! @brief Sets values. //! //! Updates the value being managed by this instance. //! //! @param[in] e New values to set. //--------------------------------------------------------------------------- void Set(EnumT e) { m_EnumValue = static_cast(e); } //--------------------------------------------------------------------------- //! @brief Gets values. //! //! Gets the value being managed by this instance as an enumerated type. //! //! @return Returns the value of this instance. //--------------------------------------------------------------------------- EnumT Get() const { return static_cast(m_EnumValue); } }; //--------------------------------------------------------------------------- //! :category Utility class template. //! //! @tparam EnumT Enumeration type of the target //! //! @brief Partially specialized class template for @ref SizedEnum of 1 byte. //! //! The class for handling EnumT type enumerated types as 1 byte. //--------------------------------------------------------------------------- template class SizedEnum1 : public SizedEnum { public: //--------------------------------------------------------------------------- //! @brief Instantiates an object. //! //! Constructor that does no initialization. //--------------------------------------------------------------------------- SizedEnum1() : SizedEnum() {} //--------------------------------------------------------------------------- //! @brief //! //! Constructor that initializes using the specified initial value. //! //! @param[in] e Default instance values. //--------------------------------------------------------------------------- SizedEnum1(EnumT e) : SizedEnum(e) {} }; //--------------------------------------------------------------------------- //! :category Utility class template. //! //! @tparam EnumT Enumeration type of the target //! //! @brief Partially specialized class template for @ref SizedEnum of 2 byte. //! //! The class for handling EnumT type enumerated types as 2 byte. //--------------------------------------------------------------------------- template class SizedEnum2 : public SizedEnum { public: //--------------------------------------------------------------------------- //! @brief Instantiates an object. //! //! Constructor that does no initialization. //--------------------------------------------------------------------------- SizedEnum2() : SizedEnum() {} //--------------------------------------------------------------------------- //! @brief //! //! Constructor that initializes using the specified initial value. //! //! @param[in] e Default instance values. //--------------------------------------------------------------------------- SizedEnum2(EnumT e) : SizedEnum(e) {} }; //--------------------------------------------------------------------------- //! :category Utility class template. //! //! @tparam EnumT Enumeration type of the target //! //! @brief Partially specialized class template for @ref SizedEnum of 4 byte. //! //! The class for handling EnumT type enumerated types as 4 byte. //--------------------------------------------------------------------------- template class SizedEnum4 : public SizedEnum { public: //--------------------------------------------------------------------------- //! @brief Instantiates an object. //! //! Constructor that does no initialization. //--------------------------------------------------------------------------- SizedEnum4() : SizedEnum() {} //--------------------------------------------------------------------------- //! @brief //! //! Constructor that initializes using the specified initial value. //! //! @param[in] e Default instance values. //--------------------------------------------------------------------------- SizedEnum4(EnumT e) : SizedEnum(e) {} }; }} #endif // __cplusplus #endif /* NN_UTIL_UTIL_SIZEDENUM_H_ */