bitfields

fnstring bitfields(T...)()

Allows creating bitfields inside structs, classes and unions.

A bitfield consists of one or more entries with a fixed number of bits reserved for each of the entries. The types of the entries can be bools, integral types or enumerated types, arbitrarily mixed. The most efficient type to store in bitfields is bool, followed by unsigned types, followed by signed types.

Each non-bool entry of the bitfield will be represented by the number of bits specified by the user. The minimum and the maximum numbers that represent this domain can be queried by using the name of the variable followed by _min or _max.

Limitation: The number of bits in a bitfield is limited to 8, 16, 32 or 64. If padding is needed, an entry should be explicitly allocated with an empty name.

Implementation_details: Bitfields are internally stored in an ubyte, ushort, uint or ulong depending on the number of bits used. The bits are filled in the order given by the parameters, starting with the lowest significant bit. The name of the (private) variable used for saving the bitfield is created by concatenating all of the variable names, each preceded by an underscore, and a suffix _bf.

Parameters

TA list of template parameters divided into chunks of 3 items. Each chunk consists (in this order) of a type, a name and a number. Together they define an entry of the bitfield: a variable of the given type and name, which can hold as many bits as the number denotes.

Returns

A string that can be used in a mixin to add the bitfield.

See Also