3 /* ddt_declare - user functions to create datatypes on locale machine */
5 /* Authors: Olivier Aumage, Martin Quinson */
6 /* Copyright (C) 2003, 2004 the GRAS posse. */
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. */
11 #include "DataDesc/datadesc_private.h"
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,
19 gras_datadesc_type_t *type;
20 TRY(gras_ddt_new_struct(name, pre, post, &type));
21 TRY(gras_ddt_register(type));
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) {
34 gras_datadesc_type_t *struct_type;
35 gras_datadesc_type_t *field_type;
37 TRY(gras_datadesc_by_id(struct_code,&struct_type));
38 TRY(gras_datadesc_by_name(field_type_name,&field_type));
40 TRY(gras_ddt_new_struct_append(struct_type,
41 field_name, field_type,
47 gras_datadesc_declare_struct_add_code_cb(long int struct_code,
48 const char *field_name,
50 gras_datadesc_type_cb_void_t pre_cb,
51 gras_datadesc_type_cb_void_t post_cb) {
53 gras_datadesc_type_t *struct_type;
54 gras_datadesc_type_t *field_type;
56 TRY(gras_datadesc_by_id(struct_code,&struct_type));
57 TRY(gras_datadesc_by_id(field_code, &field_type));
59 TRY(gras_ddt_new_struct_append(struct_type,
60 field_name, field_type,
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,
72 gras_datadesc_type_t *type;
73 TRY(gras_ddt_new_union(name, field_count, post, &type));
74 TRY(gras_ddt_register(type));
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) {
86 gras_datadesc_type_t *union_type;
87 gras_datadesc_type_t *field_type;
89 TRY(gras_datadesc_by_id (union_code, &union_type));
90 TRY(gras_datadesc_by_name(field_type_name, &field_type));
92 TRY(gras_ddt_new_union_append(union_type,
93 field_name, field_type,
99 gras_datadesc_declare_union_add_code_cb(long int union_code,
100 const char *field_name,
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;
108 TRY(gras_datadesc_by_id(union_code, &union_type));
109 TRY(gras_datadesc_by_id(field_code, &field_type));
111 TRY(gras_ddt_new_union_append(union_type,
112 field_name, field_type,
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,
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));
133 gras_datadesc_declare_array_cb(const char *name,
134 gras_datadesc_type_t *element_type,
136 gras_datadesc_type_cb_int_t dynamic_size,
137 gras_datadesc_type_cb_void_t post,
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));
148 * gras_datadesc_parse:
150 * Parse a C type declaration, and declare locally the corresponding type description
153 gras_datadesc_parse(const char *name,
154 const char *definition,
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));
165 * gras_datadesc_parse:
167 * Parse a NWS type declaration, and declare locally the corresponding type description
170 gras_datadesc_from_nws(const char *name,
171 const DataDescriptor *desc,
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));