Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
83d32c1afc774ac5f7df59aea4c594eefccb12d3
[simgrid.git] / src / gras / DataDesc / datadesc_private.h
1 /* $Id$ */
2
3 /* datadesc_private - declarations visible only from within datadesc        */
4
5 /* Authors: Olivier Aumage, Martin Quinson                                  */
6 /* Copyright (C) 2003, 2004 the GRAS posse.                                 */
7
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. */
10
11 #ifndef GRAS_DATADESC_PRIVATE_H
12 #define GRAS_DATADESC_PRIVATE_H
13
14 #include "gras_private.h"
15 #include "DataDesc/datadesc_interface.h"
16
17 /**
18  * aligned:
19  * 
20  * Align the data v on the boundary a.
21  */
22 #define aligned(v, a) (((v) + (a - 1)) & ~(a - 1))
23
24 extern gras_set_t *gras_datadesc_set_local;
25
26 /**********************************************************/
27 /* Actual definitions of the stuff in the type descriptor */
28 /**********************************************************/
29
30 /**
31  * e_gras_datadesc_type_category:
32  *
33  * Defines all possible type categories
34  */
35 typedef enum e_gras_datadesc_type_category {
36         e_gras_datadesc_type_cat_undefined = 0,
37
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,
44
45         e_gras_datadesc_type_cat_invalid
46 } gras_datadesc_type_category_t;
47
48
49 /*------------------------------------------------*/
50 /* definitions of specific data for each category */
51 /*------------------------------------------------*/
52 /**
53  * s_gras_dd_cat_field:
54  *
55  * Fields of struct and union
56  */
57 typedef struct s_gras_dd_cat_field {
58
59   char                        *name;
60   long int                     offset; /* only for struct */
61   int                          code;
62   
63   gras_datadesc_type_cb_void_t pre;
64   gras_datadesc_type_cb_void_t post;
65
66 } gras_dd_cat_field_t;
67 void gras_dd_cat_field_free(void *f);
68
69 /**
70  * gras_dd_cat_scalar_t:
71  *
72  * Specific fields of a scalar
73  */
74 enum e_gras_dd_scalar_encoding {
75   e_gras_dd_scalar_encoding_undefined = 0,
76   
77   e_gras_dd_scalar_encoding_uint,
78   e_gras_dd_scalar_encoding_sint,
79   e_gras_dd_scalar_encoding_float,
80   
81   e_gras_dd_scalar_encoding_invalid 
82 };
83 typedef struct s_gras_dd_cat_scalar {
84   enum e_gras_dd_scalar_encoding encoding;
85 } gras_dd_cat_scalar_t;
86
87 /**
88  * gras_dd_cat_struct_t:
89  *
90  * Specific fields of a struct
91  */
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;
95
96 /**
97  * gras_dd_cat_union_t:
98  *
99  * Specific fields of a union
100  */
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;
105
106 /**
107  * gras_dd_cat_ref_t:
108  *
109  * Specific fields of a reference
110  */
111 typedef struct s_gras_dd_cat_ref {
112   int                           code;
113
114   /* callback used to return the referenced type number  */
115   gras_datadesc_type_cb_int_t   discriminant;
116 } gras_dd_cat_ref_t;
117
118
119 /**
120  * gras_dd_cat_array_t:
121  *
122  * Specific fields of an array
123  */
124 typedef struct s_gras_dd_cat_array {
125   int                           code;
126
127   /* element_count < 0 means dynamically defined */
128   long int                        fixed_size;
129
130   /* callback used to return the dynamic length */
131   gras_datadesc_type_cb_int_t dynamic_size;
132 } gras_dd_cat_array_t;
133
134 /**
135  * gras_dd_cat_ignored_t:
136  *
137  * Specific fields of an ignored field
138  */
139 typedef struct s_gras_dd_cat_ignored {
140   void                          *default_value;
141   void_f_pvoid_t                *free_func;
142 } gras_dd_cat_ignored_t;
143
144
145 /**
146  * u_gras_datadesc_category:
147  *
148  * Specific data to each possible category
149  */
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;
158 };
159
160
161 /****************************************/
162 /* The holy grail: type descriptor type */
163 /****************************************/
164 /**
165  * s_gras_datadesc_type:
166  *
167  * Type descriptor.
168  */
169 struct s_gras_datadesc_type {
170   /* headers for the data set */
171   unsigned int                         code;
172   char                                *name;
173   unsigned int                         name_len;
174         
175   /* payload */
176   long int                             size;
177   
178   long int                             alignment;
179   long int                             aligned_size;
180   
181   enum  e_gras_datadesc_type_category  category_code;
182   union u_gras_datadesc_category       category;
183   
184   gras_datadesc_type_cb_void_t         pre;
185   gras_datadesc_type_cb_void_t         post;
186 };
187
188 /***************************
189  * Type creation functions *
190  ***************************/
191 gras_error_t 
192 gras_ddt_new_scalar(const char                       *name,
193                     long int                         size,
194                     enum e_gras_dd_scalar_encoding   encoding,
195                     gras_datadesc_type_cb_void_t     cb,
196                     gras_datadesc_type_t           **dst);
197 gras_error_t 
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);
202 gras_error_t 
203 gras_ddt_new_struct_append(gras_datadesc_type_t            *struct_type,
204                            const char                      *name,
205                            gras_datadesc_type_t            *field_type,
206                            gras_datadesc_type_cb_void_t     pre,
207                            gras_datadesc_type_cb_void_t     post);
208 gras_error_t 
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);
213 gras_error_t 
214 gras_ddt_new_union_append(gras_datadesc_type_t            *union_type,
215                           const char                      *name,
216                           gras_datadesc_type_t            *field_type,
217                           gras_datadesc_type_cb_void_t     pre,
218                           gras_datadesc_type_cb_void_t     post);
219 gras_error_t 
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);
225 gras_error_t 
226 gras_ddt_new_array(const char                      *name,
227                    gras_datadesc_type_t            *element_type,
228                    long int                         fixed_size,
229                    gras_datadesc_type_cb_int_t      dynamic_size,
230                    gras_datadesc_type_cb_void_t     post,
231                    gras_datadesc_type_t           **dst);
232 gras_error_t 
233 gras_ddt_new_ignored(const char       *name,
234                      void             *default_value,
235                      void_f_pvoid_t   *free_func,
236                      long int                       size,
237                      long int                       alignment,
238                      gras_datadesc_type_cb_void_t     post,
239                      gras_datadesc_type_t           **dst);
240
241
242
243 #endif /* GRAS_DATADESC_PRIVATE_H */