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