/bitfield/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/bitfield/trunk

« back to all changes in this revision

Viewing changes to src/bit_map.vala

  • Committer: Gustav Hartvigsson
  • Date: 2020-06-06 21:24:51 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20200606212451-4qiz5gog39p3stb2
* added ignore for build directory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
  
17
17
  private static GLib.Tree<FieldInfo?, uint16> mask_cache;
18
18
  
19
 
  public void init () {
 
19
  void init () {
20
20
    list_of_types = new GLib.Tree<string, Type?> ((a, b) => {
21
21
      return (GLib.strcmp (a,b));
22
22
    });
26
26
    });
27
27
  }
28
28
  
29
 
  public void deinit () {
 
29
  void deinit () {
30
30
    list_of_types.foreach ((_key, _val) => {
31
31
      list_of_types.remove (_key);
 
32
      
32
33
      return false;
33
34
    });
34
35
  }
35
36
  
36
 
  public static bool add_type_v (string name, FieldInfo first_field, ...) {
 
37
  static bool add_type_v (string name, FieldInfo first_field, ...) {
37
38
    var va = va_list ();
38
39
    
39
40
    GLib.List<FieldInfo?> lst = new GLib.List<FieldInfo?> ();
46
47
    
47
48
    FieldInfo[] lst2 = new FieldInfo[lst.length ()];
48
49
    
49
 
    for (uint i = 0; i < lst.length (); i++) {
50
 
      lst2[i] = lst.nth_data (i);
51
 
    }
52
 
   
53
 
    return add_type (name, lst2);
 
50
    add_type (name, lst2);
 
51
    
 
52
    return false;
54
53
  }
55
54
  
56
55
  /**
170
169
  /**
171
170
   * Create a new FieldInfo using the following syntax:
172
171
   * {{{
173
 
   *  enum MyTypeFields {
174
 
   *    F1,
175
 
   *    F2,
176
 
   *    //....
177
 
   *  }
178
 
   *
179
 
   *  BitField.FieldInfo[] my_fields_info = {
180
 
   *    BitField.FieldInfo (MyTypeFields.F1, 0, 5, 6),
181
 
   *    BitField.FieldInfo (MyTypeFields.F2, 0, 5, 6),
182
 
   *    //.....
183
 
   *  }
184
 
   *  
185
 
   *  if (FieldInfo.add_type ("MyType", my_fields_info)) {
186
 
   *    stderr.printf ("Something went wrong!");
187
 
   *  }
188
172
   * }}}
189
173
   * 
190
174
   */
191
 
  [CCode (cprefix="bit_field_info_", cname="BitFieldInfo")]
192
175
  public struct FieldInfo {
193
176
    int field_id;
194
177
    uint8 start;
195
178
    uint8 end;
196
179
    uint8 length;
 
180
    GLib.pointer padding;
197
181
    
198
182
    public FieldInfo (int field_id, uint8 start, uint8 end, uint8 length) {
199
183
      this.field_id = field_id;
200
184
      this.start = start;
201
185
      this.end = end;
202
186
      this.length = length; 
 
187
      this.padding = null;
203
188
    }
204
189
    
205
190
    public int compare (FieldInfo other) {
213
198
        return this.length - other.length;
214
199
      }
215
200
      
 
201
      #if 0
 
202
      if (this.start > other.start) {
 
203
        return -1;
 
204
      } else if (this.start < other.start) {
 
205
        return 1;
 
206
      } else {
 
207
        if (this.end > other.end) {
 
208
          return -1;
 
209
        } else if (this.end < other.end) {
 
210
          return 1;
 
211
        } else {
 
212
          if (this.length > other.length) {
 
213
            return -1;
 
214
          } else if (this.length < other.length) {
 
215
            return 1;
 
216
          }
 
217
        }
 
218
      }
 
219
      #endif
 
220
      
216
221
      return 0;
217
222
    }
218
223
    
219
 
    [CCode (cname = "bit_field_info_compare")]
220
 
    public static extern int static_compare (FieldInfo a, FieldInfo b);
221
 
    
 
224
    [CCode (cname = "bit_field_field_info_compare")]
 
225
    public static extern int static_campare (FieldInfo a, FieldInfo b);
222
226
    
223
227
    
224
228
    public bool overlap (FieldInfo other) {
225
229
      return (!((this.start < other.end) || (this.end > other.start)));
226
230
    }
227
231
    
228
 
    [CCode (cname = "bit_field_info_overlap")]
229
 
    public static extern bool static_overlap (FieldInfo a, FieldInfo b);
 
232
    [CCode (cname = "bit_field_field_info_overlap")]
 
233
    public static extern int static_overlap (FieldInfo a, FieldInfo b);
230
234
    
231
235
    
232
236
    public string to_string () {
248
252
      return false;
249
253
    }
250
254
    
251
 
    [CCode (cname = "bit_field_info_validate")]
 
255
    [CCode (cname = "bit_field_field_info_validate")]
252
256
    public extern static bool static_validate (FieldInfo info);
253
257
    
254
258
    public uint16 generate_mask () {
264
268
      return mask;
265
269
    }
266
270
    
267
 
    [CCode (cname = "bit_field_info_generate_mask")]
 
271
    [CCode (cname = "bit_field_field_generate_mask")]
268
272
    public extern static uint16 static_generate_mask (FieldInfo info);
269
273
  }
270
274