32 |
@author Matthieu Lagacherie |
@author Matthieu Lagacherie |
33 |
@author Olivier Ricordeau |
@author Olivier Ricordeau |
34 |
|
|
35 |
|
This class use the design pattern Singleton in order |
36 |
|
to provide only one instance of the environment class |
37 |
*) |
*) |
38 |
|
|
39 |
class environment = |
class type environment = |
40 |
|
object |
41 |
|
method toChannel : string -> unit |
42 |
|
method setVerbosity : int-> unit |
43 |
|
end |
44 |
|
|
45 |
|
class environmentImpl: singleton = |
46 |
object |
object |
47 |
val mutable _verbosity = 0 |
val mutable _verbosity = 0 |
48 |
val mutable _channel = stderr |
val mutable _channel = stderr |
49 |
method toChannel str = Printf.fprintf _channel "%s\n" str |
method toChannel str = Printf.fprintf _channel "%s\n" str |
50 |
method setVerbosity newval = _verbosity <- newval |
method setVerbosity newval = _verbosity <- newval |
51 |
end;; |
end |
52 |
|
|
53 |
|
let env : environment option ref = ref None |
54 |
|
|
55 |
|
let getInstance () : environment = |
56 |
|
match !env with |
57 |
|
None -> |
58 |
|
let result = new environmentImpl |
59 |
|
in |
60 |
|
env := Some result; |
61 |
|
result |
62 |
|
| Some result -> result |
63 |
|
|