2
* The contects of this file is in the Public Domain.
4
* Created by Gustav Hartivgsson.
6
[CCode (cname = "V", cprefix = "v_")]
8
[CCode (cname = "VNamedVector", cprefix = "v_named_vector_")]
9
public class NamedVector<T> {
11
public string[] names;
13
public delegate bool ForeachFunc<V> (string name, V val);
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];
21
var list = va_list ();
23
var tmp_name = list.arg<string?> ();
24
var tmp_val = list.arg<T?> ();
27
while (tmp_name != null && tmp_val != null) {
28
T_buf[i] = tmp_val; N_buf[i] = tmp_name;
30
tmp_name = list.arg<string?> ();
31
tmp_val = list.arg<T?> ();
34
names = new string[i];
35
for (var j = 0; j < i; j++) {
40
assert (this.names != null);
41
assert (this.values != null);
44
public Pair @get (int i) {
45
var ret_val = new Pair<string, T> (this.names[i], this.values[i]);
49
public void @foreach (ForeachFunc<T> funk) {
50
for (var i = 0; i < values.length; i++) {
51
if (!funk (names[i], values[i])) {