bzr branch
http://gegoxaren.bato24.eu/bzr/vqdr/trunk
1
by Gustav Hartvigsson
* Initial code - far from done |
1 |
using Gee; |
2 |
using VQDR.Common; |
|
3 |
||
4 |
namespace VQDR.Expression { |
|
5 |
|
|
6 |
public class Context : GLib.Object{ |
|
7 |
private bool changed; |
|
8 |
private Gee.TreeMap<string, Variable?> values; |
|
9 |
|
|
10 |
|
|
11 |
construct { |
|
12 |
changed = false; |
|
13 |
values = new Gee.TreeMap<string, Variable?> |
|
14 |
(Common.Utils.str_cmp, null); |
|
15 |
} |
|
16 |
|
|
17 |
public Context () { |
|
18 |
} |
|
19 |
|
|
20 |
public void set_value (string name, |
|
21 |
int min_val, |
|
22 |
int max_val, |
|
23 |
int current_val) { |
|
24 |
set_variable (name, Variable (min_val, max_val, current_val)); |
|
25 |
} |
|
26 |
|
|
27 |
public Variable get_variable (string name) throws ArgError { |
|
28 |
throw_name (name); |
|
29 |
return values.@get (name.down ()); |
|
30 |
} |
|
31 |
|
|
32 |
public void set_variable (string name, Variable? variable) { |
|
33 |
string new_name = name.down (); |
|
34 |
|
|
35 |
if (!(values.has_key (new_name)) || |
|
36 |
!(values.get(new_name).equals(variable))) { |
|
37 |
|
|
38 |
values.set (new_name, variable); |
|
39 |
changed = true; |
|
40 |
} |
|
41 |
} |
|
42 |
|
|
43 |
private void throw_name (string name) throws ArgError { |
|
44 |
if (! (values.has_key (name.down ()))) { |
|
45 |
throw new ArgError.INVALID_ARGUMENT ("Name \"" + |
|
46 |
name.down () + |
|
47 |
"\" not defined."); |
|
48 |
} |
|
49 |
} |
|
50 |
|
|
51 |
public int get_value (string name) throws ArgError { |
|
52 |
throw_name (name); |
|
53 |
return values.@get (name.down ()).current_val; |
|
54 |
} |
|
55 |
|
|
56 |
public int get_min_value (string name) throws ArgError { |
|
57 |
throw_name (name); |
|
58 |
return values.@get (name.down ()).min_val; |
|
59 |
} |
|
60 |
|
|
61 |
public int get_max_value (string name) throws ArgError { |
|
62 |
throw_name (name); |
|
63 |
return values.@get (name.down ()).max_val; |
|
64 |
} |
|
65 |
||
66 |
public int get_current_value (string name) throws ArgError { |
|
67 |
throw_name (name); |
|
68 |
return values.@get (name.down ()).current_val; |
|
69 |
} |
|
70 |
|
|
71 |
public bool has_name (string name) { |
|
72 |
return values.has_key (name.down ()); |
|
73 |
} |
|
74 |
|
|
75 |
protected void reset () { |
|
76 |
changed = false; |
|
77 |
} |
|
78 |
|
|
79 |
} |
|
80 |
}
|