/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-11-03 21:37:26 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20201103213726-cnc5g98qp233eio6
* removed unused code
* Added a bit of information on how to use this to the comments

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
 
      
33
32
      return false;
34
33
    });
35
34
  }
36
35
  
37
 
  static bool add_type_v (string name, FieldInfo first_field, ...) {
 
36
  public static bool add_type_v (string name, FieldInfo first_field, ...) {
38
37
    var va = va_list ();
39
38
    
40
39
    GLib.List<FieldInfo?> lst = new GLib.List<FieldInfo?> ();
47
46
    
48
47
    FieldInfo[] lst2 = new FieldInfo[lst.length ()];
49
48
    
50
 
    add_type (name, lst2);
51
 
    
52
 
    return false;
 
49
    for (uint i = 0; i < lst.length (); i++) {
 
50
      lst2[i] = lst.nth_data (i);
 
51
    }
 
52
   
 
53
    return add_type (name, lst2);
53
54
  }
54
55
  
55
56
  /**
169
170
  /**
170
171
   * Create a new FieldInfo using the following syntax:
171
172
   * {{{
 
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
   *  }
172
188
   * }}}
173
189
   * 
174
190
   */
 
191
  [CCode (cprefix="bit_field_info_", cname="BitFieldInfo")]
175
192
  public struct FieldInfo {
176
193
    int field_id;
177
194
    uint8 start;
178
195
    uint8 end;
179
196
    uint8 length;
180
 
    GLib.pointer padding;
181
197
    
182
198
    public FieldInfo (int field_id, uint8 start, uint8 end, uint8 length) {
183
199
      this.field_id = field_id;
184
200
      this.start = start;
185
201
      this.end = end;
186
202
      this.length = length; 
187
 
      this.padding = null;
188
203
    }
189
204
    
190
205
    public int compare (FieldInfo other) {
198
213
        return this.length - other.length;
199
214
      }
200
215
      
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
 
      
221
216
      return 0;
222
217
    }
223
218
    
224
 
    [CCode (cname = "bit_field_field_info_compare")]
225
 
    public static extern int static_campare (FieldInfo a, FieldInfo b);
 
219
    [CCode (cname = "bit_field_info_compare")]
 
220
    public static extern int static_compare (FieldInfo a, FieldInfo b);
 
221
    
226
222
    
227
223
    
228
224
    public bool overlap (FieldInfo other) {
229
225
      return (!((this.start < other.end) || (this.end > other.start)));
230
226
    }
231
227
    
232
 
    [CCode (cname = "bit_field_field_info_overlap")]
233
 
    public static extern int static_overlap (FieldInfo a, FieldInfo b);
 
228
    [CCode (cname = "bit_field_info_overlap")]
 
229
    public static extern bool static_overlap (FieldInfo a, FieldInfo b);
234
230
    
235
231
    
236
232
    public string to_string () {
252
248
      return false;
253
249
    }
254
250
    
255
 
    [CCode (cname = "bit_field_field_info_validate")]
 
251
    [CCode (cname = "bit_field_info_validate")]
256
252
    public extern static bool static_validate (FieldInfo info);
257
253
    
258
254
    public uint16 generate_mask () {
268
264
      return mask;
269
265
    }
270
266
    
271
 
    [CCode (cname = "bit_field_field_generate_mask")]
 
267
    [CCode (cname = "bit_field_info_generate_mask")]
272
268
    public extern static uint16 static_generate_mask (FieldInfo info);
273
269
  }
274
270