Harry Tran | 1f1098a | 2020-03-10 10:40:10 -0400 | [diff] [blame] | 1 | /***************************************************************************** |
| 2 | # * |
| 3 | # Copyright 2019 AT&T Intellectual Property * |
| 4 | # * |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); * |
| 6 | # you may not use this file except in compliance with the License. * |
| 7 | # You may obtain a copy of the License at * |
| 8 | # * |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 * |
| 10 | # * |
| 11 | # Unless required by applicable law or agreed to in writing, software * |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, * |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * |
| 14 | # See the License for the specific language governing permissions and * |
| 15 | # limitations under the License. * |
| 16 | # * |
| 17 | ******************************************************************************/ |
| 18 | |
| 19 | /*- |
| 20 | * Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>. All rights reserved. |
| 21 | * Redistribution and modifications are permitted subject to BSD license. |
| 22 | */ |
| 23 | #ifndef ASN_SET_OF_H |
| 24 | #define ASN_SET_OF_H |
| 25 | |
| 26 | #ifdef __cplusplus |
| 27 | #define A_SET_OF(type) \ |
| 28 | struct { \ |
| 29 | type **array; \ |
| 30 | int count; /* Meaningful size */ \ |
| 31 | int size; /* Allocated size */ \ |
| 32 | void (*free)(decltype(*array)); \ |
| 33 | } |
| 34 | #else /* C */ |
| 35 | #define A_SET_OF(type) \ |
| 36 | struct { \ |
| 37 | type **array; \ |
| 38 | int count; /* Meaningful size */ \ |
| 39 | int size; /* Allocated size */ \ |
| 40 | void (*free)(type *); \ |
| 41 | } |
| 42 | #endif |
| 43 | |
| 44 | #ifdef __cplusplus |
| 45 | extern "C" { |
| 46 | #endif |
| 47 | |
| 48 | #define ASN_SET_ADD(headptr, ptr) \ |
| 49 | asn_set_add((headptr), (ptr)) |
| 50 | |
| 51 | /******************************************* |
| 52 | * Implementation of the SET OF structure. |
| 53 | */ |
| 54 | |
| 55 | /* |
| 56 | * Add another structure into the set by its pointer. |
| 57 | * RETURN VALUES: |
| 58 | * 0 for success and -1/errno for failure. |
| 59 | */ |
| 60 | int asn_set_add(void *asn_set_of_x, void *ptr); |
| 61 | |
| 62 | /* |
| 63 | * Delete the element from the set by its number (base 0). |
| 64 | * This is a constant-time operation. The order of elements before the |
| 65 | * deleted ones is guaranteed, the order of elements after the deleted |
| 66 | * one is NOT guaranteed. |
| 67 | * If _do_free is given AND the (*free) is initialized, the element |
| 68 | * will be freed using the custom (*free) function as well. |
| 69 | */ |
| 70 | void asn_set_del(void *asn_set_of_x, int number, int _do_free); |
| 71 | |
| 72 | /* |
| 73 | * Empty the contents of the set. Will free the elements, if (*free) is given. |
| 74 | * Will NOT free the set itself. |
| 75 | */ |
| 76 | void asn_set_empty(void *asn_set_of_x); |
| 77 | |
| 78 | /* |
| 79 | * Cope with different conversions requirements to/from void in C and C++. |
| 80 | * This is mostly useful for support library. |
| 81 | */ |
| 82 | typedef A_SET_OF(void) asn_anonymous_set_; |
| 83 | #define _A_SET_FROM_VOID(ptr) ((asn_anonymous_set_ *)(ptr)) |
| 84 | #define _A_CSET_FROM_VOID(ptr) ((const asn_anonymous_set_ *)(ptr)) |
| 85 | |
| 86 | #ifdef __cplusplus |
| 87 | } |
| 88 | #endif |
| 89 | |
| 90 | #endif /* ASN_SET_OF_H */ |