author | zautrix <zautrix> | 2004-07-03 16:33:12 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-07-03 16:33:12 (UTC) |
commit | e3b89230f065c48c84b48c88edb6eb088374c487 (patch) (unidiff) | |
tree | 162ea2ef909a6f82ccfcedf45d80d6c821174912 /kmicromail/libetpan/tools/carray.h | |
parent | 2dd6ac0b2d24c91d35ce674a6c26351352df2b15 (diff) | |
download | kdepimpi-e3b89230f065c48c84b48c88edb6eb088374c487.zip kdepimpi-e3b89230f065c48c84b48c88edb6eb088374c487.tar.gz kdepimpi-e3b89230f065c48c84b48c88edb6eb088374c487.tar.bz2 |
Initial revision
Diffstat (limited to 'kmicromail/libetpan/tools/carray.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kmicromail/libetpan/tools/carray.h | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/kmicromail/libetpan/tools/carray.h b/kmicromail/libetpan/tools/carray.h new file mode 100644 index 0000000..06003aa --- a/dev/null +++ b/kmicromail/libetpan/tools/carray.h | |||
@@ -0,0 +1,124 @@ | |||
1 | |||
2 | /* | ||
3 | * libEtPan! -- a mail stuff library | ||
4 | * | ||
5 | * carray - Implements simple dynamic pointer arrays | ||
6 | * | ||
7 | * Copyright (c) 1999-2000, Gaël Roualland <gael.roualland@iname.com> | ||
8 | * interface changes - 2002 - DINH Viet Hoa | ||
9 | * All rights reserved. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * 3. Neither the name of the libEtPan! project nor the names of its | ||
20 | * contributors may be used to endorse or promote products derived | ||
21 | * from this software without specific prior written permission. | ||
22 | * | ||
23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
33 | * SUCH DAMAGE. | ||
34 | */ | ||
35 | |||
36 | /* | ||
37 | * $Id$ | ||
38 | */ | ||
39 | |||
40 | #ifndef CARRAY_H | ||
41 | #define CARRAY_H | ||
42 | |||
43 | #ifdef __cplusplus | ||
44 | extern "C" { | ||
45 | #endif | ||
46 | |||
47 | struct carray_s { | ||
48 | void ** array; | ||
49 | unsigned int len; | ||
50 | unsigned int max; | ||
51 | }; | ||
52 | |||
53 | typedef struct carray_s carray; | ||
54 | |||
55 | /* Creates a new array of pointers, with initsize preallocated cells */ | ||
56 | carray * carray_new(unsigned int initsize); | ||
57 | |||
58 | /* Adds the pointer to data in the array. | ||
59 | Returns the index of the pointer in the array or -1 on error */ | ||
60 | int carray_add(carray * array, void * data, unsigned int * index); | ||
61 | |||
62 | int carray_set_size(carray * array, unsigned int new_size); | ||
63 | |||
64 | /* Removes the cell at this index position. Returns TRUE on success. | ||
65 | Order of elements in the array IS changed. */ | ||
66 | int carray_delete(carray * array, unsigned int indx); | ||
67 | |||
68 | /* Removes the cell at this index position. Returns TRUE on success. | ||
69 | Order of elements in the array IS not changed. */ | ||
70 | int carray_delete_slow(carray * array, unsigned int indx); | ||
71 | |||
72 | /* remove without decreasing the size of the array */ | ||
73 | int carray_delete_fast(carray * array, unsigned int indx); | ||
74 | |||
75 | /* Some of the following routines can be implemented as macros to | ||
76 | be faster. If you don't want it, define NO_MACROS */ | ||
77 | #ifdef NO_MACROS | ||
78 | |||
79 | /* Returns the array itself */ | ||
80 | void ** carray_data(carray *); | ||
81 | |||
82 | /* Returns the number of elements in the array */ | ||
83 | int carray_count(carray *); | ||
84 | |||
85 | /* Returns the contents of one cell */ | ||
86 | void * carray_get(carray * array, unsigned int indx); | ||
87 | |||
88 | /* Sets the contents of one cell */ | ||
89 | void carray_set(carray * array, unsigned int indx, void * value); | ||
90 | |||
91 | #else | ||
92 | |||
93 | #if 0 | ||
94 | #define carray_data(a) (a->array) | ||
95 | #define carray_count(a) (a->len) | ||
96 | #define carray_get(a, indx) (a->array[indx]) | ||
97 | #define carray_set(a, indx, v) do { a->array[indx]=v; } while(0) | ||
98 | #endif | ||
99 | |||
100 | static inline void ** carray_data(carray * array) { | ||
101 | return array->array; | ||
102 | } | ||
103 | |||
104 | static inline unsigned int carray_count(carray * array) { | ||
105 | return array->len; | ||
106 | } | ||
107 | |||
108 | static inline void * carray_get(carray * array, unsigned int indx) { | ||
109 | return array->array[indx]; | ||
110 | } | ||
111 | |||
112 | static inline void carray_set(carray * array, | ||
113 | unsigned int indx, void * value) { | ||
114 | array->array[indx] = value; | ||
115 | } | ||
116 | #endif | ||
117 | |||
118 | void carray_free(carray * array); | ||
119 | |||
120 | #ifdef __cplusplus | ||
121 | } | ||
122 | #endif | ||
123 | |||
124 | #endif | ||