X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=include%2Fbabeltrace%2Ftypes.h;h=7da11af24bab4c8e02b9c56f1322afaa45768f0c;hp=862624084371ecfcf1d1692f7fe10762136ed5b5;hb=2e7d72cf823b70b03d84e287ae4fda5b9ead7cb5;hpb=bed864a75d2315c344a6e625db66ae9bfbc51e27 diff --git a/include/babeltrace/types.h b/include/babeltrace/types.h index 86262408..7da11af2 100644 --- a/include/babeltrace/types.h +++ b/include/babeltrace/types.h @@ -27,6 +27,9 @@ #include #include +/* Preallocate this many fields for structures */ +#define DEFAULT_NR_STRUCT_FIELDS 8 + /* * Always update stream_pos with move_pos and init_pos. */ @@ -93,26 +96,23 @@ struct type_class { void (*free)(struct type_class *type_class); }; -struct type_class_integer { - struct type_class p; - size_t len; /* length, in bits. */ - int byte_order; /* byte order */ - int signedness; -}; - /* * Because we address in bits, bitfields end up being exactly the same as * integers, except that their read/write functions must be able to deal with * read/write non aligned on CHAR_BIT. */ -struct type_class_bitfield { - struct type_class_integer p; +struct type_class_integer { + struct type_class p; + size_t len; /* length, in bits. */ + int byte_order; /* byte order */ + int signedness; }; struct type_class_float { struct type_class p; - struct bitfield_class *mantissa; - struct bitfield_class *exp; + struct int_class *sign; + struct int_class *mantissa; + struct int_class *exp; int byte_order; /* TODO: we might want to express more info about NaN, +inf and -inf */ }; @@ -123,7 +123,7 @@ struct enum_table { }; struct type_class_enum { - struct type_class_bitfield p; /* inherit from bitfield */ + struct type_class_int p; /* inherit from integer */ struct enum_table table; }; @@ -131,9 +131,27 @@ struct type_class_string { struct type_class p; }; +struct field { + GQuark name; + struct type_class *type_class; +}; + struct type_class_struct { struct type_class p; - /* TODO */ + GHashTable *fields_by_name; /* Tuples (field name, field index) */ + GArray *fields; /* Array of fields */ +}; + +struct type_class_array { + struct type_class p; + size_t len; + struct type_class *elem; +}; + +struct type_class_sequence { + struct type_class p; + struct type_class_integer *len_class; + struct type_class *elem; }; struct type_class *ctf_lookup_type(GQuark qname); @@ -142,17 +160,15 @@ int ctf_register_type(struct type_class *type_class); /* Nameless types can be created by passing a NULL name */ struct type_class_integer *integer_type_new(const char *name, - size_t start_offset, size_t len, int byte_order, - int signedness); + int signedness, + size_t alignment); void integer_type_free(struct type_class_integer *int_class); -struct type_class_bitfield *bitfield_type_new(const char *name, - size_t start_offset, - size_t len, int byte_order, - int signedness); -void bitfield_type_free(struct type_class_bitfield *bitfield_class); - +/* + * mantissa_len is the length of the number of bytes represented by the mantissa + * (e.g. result of DBL_MANT_DIG). It includes the leading 1. + */ struct type_class_float *float_type_new(const char *name, size_t mantissa_len, size_t exp_len, int byte_order, @@ -175,10 +191,45 @@ void enum_unsigned_insert(struct type_class_enum *enum_class, uint64_t v, GQuark q); struct type_class_enum *enum_type_new(const char *name, - size_t start_offset, size_t len, int byte_order, int signedness, size_t alignment); void enum_type_free(struct type_class_enum *enum_class); +struct type_class_struct *struct_type_new(const char *name); +void struct_type_free(struct type_class_struct *struct_class); +void struct_type_add_field(struct type_class_struct *struct_class, + GQuark field_name, + struct type_class *type_class); +/* + * Returns the index of a field within a structure. + */ +unsigned long +struct_type_lookup_field_index(struct type_class_struct *struct_class, + GQuark field_name); +/* + * field returned only valid as long as the field structure is not appended to. + */ +struct field * +struct_type_get_field_from_index(struct type_class_struct *struct_class, + unsigned long index); + +/* + * elem_class passed as parameter now belongs to the array. No need to free it + * explicitely. + */ +struct type_class_array *array_type_new(const char *name, + size_t len, + struct type_class *elem_class); +void array_type_free(struct type_class_array *array_class); + +/* + * int_class and elem_class passed as parameter now belongs to the sequence. No + * need to free them explicitely. + */ +struct type_class_sequence *sequence_type_new(const char *name, + struct type_class_integer *len_class, + struct type_class *elem_class); +void sequence_type_free(struct type_class_sequence *sequence_class); + #endif /* _BABELTRACE_TYPES_H */