SIM-115: update simulator to use latest E2SM KPM version 3
[sim/e2-interface.git] / e2sim / asn1c / constr_SEQUENCE_OF.c
1 /*-
2  * Copyright (c) 2003, 2004, 2006 Lev Walkin <vlm@lionet.info>.
3  * All rights reserved.
4  * Redistribution and modifications are permitted subject to BSD license.
5  */
6 #include <asn_internal.h>
7 #include <constr_SEQUENCE_OF.h>
8 #include <asn_SEQUENCE_OF.h>
9
10 asn_TYPE_operation_t asn_OP_SEQUENCE_OF = {
11     SEQUENCE_OF_free,
12 #if !defined(ASN_DISABLE_PRINT_SUPPORT)
13     SEQUENCE_OF_print,
14 #else
15     0,
16 #endif  /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
17     SEQUENCE_OF_compare,
18 #if !defined(ASN_DISABLE_BER_SUPPORT)
19     SEQUENCE_OF_decode_ber,
20     SEQUENCE_OF_encode_der,
21 #else
22     0,
23     0,
24 #endif  /* !defined(ASN_DISABLE_BER_SUPPORT) */
25 #if !defined(ASN_DISABLE_XER_SUPPORT)
26     SEQUENCE_OF_decode_xer,
27     SEQUENCE_OF_encode_xer,
28 #else
29     0,
30     0,
31 #endif  /* !defined(ASN_DISABLE_XER_SUPPORT) */
32 #if !defined(ASN_DISABLE_JER_SUPPORT)
33     SEQUENCE_OF_encode_jer,
34 #else
35     0,
36 #endif  /* !defined(ASN_DISABLE_JER_SUPPORT) */
37 #if !defined(ASN_DISABLE_OER_SUPPORT)
38     SEQUENCE_OF_decode_oer,  /* Same as SET OF decoder. */
39     SEQUENCE_OF_encode_oer,  /* Same as SET OF encoder */
40 #else
41     0,
42     0,
43 #endif  /* !defined(ASN_DISABLE_OER_SUPPORT) */
44 #if !defined(ASN_DISABLE_UPER_SUPPORT)
45     SEQUENCE_OF_decode_uper,  /* Same as SET OF decoder */
46     SEQUENCE_OF_encode_uper,
47 #else
48     0,
49     0,
50 #endif  /* !defined(ASN_DISABLE_UPER_SUPPORT) */
51 #if !defined(ASN_DISABLE_APER_SUPPORT)
52     SEQUENCE_OF_decode_aper,
53     SEQUENCE_OF_encode_aper,
54 #else
55     0,
56     0,
57 #endif  /* !defined(ASN_DISABLE_APER_SUPPORT) */
58 #if !defined(ASN_DISABLE_RFILL_SUPPORT)
59     SEQUENCE_OF_random_fill,
60 #else
61     0,
62 #endif  /* !defined(ASN_DISABLE_RFILL_SUPPORT) */
63     0  /* Use generic outmost tag fetcher */
64 };
65
66 int
67 SEQUENCE_OF_compare(const asn_TYPE_descriptor_t *td, const void *aptr,
68                const void *bptr) {
69     const asn_anonymous_sequence_ *a = _A_CSEQUENCE_FROM_VOID(aptr);
70     const asn_anonymous_sequence_ *b = _A_CSEQUENCE_FROM_VOID(bptr);
71     ssize_t idx;
72
73     if(a && b) {
74         ssize_t common_length = (a->count < b->count ? a->count : b->count);
75         for(idx = 0; idx < common_length; idx++) {
76             int ret = td->elements->type->op->compare_struct(
77                 td->elements->type, a->array[idx], b->array[idx]);
78             if(ret) return ret;
79         }
80
81         if(idx < b->count) /* more elements in b */
82             return -1;    /* a is shorter, so put it first */
83         if(idx < a->count) return 1;
84
85     } else if(!a) {
86         return -1;
87     } else if(!b) {
88         return 1;
89     }
90
91     return 0;
92 }