Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Split the DataDesc in subfiles; implement ignored category; implement datatype compar...
[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 extern gras_set_t *gras_datadesc_set_local;
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   void_f_pvoid_t                *free_func;
137 } gras_dd_cat_ignored_t;
138
139
140 /**
141  * u_gras_datadesc_category:
142  *
143  * Specific data to each possible category
144  */
145 union u_gras_datadesc_category {
146         void                  *undefined_data;
147         gras_dd_cat_scalar_t   scalar_data;
148         gras_dd_cat_struct_t   struct_data;
149         gras_dd_cat_union_t    union_data;
150         gras_dd_cat_ref_t      ref_data;
151         gras_dd_cat_array_t    array_data;
152         gras_dd_cat_ignored_t  ignored_data;
153 };
154
155
156 /****************************************/
157 /* The holy grail: type descriptor type */
158 /****************************************/
159 /**
160  * s_gras_datadesc_type:
161  *
162  * Type descriptor.
163  */
164 struct s_gras_datadesc_type {
165   /* headers for the data set */
166   unsigned int                         code;
167   char                                *name;
168   unsigned int                         name_len;
169         
170   /* payload */
171   long int                             size;
172   
173   long int                             alignment;
174   long int                             aligned_size;
175   
176   enum  e_gras_datadesc_type_category  category_code;
177   union u_gras_datadesc_category       category;
178   
179   gras_datadesc_type_cb_void_t         pre;
180   gras_datadesc_type_cb_void_t         post;
181 };
182
183 /***************************
184  * Type creation functions *
185  ***************************/
186 gras_error_t 
187 gras_ddt_new_scalar(const char                       *name,
188                     long int                         size,
189                     enum e_gras_dd_scalar_encoding   encoding,
190                     gras_datadesc_type_cb_void_t     cb,
191                     gras_datadesc_type_t           **dst);
192 gras_error_t 
193 gras_ddt_new_struct(const char                      *name,
194                     gras_datadesc_type_cb_void_t     pre,
195                     gras_datadesc_type_cb_void_t     post,
196                     gras_datadesc_type_t           **dst);
197 gras_error_t 
198 gras_ddt_new_struct_append(gras_datadesc_type_t            *struct_type,
199                            const char                      *name,
200                            gras_datadesc_type_t            *field_type,
201                            gras_datadesc_type_cb_void_t     pre,
202                            gras_datadesc_type_cb_void_t     post);
203 gras_error_t 
204 gras_ddt_new_union(const char                      *name,
205                    gras_datadesc_type_cb_int_t      field_count,
206                    gras_datadesc_type_cb_void_t     post,
207                    gras_datadesc_type_t           **dst);
208 gras_error_t 
209 gras_ddt_new_union_append(gras_datadesc_type_t            *union_type,
210                           const char                      *name,
211                           gras_datadesc_type_t            *field_type,
212                           gras_datadesc_type_cb_void_t     pre,
213                           gras_datadesc_type_cb_void_t     post);
214 gras_error_t 
215 gras_ddt_new_ref(const char                      *name,
216                  gras_datadesc_type_t            *referenced_type,
217                  gras_datadesc_type_cb_int_t      discriminant,
218                  gras_datadesc_type_cb_void_t     post,
219                  gras_datadesc_type_t           **dst);
220 gras_error_t 
221 gras_ddt_new_array(const char                      *name,
222                    gras_datadesc_type_t            *element_type,
223                    long int                         fixed_size,
224                    gras_datadesc_type_cb_int_t      dynamic_size,
225                    gras_datadesc_type_cb_void_t     post,
226                    gras_datadesc_type_t           **dst);
227 gras_error_t 
228 gras_ddt_new_ignored(const char       *name,
229                      void             *default_value,
230                      void_f_pvoid_t   *free_func,
231                      long int                       size,
232                      long int                       alignment,
233                      gras_datadesc_type_cb_void_t     post,
234                      gras_datadesc_type_t           **dst);
235
236
237
238 #endif /* GRAS_DATADESC_PRIVATE_H */