/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 17:19:50 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20201103171950-u9cjz5g22bcrvmyd
* Fixed type : campare->compare.
* Fixed type for function alias.

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?> ();
49
50
    for (uint i = 0; i < lst.length (); i++) {
50
51
      lst2[i] = lst.nth_data (i);
51
52
    }
52
 
   
53
 
    return add_type (name, lst2);
 
53
    
 
54
    add_type (name, lst2);
 
55
    
 
56
    return false;
54
57
  }
55
58
  
56
59
  /**
170
173
  /**
171
174
   * Create a new FieldInfo using the following syntax:
172
175
   * {{{
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
176
   * }}}
189
177
   * 
190
178
   */
191
 
  [CCode (cprefix="bit_field_info_", cname="BitFieldInfo")]
192
179
  public struct FieldInfo {
193
180
    int field_id;
194
181
    uint8 start;
195
182
    uint8 end;
196
183
    uint8 length;
 
184
    GLib.pointer padding;
197
185
    
198
186
    public FieldInfo (int field_id, uint8 start, uint8 end, uint8 length) {
199
187
      this.field_id = field_id;
200
188
      this.start = start;
201
189
      this.end = end;
202
190
      this.length = length; 
 
191
      this.padding = null;
203
192
    }
204
193
    
205
194
    public int compare (FieldInfo other) {
213
202
        return this.length - other.length;
214
203
      }
215
204
      
 
205
      #if 0
 
206
      if (this.start > other.start) {
 
207
        return -1;
 
208
      } else if (this.start < other.start) {
 
209
        return 1;
 
210
      } else {
 
211
        if (this.end > other.end) {
 
212
          return -1;
 
213
        } else if (this.end < other.end) {
 
214
          return 1;
 
215
        } else {
 
216
          if (this.length > other.length) {
 
217
            return -1;
 
218
          } else if (this.length < other.length) {
 
219
            return 1;
 
220
          }
 
221
        }
 
222
      }
 
223
      #endif
 
224
      
216
225
      return 0;
217
226
    }
218
227
    
219
 
    [CCode (cname = "bit_field_info_compare")]
 
228
    [CCode (cname = "bit_field_field_info_compare")]
220
229
    public static extern int static_compare (FieldInfo a, FieldInfo b);
221
230
    
222
231
    
225
234
      return (!((this.start < other.end) || (this.end > other.start)));
226
235
    }
227
236
    
228
 
    [CCode (cname = "bit_field_info_overlap")]
 
237
    [CCode (cname = "bit_field_field_info_overlap")]
229
238
    public static extern bool static_overlap (FieldInfo a, FieldInfo b);
230
239
    
231
240
    
248
257
      return false;
249
258
    }
250
259
    
251
 
    [CCode (cname = "bit_field_info_validate")]
 
260
    [CCode (cname = "bit_field_field_info_validate")]
252
261
    public extern static bool static_validate (FieldInfo info);
253
262
    
254
263
    public uint16 generate_mask () {
264
273
      return mask;
265
274
    }
266
275
    
267
 
    [CCode (cname = "bit_field_info_generate_mask")]
 
276
    [CCode (cname = "bit_field_field_generate_mask")]
268
277
    public extern static uint16 static_generate_mask (FieldInfo info);
269
278
  }
270
279