]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/ng_kernel/nCicLibrary.ml
wrap object_not_found
[helm.git] / helm / software / components / ng_kernel / nCicLibrary.ml
1 (*
2     ||M||  This file is part of HELM, an Hypertextual, Electronic        
3     ||A||  Library of Mathematics, developed at the Computer Science     
4     ||T||  Department, University of Bologna, Italy.                     
5     ||I||                                                                
6     ||T||  HELM is free software; you can redistribute it and/or         
7     ||A||  modify it under the terms of the GNU General Public License   
8     \   /  version 2 or (at your option) any later version.      
9      \ /   This software is distributed as is, NO WARRANTY.     
10       V_______________________________________________________________ *)
11
12 (* $Id$ *)
13
14 exception ObjectNotFound of string Lazy.t
15
16 let cache = NUri.UriHash.create 313;;
17
18 let get_obj u =
19   try NUri.UriHash.find cache u
20   with Not_found ->
21     (* in the final implementation should get it from disk *)
22     let ouri = NCic2OCic.ouri_of_nuri u in
23     try
24       let o,_ = CicEnvironment.get_obj CicUniv.oblivion_ugraph ouri in
25       let l = OCic2NCic.convert_obj ouri o in
26       List.iter (fun (u,_,_,_,_ as o) -> 
27   (*       prerr_endline ("+"^NUri.string_of_uri u);  *)
28         NUri.UriHash.add cache u o) l;
29       HExtlib.list_last l
30     with CicEnvironment.Object_not_found u -> 
31       raise (ObjectNotFound 
32                (lazy (NUri.string_of_uri (OCic2NCic.nuri_of_ouri u))))
33 ;;
34
35 let clear_cache () = NUri.UriHash.clear cache;;