15 #include <type_traits> 18 #define DECLARE_POSTFIX_INCREMENT(enum_type) \ 19 inline enum_type operator ++(enum_type& e, int) \ 21 enum_type e_org = e; \ 22 e = (enum_type)((std::underlying_type<enum_type>::type)e + 1); \ 25 inline enum_type operator --(enum_type& e, int) \ 27 enum_type e_org = e; \ 28 e = (enum_type)((std::underlying_type<enum_type>::type)e - 1); \ 35 # define DECLARE_ENUM_AS_BIT_SET(mask_t) \ 36 inline mask_t operator | (mask_t m1, mask_t m2) {return (mask_t)((std::underlying_type<mask_t>::type)m1 | m2);} \ 37 inline mask_t operator & (mask_t m1, mask_t m2) {return (mask_t)((std::underlying_type<mask_t>::type)m1 & m2);} \ 38 inline mask_t operator ^ (mask_t m1, mask_t m2) {return (mask_t)((std::underlying_type<mask_t>::type)m1 ^ m2);} \ 39 inline mask_t& operator |= (mask_t& m1, mask_t m2) {m1 = m1 | m2; return m1;} \ 40 inline mask_t& operator &= (mask_t& m1, mask_t m2) {m1 = m1 & m2; return m1;} \ 41 inline mask_t& operator ^= (mask_t& m1, mask_t m2) {m1 = m1 ^ m2; return m1;} \ 42 inline mask_t operator ~(mask_t m) {return (mask_t)(~(std::underlying_type<mask_t>::type)m);} 67 template <
typename Tenum_t,
typename Tstorage_t, Tenum_t Tbegin, Tenum_t Tend, Tenum_t Tinval
id, u
int Tnum_bits = 8 * sizeof(Tstorage_t)>
71 static const Tenum_t
begin = Tbegin;
72 static const Tenum_t
end = Tend;
91 template <
typename Tenum_t>
96 static const enum_type
begin = Props::begin;
97 static const enum_type
end = Props::end;
98 static const enum_type
invalid = Props::invalid;
103 inline operator enum_type ()
const 105 return (enum_type)m_val;
111 m_val = (storage_type)e;
118 m_val = (storage_type)u;
126 if (++m_val >= end) m_val -= (storage_type)(end - begin);
133 if (++m_val >= end) m_val -= (storage_type)(end - begin);
140 template <
typename enum_type,
typename storage_type>
145 inline operator enum_type ()
const 147 return (enum_type)this->m_val;
153 this->m_val = (storage_type)e;
160 this->m_val = (storage_type)u;
167 this->m_val = (storage_type)((enum_type)this->m_val | e);
174 this->m_val = (storage_type)((enum_type)this->m_val & e);
Helper template class that makes basic properties of given enumeration type visible from outsize...
Tstorage_t storage
storage type (i.e. byte)
static const Tenum_t invalid
what value is used as invalid value (i.e. INVALID_TRACKDIR)
static const uint num_bits
Number of bits for storing the enum in command parameters.
static const Tenum_t end
one after the last valid value (i.e. TRACKDIR_END)
storage_type m_val
here we hold the actual value in small (i.e. byte) form
Tenum_t type
enum type (i.e. Trackdir)
EnumPropsT< Tenum_t > Props
make easier access to our enumeration properties
Informative template class exposing basic enumeration properties used by several other templates belo...
Props::storage storage_type
small storage type
In some cases we use byte or uint16 to store values that are defined as enum.
Template of struct holding enum types (on most archs, enums are stored in an int32).
static const Tenum_t begin
lowest valid value (i.e. TRACKDIR_BEGIN)
storage_type m_val
here we hold the actual value in small (i.e. byte) form
Tenum_t enum_type
expose our enumeration type (i.e. Trackdir) to outside