enumset-0.0.2: Sets of enumeration values represented by machine words



A bit vector that represents a record in a bit-packed way.



newtype T word a Source

The basic bit vector data type. It does not provide a lot of functionality, since that could not be done in a safe way.

The type a identifies the maintained flags. It may be an empty type but it may also be an enumeration of record fields with concrete values. In the latter case you are encouraged to define an Enum instance for this enumeration. Be aware that it is different from Enum of Prelude.




decons :: word


Eq word => Eq (T word a) 
Storable w => Storable (T w a) 

match :: Bits w => T w a -> MaskedValue w a -> BoolSource

class Enum a whereSource


fromEnum :: Bits w => a -> MaskedValue w aSource

fromEnum should return an integer that represents the position of the a value in the list of all enumeration items. In contrast to that, fromEnum must return the according bit pattern.

compose :: (Enum a, Enum a, Bits w) => [a] -> T w aSource

Compose a flag set from a list of flags. However you may prefer to assemble flags using mconcat or mappend on MaskedValues.

decompose :: (Bounded a, Enum a, Enum a, Bits w) => T w a -> [a]Source

Decompose a flag set into flags. The flags are generated using the Bounded and Enum instance. We do not recommend to use the result list for further processing, since testing of flags is much faster using match. However you may find it useful to show the list.

newtype Mask w a b Source

Mask w a b describes a field of a T w a that has type Value w b. On the machine level a Mask value is a vector of bits, where set bits represent the bits belonging to one record field. There must be only one mask value for every pair of types (a,b).




unmask :: w


Eq w => Eq (Mask w a b) 
Show w => Show (Mask w a b) 

maskValue :: Mask w a b -> Value w b -> MaskedValue w aSource

newtype Value w b Source




unvalue :: w


Eq w => Eq (Value w b) 
Show w => Show (Value w b) 

data MaskedValue w a Source

Combines a mask with a value, that matches this mask. In MaskedValue mask value, value must be a subset of mask.


MaskedValue w w 


Eq w => Eq (MaskedValue w a) 
Show w => Show (MaskedValue w a) 
Bits w => Monoid (MaskedValue w a)

mappend a b means that values stored in b overwrite corresponding values in a.

get :: (Enum a, Bits w) => Mask w a b -> T w a -> Value w bSource

put :: (Enum a, Bits w) => Mask w a b -> Value w b -> T w a -> T w aSource

accessor :: (Enum a, Bits w) => Mask w a b -> T (T w a) (Value w b)Source