3
private static GLib.Tree<string, Type?> list_of_types;
5
private static GLib.Tree<FieldInfo?, uint16> mask_cash;
8
list_of_types = new GLib.Tree<string, Type?> ((a, b) => {
9
return (GLib.strcmp (a,b));
12
mask_cash = new GLib.Tree<FieldInfo?, uint16> ((a, b) => {
18
list_of_types.foreach ((_key, _val) => {
19
list_of_types.remove (_key);
26
* @Return true on error.
28
public bool add_type (string name, FieldInfo first_field, ...) {
31
GLib.List<FieldInfo?> lst = new GLib.List<FieldInfo?> ();
33
lst.append (first_field);
34
for (FieldInfo? fi = va.arg<FieldInfo> (); fi != null;
35
fi = va.arg<FieldInfo> ()) {
39
if (lst.length () >= 16) {
43
lst.sort ((a,b) => {return a.compare (b);});
46
for (uint8 i = 0; i < lst.length (); i++) {
47
var a = lst.nth_data (i);
48
// We valitade the items whilst we are at it.
52
for (uint8 j = i + 1; i < lst.length (); j++) {
53
var b = lst.nth_data (i);
57
GLib.critical ("Overlappinng fields in %s: (%s) (%s).\n" +
58
"\t Will not add bitmap type defitions.",
59
lst.nth_data (i).to_string (),
60
lst.nth_data (j).to_string ());
67
for (uint8 i = 0; i < lst.length (); i++) {
68
t.fields[i] = lst.nth_data (i);
74
public void set_8 (ref uint8 field_id, string type_name, uint8 data) {
80
public struct FieldInfo {
86
public int compare (FieldInfo other) {
87
if (this.field_id != other.field_id) {
88
return other.field_id - this.field_id;
89
} else if (this.start != other.start) {
90
return other.start - this.start;
91
} else if (this.end != other.end) {
92
return other.end - this.end;
93
} else if (this.length != other.length) {
94
return other.length - this.length;
98
if (this.start > other.start) {
100
} else if (this.start < other.start) {
103
if (this.end > other.end) {
105
} else if (this.end < other.end) {
108
if (this.length > other.length) {
110
} else if (this.length < other.length) {
120
[CCode (cname = "bit_field_field_info_compare")]
121
public static extern int static_campare (FieldInfo a, FieldInfo b);
124
public bool overlap (FieldInfo other) {
125
return (!((this.start < other.end) || (this.end > other.start)));
128
[CCode (cname = "bit_field_field_info_overlap")]
129
public static extern int static_overlap (FieldInfo a, FieldInfo b);
132
public string to_string () {
133
return "start: %i, end: %i, length: %i".printf (this.start,
139
* returns true on error;
141
public bool validate () {
142
var distance = this.start - this.end;
143
if (distance < 1 || distance != this.length) {
144
GLib.critical ("Validtion if FieldInfo object failed: (%s)",
151
[CCode (cname = "bit_field_field_info_validate")]
152
public extern static bool static_validate (FieldInfo info);
154
public uint16 generate_mask () {
156
for (size_t i = 0; i < this.length; i++) {
157
mask += 0x8000; // set the left-most bit in the field
158
mask >> 1; // shit it over to the right one.
166
[CCode (cname = "bit_field_field_generate_mask")]
167
public extern static uint16 static_generate_mask (FieldInfo info);
170
private struct Type {
174
fields = new FieldInfo[16];
177
public string to_string () {
178
var sb = new GLib.StringBuilder ();
180
sb.append (typeof (Type).name ())
182
for (size_t i = 0; i < fields.length; i++) {
184
.append (fields[i].to_string ())