module Parameter: sig
.. end
Check parameters.
Exception
type
error =
exception Exception of error
Exception to be raised when a function of this module fails.
Single parameters
type 'a
t
The type of parameters.
type 'a
predicate = 'a -> bool
The type of predicates over a parameter value.
type 'a
desc = ParameterName.t * string * 'a * 'a predicate
The type of parameter descriptors, components being:
- name;
- short documentation;
- default value;
- predicate validating a value.
val bool : bool desc -> bool t
Converts a boolean descriptor into a boolean parameter.
val int : int desc -> int t
Converts an int descriptor into an int parameter.
val string : string desc -> string t
Converts a string descriptor into a string parameter.
val symbol : string desc -> string t
Converts a symbol descriptor into a symbol parameter.
val symbol_list : string list desc -> string list t
Converts a symbol descriptor into a list parameter.
Parameter maps
type
map
The type of parameter maps associating name to values.
val empty_map : map
The empty parameter map.
val size : map -> int
Returns the number of parameters in the passed map.
val add_desc : 'a t -> map -> map
add_desc d m
returns m
augmented with parameter descriptor d
.
Raises Exception
if a parameter with the same name already exists.
val set_bool : ParameterName.t -> bool -> map -> map
set_bool n v m
returns m
with the value named n
being replaced by v
.
Raises Exception
if m
does not contain a parameter named n
.
Raises Exception
if the type of n
is not bool
.
Raises Exception
if v
does not satisfy parameter predicate.
val set_int : ParameterName.t -> int -> map -> map
set_int n v m
returns m
with the value named n
being replaced by v
.
Raises Exception
if m
does not contain a parameter named n
.
Raises Exception
if the type of n
is not int
.
Raises Exception
if v
does not satisfy parameter predicate.
val set_string : ParameterName.t -> string -> map -> map
set_string n v m
returns m
with the value named n
being replaced by v
.
Raises Exception
if m
does not contain a parameter named n
.
Raises Exception
if the type of n
is not string
.
Raises Exception
if v
does not satisfy parameter predicate.
val set_symbol : ParameterName.t -> string -> map -> map
set_symbol n v m
returns m
with the value named n
being replaced by v
.
Raises Exception
if m
does not contain a parameter named n
.
Raises Exception
if the type of n
is not symbol
.
Raises Exception
if v
does not satisfy parameter predicate.
val set_symbol_list : ParameterName.t -> string list -> map -> map
set_symbol_list n v m
returns m
with the value named n
being replaced by v
.
Raises Exception
if m
does not contain a parameter named n
.
Raises Exception
if the type of n
is not symbol_list
.
Raises Exception
if v
does not satisfy parameter predicate.
val get_bool : ParameterName.t -> map -> bool
get_bool n m
returns the value of the parameter named n
in m
.
Raises Exception
if m
does not contain a parameter named n
.
Raises Exception
if the type of n
is not bool
.
val get_int : ParameterName.t -> map -> int
get_int n m
returns the value of the parameter named n
in m
.
Raises Exception
if m
does not contain a parameter named n
.
Raises Exception
if the type of n
is not int
.
val get_string : ParameterName.t -> map -> string
get_string n m
returns the value of the parameter named n
in m
.
Raises Exception
if m
does not contain a parameter named n
.
Raises Exception
if the type of n
is not string
.
val get_symbol : ParameterName.t -> map -> string
get_symbol n m
returns the value of the parameter named n
in m
.
Raises Exception
if m
does not contain a parameter named n
.
Raises Exception
if the type of n
is not symbol
.
val get_symbol_list : ParameterName.t -> map -> string list
get_symbol_list n m
returns the value of the parameter named n
in m
.
Raises Exception
if m
does not contain a parameter named n
.
Raises Exception
if the type of n
is not symbol_list
.
val iter : (ParameterName.t -> string -> string -> string -> unit) ->
map -> unit
iter f m
iterates over parameter map
m
with function
f
.
The following elements are passed to
f
:
- parameter name;
- parameter type;
- parameter value;
- parameter documentation.
Parameter map builders
val make1 : 'a t -> map * (map -> 'a)
make1 d1
returns a map along with a getter to retrieve the value
associated with the passed descriptor.
val make2 : 'a t ->
'b t ->
map * (map -> 'a) * (map -> 'b)
make2 d1 d2
returns a map along with getters to retrieve the values
associated with the passed descriptors.
val make3 : 'a t ->
'b t ->
'c t ->
map * (map -> 'a) * (map -> 'b) *
(map -> 'c)
make3 d1 d2 d3
returns a map along with getters to retrieve the values
associated with the passed descriptors.
val make4 : 'a t ->
'b t ->
'c t ->
'd t ->
map * (map -> 'a) * (map -> 'b) *
(map -> 'c) * (map -> 'd)
make4 d1 d2 d3 d4
returns a map along with getters to retrieve the values
associated with the passed descriptors.
Predefined predicates
val any : 'a predicate
Always returns true
.
val positive : int predicate
Checks whether the passed value is either positive or null.
val strictly_positive : int predicate
Checks whether the passed value is strictly positive.
val non_empty_string : string predicate
Checks whether the passed string is not empty.
val level_symbol : string predicate
Checks whether the passed string is one of:
"info"
;
"warning"
;
"error"
.