5 (* !!take care!!: this class does side effect, not a pure oassoc.
7 * The fv/unv are here to give the opportunity to translate the value
8 * from the dbm, before marshalling. This is useful for instance if you
9 * want to store objects such as oset. Indeed we cant marshall
10 * conveniently functions/closures, and so objects (you can but you can
11 * load them back only from the same binary, which limits the
12 * practicallibity of the approach). You have to translate them to
13 * traditionnal data structures before marshalling them, and you have
14 * to rebuild the object from the traditionnal data structure when you
15 * get them from the dbm. Hence fv/unv. You can do the same for the key
16 * with fkey/unkey, but as key are usually simple data structures,
17 * there is less need for them, so I have commented them. *)
18 class ['a
,'b
] oassocdbm xs db
(*fkey unkey*) fv unv
=
20 inherit ['a
,'b
] oassoc
24 method empty
= raise Todo
29 (* try Db.del data None
30 (Marshal.to_string k []) []
31 with Not_found -> ());
33 let k'
= Marshal.to_string
k [] in
34 let v'
= (Marshal.to_string
(fv
v) [(*Marshal.Closures*)]) in
36 with _
-> Dbm.replace db
k'
v'
41 db
+> Dbm.iter
(fun key data
->
42 let k'
= (* unkey *) Marshal.from_string key
0 in
43 let v'
= unv
(Marshal.from_string data
0) in
47 method view
= raise Todo
49 method del
(k,v) = raise Todo
50 method mem e
= raise Todo
51 method null
= raise Todo
54 let k'
= Marshal.to_string
k [] in
55 unv
(Marshal.from_string
(Dbm.find db
k'
) 0)
58 let k'
= Marshal.to_string
k [] in
62 with Dbm.Dbm_error
"dbm_delete" ->
67 let create_dbm metapath dbname
=
68 let x_db = Dbm.opendbm
(metapath^dbname
) [Dbm.Dbm_create
;Dbm.Dbm_rdwr
] 0o777
70 let assoc = new oassocdbm
[] x_db id id
in