34 template<
typename T,
unsigned LSB,
unsigned MSB>
38 static_assert(MSB >= LSB,
"boundary mismatch in bit-field definition");
39 static_assert(MSB <
sizeof(T) * 8,
"MSB outside of bit-field type");
40 static_assert(LSB <
sizeof(T) * 8,
"LSB outside of bit-field type");
47 template<
unsigned BITS>
struct Best_type
49 template<
typename TY >
struct Cmp {
enum { value = (BITS <=
sizeof(TY)*8) }; };
50 typedef cxx::type_list<
57 typedef typename cxx::find_type<Unsigned_types, Cmp>::type Type;
93 static_assert(
sizeof(
Bits_type)*8 >=
Bits,
"error finding the type to store the bits");
94 static_assert(
sizeof(
Shift_type)*8 >=
Bits +
Lsb,
"error finding the type to keep the shifted bits");
95 static_assert(
sizeof(
Bits_type) <=
sizeof(T),
"size mismatch for Bits_type");
96 static_assert(
sizeof(
Shift_type) <=
sizeof(T),
"size mismatch for Shift_type");
97 static_assert(
sizeof(
Bits_type) <=
sizeof(
Shift_type),
"size mismacht for Shift_type and Bits_type");
217 template<
typename TT >
235 template<
typename TT >
240 operator Bits_type ()
const {
return this->get(); }
242 Value &operator = (
Value const &o) { this->set(o.get());
return *
this; }
246 template<
typename TT >
251 operator Shift_type ()
const {
return this->get_unshifted(); }
255 this->set_unshifted(o.get_unshifted());
271 #define CXX_BITFIELD_MEMBER(LSB, MSB, name, data_member) \
274 typedef cxx::Bitfield<decltype(data_member), LSB, MSB> name ## _bfm_t; \
276 typename name ## _bfm_t::Val name() const { return data_member; } \
278 typename name ## _bfm_t::Ref name() { return data_member; } \
281 #define CXX_BITFIELD_MEMBER_RO(LSB, MSB, name, data_member) \
284 typedef cxx::Bitfield<decltype(data_member), LSB, MSB> name ## _bfm_t; \
286 typename name ## _bfm_t::Val name() const { return data_member; } \
289 #define CXX_BITFIELD_MEMBER_UNSHIFTED(LSB, MSB, name, data_member) \
292 typedef cxx::Bitfield<decltype(data_member), LSB, MSB> name ## _bfm_t; \
294 typename name ## _bfm_t::Val_unshifted name() const { return data_member; } \
296 typename name ## _bfm_t::Ref_unshifted name() { return data_member; } \
299 #define CXX_BITFIELD_MEMBER_UNSHIFTED_RO(LSB, MSB, name, data_member) \
302 typedef cxx::Bitfield<decltype(data_member), LSB, MSB> name ## _bfm_t; \
304 typename name ## _bfm_t::Val_unshifted name() const { return data_member; } \
Definition for a member (part) of a bit field.
static T set(T dest, Bits_type val)
Set the bits corresponding to val.
Value_unshifted< T const > Val_unshifted
Value type to access the bits inside a raw bit field (in place).
static T val(Bits_type val)
Get the shifted bits for val.
static Bits_type get(Shift_type val)
Get the bits out of val.
Value_unshifted< T & > Ref_unshifted
Reference type to access the bits inside a raw bit field (in place).
static T set_dirty(T dest, Shift_type val)
Set the bits corresponding to val.
static T val_dirty(Shift_type val)
Get the shifted bits for val.
@ Low_mask
Mask value to get Bits bits.
@ Mask
Mask value to the bits out of a T.
Value< T const > Val
Value type to access the bits inside a raw bit field.
static T val_unshifted(Shift_type val)
Get the shifted bits for val.
Value< T & > Ref
Reference type to access the bits inside a raw bit field.
Best_type< Bits >::Type Bits_type
Type to hold at least Bits bits.
static T set_unshifted_dirty(T dest, Shift_type val)
Set the bits corresponding to val.
Best_type< Bits+Lsb >::Type Shift_type
Type to hold at least Bits + Lsb bits.
static T set_unshifted(T dest, Shift_type val)
Set the bits corresponding to val.
static T get_unshifted(Shift_type val)
Get the bits in place out of val.