enum_type.hpp
Go to the documentation of this file.00001
00002
00005 #ifndef ENUM_TYPE_HPP
00006 #define ENUM_TYPE_HPP
00007
00009 #define DECLARE_POSTFIX_INCREMENT(type) \
00010 FORCEINLINE type operator ++(type& e, int) \
00011 { \
00012 type e_org = e; \
00013 e = (type)((int)e + 1); \
00014 return e_org; \
00015 } \
00016 FORCEINLINE type operator --(type& e, int) \
00017 { \
00018 type e_org = e; \
00019 e = (type)((int)e - 1); \
00020 return e_org; \
00021 }
00022
00023
00024
00026 # define DECLARE_ENUM_AS_BIT_SET(mask_t) \
00027 FORCEINLINE mask_t operator | (mask_t m1, mask_t m2) {return (mask_t)((int)m1 | m2);} \
00028 FORCEINLINE mask_t operator & (mask_t m1, mask_t m2) {return (mask_t)((int)m1 & m2);} \
00029 FORCEINLINE mask_t operator ^ (mask_t m1, mask_t m2) {return (mask_t)((int)m1 ^ m2);} \
00030 FORCEINLINE mask_t& operator |= (mask_t& m1, mask_t m2) {m1 = m1 | m2; return m1;} \
00031 FORCEINLINE mask_t& operator &= (mask_t& m1, mask_t m2) {m1 = m1 & m2; return m1;} \
00032 FORCEINLINE mask_t& operator ^= (mask_t& m1, mask_t m2) {m1 = m1 ^ m2; return m1;} \
00033 FORCEINLINE mask_t operator ~(mask_t m) {return (mask_t)(~(int)m);}
00034
00035
00044 template <typename Tenum_t> struct EnumPropsT;
00045
00055 template <typename Tenum_t, typename Tstorage_t, Tenum_t Tbegin, Tenum_t Tend, Tenum_t Tinvalid>
00056 struct MakeEnumPropsT {
00057 typedef Tenum_t type;
00058 typedef Tstorage_t storage;
00059 static const Tenum_t begin = Tbegin;
00060 static const Tenum_t end = Tend;
00061 static const Tenum_t invalid = Tinvalid;
00062 };
00063
00064
00065
00073 template <typename Tenum_t> struct TinyEnumT;
00074
00076 template <typename Tenum_t>
00077 struct TinyEnumT {
00078 typedef Tenum_t enum_type;
00079 typedef EnumPropsT<Tenum_t> Props;
00080 typedef typename Props::storage storage_type;
00081 static const enum_type begin = Props::begin;
00082 static const enum_type end = Props::end;
00083 static const enum_type invalid = Props::invalid;
00084
00085 storage_type m_val;
00086
00088 FORCEINLINE operator enum_type () const
00089 {
00090 return (enum_type)m_val;
00091 }
00092
00094 FORCEINLINE TinyEnumT& operator = (enum_type e)
00095 {
00096 m_val = (storage_type)e;
00097 return *this;
00098 }
00099
00101 FORCEINLINE TinyEnumT& operator = (uint u)
00102 {
00103 m_val = (storage_type)u;
00104 return *this;
00105 }
00106
00108 FORCEINLINE TinyEnumT operator ++ (int)
00109 {
00110 TinyEnumT org = *this;
00111 if (++m_val >= end) m_val -= (storage_type)(end - begin);
00112 return org;
00113 }
00114
00116 FORCEINLINE TinyEnumT& operator ++ ()
00117 {
00118 if (++m_val >= end) m_val -= (storage_type)(end - begin);
00119 return *this;
00120 }
00121 };
00122
00123
00125 template <typename enum_type, typename storage_type>
00126 struct SimpleTinyEnumT {
00127 storage_type m_val;
00128
00130 FORCEINLINE operator enum_type () const
00131 {
00132 return (enum_type)this->m_val;
00133 }
00134
00136 FORCEINLINE SimpleTinyEnumT &operator = (enum_type e)
00137 {
00138 this->m_val = (storage_type)e;
00139 return *this;
00140 }
00141
00143 FORCEINLINE SimpleTinyEnumT &operator = (uint u)
00144 {
00145 this->m_val = (storage_type)u;
00146 return *this;
00147 }
00148 };
00149
00150 #endif