]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/registry/helm_registry.mli
helm registry --- first release
[helm.git] / helm / ocaml / registry / helm_registry.mli
1 (* Copyright (C) 2004, HELM Team.
2  * 
3  * This file is part of HELM, an Hypertextual, Electronic
4  * Library of Mathematics, developed at the Computer Science
5  * Department, University of Bologna, Italy.
6  * 
7  * HELM is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  * 
12  * HELM is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with HELM; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://helm.cs.unibo.it/
24  *)
25
26 (** Configuration repository for HELM applications.
27  *
28  * key ::= path
29  * path ::= component ( '.' component )*
30  * component ::= ( alpha | num | '_' )+
31  *
32  * Suggested usage <application>.<setting>:
33  * e.g. gTopLevel.prooffile, http_getter.port, ...
34  *
35  * Configuration file example:
36  *
37  *  gTopLevel.prooffile = "/home/zack/prooffile"
38  *  http_getter.port = "58080"
39  *)
40
41   (** raised when a looked up key can't be found
42    * @param key looked up key *)
43 exception Key_not_found of string
44
45   (** raised when a looked up key doesn't have the required type
46    * @param expected_type
47    * @param value
48    * @param msg *)
49 exception Type_error of string * string * string
50
51   (** raised when a malformed key is encountered
52    * @param key malformed key *)
53 exception Malformed_key of string
54
55   (** raised when an error is encountered while parsing a configuration file
56    * @param fname file name 
57    * @param lno line number *)
58 exception Parse_error of string * int
59
60   (** raised when a given <key,value> pair fails validity test(s)
61    * @param pair <key,value> pair
62    * @param descr description of the failed test *)
63 exception Invalid_value of (string * string) * string
64
65 (** {2 Generic untyped interface}
66  * Using the functions below this module could be used as a repository of
67  * key/value pairs *)
68
69 val get: string -> string
70 val set: key:string -> value:string -> unit
71
72 (** {2 Typed interface}
73  * Three basic types are supported: strings, int and strings list. Strings
74  * correspond literally to what is written inside double quotes; int to the
75  * parsing of an integer number from ; strings list to the splitting at blanks
76  * of it (heading and trailing blanks are removed before splitting) *)
77
78 val get_int: string -> int
79 val get_float: string -> float
80 val get_string_list: string -> string list
81
82 val set_int: key:string -> value:int -> unit
83 val set_float: key:string -> value:float -> unit
84 val set_string_list: key:string -> value:string list -> unit
85
86 (** {2 Validators}
87  * Each key may have zero or more associated validators, that are predicates
88  * "this value is valid for this key". Each time a value is set, all validators
89  * associated to the corresponding key are executed, if at least one of them
90  * fails, Invalid_value exception will be raised *)
91
92 type validator_id
93
94   (** register a new validator for a given key
95    * @param key key to which validator applies
96    * @param validator a function applying to a value returning true if that
97    *  value is valid, false otherwise
98    * @param descr validator description, for the final user when a validation
99    *  attempt fails
100    * @return validator_id should be used to remove the validator later on *)
101 val add_validator:
102   key:string -> validator:(string -> bool) -> descr:string ->
103     validator_id
104 (* val remove_validator: validator_id -> unit *)
105
106 (** {2 Persistent configuration}
107  * Validators aren't saved. load_from/save_to sequences don't preserve comments
108  *)
109
110   (** @param fname file to which save current configuration *)
111 val save_to: string -> unit
112
113   (** @param fname file from which load new configuration *)
114 val load_from: string -> unit
115
116 (*
117 (* DEBUGGING *)
118 val dump: unit -> unit
119 *)
120