blob: 882e1a47d4ad0b8cdfd359be63b8f577d158cd43 [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001/*-
Lev Walkin20696a42017-10-17 21:27:33 -07002 * Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
Lev Walkinf15320b2004-06-03 03:38:44 +00003 * Redistribution and modifications are permitted subject to BSD license.
4 */
5#ifndef ASN_SET_OF_H
6#define ASN_SET_OF_H
7
Lev Walkin21b41ac2005-07-24 09:03:44 +00008#ifdef __cplusplus
Lev Walkin46fc2bd2017-03-26 05:49:10 -07009#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 }
Lev Walkin21b41ac2005-07-24 09:03:44 +000024#endif
25
Lev Walkin46fc2bd2017-03-26 05:49:10 -070026#ifdef __cplusplus
27extern "C" {
28#endif
Lev Walkinf15320b2004-06-03 03:38:44 +000029
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 */
42int 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 */
52void 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 */
58void asn_set_empty(void *asn_set_of_x);
59
Lev Walkin089b8e92005-07-02 20:22:20 +000060/*
61 * Cope with different conversions requirements to/from void in C and C++.
62 * This is mostly useful for support library.
63 */
64typedef 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
Lev Walkin21b41ac2005-07-24 09:03:44 +000068#ifdef __cplusplus
69}
70#endif
71
Lev Walkinf15320b2004-06-03 03:38:44 +000072#endif /* ASN_SET_OF_H */