34template<
typename T,
unsigned LSB,
unsigned MSB>
38 typedef remove_reference_t<T> Base_type;
40 static_assert(MSB >= LSB,
"boundary mismatch in bit-field definition");
41 static_assert(MSB <
sizeof(Base_type) * 8,
"MSB outside of bit-field type");
42 static_assert(LSB <
sizeof(Base_type) * 8,
"LSB outside of bit-field type");
49 template<
unsigned BITS>
struct Best_type
51 template<
typename TY >
struct Cmp {
enum { value = (BITS <=
sizeof(TY)*8) }; };
52 typedef cxx::type_list<
59 typedef cxx::find_type_t<Unsigned_types, Cmp> Type;
74 Low_mask =
static_cast<Base_type
>(~0ULL) >> (
sizeof(Base_type)*8 -
Bits),
96 static_assert(
sizeof(
Bits_type)*8 >=
Bits,
"error finding the type to store the bits");
97 static_assert(
sizeof(
Shift_type)*8 >=
Bits +
Lsb,
"error finding the type to keep the shifted bits");
98 static_assert(
sizeof(
Bits_type) <=
sizeof(Base_type),
"size mismatch for Bits_type");
99 static_assert(
sizeof(
Shift_type) <=
sizeof(Base_type),
"size mismatch for Shift_type");
100 static_assert(
sizeof(
Bits_type) <=
sizeof(
Shift_type),
"size mismacht for Shift_type and Bits_type");
220 template<
typename TT >
238 template<
typename TT >
243 constexpr operator Bits_type ()
const {
return this->get(); }
246 { this->set(
val.get());
return *
this; }
251 template<
typename TT >
256 constexpr operator Shift_type ()
const {
return this->get_unshifted(); }
259 { this->set_unshifted(
val.get_unshifted());
return *
this; }
278#define CXX_BITFIELD_MEMBER(LSB, MSB, name, data_member) \
281 typedef cxx::Bitfield<decltype(data_member), LSB, MSB> name ## _bfm_t; \
283 constexpr typename name ## _bfm_t::Val name() const { return data_member; } \
284 typename name ## _bfm_t::Val name() const volatile { return data_member; } \
286 constexpr typename name ## _bfm_t::Ref name() { return data_member; } \
287 typename name ## _bfm_t::Ref_volatile name() volatile { return data_member; } \
290#define CXX_BITFIELD_MEMBER_RO(LSB, MSB, name, data_member) \
293 typedef cxx::Bitfield<decltype(data_member), LSB, MSB> name ## _bfm_t; \
295 constexpr typename name ## _bfm_t::Val name() const { return data_member; } \
296 typename name ## _bfm_t::Val name() const volatile { return data_member; } \
299#define CXX_BITFIELD_MEMBER_UNSHIFTED(LSB, MSB, name, data_member) \
302 typedef cxx::Bitfield<decltype(data_member), LSB, MSB> name ## _bfm_t; \
304 constexpr typename name ## _bfm_t::Val_unshifted name() const { return data_member; } \
305 typename name ## _bfm_t::Val_unshifted name() const volatile { return data_member; } \
307 constexpr typename name ## _bfm_t::Ref_unshifted name() { return data_member; } \
308 typename name ## _bfm_t::Ref_unshifted_volatile name() volatile { return data_member; } \
311#define CXX_BITFIELD_MEMBER_UNSHIFTED_RO(LSB, MSB, name, data_member) \
314 typedef cxx::Bitfield<decltype(data_member), LSB, MSB> name ## _bfm_t; \
316 constexpr typename name ## _bfm_t::Val_unshifted name() const { return data_member; } \
317 typename name ## _bfm_t::Val_unshifted name() const volatile { return data_member; } \
Definition for a member (part) of a bit field.
static constexpr Bits_type get(Shift_type val)
Get the bits out of val.
Value_unshifted< Base_type volatile & > Ref_unshifted_volatile
Volatile reference type to access the bits inside a raw bit field (in place).
static constexpr Base_type val_unshifted(Shift_type val)
Get the shifted bits for val.
Value< Base_type volatile & > Ref_volatile
Volatile reference type to access the bits inside a raw bit field.
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.
static Base_type set(Base_type dest, Bits_type val)
Set the bits corresponding to val.
Best_type< Bits+Lsb >::Type Shift_type
Type to hold at least Bits + Lsb bits.
Value< Base_type const > Val
Value type to access the bits inside a raw bit field.
static constexpr Base_type val_dirty(Shift_type val)
Get the shifted bits for val.
static constexpr Base_type set_unshifted_dirty(Base_type dest, Shift_type val)
Set the bits corresponding to val.
static constexpr Base_type val(Bits_type val)
Get the shifted bits for val.
Best_type< Bits >::Type Bits_type
Type to hold at least Bits bits.
static Base_type set_unshifted(Base_type dest, Shift_type val)
Set the bits corresponding to val.
Value_unshifted< Base_type & > Ref_unshifted
Reference type to access the bits inside a raw bit field (in place).
static constexpr Base_type get_unshifted(Shift_type val)
Get the bits in place out of val.
static constexpr Base_type set_dirty(Base_type dest, Shift_type val)
Set the bits corresponding to val.
Value_unshifted< Base_type const > Val_unshifted
Value type to access the bits inside a raw bit field (in place).
Value< Base_type & > Ref
Reference type to access the bits inside a raw bit field.