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

Data.FlagSet

Description

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

Synopsis

Documentation

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.

Constructors

Cons 

Fields

decons :: word
 

Instances

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

Methods

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).

Constructors

Mask 

Fields

unmask :: w
 

Instances

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

The type parameter w is the type of the underlying bit vector. The type parameter b is a phantom type, that is specific for a certain range of bits.

Constructors

Value 

Fields

unvalue :: w
 

Instances

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.

Constructors

MaskedValue w w 

Instances

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

All bits in Value must be contained in the mask. This condition is not checked by put.

According to names in Data.Accessor it should be called set, but in Data.Bits and thus Data.EnumSet this is already used in the pair set/clear. put/get resembles the pair in Control.Monad.State in the mtl package.

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