unison

Fork of Unison, a bi-directional file synchronization tool
git clone git://git.laack.co/unison.git
Log | Files | Refs | README | LICENSE

proplist.ml (1761B)


      1 (* Unison file synchronizer: src/ubase/proplist.ml *)
      2 (* Copyright 1999-2020, Benjamin C. Pierce
      3 
      4     This program is free software: you can redistribute it and/or modify
      5     it under the terms of the GNU General Public License as published by
      6     the Free Software Foundation, either version 3 of the License, or
      7     (at your option) any later version.
      8 
      9     This program is distributed in the hope that it will be useful,
     10     but WITHOUT ANY WARRANTY; without even the implied warranty of
     11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12     GNU General Public License for more details.
     13 
     14     You should have received a copy of the GNU General Public License
     15     along with this program.  If not, see <http://www.gnu.org/licenses/>.
     16 *)
     17 
     18 type 'a key = string
     19 type t = Obj.t Util.StringMap.t
     20 
     21 let names = ref Util.StringMap.empty
     22 
     23 let register nm m =
     24   if (Util.StringMap.mem nm !names) then
     25     raise (Util.Fatal
     26             (Format.sprintf "Property lists: %s already registered!" nm));
     27   names := Util.StringMap.add nm (Obj.repr m) !names;
     28   nm
     29 
     30 let empty = Util.StringMap.empty
     31 
     32 let mem = Util.StringMap.mem
     33 
     34 let find (k : 'a key) m : 'a = Obj.obj (Util.StringMap.find k m)
     35 
     36 let add (k : 'a key) (v : 'a) m = Util.StringMap.add k (Obj.repr v) m
     37 
     38 let find_m (k : 'a key) : 'a Umarshal.t =
     39   try Obj.obj (Util.StringMap.find k !names) with
     40   | Not_found -> raise (Util.Fatal (Format.sprintf "Property lists: %s not yet registered!" k))
     41 
     42 let remove = Util.StringMap.remove
     43 
     44 module S = struct
     45   type key = string
     46   type value = Obj.t
     47   type map = t
     48   let cardinal = Util.StringMap.cardinal
     49   let empty = Util.StringMap.empty
     50   let add = Util.StringMap.add
     51   let iter = Util.StringMap.iter
     52   let find_m = find_m
     53 end
     54 
     55 include Umarshal.Proplist (S)