NativeEnumerated.c vars NULL init and check
[com/asn1c.git] / tests / tests-asn1c-compiler / 141-component-relation-OK.asn1.-P
1
2 /*** <<< INCLUDES [Frame] >>> ***/
3
4 #include "ConstrainedInteger.h"
5 #include <ANY.h>
6 #include <asn_ioc.h>
7 #include "PrimitiveMessage.h"
8 #include "ComplexMessage.h"
9 #include <OPEN_TYPE.h>
10 #include <constr_CHOICE.h>
11 #include <constr_SEQUENCE.h>
12
13 /*** <<< DEPS [Frame] >>> ***/
14
15 typedef enum value_PR {
16         value_PR_NOTHING,       /* No components present */
17         value_PR_PrimitiveMessage,
18         value_PR_ComplexMessage
19 } value_PR;
20
21 /*** <<< TYPE-DECLS [Frame] >>> ***/
22
23 typedef struct Frame {
24         ConstrainedInteger_t     ident;
25         struct value {
26                 value_PR present;
27                 union Frame__value_u {
28                         PrimitiveMessage_t       PrimitiveMessage;
29                         ComplexMessage_t         ComplexMessage;
30                 } choice;
31                 
32                 /* Context for parsing across buffer boundaries */
33                 asn_struct_ctx_t _asn_ctx;
34         } value;
35         /*
36          * This type is extensible,
37          * possible extensions are below.
38          */
39         
40         /* Context for parsing across buffer boundaries */
41         asn_struct_ctx_t _asn_ctx;
42 } Frame_t;
43
44 /*** <<< FUNC-DECLS [Frame] >>> ***/
45
46 extern asn_TYPE_descriptor_t asn_DEF_Frame;
47
48 /*** <<< IOC-TABLES [Frame] >>> ***/
49
50 static const long asn_VAL_1_primMessage = 1;
51 static const long asn_VAL_2_cplxMessage = 2;
52 static const asn_ioc_cell_t asn_IOS_FrameTypes_1_rows[] = {
53         { "&id", aioc__value, &asn_DEF_ConstrainedInteger, &asn_VAL_1_primMessage },
54         { "&Type", aioc__type, &asn_DEF_PrimitiveMessage },
55         { "&id", aioc__value, &asn_DEF_ConstrainedInteger, &asn_VAL_2_cplxMessage },
56         { "&Type", aioc__type, &asn_DEF_ComplexMessage }
57 };
58 static const asn_ioc_set_t asn_IOS_FrameTypes_1[] = {
59         { 2, 2, asn_IOS_FrameTypes_1_rows }
60 };
61
62 /*** <<< CODE [Frame] >>> ***/
63
64 static int
65 memb_ident_constraint_1(const asn_TYPE_descriptor_t *td, const void *sptr,
66                         asn_app_constraint_failed_f *ctfailcb, void *app_key) {
67         long value;
68         
69         if(!sptr) {
70                 ASN__CTFAIL(app_key, td, sptr,
71                         "%s: value not given (%s:%d)",
72                         td->name, __FILE__, __LINE__);
73                 return -1;
74         }
75         
76         value = *(const long *)sptr;
77         
78         if((value >= 0 && value <= 32767)) {
79                 /* Constraint check succeeded */
80                 return 0;
81         } else {
82                 ASN__CTFAIL(app_key, td, sptr,
83                         "%s: constraint failed (%s:%d)",
84                         td->name, __FILE__, __LINE__);
85                 return -1;
86         }
87 }
88
89 static asn_type_selector_result_t
90 select_Frame_value_type(const asn_TYPE_descriptor_t *parent_type, const void *parent_sptr) {
91         asn_type_selector_result_t result = {0, 0};
92         const asn_ioc_set_t *itable = asn_IOS_FrameTypes_1;
93         size_t constraining_column = 0; /* &id */
94         size_t for_column = 1; /* &Type */
95         size_t row, presence_index = 0;
96         const long *constraining_value = (const long *)((const char *)parent_sptr + offsetof(struct Frame, ident));
97         
98         for(row=0; row < itable->rows_count; row++) {
99             const asn_ioc_cell_t *constraining_cell = &itable->rows[row * itable->columns_count + constraining_column];
100             const asn_ioc_cell_t *type_cell = &itable->rows[row * itable->columns_count + for_column];
101         
102             if(type_cell->cell_kind == aioc__undefined)
103                 continue;
104         
105             presence_index++;
106             if(constraining_cell->type_descriptor->op->compare_struct(constraining_cell->type_descriptor, constraining_value, constraining_cell->value_sptr) == 0) {
107                 result.type_descriptor = type_cell->type_descriptor;
108                 result.presence_index = presence_index;
109                 break;
110             }
111         }
112         
113         return result;
114 }
115
116 static int
117 memb_value_constraint_1(const asn_TYPE_descriptor_t *td, const void *sptr,
118                         asn_app_constraint_failed_f *ctfailcb, void *app_key) {
119         
120         if(!sptr) {
121                 ASN__CTFAIL(app_key, td, sptr,
122                         "%s: value not given (%s:%d)",
123                         td->name, __FILE__, __LINE__);
124                 return -1;
125         }
126         
127         
128         if(1 /* No applicable constraints whatsoever */) {
129                 /* Nothing is here. See below */
130         }
131         
132         return td->encoding_constraints.general_constraints(td, sptr, ctfailcb, app_key);
133 }
134
135
136 /*** <<< STAT-DEFS [Frame] >>> ***/
137
138 static asn_TYPE_member_t asn_MBR_value_3[] = {
139         { ATF_NOFLAGS, 0, offsetof(struct value, choice.PrimitiveMessage),
140                 .tag = (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)),
141                 .tag_mode = 0,
142                 .type = &asn_DEF_PrimitiveMessage,
143                 .type_selector = 0,
144                 { .oer_constraints = 0, .per_constraints = 0, .general_constraints = 0 },
145                 0, 0, /* No default value */
146                 .name = "PrimitiveMessage"
147                 },
148         { ATF_NOFLAGS, 0, offsetof(struct value, choice.ComplexMessage),
149                 .tag = (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)),
150                 .tag_mode = 0,
151                 .type = &asn_DEF_ComplexMessage,
152                 .type_selector = 0,
153                 { .oer_constraints = 0, .per_constraints = 0, .general_constraints = 0 },
154                 0, 0, /* No default value */
155                 .name = "ComplexMessage"
156                 },
157 };
158 static const asn_TYPE_tag2member_t asn_MAP_value_tag2el_3[] = {
159     { (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)), 0, 0, 1 }, /* PrimitiveMessage */
160     { (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)), 1, -1, 0 } /* ComplexMessage */
161 };
162 static asn_CHOICE_specifics_t asn_SPC_value_specs_3 = {
163         sizeof(struct value),
164         offsetof(struct value, _asn_ctx),
165         offsetof(struct value, present),
166         sizeof(((struct value *)0)->present),
167         .tag2el = asn_MAP_value_tag2el_3,
168         .tag2el_count = 2,      /* Count of tags in the map */
169         0, 0,
170         .first_extension = -1   /* Extensions start */
171 };
172 static /* Use -fall-defs-global to expose */
173 asn_TYPE_descriptor_t asn_DEF_value_3 = {
174         "value",
175         "value",
176         &asn_OP_OPEN_TYPE,
177         0,      /* No effective tags (pointer) */
178         0,      /* No effective tags (count) */
179         0,      /* No tags (pointer) */
180         0,      /* No tags (count) */
181         { 0, 0, OPEN_TYPE_constraint },
182         asn_MBR_value_3,
183         2,      /* Elements count */
184         &asn_SPC_value_specs_3  /* Additional specs */
185 };
186
187 static asn_TYPE_member_t asn_MBR_Frame_1[] = {
188         { ATF_NOFLAGS, 0, offsetof(struct Frame, ident),
189                 .tag = (ASN_TAG_CLASS_CONTEXT | (0 << 2)),
190                 .tag_mode = -1, /* IMPLICIT tag at current level */
191                 .type = &asn_DEF_ConstrainedInteger,
192                 .type_selector = 0,
193                 { .oer_constraints = 0, .per_constraints = 0, .general_constraints =  memb_ident_constraint_1 },
194                 0, 0, /* No default value */
195                 .name = "ident"
196                 },
197         { ATF_OPEN_TYPE | ATF_NOFLAGS, 0, offsetof(struct Frame, value),
198                 .tag = (ASN_TAG_CLASS_CONTEXT | (1 << 2)),
199                 .tag_mode = +1, /* EXPLICIT tag at current level */
200                 .type = &asn_DEF_value_3,
201                 .type_selector = select_Frame_value_type,
202                 { .oer_constraints = 0, .per_constraints = 0, .general_constraints =  memb_value_constraint_1 },
203                 0, 0, /* No default value */
204                 .name = "value"
205                 },
206 };
207 static const ber_tlv_tag_t asn_DEF_Frame_tags_1[] = {
208         (ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
209 };
210 static const asn_TYPE_tag2member_t asn_MAP_Frame_tag2el_1[] = {
211     { (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 }, /* ident */
212     { (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 1, 0, 0 } /* value */
213 };
214 static asn_SEQUENCE_specifics_t asn_SPC_Frame_specs_1 = {
215         sizeof(struct Frame),
216         offsetof(struct Frame, _asn_ctx),
217         .tag2el = asn_MAP_Frame_tag2el_1,
218         .tag2el_count = 2,      /* Count of tags in the map */
219         0, 0, 0,        /* Optional elements (not needed) */
220         2,      /* First extension addition */
221 };
222 asn_TYPE_descriptor_t asn_DEF_Frame = {
223         "Frame",
224         "Frame",
225         &asn_OP_SEQUENCE,
226         asn_DEF_Frame_tags_1,
227         sizeof(asn_DEF_Frame_tags_1)
228                 /sizeof(asn_DEF_Frame_tags_1[0]), /* 1 */
229         asn_DEF_Frame_tags_1,   /* Same as above */
230         sizeof(asn_DEF_Frame_tags_1)
231                 /sizeof(asn_DEF_Frame_tags_1[0]), /* 1 */
232         { 0, 0, SEQUENCE_constraint },
233         asn_MBR_Frame_1,
234         2,      /* Elements count */
235         &asn_SPC_Frame_specs_1  /* Additional specs */
236 };
237
238
239 /*** <<< INCLUDES [ConstrainedInteger] >>> ***/
240
241 #include <NativeInteger.h>
242
243 /*** <<< TYPE-DECLS [ConstrainedInteger] >>> ***/
244
245 typedef long     ConstrainedInteger_t;
246
247 /*** <<< FUNC-DECLS [ConstrainedInteger] >>> ***/
248
249 extern asn_TYPE_descriptor_t asn_DEF_ConstrainedInteger;
250 asn_struct_free_f ConstrainedInteger_free;
251 asn_struct_print_f ConstrainedInteger_print;
252 asn_constr_check_f ConstrainedInteger_constraint;
253 ber_type_decoder_f ConstrainedInteger_decode_ber;
254 der_type_encoder_f ConstrainedInteger_encode_der;
255 xer_type_decoder_f ConstrainedInteger_decode_xer;
256 xer_type_encoder_f ConstrainedInteger_encode_xer;
257
258 /*** <<< CODE [ConstrainedInteger] >>> ***/
259
260 int
261 ConstrainedInteger_constraint(const asn_TYPE_descriptor_t *td, const void *sptr,
262                         asn_app_constraint_failed_f *ctfailcb, void *app_key) {
263         long value;
264         
265         if(!sptr) {
266                 ASN__CTFAIL(app_key, td, sptr,
267                         "%s: value not given (%s:%d)",
268                         td->name, __FILE__, __LINE__);
269                 return -1;
270         }
271         
272         value = *(const long *)sptr;
273         
274         if((value >= 0 && value <= 32767)) {
275                 /* Constraint check succeeded */
276                 return 0;
277         } else {
278                 ASN__CTFAIL(app_key, td, sptr,
279                         "%s: constraint failed (%s:%d)",
280                         td->name, __FILE__, __LINE__);
281                 return -1;
282         }
283 }
284
285 /*
286  * This type is implemented using NativeInteger,
287  * so here we adjust the DEF accordingly.
288  */
289
290 /*** <<< STAT-DEFS [ConstrainedInteger] >>> ***/
291
292 static const ber_tlv_tag_t asn_DEF_ConstrainedInteger_tags_1[] = {
293         (ASN_TAG_CLASS_UNIVERSAL | (2 << 2))
294 };
295 asn_TYPE_descriptor_t asn_DEF_ConstrainedInteger = {
296         "ConstrainedInteger",
297         "ConstrainedInteger",
298         &asn_OP_NativeInteger,
299         asn_DEF_ConstrainedInteger_tags_1,
300         sizeof(asn_DEF_ConstrainedInteger_tags_1)
301                 /sizeof(asn_DEF_ConstrainedInteger_tags_1[0]), /* 1 */
302         asn_DEF_ConstrainedInteger_tags_1,      /* Same as above */
303         sizeof(asn_DEF_ConstrainedInteger_tags_1)
304                 /sizeof(asn_DEF_ConstrainedInteger_tags_1[0]), /* 1 */
305         { 0, 0, ConstrainedInteger_constraint },
306         0, 0,   /* No members */
307         0       /* No specifics */
308 };
309
310
311 /*** <<< INCLUDES [PrimitiveMessage] >>> ***/
312
313 #include <constr_SEQUENCE.h>
314
315 /*** <<< TYPE-DECLS [PrimitiveMessage] >>> ***/
316
317 typedef struct PrimitiveMessage {
318         
319         /* Context for parsing across buffer boundaries */
320         asn_struct_ctx_t _asn_ctx;
321 } PrimitiveMessage_t;
322
323 /*** <<< FUNC-DECLS [PrimitiveMessage] >>> ***/
324
325 extern asn_TYPE_descriptor_t asn_DEF_PrimitiveMessage;
326 extern asn_SEQUENCE_specifics_t asn_SPC_PrimitiveMessage_specs_1;
327
328 /*** <<< STAT-DEFS [PrimitiveMessage] >>> ***/
329
330 static const ber_tlv_tag_t asn_DEF_PrimitiveMessage_tags_1[] = {
331         (ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
332 };
333 asn_SEQUENCE_specifics_t asn_SPC_PrimitiveMessage_specs_1 = {
334         sizeof(struct PrimitiveMessage),
335         offsetof(struct PrimitiveMessage, _asn_ctx),
336         0,      /* No top level tags */
337         0,      /* No tags in the map */
338         0, 0, 0,        /* Optional elements (not needed) */
339         -1,     /* First extension addition */
340 };
341 asn_TYPE_descriptor_t asn_DEF_PrimitiveMessage = {
342         "PrimitiveMessage",
343         "PrimitiveMessage",
344         &asn_OP_SEQUENCE,
345         asn_DEF_PrimitiveMessage_tags_1,
346         sizeof(asn_DEF_PrimitiveMessage_tags_1)
347                 /sizeof(asn_DEF_PrimitiveMessage_tags_1[0]), /* 1 */
348         asn_DEF_PrimitiveMessage_tags_1,        /* Same as above */
349         sizeof(asn_DEF_PrimitiveMessage_tags_1)
350                 /sizeof(asn_DEF_PrimitiveMessage_tags_1[0]), /* 1 */
351         { 0, 0, SEQUENCE_constraint },
352         0, 0,   /* No members */
353         &asn_SPC_PrimitiveMessage_specs_1       /* Additional specs */
354 };
355
356
357 /*** <<< INCLUDES [ComplexMessage] >>> ***/
358
359 #include <constr_SEQUENCE.h>
360
361 /*** <<< TYPE-DECLS [ComplexMessage] >>> ***/
362
363 typedef struct ComplexMessage {
364         
365         /* Context for parsing across buffer boundaries */
366         asn_struct_ctx_t _asn_ctx;
367 } ComplexMessage_t;
368
369 /*** <<< FUNC-DECLS [ComplexMessage] >>> ***/
370
371 extern asn_TYPE_descriptor_t asn_DEF_ComplexMessage;
372 extern asn_SEQUENCE_specifics_t asn_SPC_ComplexMessage_specs_1;
373
374 /*** <<< STAT-DEFS [ComplexMessage] >>> ***/
375
376 static const ber_tlv_tag_t asn_DEF_ComplexMessage_tags_1[] = {
377         (ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
378 };
379 asn_SEQUENCE_specifics_t asn_SPC_ComplexMessage_specs_1 = {
380         sizeof(struct ComplexMessage),
381         offsetof(struct ComplexMessage, _asn_ctx),
382         0,      /* No top level tags */
383         0,      /* No tags in the map */
384         0, 0, 0,        /* Optional elements (not needed) */
385         -1,     /* First extension addition */
386 };
387 asn_TYPE_descriptor_t asn_DEF_ComplexMessage = {
388         "ComplexMessage",
389         "ComplexMessage",
390         &asn_OP_SEQUENCE,
391         asn_DEF_ComplexMessage_tags_1,
392         sizeof(asn_DEF_ComplexMessage_tags_1)
393                 /sizeof(asn_DEF_ComplexMessage_tags_1[0]), /* 1 */
394         asn_DEF_ComplexMessage_tags_1,  /* Same as above */
395         sizeof(asn_DEF_ComplexMessage_tags_1)
396                 /sizeof(asn_DEF_ComplexMessage_tags_1[0]), /* 1 */
397         { 0, 0, SEQUENCE_constraint },
398         0, 0,   /* No members */
399         &asn_SPC_ComplexMessage_specs_1 /* Additional specs */
400 };
401
402
403 /*** <<< asn_constant.h >>> ***/
404
405 /*
406  * Generated by asn1c-0.9.29 (http://lionet.info/asn1c)
407  */
408
409 #ifndef _ASN_CONSTANT_H
410 #define _ASN_CONSTANT_H
411
412 #ifdef __cplusplus
413 extern "C" {
414 #endif
415
416 #define primMessage (1)
417 #define cplxMessage (2)
418
419
420 #ifdef __cplusplus
421 }
422 #endif
423
424 #endif /* _ASN_CONSTANT_H */