blob: 7edf14b51b984d545b818fcf3a93204935d46a80 [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001/*-
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
Lev Walkin21b41ac2005-07-24 09:03:44 +00008#ifdef __cplusplus
9extern "C" {
10#endif
11
Lev Walkinf15320b2004-06-03 03:38:44 +000012#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 */
32int 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 */
42void 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 */
48void asn_set_empty(void *asn_set_of_x);
49
Lev Walkin089b8e92005-07-02 20:22:20 +000050/*
51 * Cope with different conversions requirements to/from void in C and C++.
52 * This is mostly useful for support library.
53 */
54typedef 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
Lev Walkin21b41ac2005-07-24 09:03:44 +000058#ifdef __cplusplus
59}
60#endif
61
Lev Walkinf15320b2004-06-03 03:38:44 +000062#endif /* ASN_SET_OF_H */