2 * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
\r
3 * Redistribution and modifications are permitted subject to BSD license.
\r
5 #include <asn_internal.h>
\r
6 #include <asn_SET_OF.h>
\r
10 * Add another element into the set.
\r
13 asn_set_add(void *asn_set_of_x, void *ptr) {
\r
14 asn_anonymous_set_ *as = _A_SET_FROM_VOID(asn_set_of_x);
\r
16 if(as == 0 || ptr == 0) {
\r
17 errno = EINVAL; /* Invalid arguments */
\r
22 * Make sure there's enough space to insert an element.
\r
24 if(as->count == as->size) {
\r
25 int _newsize = as->size ? (as->size << 1) : 4;
\r
27 _new_arr = REALLOC(as->array, _newsize * sizeof(as->array[0]));
\r
29 as->array = (void **)_new_arr;
\r
30 as->size = _newsize;
\r
37 as->array[as->count++] = ptr;
\r
43 asn_set_del(void *asn_set_of_x, int number, int _do_free) {
\r
44 asn_anonymous_set_ *as = _A_SET_FROM_VOID(asn_set_of_x);
\r
48 if(number < 0 || number >= as->count)
\r
51 if(_do_free && as->free) {
\r
52 ptr = as->array[number];
\r
57 as->array[number] = as->array[--as->count];
\r
60 * Invoke the third-party function only when the state
\r
61 * of the parent structure is consistent.
\r
63 if(ptr) as->free(ptr);
\r
68 * Free the contents of the set, do not free the set itself.
\r
71 asn_set_empty(void *asn_set_of_x) {
\r
72 asn_anonymous_set_ *as = _A_SET_FROM_VOID(asn_set_of_x);
\r
78 as->free(as->array[as->count]);
\r