/bitfield/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/bitfield/trunk
11 by Gustav Hartvigsson
* Forgot the c-file... Woops
1
#include <stdio.h>
2
#include <glib.h>
3
#include "vbitfield.h"
4
5
enum {
6
  FOO_A,
7
  FOO_B,
8
  FOO_C,
9
  FOO_LEN
10
};
11
12
int
13
main (int argc, char ** argv) {
14
  bit_field_init ();
15
  
12 by Gustav Hartvigsson
* Made the C api better.
16
  BitFieldInfo info[] = {
11 by Gustav Hartvigsson
* Forgot the c-file... Woops
17
    {FOO_A, 0, 5, 6},
18
    {FOO_B, 6, 7, 2},
19
    {FOO_C, 8, 15, 8},
20
  };
21
22
  if (bit_field_add_type ("foo", info, FOO_LEN)) {
23
    fprintf (stdout, "Something went wrong when adding info.\n");
24
  }
25
26
  guint16 t1 = 0;
27
  bit_field_set (&t1, "foo", FOO_C, 137);
28
  fprintf (stdout, "%i\n", t1);
29
  bit_field_set (&t1, "foo", FOO_B, 3);
30
  fprintf (stdout, "%i\n", t1);
31
  bit_field_set (&t1, "foo", FOO_A, 7);
32
  fprintf (stdout, "%i\n", t1);
33
34
  guint16 t2 = bit_field_get (t1, "foo", FOO_C);
35
  fprintf (stdout, "C: %i\n", t2);
36
  t2 = bit_field_get (t1, "foo", FOO_B);
37
  fprintf (stdout, "B: %i\n", t2);
38
  t2 = bit_field_get (t1, "foo", FOO_A);
39
  fprintf (stdout, "A: %i\n", t2);
40
41
  bit_field_deinit ();
42
43
  return 0;
44
}