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> struct TinyEnumT
00077 {
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; return *this;
00097 }
00098
00100 FORCEINLINE TinyEnumT operator ++ (int)
00101 {
00102 TinyEnumT org = *this;
00103 if (++m_val >= end) m_val -= (storage_type)(end - begin);
00104 return org;
00105 }
00106
00108 FORCEINLINE TinyEnumT& operator ++ ()
00109 {
00110 if (++m_val >= end) m_val -= (storage_type)(end - begin);
00111 return *this;
00112 }
00113 };
00114
00115 #endif