Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
New datadesc implementation. Reformulating of Grassouillet (take error codes, cosmeti...
[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 #define aligned(v, a) (((v) + (a - 1)) & ~(a - 1))
18
19
20
21 /**********************************************************/
22 /* Actual definitions of the stuff in the type descriptor */
23 /**********************************************************/
24
25 /**
26  * e_gras_datadesc_type_category:
27  *
28  * Defines all possible type categories
29  */
30 typedef enum e_gras_datadesc_type_category {
31         e_gras_datadesc_type_cat_undefined = 0,
32
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,
39
40         e_gras_datadesc_type_cat_invalid
41 } gras_datadesc_type_category_t;
42
43
44 /*------------------------------------------------*/
45 /* definitions of specific data for each category */
46 /*------------------------------------------------*/
47 /**
48  * s_gras_dd_cat_field:
49  *
50  * Fields of struct and union
51  */
52 typedef struct s_gras_dd_cat_field {
53
54   char                        *name;
55   long int                     offset; /* only for struct */
56   int                          code;
57   
58   gras_datadesc_type_cb_void_t pre;
59   gras_datadesc_type_cb_void_t post;
60
61 } gras_dd_cat_field_t;
62 void gras_dd_cat_field_free(void *f);
63
64 /**
65  * gras_dd_cat_scalar_t:
66  *
67  * Specific fields of a scalar
68  */
69 enum e_gras_dd_scalar_encoding {
70   e_gras_dd_scalar_encoding_undefined = 0,
71   
72   e_gras_dd_scalar_encoding_uint,
73   e_gras_dd_scalar_encoding_sint,
74   e_gras_dd_scalar_encoding_float,
75   
76   e_gras_dd_scalar_encoding_invalid 
77 };
78 typedef struct s_gras_dd_cat_scalar {
79   enum e_gras_dd_scalar_encoding encoding;
80 } gras_dd_cat_scalar_t;
81
82 /**
83  * gras_dd_cat_struct_t:
84  *
85  * Specific fields of a struct
86  */
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;
90
91 /**
92  * gras_dd_cat_union_t:
93  *
94  * Specific fields of a union
95  */
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;
100
101 /**
102  * gras_dd_cat_ref_t:
103  *
104  * Specific fields of a reference
105  */
106 typedef struct s_gras_dd_cat_ref {
107   int                           code;
108
109   /* callback used to return the referenced type number  */
110   gras_datadesc_type_cb_int_t   discriminant;
111 } gras_dd_cat_ref_t;
112
113
114 /**
115  * gras_dd_cat_array_t:
116  *
117  * Specific fields of an array
118  */
119 typedef struct s_gras_dd_cat_array {
120   int                           code;
121
122   /* element_count < 0 means dynamically defined */
123   long int                        fixed_size;
124
125   /* callback used to return the dynamic length */
126   gras_datadesc_type_cb_int_t dynamic_size;
127 } gras_dd_cat_array_t;
128
129 /**
130  * gras_dd_cat_ignored_t:
131  *
132  * Specific fields of an ignored field
133  */
134 typedef struct s_gras_dd_cat_ignored {
135         void                            *default_value;
136 } gras_dd_cat_ignored_t;
137
138
139 /**
140  * u_gras_datadesc_category:
141  *
142  * Specific data to each possible category
143  */
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;
152 };
153
154
155 /****************************************/
156 /* The holy grail: type descriptor type */
157 /****************************************/
158 /**
159  * s_gras_datadesc_type:
160  *
161  * Type descriptor.
162  */
163 struct s_gras_datadesc_type {
164   /* headers for the data set */
165   unsigned int                         code;
166   char                                *name;
167   unsigned int                         name_len;
168         
169   /* payload */
170   long int                             size;
171   
172   long int                             alignment;
173   long int                             aligned_size;
174   
175   enum  e_gras_datadesc_type_category  category_code;
176   union u_gras_datadesc_category       category;
177   
178   gras_datadesc_type_cb_void_t         pre;
179   gras_datadesc_type_cb_void_t         post;
180 };
181
182 /***************************
183  * Type creation functions *
184  ***************************/
185 gras_error_t 
186 gras_ddt_new_scalar(const char                       *name,
187                     long int                         size,
188                     enum e_gras_dd_scalar_encoding   encoding,
189                     gras_datadesc_type_cb_void_t     cb,
190                     gras_datadesc_type_t           **dst);
191 gras_error_t 
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);
196 gras_error_t 
197 gras_ddt_new_struct_append(gras_datadesc_type_t            *struct_type,
198                            const char                      *name,
199                            gras_datadesc_type_t            *field_type,
200                            gras_datadesc_type_cb_void_t     pre,
201                            gras_datadesc_type_cb_void_t     post);
202 gras_error_t 
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);
207 gras_error_t 
208 gras_ddt_new_union_append(gras_datadesc_type_t            *union_type,
209                           const char                      *name,
210                           gras_datadesc_type_t            *field_type,
211                           gras_datadesc_type_cb_void_t     pre,
212                           gras_datadesc_type_cb_void_t     post);
213 gras_error_t 
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);
219 gras_error_t 
220 gras_ddt_new_array(const char                      *name,
221                    gras_datadesc_type_t            *element_type,
222                    long int                         fixed_size,
223                    gras_datadesc_type_cb_int_t      dynamic_size,
224                    gras_datadesc_type_cb_void_t     post,
225                    gras_datadesc_type_t           **dst);
226
227
228
229 #endif /* GRAS_DATADESC_PRIVATE_H */