/+junk/vala-bit-field

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/%2Bjunk/vala-bit-field

« back to all changes in this revision

Viewing changes to src/bit_map.vala

  • Committer: Gustav Hartvigsson
  • Date: 2020-11-03 20:46:10 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20201103204610-csia10wdkva1gbr6
* Made the C api better.
* Fixed the CCode for the static version of static_generate_mask ()

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
 
  void init () {
 
19
  public 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
 
  void deinit () {
 
29
  public void deinit () {
30
30
    list_of_types.foreach ((_key, _val) => {
31
31
      list_of_types.remove (_key);
32
32
      
34
34
    });
35
35
  }
36
36
  
37
 
  static bool add_type_v (string name, FieldInfo first_field, ...) {
 
37
  public static bool add_type_v (string name, FieldInfo first_field, ...) {
38
38
    var va = va_list ();
39
39
    
40
40
    GLib.List<FieldInfo?> lst = new GLib.List<FieldInfo?> ();
47
47
    
48
48
    FieldInfo[] lst2 = new FieldInfo[lst.length ()];
49
49
    
50
 
    add_type (name, lst2);
51
 
    
52
 
    return false;
 
50
    for (uint i = 0; i < lst.length (); i++) {
 
51
      lst2[i] = lst.nth_data (i);
 
52
    }
 
53
   
 
54
    return add_type (name, lst2);
53
55
  }
54
56
  
55
57
  /**
172
174
   * }}}
173
175
   * 
174
176
   */
 
177
  [CCode (cprefix="bit_field_info_", cname="BitFieldInfo")]
175
178
  public struct FieldInfo {
176
179
    int field_id;
177
180
    uint8 start;
178
181
    uint8 end;
179
182
    uint8 length;
180
 
    GLib.pointer padding;
181
183
    
182
184
    public FieldInfo (int field_id, uint8 start, uint8 end, uint8 length) {
183
185
      this.field_id = field_id;
184
186
      this.start = start;
185
187
      this.end = end;
186
188
      this.length = length; 
187
 
      this.padding = null;
188
189
    }
189
190
    
190
191
    public int compare (FieldInfo other) {
221
222
      return 0;
222
223
    }
223
224
    
224
 
    [CCode (cname = "bit_field_field_info_compare")]
225
 
    public static extern int static_campare (FieldInfo a, FieldInfo b);
 
225
    [CCode (cname = "bit_field_info_compare")]
 
226
    public static extern int static_compare (FieldInfo a, FieldInfo b);
 
227
    
226
228
    
227
229
    
228
230
    public bool overlap (FieldInfo other) {
229
231
      return (!((this.start < other.end) || (this.end > other.start)));
230
232
    }
231
233
    
232
 
    [CCode (cname = "bit_field_field_info_overlap")]
233
 
    public static extern int static_overlap (FieldInfo a, FieldInfo b);
 
234
    [CCode (cname = "bit_field_info_overlap")]
 
235
    public static extern bool static_overlap (FieldInfo a, FieldInfo b);
234
236
    
235
237
    
236
238
    public string to_string () {
252
254
      return false;
253
255
    }
254
256
    
255
 
    [CCode (cname = "bit_field_field_info_validate")]
 
257
    [CCode (cname = "bit_field_info_validate")]
256
258
    public extern static bool static_validate (FieldInfo info);
257
259
    
258
260
    public uint16 generate_mask () {
268
270
      return mask;
269
271
    }
270
272
    
271
 
    [CCode (cname = "bit_field_field_generate_mask")]
 
273
    [CCode (cname = "bit_field_info_generate_mask")]
272
274
    public extern static uint16 static_generate_mask (FieldInfo info);
273
275
  }
274
276