]> matita.cs.unibo.it Git - helm.git/commitdiff
added get_pair method
authorStefano Zacchiroli <zack@upsilon.cc>
Tue, 28 Jun 2005 08:19:36 +0000 (08:19 +0000)
committerStefano Zacchiroli <zack@upsilon.cc>
Tue, 28 Jun 2005 08:19:36 +0000 (08:19 +0000)
helm/ocaml/registry/helm_registry.ml
helm/ocaml/registry/helm_registry.mli
helm/ocaml/registry/tests/sample.xml

index 501f689d83f3edf7f2aca9b6a63162ada86d9167..0b54116cb9bb3d43698b8cc5aff2a5f8d717c08f 100644 (file)
@@ -62,7 +62,6 @@ exception Key_not_found of string
 exception Cyclic_definition of string
 exception Type_error of string (* expected type, value, msg *)
 exception Parse_error of string * int * int * string  (* file, line, col, msg *)
-exception Invalid_value of (string * string) * string (* key, value, descr *)
 
   (* root XML tag: used by save_to, ignored by load_from *)
 let root_tag = "helm_registry"
@@ -195,6 +194,12 @@ let get_list registry unmarshaller key =
     List.map unmarshaller (get registry key)
   with Key_not_found _ -> []
 
+let get_pair registry unmarshaller key =
+  let v = singleton (get registry key) in
+  match Str.split spaces_rex v with
+  | [fst; snd] -> unmarshaller fst, unmarshaller snd
+  | _ -> raise (Type_error "not a pair")
+
 let set_list registry marshaller ~key ~value =
   List.iter (fun v -> set registry ~key ~value:(marshaller v)) value
 
@@ -389,6 +394,7 @@ let get_typed unmarshaller = get_typed default_registry unmarshaller
 let get_opt unmarshaller = get_opt default_registry unmarshaller
 let get_opt_default unmarshaller = get_opt_default default_registry unmarshaller
 let get_list unmarshaller = get_list default_registry unmarshaller
+let get_pair unmarshaller = get_pair default_registry unmarshaller
 let set_typed marshaller = set_typed default_registry marshaller
 let set_opt unmarshaller = set_opt default_registry unmarshaller
 let set_list marshaller = set_list default_registry marshaller
index e9ee901e84dc8566ae4a627e1403044fc927f1cf..7dd2a68d436126fd710f43949625c692aa4ea3b0 100644 (file)
@@ -88,11 +88,6 @@ exception Malformed_key of string
    *)
 exception Parse_error of string * int * int * string
 
-  (** raised when a given <key,value> pair fails validity test(s)
-   * @param pair <key,value> pair
-   * @param descr description of the failed test *)
-exception Invalid_value of (string * string) * string
-
 (** {2 Generic untyped interface}
  * Using the functions below this module could be used as a repository of
  * key/value pairs *)
@@ -151,6 +146,9 @@ val get_opt_default: (string -> 'a) -> default:'a -> string -> 'a
   (** never fails with Key_not_found, instead return the empty list *)
 val get_list: (string -> 'a) -> string -> 'a list
 
+  (** same as get_list, but assumes list length to be 2 *)
+val get_pair: (string -> 'a) -> string -> 'a * 'a
+
 (** {4 Shorthands} *)
 
 val get_string: string -> string
index e8ebdc76bbb7478a4adf477dcbd98659142375b9..d08ce5644a9267e25e07075fe7d12e70f7e12655 100644 (file)
@@ -17,6 +17,7 @@
     <key name="int_list">13</key>
     <key name="int_list">17</key>
     <key name="int_list">19</key>
+    <key name="int_pair">19 23</key>
   </section>
   <section name="triciclo">
     <section name="foo1">