module Flagsimplements Unix-style sets of flags that are represented as an
intwith various bits set, one bit for each flag. E.g.
Flags defines a module type
Flags.S, the interface for a flags, and a functor
Flags.Make for creating a flags implementation.
module type S =
module type Sis the interface for a set of flags. Values of
type tare set of flags, and the various functions operate on sets of flags. There is a finite universe of flags (in particular 63 flags, one for each bit).
t_of_sexp use the flag names supplied to
val of_int :
int -> t
val to_int_exn :
t -> int
val empty :
val is_empty :
t -> bool
val t_of_sexp :
Sexplib.Sexp.t -> t
val sexp_of_t :
t -> Sexplib.Sexp.t
module type Make_arg =
val known :
(Int63.t * string) list
knownmeans that the bit(s) in
flagis (are) called
name; i.e. if
bit_and flags flag = flag, then the bit(s) is (are) set and
namewill appear in
knownis only used to make
sexp_of_t's output human readable.
The flags in the output of
sexp_of_t will occur in the same order as they appear
It is allowed to have a single flag with multiple bits set.
It is an error if different flags intersect, and
allow_intersecting = false.
val remove_zero_flags :
val allow_intersecting :
allow_intersectingsays whether to allow intersecting
knownflags. It is common to do
allow_intersecting = false, however in some situations, e.g. Unix open flags, the flags intersect.
val should_print_error :
should_print_errorsays whether to print an error message if there is an error in the known flags. It is typical to use
should_print_error = truebecause
Flags.Makeis applied at the module level, where the exception raised isn't displayed nicely.
module type Flags =
val create :
bit:int -> Int63.t
create ~bit:ncreates a flag with the
nth bit set.
nmust be between 0 and 62.
Typically a flag has one bit set;
create is useful in exactly those cases. For
flags with multiple bits one can either define the Int63.t directly or create it in
terms of simpler flags, using
module Make :
Flags.Makebuilds a new flags module. If there is an error in the
knownflags, it behaves as per
type t = int in the result of
Flags.Make so that one can easily use
flag constants as values of the flag type without having to coerce them. It is
typical to hide the
t = int in another signature