]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/registry/helm_registry.mli
ocaml 3.09 transition
[helm.git] / helm / ocaml / registry / helm_registry.mli
1 (* Copyright (C) 2004-2005, 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 ::= ( 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  *  - each "." is converted to "__"
55  *  E.g.: my.Foo_iSH.Application -> my__Foo_iSH__Application
56  *
57  * ++ Variable interpolation ++
58  *
59  * Interpolation is supported with the following syntax:
60  *  
61  *  foo.bar = "quux"
62  *  foo.baz = $(foo.bar)/baz
63  *)
64
65   (** raised when a looked up key can't be found
66    * @param key looked up key *)
67 exception Key_not_found of string
68
69   (** raised when a cyclic definitions is found, e.g. after
70    * Helm_registry.set "a" "$b"
71    * Helm_registry.set "b" "$a"
72    * @param msg brief description of the definition cycle *)
73 exception Cyclic_definition of string
74
75   (** raised when a looked up key doesn't have the required type, parameter is
76    * an error message *)
77 exception Type_error of string
78
79   (** raised when a malformed key is encountered
80    * @param key malformed key *)
81 exception Malformed_key of string
82
83   (** raised when an error is encountered while parsing a configuration file
84    * @param fname file name 
85    * @param line line number
86    * @param col column number
87    * @param msg error description
88    *)
89 exception Parse_error of string * int * int * string
90
91 (** {2 Generic untyped interface}
92  * Using the functions below this module could be used as a repository of
93  * key/value pairs *)
94
95   (** lookup key in registry with environment variable override *)
96 val get: string -> string
97 val set: key:string -> value:string -> unit
98 val has: string -> bool
99
100   (** remove a key from the current environment, next get over this key will
101    * raise Key_not_found until the key will be redefined *)
102 val unset: string -> unit
103
104   (** @param interpolate defaults to true *)
105 val fold:
106   ?prefix:string -> ?interpolate:bool ->
107     ('a -> string -> string -> 'a) -> 'a -> 'a
108
109   (** @param interpolate defaults to true *)
110 val iter:
111   ?prefix:string -> ?interpolate:bool -> 
112     (string -> string -> unit) -> unit
113
114   (** @param interpolate defaults to true *)
115 val to_list:
116   ?prefix:string -> ?interpolate:bool ->
117     unit -> (string * string) list
118
119   (** @param prefix key representing the section whose contents should be listed
120   * @return section list * key list *)
121 val ls: string -> string list * string list
122
123 (** {2 Typed interface}
124  * Three basic types are supported: strings, int and strings list. Strings
125  * correspond literally to what is written inside double quotes; int to the
126  * parsing of an integer number from ; strings list to the splitting at blanks
127  * of it (heading and trailing blanks are removed before splitting) *)
128
129 (** {3 Unmarshallers} *)
130
131 val string:       string -> string
132 val int:          string -> int
133 val float:        string -> float
134 val bool:         string -> bool
135
136 (** {3 Typed getters} *)
137
138   (** like get, with an additional unmarshaller
139    * @param unmarshaller conversion function from string to the desired type.
140    * Use one of the above unmarshallers *)
141 val get_typed: (string -> 'a) -> string -> 'a
142
143 val get_opt: (string -> 'a) -> string -> 'a option
144 val get_opt_default: (string -> 'a) -> default:'a -> string -> 'a
145
146   (** never fails with Key_not_found, instead return the empty list *)
147 val get_list: (string -> 'a) -> string -> 'a list
148
149   (** decode values which are blank separated list of values, of length 2 *)
150 val get_pair: (string -> 'a) -> (string -> 'b) -> string -> 'a * 'b
151
152 (** {4 Shorthands} *)
153
154 val get_string: string -> string
155 val get_int:    string -> int
156 val get_float:  string -> float
157 val get_bool:   string -> bool
158
159 (** {3 Marshallers} *)
160
161 val of_string:      string      -> string
162 val of_int:         int         -> string
163 val of_float:       float       -> string
164 val of_bool:        bool        -> string
165
166 (** {3 Typed setters} *)
167
168   (** like set, with an additional marshaller
169    * @param marshaller conversion function to string.
170    * Use one of the above marshallers *)
171 val set_typed: ('a -> string) -> key:string -> value:'a -> unit
172
173 val set_opt: ('a -> string) -> key:string -> value:'a option -> unit
174 val set_list: ('a -> string) -> key:string -> value:'a list -> unit
175
176 (** {4 Shorthands} *)
177
178 val set_string: key:string -> value:string  -> unit
179 val set_int:    key:string -> value:int     -> unit
180 val set_float:  key:string -> value:float   -> unit
181 val set_bool:   key:string -> value:bool    -> unit
182
183 (** {2 Persistent configuration} *)
184
185   (** @param fname file to which save current configuration *)
186 val save_to: string -> unit
187
188   (** @param fname file from which load new configuration. If it's an absolute
189    * file name "path" argument is ignored.
190    * Otherwise given file name is looked up in each directory member of the
191    * given path. Each matching file is loaded overriding previous settings. If
192    * no path is given a default path composed of just the current working
193    * directory is used.
194    *)
195 val load_from: ?path:string list -> string -> unit
196
197   (** removes all keys *)
198 val clear: unit -> unit 
199