|
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 |
(** Mutable global variable.
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
Often in OCaml you want to have a global variable, which is mutable
|
|
rpm-build |
0f2925 |
and uninitialized when declared. You can use a ['a option ref] but
|
|
rpm-build |
0f2925 |
this is not very convenient. The Global module provides functions
|
|
rpm-build |
0f2925 |
to easily create and manipulate such variables.
|
|
rpm-build |
0f2925 |
*)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
type 'a t
|
|
rpm-build |
0f2925 |
(** Abstract type of a global *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
exception Global_not_initialized of string
|
|
rpm-build |
0f2925 |
(** Raised when a global variable is accessed without first having been
|
|
rpm-build |
0f2925 |
assigned a value. The parameter contains the name of the global. *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val empty : string -> 'a t
|
|
rpm-build |
0f2925 |
(** Returns an new named empty global. The name of the global can be any
|
|
rpm-build |
0f2925 |
string. It identifies the global and makes debugging easier. *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val name : 'a t -> string
|
|
rpm-build |
0f2925 |
(** Retrieve the name of a global. *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val set : 'a t -> 'a -> unit
|
|
rpm-build |
0f2925 |
(** Set the global value contents. *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val get : 'a t -> 'a
|
|
rpm-build |
0f2925 |
(** Get the global value contents - raise Global_not_initialized if not
|
|
rpm-build |
0f2925 |
defined. *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val undef : 'a t -> unit
|
|
rpm-build |
0f2925 |
(** Reset the global value contents to undefined. *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val isdef : 'a t -> bool
|
|
rpm-build |
0f2925 |
(** Return [true] if the global value has been set. *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val opt : 'a t -> 'a option
|
|
rpm-build |
0f2925 |
(** Return [None] if the global is undefined, else [Some v] where v is the
|
|
rpm-build |
0f2925 |
current global value contents. *)
|