Enhanced SIM for E2AP v1 for TS UC
[sim/e2-interface.git] / e2sim / e2apv1sim / ASN1c / asn_SET_OF.h
1 /*-
2  * Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
3  * Redistribution and modifications are permitted subject to BSD license.
4  */
5 #ifndef ASN_SET_OF_H
6 #define ASN_SET_OF_H
7
8 #ifdef __cplusplus
9 #define A_SET_OF(type)                   \
10     struct {                             \
11         type **array;                    \
12         int count; /* Meaningful size */ \
13         int size;  /* Allocated size */  \
14         void (*free)(decltype(*array));  \
15     }
16 #else   /* C */
17 #define A_SET_OF(type)                   \
18     struct {                             \
19         type **array;                    \
20         int count; /* Meaningful size */ \
21         int size;  /* Allocated size */  \
22         void (*free)(type *);    \
23     }
24 #endif
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 #define ASN_SET_ADD(headptr, ptr)               \
31         asn_set_add((headptr), (ptr))
32
33 /*******************************************
34  * Implementation of the SET OF structure.
35  */
36
37 /*
38  * Add another structure into the set by its pointer.
39  * RETURN VALUES:
40  * 0 for success and -1/errno for failure.
41  */
42 int  asn_set_add(void *asn_set_of_x, void *ptr);
43
44 /*
45  * Delete the element from the set by its number (base 0).
46  * This is a constant-time operation. The order of elements before the
47  * deleted ones is guaranteed, the order of elements after the deleted
48  * one is NOT guaranteed.
49  * If _do_free is given AND the (*free) is initialized, the element
50  * will be freed using the custom (*free) function as well.
51  */
52 void asn_set_del(void *asn_set_of_x, int number, int _do_free);
53
54 /*
55  * Empty the contents of the set. Will free the elements, if (*free) is given.
56  * Will NOT free the set itself.
57  */
58 void asn_set_empty(void *asn_set_of_x);
59
60 /*
61  * Cope with different conversions requirements to/from void in C and C++.
62  * This is mostly useful for support library.
63  */
64 typedef A_SET_OF(void) asn_anonymous_set_;
65 #define _A_SET_FROM_VOID(ptr)           ((asn_anonymous_set_ *)(ptr))
66 #define _A_CSET_FROM_VOID(ptr)          ((const asn_anonymous_set_ *)(ptr))
67
68 #ifdef __cplusplus
69 }
70 #endif
71
72 #endif  /* ASN_SET_OF_H */