/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 19:35:25 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20201103193525-tewczqy146ln4spx
* Made it able to be compiled as a library
* Added C test
* Added more tests to main.vala

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
  public 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
  }
170
171
  /**
171
172
   * Create a new FieldInfo using the following syntax:
172
173
   * {{{
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
174
   * }}}
189
175
   * 
190
176
   */
191
 
  [CCode (cprefix="bit_field_info_", cname="BitFieldInfo")]
192
177
  public struct FieldInfo {
193
178
    int field_id;
194
179
    uint8 start;
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")]
 
224
    [CCode (cname = "bit_field_field_info_compare")]
220
225
    public static extern int static_compare (FieldInfo a, FieldInfo b);
221
226
    
222
227
    
225
230
      return (!((this.start < other.end) || (this.end > other.start)));
226
231
    }
227
232
    
228
 
    [CCode (cname = "bit_field_info_overlap")]
 
233
    [CCode (cname = "bit_field_field_info_overlap")]
229
234
    public static extern bool static_overlap (FieldInfo a, FieldInfo b);
230
235
    
231
236
    
248
253
      return false;
249
254
    }
250
255
    
251
 
    [CCode (cname = "bit_field_info_validate")]
 
256
    [CCode (cname = "bit_field_field_info_validate")]
252
257
    public extern static bool static_validate (FieldInfo info);
253
258
    
254
259
    public uint16 generate_mask () {
264
269
      return mask;
265
270
    }
266
271
    
267
 
    [CCode (cname = "bit_field_info_generate_mask")]
 
272
    [CCode (cname = "bit_field_field_generate_mask")]
268
273
    public extern static uint16 static_generate_mask (FieldInfo info);
269
274
  }
270
275