3 /* datadesc - describing the data to exchange */
5 /* module's private interface masked even to other parts of GRAS. */
7 /* Authors: Olivier Aumage, Martin Quinson */
8 /* Copyright (C) 2003, 2004 the GRAS posse. */
10 /* This program is free software; you can redistribute it and/or modify it
11 under the terms of the license (GNU LGPL) which comes with this package. */
13 #ifndef GRAS_DATADESC_PRIVATE_H
14 #define GRAS_DATADESC_PRIVATE_H
16 #include "gras_private.h"
17 #include "DataDesc/datadesc_interface.h"
22 * Align the data v on the boundary a.
24 #define aligned(v, a) (((v) + (a - 1)) & ~(a - 1))
26 extern gras_set_t *gras_datadesc_set_local;
28 /*******************************************
29 * Descriptions of all known architectures *
30 *******************************************/
32 #define gras_arch_count 1
34 gras_ddt_scalar_char = 0,
35 gras_ddt_scalar_short = 1,
36 gras_ddt_scalar_int = 2,
37 gras_ddt_scalar_long = 3,
38 gras_ddt_scalar_long_long = 4,
40 gras_ddt_scalar_pdata = 5,
41 gras_ddt_scalar_pfunc = 6,
43 gras_ddt_scalar_float = 7,
44 gras_ddt_scalar_double = 8
45 } gras_ddt_scalar_type_t;
52 int sizeof_scalars[9]; /* char,short,int,long,long_long,
57 extern const gras_arch_sizes_t gras_arch_sizes[gras_arch_count];
60 /**********************************************************/
61 /* Actual definitions of the stuff in the type descriptor */
62 /**********************************************************/
65 * e_gras_datadesc_type_category:
67 * Defines all possible type categories
69 typedef enum e_gras_datadesc_type_category {
70 e_gras_datadesc_type_cat_undefined = 0,
72 e_gras_datadesc_type_cat_scalar = 1,
73 e_gras_datadesc_type_cat_struct = 2,
74 e_gras_datadesc_type_cat_union = 3,
75 e_gras_datadesc_type_cat_ref = 4, /* ref to an uniq element */
76 e_gras_datadesc_type_cat_array = 5,
77 e_gras_datadesc_type_cat_ignored = 6,
79 e_gras_datadesc_type_cat_invalid = 7
80 } gras_datadesc_type_category_t;
83 /*------------------------------------------------*/
84 /* definitions of specific data for each category */
85 /*------------------------------------------------*/
87 * s_gras_dd_cat_field:
89 * Fields of struct and union
91 typedef struct s_gras_dd_cat_field {
94 long int offset[gras_arch_count]; /* only for struct */
97 gras_datadesc_type_cb_void_t pre;
98 gras_datadesc_type_cb_void_t post;
100 } gras_dd_cat_field_t;
102 void gras_dd_cat_field_free(void *f);
105 * gras_dd_cat_scalar_t:
107 * Specific fields of a scalar
109 enum e_gras_dd_scalar_encoding {
110 e_gras_dd_scalar_encoding_undefined = 0,
112 e_gras_dd_scalar_encoding_uint,
113 e_gras_dd_scalar_encoding_sint,
114 e_gras_dd_scalar_encoding_float,
116 e_gras_dd_scalar_encoding_invalid
118 typedef struct s_gras_dd_cat_scalar {
119 enum e_gras_dd_scalar_encoding encoding;
120 } gras_dd_cat_scalar_t;
123 * gras_dd_cat_struct_t:
125 * Specific fields of a struct
127 typedef struct s_gras_dd_cat_struct {
128 gras_dynar_t *fields; /* elm type = gras_dd_cat_field_t */
129 } gras_dd_cat_struct_t;
132 * gras_dd_cat_union_t:
134 * Specific fields of a union
136 typedef struct s_gras_dd_cat_union {
137 gras_datadesc_type_cb_int_t selector;
138 gras_dynar_t *fields; /* elm type = gras_dd_cat_field_t */
139 } gras_dd_cat_union_t;
144 * Specific fields of a reference
146 typedef struct s_gras_dd_cat_ref {
149 /* callback used to return the referenced type number */
150 gras_datadesc_type_cb_int_t selector;
155 * gras_dd_cat_array_t:
157 * Specific fields of an array
159 typedef struct s_gras_dd_cat_array {
162 /* element_count < 0 means dynamically defined */
165 /* callback used to return the dynamic length */
166 gras_datadesc_type_cb_int_t dynamic_size;
167 } gras_dd_cat_array_t;
170 * gras_dd_cat_ignored_t:
172 * Specific fields of an ignored field
174 typedef struct s_gras_dd_cat_ignored {
176 void_f_pvoid_t *free_func;
177 } gras_dd_cat_ignored_t;
181 * u_gras_datadesc_category:
183 * Specific data to each possible category
185 union u_gras_datadesc_category {
186 void *undefined_data;
187 gras_dd_cat_scalar_t scalar_data;
188 gras_dd_cat_struct_t struct_data;
189 gras_dd_cat_union_t union_data;
190 gras_dd_cat_ref_t ref_data;
191 gras_dd_cat_array_t array_data;
192 gras_dd_cat_ignored_t ignored_data;
196 /****************************************/
197 /* The holy grail: type descriptor type */
198 /****************************************/
200 * s_gras_datadesc_type:
204 struct s_gras_datadesc_type {
205 /* headers for the data set */
208 unsigned int name_len;
211 long int size[gras_arch_count];
213 long int alignment[gras_arch_count];
214 long int aligned_size[gras_arch_count];
216 enum e_gras_datadesc_type_category category_code;
217 union u_gras_datadesc_category category;
219 gras_datadesc_type_cb_void_t pre;
220 gras_datadesc_type_cb_void_t post;
223 /***************************
224 * Type creation functions *
225 ***************************/
227 gras_ddt_new_scalar(const char *name,
228 gras_ddt_scalar_type_t type,
229 enum e_gras_dd_scalar_encoding encoding,
230 gras_datadesc_type_cb_void_t cb,
231 gras_datadesc_type_t **dst);
233 gras_ddt_new_struct(const char *name,
234 gras_datadesc_type_cb_void_t pre,
235 gras_datadesc_type_cb_void_t post,
236 gras_datadesc_type_t **dst);
238 gras_ddt_new_struct_append(gras_datadesc_type_t *struct_type,
240 gras_datadesc_type_t *field_type,
241 gras_datadesc_type_cb_void_t pre,
242 gras_datadesc_type_cb_void_t post);
244 gras_ddt_new_union(const char *name,
245 gras_datadesc_type_cb_int_t field_count,
246 gras_datadesc_type_cb_void_t post,
247 gras_datadesc_type_t **dst);
249 gras_ddt_new_union_append(gras_datadesc_type_t *union_type,
251 gras_datadesc_type_t *field_type,
252 gras_datadesc_type_cb_void_t pre,
253 gras_datadesc_type_cb_void_t post);
255 gras_ddt_new_ref(const char *name,
256 gras_datadesc_type_t *referenced_type,
257 gras_datadesc_type_cb_int_t discriminant,
258 gras_datadesc_type_cb_void_t post,
259 gras_datadesc_type_t **dst);
261 gras_ddt_new_array(const char *name,
262 gras_datadesc_type_t *element_type,
264 gras_datadesc_type_cb_int_t dynamic_size,
265 gras_datadesc_type_cb_void_t post,
266 gras_datadesc_type_t **dst);
268 gras_ddt_new_ignored(const char *name,
270 void_f_pvoid_t *free_func,
273 gras_datadesc_type_cb_void_t post,
274 gras_datadesc_type_t **dst);
278 gras_ddt_new_parse(const char *name,
279 const char *C_definition,
280 gras_datadesc_type_t **dst);
282 gras_ddt_new_from_nws(const char *name,
283 const DataDescriptor *desc,
285 gras_datadesc_type_t **dst);
287 /****************************************************
288 * Callback persistant state constructor/destructor *
289 ****************************************************/
291 gras_dd_cbps_new(gras_dd_cbps_t **dst);
293 gras_dd_cbps_free(gras_dd_cbps_t **state);
299 gras_dd_convert_elm(gras_datadesc_type_t *type,
301 void *src, void *dst);
303 #endif /* GRAS_DATADESC_PRIVATE_H */