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"
20 * Align the data v on the boundary a.
22 #define aligned(v, a) (((v) + (a - 1)) & ~(a - 1))
24 extern gras_set_t *gras_datadesc_set_local;
26 /**********************************************************/
27 /* Actual definitions of the stuff in the type descriptor */
28 /**********************************************************/
31 * e_gras_datadesc_type_category:
33 * Defines all possible type categories
35 typedef enum e_gras_datadesc_type_category {
36 e_gras_datadesc_type_cat_undefined = 0,
38 e_gras_datadesc_type_cat_scalar,
39 e_gras_datadesc_type_cat_struct,
40 e_gras_datadesc_type_cat_union,
41 e_gras_datadesc_type_cat_ref, /* ref to an uniq element */
42 e_gras_datadesc_type_cat_array,
43 e_gras_datadesc_type_cat_ignored,
45 e_gras_datadesc_type_cat_invalid
46 } gras_datadesc_type_category_t;
49 /*------------------------------------------------*/
50 /* definitions of specific data for each category */
51 /*------------------------------------------------*/
53 * s_gras_dd_cat_field:
55 * Fields of struct and union
57 typedef struct s_gras_dd_cat_field {
60 long int offset; /* only for struct */
63 gras_datadesc_type_cb_void_t pre;
64 gras_datadesc_type_cb_void_t post;
66 } gras_dd_cat_field_t;
67 void gras_dd_cat_field_free(void *f);
70 * gras_dd_cat_scalar_t:
72 * Specific fields of a scalar
74 enum e_gras_dd_scalar_encoding {
75 e_gras_dd_scalar_encoding_undefined = 0,
77 e_gras_dd_scalar_encoding_uint,
78 e_gras_dd_scalar_encoding_sint,
79 e_gras_dd_scalar_encoding_float,
81 e_gras_dd_scalar_encoding_invalid
83 typedef struct s_gras_dd_cat_scalar {
84 enum e_gras_dd_scalar_encoding encoding;
85 } gras_dd_cat_scalar_t;
88 * gras_dd_cat_struct_t:
90 * Specific fields of a struct
92 typedef struct s_gras_dd_cat_struct {
93 gras_dynar_t *fields; /* elm type = gras_dd_cat_struct_field_t */
94 } gras_dd_cat_struct_t;
97 * gras_dd_cat_union_t:
99 * Specific fields of a union
101 typedef struct s_gras_dd_cat_union {
102 gras_datadesc_type_cb_int_t field_count;
103 gras_dynar_t *fields; /* elm type = gras_dd_cat_union_field_t */
104 } gras_dd_cat_union_t;
109 * Specific fields of a reference
111 typedef struct s_gras_dd_cat_ref {
114 /* callback used to return the referenced type number */
115 gras_datadesc_type_cb_int_t discriminant;
120 * gras_dd_cat_array_t:
122 * Specific fields of an array
124 typedef struct s_gras_dd_cat_array {
127 /* element_count < 0 means dynamically defined */
130 /* callback used to return the dynamic length */
131 gras_datadesc_type_cb_int_t dynamic_size;
132 } gras_dd_cat_array_t;
135 * gras_dd_cat_ignored_t:
137 * Specific fields of an ignored field
139 typedef struct s_gras_dd_cat_ignored {
141 void_f_pvoid_t *free_func;
142 } gras_dd_cat_ignored_t;
146 * u_gras_datadesc_category:
148 * Specific data to each possible category
150 union u_gras_datadesc_category {
151 void *undefined_data;
152 gras_dd_cat_scalar_t scalar_data;
153 gras_dd_cat_struct_t struct_data;
154 gras_dd_cat_union_t union_data;
155 gras_dd_cat_ref_t ref_data;
156 gras_dd_cat_array_t array_data;
157 gras_dd_cat_ignored_t ignored_data;
161 /****************************************/
162 /* The holy grail: type descriptor type */
163 /****************************************/
165 * s_gras_datadesc_type:
169 struct s_gras_datadesc_type {
170 /* headers for the data set */
173 unsigned int name_len;
179 long int aligned_size;
181 enum e_gras_datadesc_type_category category_code;
182 union u_gras_datadesc_category category;
184 gras_datadesc_type_cb_void_t pre;
185 gras_datadesc_type_cb_void_t post;
188 /***************************
189 * Type creation functions *
190 ***************************/
192 gras_ddt_new_scalar(const char *name,
194 enum e_gras_dd_scalar_encoding encoding,
195 gras_datadesc_type_cb_void_t cb,
196 gras_datadesc_type_t **dst);
198 gras_ddt_new_struct(const char *name,
199 gras_datadesc_type_cb_void_t pre,
200 gras_datadesc_type_cb_void_t post,
201 gras_datadesc_type_t **dst);
203 gras_ddt_new_struct_append(gras_datadesc_type_t *struct_type,
205 gras_datadesc_type_t *field_type,
206 gras_datadesc_type_cb_void_t pre,
207 gras_datadesc_type_cb_void_t post);
209 gras_ddt_new_union(const char *name,
210 gras_datadesc_type_cb_int_t field_count,
211 gras_datadesc_type_cb_void_t post,
212 gras_datadesc_type_t **dst);
214 gras_ddt_new_union_append(gras_datadesc_type_t *union_type,
216 gras_datadesc_type_t *field_type,
217 gras_datadesc_type_cb_void_t pre,
218 gras_datadesc_type_cb_void_t post);
220 gras_ddt_new_ref(const char *name,
221 gras_datadesc_type_t *referenced_type,
222 gras_datadesc_type_cb_int_t discriminant,
223 gras_datadesc_type_cb_void_t post,
224 gras_datadesc_type_t **dst);
226 gras_ddt_new_array(const char *name,
227 gras_datadesc_type_t *element_type,
229 gras_datadesc_type_cb_int_t dynamic_size,
230 gras_datadesc_type_cb_void_t post,
231 gras_datadesc_type_t **dst);
233 gras_ddt_new_ignored(const char *name,
235 void_f_pvoid_t *free_func,
238 gras_datadesc_type_cb_void_t post,
239 gras_datadesc_type_t **dst);
243 #endif /* GRAS_DATADESC_PRIVATE_H */