Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Split the DataDesc in subfiles; implement ignored category; implement datatype compar...
[simgrid.git] / include / datadesc.h
1 /* $Id$ */
2
3 /* gras/datadesc.h - Describing the data you want to exchange               */
4
5 /* Authors: Martin Quinson                                                  */
6 /* Copyright (C) 2003 the OURAGAN project.                                  */
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_H
12 #define GRAS_DATADESC_H
13
14 #include <stddef.h>    /* offsetof() */
15 #include <sys/types.h>  /* size_t */
16 #include <stdarg.h>
17
18
19 /*! C++ users need love */
20 #ifndef BEGIN_DECL
21 # ifdef __cplusplus
22 #  define BEGIN_DECL extern "C" {
23 # else
24 #  define BEGIN_DECL 
25 # endif
26 #endif
27
28 /*! C++ users need love */
29 #ifndef END_DECL
30 # ifdef __cplusplus
31 #  define END_DECL }
32 # else
33 #  define END_DECL 
34 # endif
35 #endif
36 /* End of cruft for C++ */
37
38 BEGIN_DECL
39
40 /**
41  * Basic types we can embeed in DataDescriptors.
42  */
43 typedef enum
44   {CHAR_TYPE, DOUBLE_TYPE, FLOAT_TYPE, INT_TYPE, LONG_TYPE, SHORT_TYPE,
45    UNSIGNED_INT_TYPE, UNSIGNED_LONG_TYPE, UNSIGNED_SHORT_TYPE, STRUCT_TYPE}
46   DataTypes;
47 #define SIMPLE_TYPE_COUNT 9
48
49 /*!  \brief Describe a collection of data.
50  * 
51 ** A description of a collection of #type# data.  #repetitions# is used only
52 ** for arrays; it contains the number of elements.  #offset# is used only for
53 ** struct members in host format; it contains the offset of the member from the
54 ** beginning of the struct, taking into account internal padding added by the
55 ** compiler for alignment purposes.  #members#, #length#, and #tailPadding# are
56 ** used only for STRUCT_TYPE data; the #length#-long array #members# describes
57 ** the members of the nested struct, and #tailPadding# indicates how many
58 ** padding bytes the compiler adds to the end of the structure.
59 */
60
61 typedef struct DataDescriptorStruct {
62   DataTypes type;
63   size_t repetitions;
64   size_t offset;
65   /*@null@*/ struct DataDescriptorStruct *members;
66   size_t length;
67   size_t tailPadding;
68 } DataDescriptor;
69 /** DataDescriptor for an array */
70 #define SIMPLE_DATA(type,repetitions) \
71   {type, repetitions, 0, NULL, 0, 0}
72 /** DataDescriptor for an structure member */
73 #define SIMPLE_MEMBER(type,repetitions,offset) \
74   {type, repetitions, offset, NULL, 0, 0}
75 /** DataDescriptor for padding bytes */
76 #define PAD_BYTES(structType,lastMember,memberType,repetitions) \
77   sizeof(structType) - offsetof(structType, lastMember) - \
78   sizeof(memberType) * repetitions
79
80 /*
81 gras_error_t gras_datadesc_parse(const char       *def,
82                                  gras_datadesc__t **dst);
83 gras_error_t gras_datadesc_from_nws(const DataDescriptor *desc,
84                                     size_t                howmany,
85                                     gras_datadesc_t     **dst);
86 gras_error_t gras_datadesc_eq(const gras_datadesc_t *d1,
87                               const gras_datadesc_t *d2);
88 gras_error_t gras_datadesc_cpy(gras_datadesc_t  *src,
89                                gras_datadesc_t **dst);
90 gras_error_t gras_datadesc_sizeof_host(gras_datadesc_t *desc,
91                                        size_t          *dst);
92 gras_error_t gras_datadesc_sizeof_network(gras_datadesc_t *desc,
93                                           size_t          *dst);
94 */
95
96 typedef struct s_gras_datadesc_type gras_datadesc_type_t;
97
98 typedef void (*gras_datadesc_type_cb_void_t)(void                 *vars,
99                                              gras_datadesc_type_t *p_type,
100                                              void                 *data);
101 typedef int (*gras_datadesc_type_cb_int_t)(void                 *vars,
102                                            gras_datadesc_type_t *p_type,
103                                            void                 *data);
104
105
106
107 /* Create a new type and register it on the local machine */
108 #define gras_datadesc_declare_struct(   name,             code) \
109         gras_datadesc_declare_struct_cb(name, NULL, NULL, code)
110
111 #define gras_datadesc_declare_struct_add_name(   struct_code,field_name,field_type_name) \
112         gras_datadesc_declare_struct_add_name_cb(struct_code,field_name,field_type_name, NULL, NULL)
113
114 #define gras_datadesc_declare_struct_add_code(   struct_code,field_name,field_type_code) \
115         gras_datadesc_declare_struct_add_code_cb(struct_code,field_name,field_type_code, NULL, NULL)
116
117 gras_error_t 
118 gras_datadesc_declare_struct_cb(const char                   *name,
119                                 gras_datadesc_type_cb_void_t  pre_cb,
120                                 gras_datadesc_type_cb_void_t  post_cb,
121                                 long int                     *code);
122 gras_error_t 
123 gras_datadesc_declare_struct_add_name_cb(long int                      struct_code,
124                                          const char                   *field_name,
125                                          const char                   *field_type_name,
126                                          gras_datadesc_type_cb_void_t  pre_cb,
127                                          gras_datadesc_type_cb_void_t  post_cb);
128
129 gras_error_t 
130 gras_datadesc_declare_struct_add_code_cb(long int                      struct_code,
131                                          const char                   *field_name,
132                                          long int                      field_code,
133                                          gras_datadesc_type_cb_void_t  pre_cb,
134                                          gras_datadesc_type_cb_void_t  post_cb);
135 /* union */
136 #define gras_datadesc_declare_union(   name,             code) \
137         gras_datadesc_declare_union_cb(name, NULL, NULL, code)
138
139 #define gras_datadesc_declare_union_add_name(   union_code,field_name,field_type_name) \
140         gras_datadesc_declare_union_add_name_cb(union_code,field_name,field_type_name, NULL, NULL)
141
142 #define gras_datadesc_declare_union_add_code(   union_code,field_name,field_type_code) \
143         gras_datadesc_declare_union_add_code_cb(union_code,field_name,field_type_code, NULL, NULL)
144
145 gras_error_t 
146 gras_datadesc_declare_union_cb(const char                   *name,
147                                gras_datadesc_type_cb_int_t   field_count,
148                                gras_datadesc_type_cb_void_t  post,
149                                long int                     *code);
150 gras_error_t 
151 gras_datadesc_declare_union_add_name_cb(long int                      union_code,
152                                         const char                   *field_name,
153                                         const char                   *field_type_name,
154                                         gras_datadesc_type_cb_void_t  pre_cb,
155                                         gras_datadesc_type_cb_void_t  post_cb);
156 gras_error_t 
157 gras_datadesc_declare_union_add_code_cb(long int                      union_code,
158                                         const char                   *field_name,
159                                         long int                      field_code,
160                                         gras_datadesc_type_cb_void_t  pre_cb,
161                                         gras_datadesc_type_cb_void_t  post_cb);
162 /* ref */
163 #define gras_datadesc_declare_ref(name,ref_type, code) \
164         gras_datadesc_declare_ref_cb(name, ref_type, NULL, NULL, code)
165 #define gras_datadesc_declare_ref_disc(name,discriminant, code) \
166         gras_datadesc_declare_ref_cb(name, NULL, discriminant,  NULL, code)
167
168 gras_error_t
169 gras_datadesc_declare_ref_cb(const char                      *name,
170                              gras_datadesc_type_t            *referenced_type,
171                              gras_datadesc_type_cb_int_t      discriminant,
172                              gras_datadesc_type_cb_void_t     post,
173                              long int                        *code);
174 /* array */
175 #define gras_datadesc_declare_array(name,elm_type, size, code) \
176         gras_datadesc_declare_array_cb(name, elm_type, size, NULL,         NULL, code)
177 #define gras_datadesc_declare_array_dyn(name,elm_type, dynamic_size, code) \
178         gras_datadesc_declare_array_cb(name, elm_type, -1,   dynamic_size, NULL, code)
179
180 gras_error_t 
181 gras_datadesc_declare_array_cb(const char                      *name,
182                                gras_datadesc_type_t            *element_type,
183                                long int                         fixed_size,
184                                gras_datadesc_type_cb_int_t      dynamic_size,
185                                gras_datadesc_type_cb_void_t     post,
186                                long int                        *code);
187
188 END_DECL
189
190 #endif /* GRAS_DATADESC_H */