Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
J'en ai marre de faire des messages detailles. 'Current state' ;)
[simgrid.git] / src / gras / DataDesc / ddt_declare.c
1 /* $Id$ */
2
3 /* ddt_declare - user functions to create datatypes on locale machine       */
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 #include "DataDesc/datadesc_private.h"
12
13 gras_error_t 
14 gras_datadesc_declare_struct_cb(const char                   *name,
15                                 gras_datadesc_type_cb_void_t  pre,
16                                 gras_datadesc_type_cb_void_t  post,
17                                 long int                     *code) {
18   gras_error_t errcode;
19   gras_datadesc_type_t *type;
20   TRY(gras_ddt_new_struct(name, pre, post, &type));
21   TRY(gras_ddt_register(type));
22   *code = type->code;
23   return no_error;
24 }
25
26 gras_error_t 
27 gras_datadesc_declare_struct_add_name_cb(long int    struct_code,
28                                          const char *field_name,
29                                          const char *field_type_name,
30                                          gras_datadesc_type_cb_void_t     pre_cb,
31                                          gras_datadesc_type_cb_void_t     post_cb) {
32
33   gras_error_t errcode;
34   gras_datadesc_type_t *struct_type;
35   gras_datadesc_type_t *field_type;
36   
37   TRY(gras_set_get_by_id(gras_datadesc_set_local,struct_code,
38                          (gras_set_elm_t**)struct_type));
39   TRY(gras_set_get_by_name(gras_datadesc_set_local,field_type_name,
40                          (gras_set_elm_t**)field_type));
41
42   TRY(gras_ddt_new_struct_append(struct_type,
43                                  field_name,  field_type,
44                                  pre_cb,      post_cb));
45   
46   return no_error;
47 }
48 gras_error_t 
49 gras_datadesc_declare_struct_add_code_cb(long int    struct_code,
50                                          const char *field_name,
51                                          long int    field_code,
52                                          gras_datadesc_type_cb_void_t     pre_cb,
53                                          gras_datadesc_type_cb_void_t     post_cb) {
54   gras_error_t errcode;
55   gras_datadesc_type_t *struct_type;
56   gras_datadesc_type_t *field_type;
57   
58   TRY(gras_set_get_by_id(gras_datadesc_set_local,struct_code,
59                          (gras_set_elm_t**)struct_type));
60   TRY(gras_set_get_by_id(gras_datadesc_set_local,field_code,
61                          (gras_set_elm_t**)field_type));
62
63   TRY(gras_ddt_new_struct_append(struct_type,
64                                  field_name,  field_type,
65                                  pre_cb,      post_cb));
66   
67   return no_error;
68 }
69
70 gras_error_t 
71 gras_datadesc_declare_union_cb(const char                   *name,
72                                gras_datadesc_type_cb_int_t   field_count,
73                                gras_datadesc_type_cb_void_t  post,
74                                long int                     *code) {
75   gras_error_t errcode;
76   gras_datadesc_type_t *type;
77   TRY(gras_ddt_new_union(name, field_count, post, &type));
78   TRY(gras_ddt_register(type));
79   *code = type->code;
80   return no_error;
81 }
82
83 gras_error_t 
84 gras_datadesc_declare_union_add_name_cb(long int                      union_code,
85                                         const char                   *field_name,
86                                         const char                   *field_type_name,
87                                         gras_datadesc_type_cb_void_t  pre_cb,
88                                         gras_datadesc_type_cb_void_t  post_cb) {
89   gras_error_t errcode;
90   gras_datadesc_type_t *union_type;
91   gras_datadesc_type_t *field_type;
92   
93   TRY(gras_set_get_by_id(gras_datadesc_set_local,union_code,
94                          (gras_set_elm_t**)union_type));
95   TRY(gras_set_get_by_name(gras_datadesc_set_local,field_type_name,
96                          (gras_set_elm_t**)field_type));
97
98   TRY(gras_ddt_new_union_append(union_type,
99                                 field_name,  field_type,
100                                 pre_cb,      post_cb));
101   
102   return no_error;
103 }
104 gras_error_t 
105 gras_datadesc_declare_union_add_code_cb(long int                      union_code,
106                                         const char                   *field_name,
107                                         long int                      field_code,
108                                         gras_datadesc_type_cb_void_t  pre_cb,
109                                         gras_datadesc_type_cb_void_t  post_cb) {
110   gras_error_t errcode;
111   gras_datadesc_type_t *union_type;
112   gras_datadesc_type_t *field_type;
113   
114   TRY(gras_set_get_by_id(gras_datadesc_set_local,union_code,
115                          (gras_set_elm_t**)union_type));
116   TRY(gras_set_get_by_id(gras_datadesc_set_local,field_code,
117                          (gras_set_elm_t**)field_type));
118
119   TRY(gras_ddt_new_union_append(union_type,
120                                 field_name,  field_type,
121                                 pre_cb,      post_cb));
122   
123   return no_error;
124 }
125
126 gras_error_t
127 gras_datadesc_declare_ref_cb(const char                      *name,
128                              gras_datadesc_type_t            *referenced_type,
129                              gras_datadesc_type_cb_int_t      discriminant,
130                              gras_datadesc_type_cb_void_t     post,
131                              long int                        *code){
132   gras_error_t errcode;
133   gras_datadesc_type_t *type;
134   TRY(gras_ddt_new_ref(name, referenced_type,discriminant,post, &type));
135   TRY(gras_ddt_register(type));
136   *code = type->code;
137   return no_error;
138 }
139
140 gras_error_t 
141 gras_datadesc_declare_array_cb(const char                      *name,
142                                gras_datadesc_type_t            *element_type,
143                                long int                         fixed_size,
144                                gras_datadesc_type_cb_int_t      dynamic_size,
145                                gras_datadesc_type_cb_void_t     post,
146                                long int                        *code){
147   gras_error_t errcode;
148   gras_datadesc_type_t *type;
149   TRY(gras_ddt_new_array(name, element_type, fixed_size, dynamic_size, post, &type));
150   TRY(gras_ddt_register(type));
151   *code = type->code;
152   return no_error;
153 }
154
155 /**
156  * gras_datadesc_parse:
157  *
158  * Parse a C type declaration, and declare locally the corresponding type description
159  */
160 gras_error_t
161 gras_datadesc_parse(const char *name,
162                     const char *definition,
163                     long int   *code) {
164   gras_error_t errcode;
165   gras_datadesc_type_t *type;
166   TRY(gras_ddt_new_parse(name,definition,&type));
167   TRY(gras_ddt_register( type));
168   *code = type->code;
169   return no_error;
170 }
171
172 /**
173  * gras_datadesc_parse:
174  *
175  * Parse a NWS type declaration, and declare locally the corresponding type description
176  */
177 gras_error_t
178 gras_datadesc_from_nws(const char           *name,
179                        const DataDescriptor *desc,
180                        size_t                howmany,
181                        long int             *code) {
182
183   gras_error_t errcode;
184   gras_datadesc_type_t *type;
185   TRY(gras_ddt_new_from_nws(name,desc,howmany,&type));
186   TRY(gras_ddt_register(type));
187   *code = type->code;
188   return no_error;
189 }