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