]> git.stg.codes - stg.git/blob - libs/smux/include/stg/asn_SET_OF.h
Port to CMake, get rid of os_int.h.
[stg.git] / libs / smux / include / stg / asn_SET_OF.h
1 /*-
2  * Copyright (c) 2003, 2004 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 extern "C" {
10 #endif
11
12 #define A_SET_OF(type)                                  \
13         struct {                                        \
14                 type **array;                           \
15                 int count;      /* Meaningful size */   \
16                 int size;       /* Allocated size */    \
17                 void (*free)(type *);                   \
18         }
19
20 #define ASN_SET_ADD(headptr, ptr)               \
21         asn_set_add((headptr), (ptr))
22
23 /*******************************************
24  * Implementation of the SET OF structure.
25  */
26
27 /*
28  * Add another structure into the set by its pointer.
29  * RETURN VALUES:
30  * 0 for success and -1/errno for failure.
31  */
32 int  asn_set_add(void *asn_set_of_x, void *ptr);
33
34 /*
35  * Delete the element from the set by its number (base 0).
36  * This is a constant-time operation. The order of elements before the
37  * deleted ones is guaranteed, the order of elements after the deleted
38  * one is NOT guaranteed.
39  * If _do_free is given AND the (*free) is initialized, the element
40  * will be freed using the custom (*free) function as well.
41  */
42 void asn_set_del(void *asn_set_of_x, int number, int _do_free);
43
44 /*
45  * Empty the contents of the set. Will free the elements, if (*free) is given.
46  * Will NOT free the set itself.
47  */
48 void asn_set_empty(void *asn_set_of_x);
49
50 /*
51  * Cope with different conversions requirements to/from void in C and C++.
52  * This is mostly useful for support library.
53  */
54 typedef A_SET_OF(void) asn_anonymous_set_;
55 #define _A_SET_FROM_VOID(ptr)           ((asn_anonymous_set_ *)(ptr))
56 #define _A_CSET_FROM_VOID(ptr)          ((const asn_anonymous_set_ *)(ptr))
57
58 #ifdef __cplusplus
59 }
60 #endif
61
62 #endif  /* ASN_SET_OF_H */