]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/ng_kernel/nCicLibrary.ml
Quick&dirty implementation of neqd:
[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 storage = ref [];;
17 let add_obj u obj = storage := (u,obj)::!storage;;
18
19 let cache = NUri.UriHash.create 313;;
20
21 let get_obj u =
22  try List.assq u !storage
23  with Not_found ->
24   try NUri.UriHash.find cache u
25   with Not_found ->
26     (* in the final implementation should get it from disk *)
27     let ouri = NCic2OCic.ouri_of_nuri u in
28     try
29       let o,_ = CicEnvironment.get_obj CicUniv.oblivion_ugraph ouri in
30       let l = OCic2NCic.convert_obj ouri o in
31       List.iter (fun (u,_,_,_,_ as o) -> 
32   (*       prerr_endline ("+"^NUri.string_of_uri u);  *)
33         NUri.UriHash.add cache u o) l;
34       HExtlib.list_last l
35     with CicEnvironment.Object_not_found u -> 
36       raise (ObjectNotFound 
37                (lazy (NUri.string_of_uri (OCic2NCic.nuri_of_ouri u))))
38 ;;
39
40 let clear_cache () = NUri.UriHash.clear cache;;