3 /* datadesc_private - declarations visible only from within datadesc */
5 /* Authors: Olivier Aumage, Martin Quinson */
6 /* Copyright (C) 2003, 2004 the GRAS posse. */
8 /* This program is free software; you can redistribute it and/or modify it
9 under the terms of the license (GNU LGPL) which comes with this package. */
11 #ifndef GRAS_DATADESC_PRIVATE_H
12 #define GRAS_DATADESC_PRIVATE_H
14 #include "gras_private.h"
15 #include "DataDesc/datadesc_interface.h"
17 #define aligned(v, a) (((v) + (a - 1)) & ~(a - 1))
21 /**********************************************************/
22 /* Actual definitions of the stuff in the type descriptor */
23 /**********************************************************/
26 * e_gras_datadesc_type_category:
28 * Defines all possible type categories
30 typedef enum e_gras_datadesc_type_category {
31 e_gras_datadesc_type_cat_undefined = 0,
33 e_gras_datadesc_type_cat_scalar,
34 e_gras_datadesc_type_cat_struct,
35 e_gras_datadesc_type_cat_union,
36 e_gras_datadesc_type_cat_ref, /* ref to an uniq element */
37 e_gras_datadesc_type_cat_array,
38 e_gras_datadesc_type_cat_ignored,
40 e_gras_datadesc_type_cat_invalid
41 } gras_datadesc_type_category_t;
44 /*------------------------------------------------*/
45 /* definitions of specific data for each category */
46 /*------------------------------------------------*/
48 * s_gras_dd_cat_field:
50 * Fields of struct and union
52 typedef struct s_gras_dd_cat_field {
55 long int offset; /* only for struct */
58 gras_datadesc_type_cb_void_t pre;
59 gras_datadesc_type_cb_void_t post;
61 } gras_dd_cat_field_t;
62 void gras_dd_cat_field_free(void *f);
65 * gras_dd_cat_scalar_t:
67 * Specific fields of a scalar
69 enum e_gras_dd_scalar_encoding {
70 e_gras_dd_scalar_encoding_undefined = 0,
72 e_gras_dd_scalar_encoding_uint,
73 e_gras_dd_scalar_encoding_sint,
74 e_gras_dd_scalar_encoding_float,
76 e_gras_dd_scalar_encoding_invalid
78 typedef struct s_gras_dd_cat_scalar {
79 enum e_gras_dd_scalar_encoding encoding;
80 } gras_dd_cat_scalar_t;
83 * gras_dd_cat_struct_t:
85 * Specific fields of a struct
87 typedef struct s_gras_dd_cat_struct {
88 gras_dynar_t *fields; /* elm type = gras_dd_cat_struct_field_t */
89 } gras_dd_cat_struct_t;
92 * gras_dd_cat_union_t:
94 * Specific fields of a union
96 typedef struct s_gras_dd_cat_union {
97 gras_datadesc_type_cb_int_t field_count;
98 gras_dynar_t *fields; /* elm type = gras_dd_cat_union_field_t */
99 } gras_dd_cat_union_t;
104 * Specific fields of a reference
106 typedef struct s_gras_dd_cat_ref {
109 /* callback used to return the referenced type number */
110 gras_datadesc_type_cb_int_t discriminant;
115 * gras_dd_cat_array_t:
117 * Specific fields of an array
119 typedef struct s_gras_dd_cat_array {
122 /* element_count < 0 means dynamically defined */
125 /* callback used to return the dynamic length */
126 gras_datadesc_type_cb_int_t dynamic_size;
127 } gras_dd_cat_array_t;
130 * gras_dd_cat_ignored_t:
132 * Specific fields of an ignored field
134 typedef struct s_gras_dd_cat_ignored {
136 } gras_dd_cat_ignored_t;
140 * u_gras_datadesc_category:
142 * Specific data to each possible category
144 union u_gras_datadesc_category {
145 void *undefined_data;
146 gras_dd_cat_scalar_t scalar_data;
147 gras_dd_cat_struct_t struct_data;
148 gras_dd_cat_union_t union_data;
149 gras_dd_cat_ref_t ref_data;
150 gras_dd_cat_array_t array_data;
151 gras_dd_cat_ignored_t ignored_data;
155 /****************************************/
156 /* The holy grail: type descriptor type */
157 /****************************************/
159 * s_gras_datadesc_type:
163 struct s_gras_datadesc_type {
164 /* headers for the data set */
167 unsigned int name_len;
173 long int aligned_size;
175 enum e_gras_datadesc_type_category category_code;
176 union u_gras_datadesc_category category;
178 gras_datadesc_type_cb_void_t pre;
179 gras_datadesc_type_cb_void_t post;
182 /***************************
183 * Type creation functions *
184 ***************************/
186 gras_ddt_new_scalar(const char *name,
188 enum e_gras_dd_scalar_encoding encoding,
189 gras_datadesc_type_cb_void_t cb,
190 gras_datadesc_type_t **dst);
192 gras_ddt_new_struct(const char *name,
193 gras_datadesc_type_cb_void_t pre,
194 gras_datadesc_type_cb_void_t post,
195 gras_datadesc_type_t **dst);
197 gras_ddt_new_struct_append(gras_datadesc_type_t *struct_type,
199 gras_datadesc_type_t *field_type,
200 gras_datadesc_type_cb_void_t pre,
201 gras_datadesc_type_cb_void_t post);
203 gras_ddt_new_union(const char *name,
204 gras_datadesc_type_cb_int_t field_count,
205 gras_datadesc_type_cb_void_t post,
206 gras_datadesc_type_t **dst);
208 gras_ddt_new_union_append(gras_datadesc_type_t *union_type,
210 gras_datadesc_type_t *field_type,
211 gras_datadesc_type_cb_void_t pre,
212 gras_datadesc_type_cb_void_t post);
214 gras_ddt_new_ref(const char *name,
215 gras_datadesc_type_t *referenced_type,
216 gras_datadesc_type_cb_int_t discriminant,
217 gras_datadesc_type_cb_void_t post,
218 gras_datadesc_type_t **dst);
220 gras_ddt_new_array(const char *name,
221 gras_datadesc_type_t *element_type,
223 gras_datadesc_type_cb_int_t dynamic_size,
224 gras_datadesc_type_cb_void_t post,
225 gras_datadesc_type_t **dst);
229 #endif /* GRAS_DATADESC_PRIVATE_H */