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;
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;
if cur = size then cur <- 0;
data.(cur)
method add (e:'a) =
- cur <- cur + 1;
- if cur = size then cur <- 0;
- if cur = tl then tl <- tl + 1;
- if tl = size then tl <- 0;
- hd <- cur;
- data.(cur) <- e
+ if e <> data.(cur) then
+ begin
+ cur <- cur + 1;
+ if cur = size then cur <- 0;
+ if cur = tl then tl <- tl + 1;
+ if tl = size then tl <- 0;
+ hd <- cur;
+ data.(cur) <- e
+ end
method load (data', hd', tl', cur') =
assert (Array.length data = Array.length data');
hd <- hd'; tl <- tl'; cur <- cur';
let unopt = function None -> failwith "unopt: None" | Some v -> v
+let image_path n = sprintf "%s/%s" BuildTimeConf.images_dir n
+