]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/matita/matitaMisc.ml
added comments, fixed history, added loadList to browser
[helm.git] / helm / matita / matitaMisc.ml
index 41b96793884d88546a2cd42ce06101551ddeef44..e1c55feb204e02ca0e3c9354d9b1aa7eaa48c2b2 100644 (file)
@@ -76,17 +76,30 @@ class type ['a] history =
     method previous : 'a
     method load: 'a memento -> unit
     method save: 'a memento
+    method is_begin: bool
+    method is_end: bool
   end
 
+class basic_history (head, tail, cur) =
+  object
+    val mutable hd = head  (* insertion point *)
+    val mutable tl = tail (* oldest inserted item *)
+    val mutable cur = cur  (* current item for the history *)
+    
+    method is_begin = cur <= tl
+    method is_end = cur >= hd
+  end
+  
+  
 class shell_history size =
   let size = size + 1 in
   let decr x = let x' = x - 1 in if x' < 0 then size + x' else x' in
   let incr x = (x + 1) mod size in
   object (self)
     val data = Array.create size ""
-    val mutable hd = 0  (* insertion point *)
-    val mutable tl = -1 (* oldest inserted item *)
-    val mutable cur = -1  (* current item for the history *)
+
+    inherit basic_history (0, -1 , -1)
+    
     method add s =
       data.(hd) <- s;
       if tl = -1 then tl <- hd;
@@ -112,9 +125,9 @@ class ['a] browser_history ?memento size init =
   object (self)
     initializer match memento with Some m -> self#load m | _ -> ()
     val data = Array.create size init
-    val mutable hd = 0
-    val mutable tl = 0
-    val mutable cur = 0
+
+    inherit basic_history (0, 0, 0)
+    
     method previous =
       if cur = tl then raise History_failure;
       cur <- cur - 1;