The Standard ML Basis Library


The BIT_FLAGS signature


Synopsis

signature BIT_FLAGS  (* OPTIONAL *)

The BIT_FLAGS signature defines a generic set of operations on an abstract representation of system flags. It is typically included as part of the interface of substructures which provide a set of options.


Interface

eqtype flags
val toWord   : flags -> SysWord.word
val fromWord : SysWord.word -> flags
val all : flags
val flags : flags list -> flags
val intersect : flags list -> flags
val clear : flags * flags -> flags
val allSet : flags * flags -> bool
val anySet : flags * flags -> bool

Description

eqtype flags
This type is the abstract representation of a set of system flags.

val toWord : flags -> SysWord.word
val fromWord : SysWord.word -> flags
These functions convert between the abstract flags type and a bit-vector that is represented as a system word. The interpretation of the bits is system-dependent, but follows the C language binding for the host operating system. Note that there is no error checking on the fromWord function's argument.

all
represents the union of all flags. Note that this may well be a superset of the flags value defined in a matching structure. For example, BIT_FLAGS is used to define the flags specified by the POSIX standard; a POSIX-conforming operating system may provide additional flags that will not be defined in the Posix structure but could be set in the all value.

flags l
returns a value that represents the union of the flags in the list l. The expression flags [] denotes the empty set.

intersect l
returns a value that represents the intersection of the sets of flags in the list l. The expression intersect [] denotes all.

clear (fl1, fl2)
returns the set of those flags in fl2 that are not set in fl1, i.e., the set difference fl2 \ fl1. It is equivalent to:
fromWord(SysWord.andb(SysWord.notb (toWord fl1), toWord fl2))


allSet (fl1, fl2)
returns true if all of the flags in fl1 are also in fl2 (i.e., this tests for inclusion of fl1 in fl2).

anySet (fl1, fl2)
returns true if any of the flags in fl1 is also in fl2 (i.e., this tests for non-empty intersection).

See Also

Posix.FileSys, Posix.IO, Posix.Process, Posix.TTY, SysWord, Windows

Discussion

The number of distinct flags in an implementation of the BIT_FLAGS interface must be less than or equal to the number of bits in the SysWord.word type. In addition, fromWord o toWord must be the identity function, and toWord o fromWord must be equivalent to

fn w => SysWord.andb(w, toWord all)

[ Top | Parent | Contents | Index | Root ]

Generated April 12, 2004
Last Modified July 1, 2002
Comments to John Reppy.


This document may be distributed freely over the internet as long as the copyright notice and license terms below are prominently displayed within every machine-readable copy.

Copyright © 2004 AT&T and Lucent Technologies. All rights reserved.

Permission is granted for internet users to make one paper copy for their own personal use. Further hardcopy reproduction is strictly prohibited. Permission to distribute the HTML document electronically on any medium other than the internet must be requested from the copyright holders by contacting the editors. Printed versions of the SML Basis Manual are available from Cambridge University Press. To order, please visit www.cup.org (North America) or www.cup.cam.ac.uk (outside North America).