23template<
typename T,
unsigned LSB,
unsigned MSB>
27 typedef remove_reference_t<T> Base_type;
29 static_assert(MSB >= LSB,
"boundary mismatch in bit-field definition");
30 static_assert(MSB <
sizeof(Base_type) * 8,
"MSB outside of bit-field type");
31 static_assert(LSB <
sizeof(Base_type) * 8,
"LSB outside of bit-field type");
38 template<
unsigned BITS>
struct Best_type
40 template<
typename TY >
struct Cmp {
enum { value = (BITS <=
sizeof(TY)*8) }; };
41 typedef cxx::type_list<
48 typedef cxx::find_type_t<Unsigned_types, Cmp> Type;
61 = Base_type(~0ULL) >> (
sizeof(Base_type) * 8 -
Bits);
82 static_assert(
sizeof(
Bits_type)*8 >=
Bits,
"error finding the type to store the bits");
83 static_assert(
sizeof(
Shift_type)*8 >=
Bits +
Lsb,
"error finding the type to keep the shifted bits");
84 static_assert(
sizeof(
Bits_type) <=
sizeof(Base_type),
"size mismatch for Bits_type");
85 static_assert(
sizeof(
Shift_type) <=
sizeof(Base_type),
"size mismatch for Shift_type");
86 static_assert(
sizeof(
Bits_type) <=
sizeof(
Shift_type),
"size mismatch for Shift_type and Bits_type");
206 template<
typename TT >
213 constexpr Value_base(TT t) : v(t) {}
224 template<
typename TT >
225 class Value :
public Value_base<TT>
228 constexpr Value(TT t) : Value_base<TT>(t) {}
229 constexpr operator Bits_type ()
const {
return this->get(); }
230 constexpr Value &operator = (
Bits_type val) { this->set(
val);
return *
this; }
231 constexpr Value &operator = (Value
const &
val)
232 { this->set(
val.get());
return *
this; }
233 Value(Value
const &) =
default;
237 template<
typename TT >
238 class Value_unshifted :
public Value_base<TT>
241 constexpr Value_unshifted(TT t) : Value_base<TT>(t) {}
242 constexpr operator Shift_type ()
const {
return this->get_unshifted(); }
243 constexpr Value_unshifted &operator = (
Shift_type val) { this->set_unshifted(
val);
return *
this; }
244 constexpr Value_unshifted &operator = (Value_unshifted
const &
val)
245 { this->set_unshifted(
val.get_unshifted());
return *
this; }
246 Value_unshifted(Value_unshifted
const &) =
default;
250 typedef Value<Base_type &>
Ref;
254 typedef Value<Base_type const>
Val;
264#define CXX_BITFIELD_MEMBER(LSB, MSB, name, data_member) \
267 typedef cxx::Bitfield<decltype(data_member), LSB, MSB> name ## _bfm_t; \
269 constexpr typename name ## _bfm_t::Val name() const { return data_member; } \
270 typename name ## _bfm_t::Val name() const volatile { return data_member; } \
272 constexpr typename name ## _bfm_t::Ref name() { return data_member; } \
273 typename name ## _bfm_t::Ref_volatile name() volatile { return data_member; } \
276#define CXX_BITFIELD_MEMBER_RO(LSB, MSB, name, data_member) \
279 typedef cxx::Bitfield<decltype(data_member), LSB, MSB> name ## _bfm_t; \
281 constexpr typename name ## _bfm_t::Val name() const { return data_member; } \
282 typename name ## _bfm_t::Val name() const volatile { return data_member; } \
285#define CXX_BITFIELD_MEMBER_UNSHIFTED(LSB, MSB, name, data_member) \
288 typedef cxx::Bitfield<decltype(data_member), LSB, MSB> name ## _bfm_t; \
290 constexpr typename name ## _bfm_t::Val_unshifted name() const { return data_member; } \
291 typename name ## _bfm_t::Val_unshifted name() const volatile { return data_member; } \
293 constexpr typename name ## _bfm_t::Ref_unshifted name() { return data_member; } \
294 typename name ## _bfm_t::Ref_unshifted_volatile name() volatile { return data_member; } \
297#define CXX_BITFIELD_MEMBER_UNSHIFTED_RO(LSB, MSB, name, data_member) \
300 typedef cxx::Bitfield<decltype(data_member), LSB, MSB> name ## _bfm_t; \
302 constexpr typename name ## _bfm_t::Val_unshifted name() const { return data_member; } \
303 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
static constexpr Base_type val_unshifted(Shift_type val)
Get the shifted bits for val.
Value< Base_type volatile & > Ref_volatile
static constexpr Base_type Mask
static Base_type set(Base_type dest, Bits_type val)
Set the bits corresponding to val.
Best_type< Bits+Lsb >::Type Shift_type
Value< Base_type const > Val
static constexpr Base_type val_dirty(Shift_type val)
Get the shifted bits for val.
static constexpr Base_type Low_mask
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)
Best_type< Bits >::Type Bits_type
static Base_type set_unshifted(Base_type dest, Shift_type val)
Set the bits corresponding to val.
Value_unshifted< Base_type & > Ref_unshifted
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