template <typename T, size_t Offset, size_t BitCount>

class BitFieldMember

Defined at line 82 of file ../../zircon/system/ulib/fbl/include/fbl/bits.h

The following contains safe wrappers for numeric bitfields. You can read or

write to the members which in the general case is undefined behavior.

However, the standard carves a special exception for types that are

standard-layout as long they share a common initial sequence which is

defined (C++11) as:

"Two standard-layout structs share a common initial sequence

if corresponding members have layout-compatible types and both

are bit-fields with the same width for a sequence of one or more

initial members"

You can use this code without macros. To do so the code should look

something like this:

union MyClass {

uint32_t full_value = initial_value; // optional

fbl::BitFieldMember

<uint32

_t, 0, 3> member1;

fbl::BitFieldMember

<uint32

_t, 3, 2> member1;

...

fbl::BitFieldMember

<uint32

_t, p,q> memberN;

};

All the members should be one 'T' type and the union should not

include any other object.

The Macros simply remove the risk of accidentally violating the rules

at the price of ugly looking code:

FBL_BITFIELD_DEF_START(MyClass, uint32_t)

FBL_BITFIELD_MEMBER(member1, 0, 3);

FBL_BITFIELD_MEMBER(member2, 4, 2);

...

FBL_BITFIELD_MEMBER(memberN, p, q);

FBL_BITFIELD_DEF_END();

The usage is simple. It behaves as a set of unsigned integers with

reduced ranges that are packed efficiently:

MyClass options_(initial_opts);

....

options_.member1 = 5u;

options_.member2 = 3u;

....

if (options_.member1

<

4u) { ..}

....

uint32_t copy = options_;

Public Members

static const T Maximum
static const T Mask

Public Methods

T maximum ()

Defined at line 90 of file ../../zircon/system/ulib/fbl/include/fbl/bits.h

T operator T ()

Defined at line 92 of file ../../zircon/system/ulib/fbl/include/fbl/bits.h

BitFieldMember<T, Offset, BitCount> & operator= (T new_value)

Defined at line 94 of file ../../zircon/system/ulib/fbl/include/fbl/bits.h

void BitFieldMember<T, Offset, BitCount> ()

Defined at line 112 of file ../../zircon/system/ulib/fbl/include/fbl/bits.h

BitFieldMember<T, Offset, BitCount> & operator= (const BitFieldMember<T, Offset, BitCount> & other)

Defined at line 114 of file ../../zircon/system/ulib/fbl/include/fbl/bits.h

void BitFieldMember<T, Offset, BitCount> (const BitFieldMember<T, Offset, BitCount> & other)

Defined at line 120 of file ../../zircon/system/ulib/fbl/include/fbl/bits.h