3 /* gras/datadesc.h - Describing the data you want to exchange */
5 /* Authors: Martin Quinson */
6 /* Copyright (C) 2003 the OURAGAN project. */
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_H
12 #define GRAS_DATADESC_H
14 #include <stddef.h> /* offsetof() */
15 #include <sys/types.h> /* size_t */
19 /*! C++ users need love */
22 # define BEGIN_DECL extern "C" {
28 /*! C++ users need love */
36 /* End of cruft for C++ */
42 typedef struct s_gras_datadesc_type gras_datadesc_type_t;
44 /* callbacks prototypes */
45 typedef void (*gras_datadesc_type_cb_void_t)(void *vars,
46 gras_datadesc_type_t *p_type,
48 typedef int (*gras_datadesc_type_cb_int_t)(void *vars,
49 gras_datadesc_type_t *p_type,
52 /***********************************************
53 **** Search and retrieve declared datatype ****
54 ***********************************************/
55 gras_datadesc_type_t *gras_datadesc_by_name(const char *name);
57 /******************************************
58 **** Declare datadescription yourself ****
59 ******************************************/
62 gras_datadesc_declare_struct(const char *name,
63 gras_datadesc_type_t **dst);
65 gras_datadesc_declare_struct_append(gras_datadesc_type_t *struct_type,
67 gras_datadesc_type_t *field_type);
69 gras_datadesc_declare_union(const char *name,
70 gras_datadesc_type_cb_int_t selector,
71 gras_datadesc_type_t **dst);
73 gras_datadesc_declare_union_append(gras_datadesc_type_t *union_type,
75 gras_datadesc_type_t *field_type);
77 gras_datadesc_declare_ref(const char *name,
78 gras_datadesc_type_t *referenced_type,
79 gras_datadesc_type_t **dst);
81 gras_datadesc_declare_ref_generic(const char *name,
82 gras_datadesc_type_cb_int_t discriminant,
83 gras_datadesc_type_t **dst);
85 gras_datadesc_declare_array_fixed(const char *name,
86 gras_datadesc_type_t *element_type,
88 gras_datadesc_type_t **dst);
90 gras_datadesc_declare_array_dyn(const char *name,
91 gras_datadesc_type_t *element_type,
92 gras_datadesc_type_cb_int_t dynamic_size,
93 gras_datadesc_type_t **dst);
95 /*********************************
96 * Change stuff within datadescs *
97 *********************************/
99 typedef struct s_gras_dd_cbps gras_dd_cbps_t;
100 void gras_datadesc_cb_set_pre (gras_datadesc_type_t *type,
101 gras_datadesc_type_cb_void_t pre);
102 void gras_datadesc_cb_set_post(gras_datadesc_type_t *type,
103 gras_datadesc_type_cb_void_t post);
105 /******************************
106 * Get stuff within datadescs *
107 ******************************/
108 char * gras_datadesc_get_name(gras_datadesc_type_t *ddt);
109 int gras_datadesc_get_id(gras_datadesc_type_t *ddt);
111 /********************************************************
112 * Advanced data describing: callback persistent states *
113 ********************************************************/
116 gras_dd_cbps_pop (gras_dd_cbps_t *ps,
118 gras_datadesc_type_t **ddt);
120 gras_dd_cbps_push(gras_dd_cbps_t *ps,
123 gras_datadesc_type_t *ddt);
125 gras_dd_cbps_set (gras_dd_cbps_t *ps,
128 gras_datadesc_type_t *ddt);
131 gras_dd_cbps_get (gras_dd_cbps_t *ps,
133 gras_datadesc_type_t **ddt);
136 gras_dd_cbps_block_begin(gras_dd_cbps_t *ps);
138 gras_dd_cbps_block_end(gras_dd_cbps_t *ps);
143 /*******************************
144 **** About data convertion ****
145 *******************************/
146 int gras_arch_selfid(void); /* ID of this arch */
148 /****************************
149 **** Parse C statements ****
150 ****************************/
152 gras_datadesc_parse(const char *name,
153 const char *Cdefinition,
154 gras_datadesc_type_t **dst);
155 #define GRAS_DEFINE_TYPE(name,def) \
156 static const char * _gras_this_type_symbol_does_not_exist__##name=#def; def
158 /*#define gras_type_symbol_parse(name) \
159 _gras_datadesc_parse(_gras_this_datadesc_type_symbol_does_not_exist__##name)
161 #define gras_datadesc_by_symbol(name) \
162 (bag->bag_ops->get_type_by_name(bag, NULL, #name) ? \
163 bag->bag_ops->get_type_by_name(bag, NULL, #name) : \
164 gras_datadesc_parse(name) \
167 /*****************************
168 **** NWS datadescription ****
169 *****************************/
172 * Basic types we can embeed in DataDescriptors.
175 {CHAR_TYPE, DOUBLE_TYPE, FLOAT_TYPE, INT_TYPE, LONG_TYPE, SHORT_TYPE,
176 UNSIGNED_INT_TYPE, UNSIGNED_LONG_TYPE, UNSIGNED_SHORT_TYPE, STRUCT_TYPE}
178 #define SIMPLE_TYPE_COUNT 9
180 /*! \brief Describe a collection of data.
182 ** A description of a collection of #type# data. #repetitions# is used only
183 ** for arrays; it contains the number of elements. #offset# is used only for
184 ** struct members in host format; it contains the offset of the member from the
185 ** beginning of the struct, taking into account internal padding added by the
186 ** compiler for alignment purposes. #members#, #length#, and #tailPadding# are
187 ** used only for STRUCT_TYPE data; the #length#-long array #members# describes
188 ** the members of the nested struct, and #tailPadding# indicates how many
189 ** padding bytes the compiler adds to the end of the structure.
192 typedef struct DataDescriptorStruct {
196 /*@null@*/ struct DataDescriptorStruct *members;
200 /** DataDescriptor for an array */
201 #define SIMPLE_DATA(type,repetitions) \
202 {type, repetitions, 0, NULL, 0, 0}
203 /** DataDescriptor for an structure member */
204 #define SIMPLE_MEMBER(type,repetitions,offset) \
205 {type, repetitions, offset, NULL, 0, 0}
206 /** DataDescriptor for padding bytes */
207 #define PAD_BYTES(structType,lastMember,memberType,repetitions) \
208 sizeof(structType) - offsetof(structType, lastMember) - \
209 sizeof(memberType) * repetitions
212 gras_datadesc_import_nws(const char *name,
213 const DataDescriptor *desc,
215 gras_datadesc_type_t **dst);
219 #endif /* GRAS_DATADESC_H */