/[svn]/misc/state.ml
ViewVC logotype

Contents of /misc/state.ml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 96 - (show annotations)
Tue Jul 10 17:05:59 2007 UTC (5 years, 10 months ago) by abate
File size: 692 byte(s)
[r2002-11-10 02:31:52 by cvscast] Empty log message

Original author: cvscast
Date: 2002-11-10 02:31:52+00:00
1 let state = ref []
2 let complete = ref false
3
4 let close () =
5 complete := true
6
7 let register name r =
8 if !complete then failwith "State.register: state already closed";
9 state := (name,Obj.magic r) :: !state
10
11 let ref name v =
12 let r = ref v in
13 register name r;
14 r
15
16 let get () =
17 if not !complete then failwith "State.get: need to close the state";
18 Obj.magic (List.map (fun (name,r) -> (name, !r)) !state)
19
20 let set s =
21 if not !complete then failwith "State.set: need to close the state";
22 let rec aux = function
23 | [],[] -> ()
24 | (n1,v)::l1, (n2,r)::l2 when n1 = n2 -> r := v; aux (l1,l2)
25 | _ -> failwith "State.set_state: failed"
26 in
27 aux (Obj.magic s,!state)
28
29

CVS Admin">CVS Admin
ViewVC Help
Powered by ViewVC 1.1.5