16 #define DECLARE_POSTFIX_INCREMENT(type) \ 17 inline type operator ++(type& e, int) \ 20 e = (type)((int)e + 1); \ 23 inline type operator --(type& e, int) \ 26 e = (type)((int)e - 1); \ 33 # define DECLARE_ENUM_AS_BIT_SET(mask_t) \ 34 inline mask_t operator | (mask_t m1, mask_t m2) {return (mask_t)((int)m1 | m2);} \ 35 inline mask_t operator & (mask_t m1, mask_t m2) {return (mask_t)((int)m1 & m2);} \ 36 inline mask_t operator ^ (mask_t m1, mask_t m2) {return (mask_t)((int)m1 ^ m2);} \ 37 inline mask_t& operator |= (mask_t& m1, mask_t m2) {m1 = m1 | m2; return m1;} \ 38 inline mask_t& operator &= (mask_t& m1, mask_t m2) {m1 = m1 & m2; return m1;} \ 39 inline mask_t& operator ^= (mask_t& m1, mask_t m2) {m1 = m1 ^ m2; return m1;} \ 40 inline mask_t operator ~(mask_t m) {return (mask_t)(~(int)m);} 65 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)>
69 static const Tenum_t
begin = Tbegin;
70 static const Tenum_t
end = Tend;
89 template <
typename Tenum_t>
94 static const enum_type
begin = Props::begin;
95 static const enum_type
end = Props::end;
96 static const enum_type
invalid = Props::invalid;
101 inline operator enum_type ()
const 103 return (enum_type)m_val;
109 m_val = (storage_type)e;
116 m_val = (storage_type)u;
124 if (++m_val >= end) m_val -= (storage_type)(end - begin);
131 if (++m_val >= end) m_val -= (storage_type)(end - begin);
138 template <
typename enum_type,
typename storage_type>
143 inline operator enum_type ()
const 145 return (enum_type)this->m_val;
151 this->m_val = (storage_type)e;
158 this->m_val = (storage_type)u;
165 this->m_val = (storage_type)((enum_type)this->m_val | e);
172 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