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