(****************************************************************** [LibML - Machine Learning Library] http://libml.org Copyright (C) 2002 - 2003 LAGACHERIE Matthieu RICORDEAU Olivier This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. SPECIAL NOTE (the beerware clause): This software is free software. However, it also falls under the beerware special category. That is, if you find this software useful, or use it every day, or want to grant us for our modest contribution to the free software community, feel free to send us a beer from one of your local brewery. Our preference goes to Belgium abbey beers and irish stout (Guiness for strength!), but we like to try new stuffs. Authors: Matthieu LAGACHERIE E-mail : matthieu@libml.org Olivier RICORDEAU E-mail : olivier@libml.org ****************************************************************) (** The Env class. Stores LibML's environment information. @author Matthieu Lagacherie @author Olivier Ricordeau @since 06/08/2003 This class uses the Singleton design pattern in order to provide only one instance of the environment class. The aim is to provide information about the learning environment to the various objects involved in LibML. Verbosity levels (possible values for the _verbosity attribute): 0 -> Nothing at all is displayed. 1 -> Only errors are displayed. 2 -> Errors and warnings are displayed. 3 -> Errors + warnings + LibML verbosity 1 (only basic informations displayed). 4 -> Errors + warnings + LibML verbosity 2 (when a method listed in the API is called, one message is displayed). 5 -> Errors + warnings + LibML verbosity 3 (when a method listed in the API is called, more than one message will be displayed). 6 -> Errors + warnings + LibML verbosity 4 (debugging informations are displayed). What verbosity level shoul I use? While writing/debugging a software that uses LibML, 4 is fine. For an official release of a software that uses LibML, 3 is fine. //FIXME explain how to use the getEnv method in other classes. @see A PDF document about Design Patterns and OCaml. *) open Common (** The environment class. *) class environment = object(this) (** The verbosity level. *) val mutable _verbosity = 0 (** The weights random generator limit. *) val mutable _randLimit = 2.0 (** The channel on which LibML is supposed to display normal information (like stdout on Unix). *) val mutable _outChannel = stdout (** Sets the current output channel. *) method setOutChannel newval = _outChannel <- newval; Common.out "environment" ("set `" ^ (this#string_of_channel _outChannel) ^ "\' as standard output.") 4 (** Gets the current output channel. *) method getOutChannel = _outChannel (** The channel on which LibML is supposed to display errors (like stderr on Unix). *) val mutable _errChannel = stdout (** Sets the current error channel. *) method setErrChannel newval = _errChannel <- newval; Common.out "environment" ("set `" ^ (this#string_of_channel _outChannel) ^ "\' as error output.") 4 (** Gets the current error channel. *) method getErrChannel = _errChannel (** Sets the current verbosity level. This method is not verbose because otherwise it would be impossible to totally mute LibML. *) method setVerbosity newval = _verbosity <- newval (** Gets the current verbosity level. *) method getVerbosity = _verbosity (** Sets the current random limit. *) method setRandLimit newval = _randLimit <- newval (** Gets the current random limit. *) method getRandLimit = _randLimit (** Converts an otuput channel to a string (useful for dumping the current output channel as xml...). @param channel The channel to convert in string. *) method string_of_channel channel = match channel with stdout when stdout = Pervasives.stdout -> "stdout" | stderr when stderr = Pervasives.stderr -> "stderr" | _ -> "unknown" end let env : environment option ref = ref None (** The function which provides a unique instance on the environment to the various objects in LibML. *) let getEnv() : environment = match !env with None -> let result = new environment in env := Some result; result | Some result -> result