Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
4001167c330b191e3d2852039aee67fb44052f59
[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_datadesc_by_id(struct_code,&struct_type));
38   TRY(gras_datadesc_by_name(field_type_name,&field_type));
39
40   TRY(gras_ddt_new_struct_append(struct_type,
41                                  field_name,  field_type,
42                                  pre_cb,      post_cb));
43   
44   return no_error;
45 }
46 gras_error_t 
47 gras_datadesc_declare_struct_add_code_cb(long int    struct_code,
48                                          const char *field_name,
49                                          long int    field_code,
50                                          gras_datadesc_type_cb_void_t     pre_cb,
51                                          gras_datadesc_type_cb_void_t     post_cb) {
52   gras_error_t errcode;
53   gras_datadesc_type_t *struct_type;
54   gras_datadesc_type_t *field_type;
55   
56   TRY(gras_datadesc_by_id(struct_code,&struct_type));
57   TRY(gras_datadesc_by_id(field_code, &field_type));
58
59   TRY(gras_ddt_new_struct_append(struct_type,
60                                  field_name,  field_type,
61                                  pre_cb,      post_cb));
62   
63   return no_error;
64 }
65
66 gras_error_t 
67 gras_datadesc_declare_union_cb(const char                   *name,
68                                gras_datadesc_type_cb_int_t   field_count,
69                                gras_datadesc_type_cb_void_t  post,
70                                long int                     *code) {
71   gras_error_t errcode;
72   gras_datadesc_type_t *type;
73   TRY(gras_ddt_new_union(name, field_count, post, &type));
74   TRY(gras_ddt_register(type));
75   *code = type->code;
76   return no_error;
77 }
78
79 gras_error_t 
80 gras_datadesc_declare_union_add_name_cb(long int                      union_code,
81                                         const char                   *field_name,
82                                         const char                   *field_type_name,
83                                         gras_datadesc_type_cb_void_t  pre_cb,
84                                         gras_datadesc_type_cb_void_t  post_cb) {
85   gras_error_t errcode;
86   gras_datadesc_type_t *union_type;
87   gras_datadesc_type_t *field_type;
88   
89   TRY(gras_datadesc_by_id  (union_code,      &union_type));
90   TRY(gras_datadesc_by_name(field_type_name, &field_type));
91
92   TRY(gras_ddt_new_union_append(union_type,
93                                 field_name,  field_type,
94                                 pre_cb,      post_cb));
95   
96   return no_error;
97 }
98 gras_error_t 
99 gras_datadesc_declare_union_add_code_cb(long int                      union_code,
100                                         const char                   *field_name,
101                                         long int                      field_code,
102                                         gras_datadesc_type_cb_void_t  pre_cb,
103                                         gras_datadesc_type_cb_void_t  post_cb) {
104   gras_error_t errcode;
105   gras_datadesc_type_t *union_type;
106   gras_datadesc_type_t *field_type;
107   
108   TRY(gras_datadesc_by_id(union_code, &union_type));
109   TRY(gras_datadesc_by_id(field_code, &field_type));
110
111   TRY(gras_ddt_new_union_append(union_type,
112                                 field_name,  field_type,
113                                 pre_cb,      post_cb));
114   
115   return no_error;
116 }
117
118 gras_error_t
119 gras_datadesc_declare_ref_cb(const char                      *name,
120                              gras_datadesc_type_t            *referenced_type,
121                              gras_datadesc_type_cb_int_t      discriminant,
122                              gras_datadesc_type_cb_void_t     post,
123                              long int                        *code){
124   gras_error_t errcode;
125   gras_datadesc_type_t *type;
126   TRY(gras_ddt_new_ref(name, referenced_type,discriminant,post, &type));
127   TRY(gras_ddt_register(type));
128   *code = type->code;
129   return no_error;
130 }
131
132 gras_error_t 
133 gras_datadesc_declare_array_cb(const char                      *name,
134                                gras_datadesc_type_t            *element_type,
135                                long int                         fixed_size,
136                                gras_datadesc_type_cb_int_t      dynamic_size,
137                                gras_datadesc_type_cb_void_t     post,
138                                long int                        *code){
139   gras_error_t errcode;
140   gras_datadesc_type_t *type;
141   TRY(gras_ddt_new_array(name, element_type, fixed_size, dynamic_size, post, &type));
142   TRY(gras_ddt_register(type));
143   *code = type->code;
144   return no_error;
145 }
146
147 /**
148  * gras_datadesc_parse:
149  *
150  * Parse a C type declaration, and declare locally the corresponding type description
151  */
152 gras_error_t
153 gras_datadesc_parse(const char *name,
154                     const char *definition,
155                     long int   *code) {
156   gras_error_t errcode;
157   gras_datadesc_type_t *type;
158   TRY(gras_ddt_new_parse(name,definition,&type));
159   TRY(gras_ddt_register( type));
160   *code = type->code;
161   return no_error;
162 }
163
164 /**
165  * gras_datadesc_parse:
166  *
167  * Parse a NWS type declaration, and declare locally the corresponding type description
168  */
169 gras_error_t
170 gras_datadesc_from_nws(const char           *name,
171                        const DataDescriptor *desc,
172                        size_t                howmany,
173                        long int             *code) {
174
175   gras_error_t errcode;
176   gras_datadesc_type_t *type;
177   TRY(gras_ddt_new_from_nws(name,desc,howmany,&type));
178   TRY(gras_ddt_register(type));
179   *code = type->code;
180   return no_error;
181 }