bzr branch
http://gegoxaren.bato24.eu/bzr/%2Bjunk/vala-bit-field
3
by Gustav Hartvigsson
* It works. :-) |
1 |
enum TestFields { |
2 |
A, |
|
3 |
B, |
|
4 |
C, |
|
5 |
}
|
|
6 |
||
2
by Gustav Hartvigsson
* encountered a bug in Valac: |
7 |
int main (string[] args) { |
8 |
|
|
9 |
BitField.init (); |
|
10 |
|
|
3
by Gustav Hartvigsson
* It works. :-) |
11 |
BitField.FieldInfo[] info = { |
12 |
BitField.FieldInfo (TestFields.A, 0, 5, 6), |
|
13 |
BitField.FieldInfo (TestFields.B, 6, 7, 2), |
|
14 |
BitField.FieldInfo (TestFields.C, 8, 15, 8), |
|
15 |
}; |
|
16 |
|
|
17 |
BitField.add_type ("foo", info); |
|
18 |
|
|
19 |
uint16 t1 = 0; |
|
20 |
BitField.set (ref t1, "foo", TestFields.C, 137); |
|
21 |
print ("%i\n", t1); |
|
10
by Gustav Hartvigsson
* Made it able to be compiled as a library |
22 |
|
23 |
BitField.set (ref t1, "foo", TestFields.B, 3); |
|
24 |
print ("%i\n", t1); |
|
25 |
||
26 |
BitField.set (ref t1, "foo", TestFields.A, 7); |
|
27 |
print ("%i\n", t1); |
|
28 |
||
3
by Gustav Hartvigsson
* It works. :-) |
29 |
uint16 t2 = BitField.get (t1 ,"foo", TestFields.C); |
10
by Gustav Hartvigsson
* Made it able to be compiled as a library |
30 |
print ("C: %i\n", t2); |
31 |
t2 = BitField.get (t1 ,"foo", TestFields.B); |
|
32 |
print ("B: %i\n", t2); |
|
33 |
t2 = BitField.get (t1 ,"foo", TestFields.A); |
|
34 |
print ("A: %i\n", t2); |
|
8
by Gustav Hartvigsson
* Fixed type : campare->compare. |
35 |
|
36 |
var my_var1 = BitField.FieldInfo.static_overlap (info[0], info[1]); |
|
37 |
|
|
38 |
var my_var2 = BitField.FieldInfo.static_compare (info[0], info[1]); |
|
39 |
||
40 |
stdout.printf ("%s\n", my_var1.to_string ()); |
|
41 |
stdout.printf ("%s\n", my_var2.to_string ()); |
|
42 |
|
|
2
by Gustav Hartvigsson
* encountered a bug in Valac: |
43 |
BitField.deinit (); |
44 |
return 0; |
|
45 |
}
|