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