bzr branch
http://gegoxaren.bato24.eu/bzr/vqdr/trunk
|
54
by Gustav Hartvigsson
More work torwards inperementing the parser. |
1 |
/*
|
2 |
* The contects of this file is in the Public Domain.
|
|
3 |
*
|
|
4 |
* Created by Gustav Hartivgsson.
|
|
5 |
*/
|
|
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
6 |
|
7 |
namespace Vee { |
|
|
62
by Gustav Hartvigsson
various changes |
8 |
[Compact] |
|
49
by Gustav Hartvigsson
Added NamedVector |
9 |
public class NamedVector<T> { |
10 |
public T[] values; |
|
11 |
public string[] names; |
|
12 |
||
13 |
public delegate bool ForeachFunc<V> (string name, V val); |
|
14 |
||
15 |
public NamedVector (string n1, T v1,...) { |
|
16 |
// allocate temporary buffer |
|
17 |
var T_buf = new T[50]; |
|
18 |
var N_buf = new string[50]; |
|
19 |
T_buf[0] = v1; |
|
20 |
N_buf[0] = n1; |
|
21 |
var list = va_list (); |
|
22 |
|
|
23 |
var tmp_name = list.arg<string?> (); |
|
24 |
var tmp_val = list.arg<T?> (); |
|
25 |
size_t i = 1; |
|
26 |
||
27 |
while (tmp_name != null && tmp_val != null) { |
|
|
62
by Gustav Hartvigsson
various changes |
28 |
T_buf[i] = tmp_val; |
29 |
N_buf[i] = tmp_name; |
|
|
49
by Gustav Hartvigsson
Added NamedVector |
30 |
i++; |
31 |
tmp_name = list.arg<string?> (); |
|
32 |
tmp_val = list.arg<T?> (); |
|
33 |
} |
|
34 |
values = new T[i]; |
|
35 |
names = new string[i]; |
|
36 |
for (var j = 0; j < i; j++) { |
|
37 |
values[j] = T_buf[j]; |
|
38 |
names[j] = N_buf[j]; |
|
39 |
} |
|
40 |
||
41 |
assert (this.names != null); |
|
42 |
assert (this.values != null); |
|
43 |
} |
|
44 |
||
45 |
public Pair @get (int i) { |
|
46 |
var ret_val = new Pair<string, T> (this.names[i], this.values[i]); |
|
47 |
return ret_val; |
|
48 |
} |
|
49 |
||
50 |
public void @foreach (ForeachFunc<T> funk) { |
|
51 |
for (var i = 0; i < values.length; i++) { |
|
52 |
if (!funk (names[i], values[i])) { |
|
53 |
break; |
|
54 |
} |
|
55 |
} |
|
56 |
} |
|
57 |
} |
|
58 |
}
|