data-flags-0.0.3.2: A package for working with bit masks and flags in general.

Safe HaskellNone
LanguageHaskell98

Data.Flags

Contents

Description

This module provides type classes for working with sets of flags. In particular, with wrappers around bit masks:

import Data.Flags

newtype MyFlags = MyFlags CInt deriving (Eq, Flags)

#{enum MyFlags, MyFlags
 , myFlag1 = C_FLAG1
 , myFlag2 = C_FLAG2
 , myFlag3 = C_FLAG3
 }

f :: MyFlags -> IO ()
f = ...

Or, using Template Haskell:

import Data.Flags.TH

$(bitmaskWrapper "MyFlags" ''CInt [] False
    [("myFlag1", #{const C_FLAG1}),
     ("myFlag2", #{const C_FLAG2}),
     ("myFlag3", #{const C_FLAG3})])

And then use it like this:

f $ myFlag1 .+. myFlag3

Synopsis

Documentation

class Eq α => Flags α where Source #

Minimal complete definition

noFlags, andFlags, butFlags

Methods

noFlags :: α Source #

The empty set of flags.

andFlags :: α -> α -> α infixl 6 Source #

Union of two flag sets.

butFlags :: α -> α -> α infixl 5 Source #

Difference between two flag sets.

commonFlags :: α -> α -> α infixl 7 Source #

Intersection of two flag sets.

(.+.) :: Flags α => α -> α -> α infixl 6 Source #

Alias for andFlags.

(.-.) :: Flags α => α -> α -> α infixl 5 Source #

Alias for butFlags.

(.*.) :: Flags α => α -> α -> α infixl 7 Source #

Alias for commonFlags.

class Flags α => BoundedFlags α where Source #

Use this class when the set of flags is fixed and not likely to change in the future.

Minimal complete definition

allFlags, enumFlags

Methods

allFlags :: α Source #

Set of all flags.

enumFlags :: α -> [α] Source #

List the individual flags.

allBut :: BoundedFlags α => α -> α Source #

Shorthand for allFlags .-. x.

containsAll :: Flags α => α -> α -> Bool infix 4 Source #

Test if the first flag set contains all flags from the second.

(.<=.) :: Flags α => α -> α -> Bool infix 4 Source #

Shorthand for flip containsAll.

(.>=.) :: Flags α => α -> α -> Bool infix 4 Source #

Alias for containsAll.

containsSome :: Flags α => α -> α -> Bool infix 4 Source #

Test if two flag sets intersect.

(.~.) :: Flags α => α -> α -> Bool infix 4 Source #

Alias for containsSome.

containsNone :: Flags α => α -> α -> Bool infix 4 Source #

Test if two flag sets do not intersect.

(./~.) :: Flags α => α -> α -> Bool infix 4 Source #

Alias for containsNone.

Orphan instances

BoundedFlags Int Source # 
BoundedFlags Int8 Source # 
BoundedFlags Int16 Source # 
BoundedFlags Int32 Source # 
BoundedFlags Int64 Source # 
BoundedFlags Word Source # 
BoundedFlags Word8 Source # 
BoundedFlags Word16 Source # 
BoundedFlags Word32 Source # 
BoundedFlags Word64 Source # 
BoundedFlags WordPtr Source # 
BoundedFlags IntPtr Source # 
BoundedFlags CChar Source # 
BoundedFlags CSChar Source # 
BoundedFlags CUChar Source # 
BoundedFlags CShort Source # 
BoundedFlags CUShort Source # 
BoundedFlags CInt Source # 
BoundedFlags CUInt Source # 
BoundedFlags CLong Source # 
BoundedFlags CULong Source # 
BoundedFlags CLLong Source # 
BoundedFlags CULLong Source # 
Flags Int Source # 
Flags Int8 Source # 
Flags Int16 Source # 
Flags Int32 Source # 
Flags Int64 Source # 
Flags Integer Source # 
Flags Word Source # 
Flags Word8 Source # 
Flags Word16 Source # 
Flags Word32 Source # 
Flags Word64 Source # 
Flags WordPtr Source # 
Flags IntPtr Source # 
Flags CChar Source # 
Flags CSChar Source # 
Flags CUChar Source # 
Flags CShort Source # 
Flags CUShort Source # 
Flags CInt Source # 
Flags CUInt Source # 
Flags CLong Source # 
Flags CULong Source # 
Flags CLLong Source # 
Flags CULLong Source #