NativeEnumerated.c vars NULL init and check
[com/asn1c.git] / libasn1parser / asn1p_value.h
1 /*
2  * A generic value of different syntaxes.
3  */
4 #ifndef ASN1_PARSER_VALUE_H
5 #define ASN1_PARSER_VALUE_H
6
7 struct asn1p_constraint_s;      /* Forward declaration */
8 struct asn1p_module_s;
9 struct asn1p_expr_s;
10
11 /*
12  * A wrapper around various kinds of values.
13  */
14 typedef struct asn1p_value_s {
15         /*
16          * The value of the element.
17          */
18         enum {
19                 ATV_NOVALUE,
20                 ATV_TYPE,       /* A type (as in CONTAINING Type) */
21                 ATV_NULL,       /* A "NULL" value of type NULL. */
22                 ATV_REAL,       /* A constant floating-point value */
23                 ATV_INTEGER,    /* An integer constant */
24                 ATV_MAX,
25                 ATV_MIN,
26                 ATV_TRUE,
27                 ATV_FALSE,
28                 ATV_TUPLE,      /* { 1, 15 } */
29                 ATV_QUADRUPLE,  /* { 0, 14, 0, 255 } */
30                 ATV_STRING,     /* "abcdef" */
31                 ATV_UNPARSED,
32                 ATV_BITVECTOR,
33                 ATV_VALUESET,   /* { 1 | 2 | 3 } */
34                 ATV_REFERENCED, /* Reference to a value defined elsewhere */
35                 ATV_CHOICE_IDENTIFIER,  /* ChoiceIdentifier value */
36         } type; /* Value type and location */
37
38         union {
39                 struct asn1p_constraint_s *constraint;  /* ValueSet */
40                 struct asn1p_expr_s     *v_type;        /* Type */
41                 asn1p_ref_t     *reference;
42                 asn1c_integer_t  v_integer;
43                 double           v_double;
44                 /*
45                  * Binary bits vector.
46                  */
47                 struct {
48                         uint8_t *buf;
49                         int size;
50                 } string;
51                 struct {
52                         uint8_t *bits;
53                         int size_in_bits;
54                 } binary_vector;
55                 struct {
56                         char *identifier;
57                         struct asn1p_value_s *value;
58                 } choice_identifier;
59         } value;
60 } asn1p_value_t;
61
62 /*
63  * Destructor and constructors for value.
64  * If ref, bits or buffer are omitted, the corresponding function returns
65  * (asn1p_value_t *)0 with errno = EINVAL.
66  * Allocated value (where applicable) is guaranteed to be NUL-terminated.
67  */
68 void asn1p_value_free(asn1p_value_t *);
69 asn1p_value_t *asn1p_value_fromref(asn1p_ref_t *ref, int do_copy);
70 asn1p_value_t *asn1p_value_fromconstr(struct asn1p_constraint_s *ct, int dc);
71 asn1p_value_t *asn1p_value_frombits(uint8_t *bits, int size_in_bits, int dc);
72 asn1p_value_t *asn1p_value_frombuf(char *buffer, int size, int do_copy);
73 asn1p_value_t *asn1p_value_fromdouble(double);
74 asn1p_value_t *asn1p_value_fromint(asn1c_integer_t);
75 asn1p_value_t *asn1p_value_fromtype(struct asn1p_expr_s *);
76 asn1p_value_t *asn1p_value_clone(asn1p_value_t *);
77 asn1p_value_t *asn1p_value_clone_with_resolver(asn1p_value_t *,
78                 asn1p_value_t *(*resolver)(asn1p_value_t *, void *rarg),
79                 void *rarg);
80 int asn1p_value_compare(const asn1p_value_t *, const asn1p_value_t *);
81 void asn1p_value_set_source(asn1p_value_t *, struct asn1p_module_s *, int line);
82
83 #endif  /* ASN1_PARSER_VALUE_H */