Blame src/global.ml

rpm-build 0f2925
(*
rpm-build 0f2925
 * Global - Mutable global variable
rpm-build 0f2925
 * Copyright (C) 2003 Nicolas Cannasse
rpm-build 0f2925
 * 
rpm-build 0f2925
 * This library is free software; you can redistribute it and/or
rpm-build 0f2925
 * modify it under the terms of the GNU Lesser General Public
rpm-build 0f2925
 * License as published by the Free Software Foundation; either
rpm-build 0f2925
 * version 2.1 of the License, or (at your option) any later version,
rpm-build 0f2925
 * with the special exception on linking described in file LICENSE.
rpm-build 0f2925
 *
rpm-build 0f2925
 * This library is distributed in the hope that it will be useful,
rpm-build 0f2925
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
rpm-build 0f2925
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
rpm-build 0f2925
 * Lesser General Public License for more details.
rpm-build 0f2925
 *
rpm-build 0f2925
 * You should have received a copy of the GNU Lesser General Public
rpm-build 0f2925
 * License along with this library; if not, write to the Free Software
rpm-build 0f2925
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
rpm-build 0f2925
 *)
rpm-build 0f2925
 
rpm-build 0f2925
exception Global_not_initialized of string
rpm-build 0f2925
rpm-build 0f2925
type 'a t = ('a option ref * string)
rpm-build 0f2925
rpm-build 0f2925
let empty name = ref None,name
rpm-build 0f2925
rpm-build 0f2925
let name = snd
rpm-build 0f2925
rpm-build 0f2925
let set (r,_) v = r := Some v
rpm-build 0f2925
rpm-build 0f2925
let get (r,name) =
rpm-build 0f2925
  match !r with
rpm-build 0f2925
  | None -> raise (Global_not_initialized name)
rpm-build 0f2925
  | Some v -> v
rpm-build 0f2925
rpm-build 0f2925
let undef (r,_) = r := None
rpm-build 0f2925
rpm-build 0f2925
let isdef (r,_) = !r <> None
rpm-build 0f2925
rpm-build 0f2925
let opt (r,_) = !r