]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/registry/helm_registry.mli
- more structured configuration file
[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  * ++ Keys format ++
29  *
30  *  key ::= path
31  *  path ::= component ( '.' component )*
32  *  component ::= ( lowercase_alpha | num | '_' )+
33  *  # with the only exception that sequences of '_' longer than 1 aren't valid
34  *  # components
35  *
36  *  Suggested usage <application>.<setting>:
37  *   e.g. gTopLevel.prooffile, http_getter.port, ...
38  *
39  * ++ Configuration file example ++
40  *
41  *  gTopLevel.prooffile = "/home/zack/prooffile"
42  *  http_getter.port = "58080"
43  *
44  * ++ Environment variable override ++
45  *
46  *  each key has an associated environment variable name. At runtime (i.e. when
47  *  "get" requests are performed) a variable with this name will be looked for,
48  *  if it's defined it will override the value present (or absent) in the
49  *  registry.
50  *  Environment variables are _not_ considered when saving the configuration to
51  *  a configuration file (via "save_to" function below) .
52  *
53  *  Mapping between keys and environment variables is as follows:
54  *  - the whole key is uppercased
55  *  - each "." is converted to "__"
56  *  E.g.: my.foo_ish.application -> MY__FOO_ISH__APPLICATION
57  *)
58
59   (** raised when a looked up key can't be found
60    * @param key looked up key *)
61 exception Key_not_found of string
62
63   (** raised when a cyclic definitions is found, e.g. after
64    * Helm_registry.set "a" "$b"
65    * Helm_registry.set "b" "$a"
66    * @param msg brief description of the definition cycle *)
67 exception Cyclic_definition of string
68
69   (** raised when a looked up key doesn't have the required type
70    * @param expected_type
71    * @param value
72    * @param msg *)
73 exception Type_error of string * string * string
74
75   (** raised when a malformed key is encountered
76    * @param key malformed key *)
77 exception Malformed_key of string
78
79   (** raised when an error is encountered while parsing a configuration file
80    * @param fname file name 
81    * @param line line number
82    * @param col column number
83    * @param msg error description
84    *)
85 exception Parse_error of string * int * int * string
86
87   (** raised when a given <key,value> pair fails validity test(s)
88    * @param pair <key,value> pair
89    * @param descr description of the failed test *)
90 exception Invalid_value of (string * string) * string
91
92 (** {2 Generic untyped interface}
93  * Using the functions below this module could be used as a repository of
94  * key/value pairs *)
95
96   (** lookup key in registry with environment variable override *)
97 val get: string -> string
98 val set: key:string -> value:string -> unit
99
100 (** {2 Typed interface}
101  * Three basic types are supported: strings, int and strings list. Strings
102  * correspond literally to what is written inside double quotes; int to the
103  * parsing of an integer number from ; strings list to the splitting at blanks
104  * of it (heading and trailing blanks are removed before splitting) *)
105
106 val get_string: string -> string  (* alias for bare "get" above *)
107 val get_int: string -> int
108 val get_float: string -> float
109 val get_string_list: string -> string list
110
111   (* alias for bare "set" above *)
112 val set_string: key:string -> value:string -> unit
113 val set_int: key:string -> value:int -> unit
114 val set_float: key:string -> value:float -> unit
115 val set_string_list: key:string -> value:string list -> unit
116
117 (** {2 Validators}
118  * Each key may have zero or more associated validators, that are predicates
119  * "this value is valid for this key". Each time a value is set, all validators
120  * associated to the corresponding key are executed, if at least one of them
121  * fails, Invalid_value exception will be raised *)
122
123 type validator_id
124
125   (** register a new validator for a given key
126    * @param key key to which validator applies
127    * @param validator a function applying to a value returning true if that
128    *  value is valid, false otherwise
129    * @param descr validator description, for the final user when a validation
130    *  attempt fails
131    * @return validator_id should be used to remove the validator later on *)
132 val add_validator:
133   key:string -> validator:(string -> bool) -> descr:string ->
134     validator_id
135 (* val remove_validator: validator_id -> unit *)
136
137 (** {2 Persistent configuration}
138  * Validators aren't saved. load_from/save_to sequences don't preserve comments
139  *)
140
141   (** @param fname file to which save current configuration *)
142 (* val save_to: string -> unit *)
143
144   (** @param fname file from which load new configuration. If it's an absolute
145    * file name "path" argument is ignored.
146    * Otherwise given file name is looked up in each directory member of the
147    * given path. Each matching file is loaded overriding previous settings. If
148    * no path is given a default path composed of just the current working
149    * directory is used.
150    *)
151 val load_from: ?path:string list -> string -> unit
152
153 (*
154 (* DEBUGGING *)
155 val dump: unit -> unit
156 *)
157