34template<
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 cxx::find_type_t<Unsigned_types, Cmp> Type;
94 static_assert(
sizeof(
Bits_type)*8 >=
Bits,
"error finding the type to store the bits");
95 static_assert(
sizeof(
Shift_type)*8 >=
Bits +
Lsb,
"error finding the type to keep the shifted bits");
96 static_assert(
sizeof(
Bits_type) <=
sizeof(T),
"size mismatch for Bits_type");
97 static_assert(
sizeof(
Shift_type) <=
sizeof(T),
"size mismatch for Shift_type");
98 static_assert(
sizeof(
Bits_type) <=
sizeof(
Shift_type),
"size mismacht for Shift_type and Bits_type");
218 template<
typename TT >
236 template<
typename TT >
241 operator Bits_type ()
const {
return this->get(); }
243 Value &operator = (
Value const &o) { this->set(o.get());
return *
this; }
250 template<
typename TT >
255 operator Shift_type ()
const {
return this->get_unshifted(); }
259 this->set_unshifted(o.get_unshifted());
278#define CXX_BITFIELD_MEMBER(LSB, MSB, name, data_member) \
281 typedef cxx::Bitfield<decltype(data_member), LSB, MSB> name ## _bfm_t; \
283 typename name ## _bfm_t::Val name() const { return data_member; } \
285 typename name ## _bfm_t::Ref name() { return data_member; } \
288#define CXX_BITFIELD_MEMBER_RO(LSB, MSB, name, data_member) \
291 typedef cxx::Bitfield<decltype(data_member), LSB, MSB> name ## _bfm_t; \
293 typename name ## _bfm_t::Val name() const { return data_member; } \
296#define CXX_BITFIELD_MEMBER_UNSHIFTED(LSB, MSB, name, data_member) \
299 typedef cxx::Bitfield<decltype(data_member), LSB, MSB> name ## _bfm_t; \
301 typename name ## _bfm_t::Val_unshifted name() const { return data_member; } \
303 typename name ## _bfm_t::Ref_unshifted name() { return data_member; } \
306#define CXX_BITFIELD_MEMBER_UNSHIFTED_RO(LSB, MSB, name, data_member) \
309 typedef cxx::Bitfield<decltype(data_member), LSB, MSB> name ## _bfm_t; \
311 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.
Best_type< Bits+Lsb >::Type Shift_type
Type to hold at least Bits + Lsb bits.
static T val_dirty(Shift_type val)
Get the shifted bits for val.
Masks
Masks for bitswise operation on internal parts of a bitfield.
@ 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.
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.