1 | /****************************************************************************** |
---|
2 | * $Id: ptrarray.h 6953 2008-10-25 02:15:37Z charles $ |
---|
3 | * |
---|
4 | * This file Copyright (C) 2007-2008 Charles Kerr <charles@rebelbase.com> |
---|
5 | * |
---|
6 | * Permission is hereby granted, free of charge, to any person obtaining a |
---|
7 | * copy of this software and associated documentation files (the "Software"), |
---|
8 | * to deal in the Software without restriction, including without limitation |
---|
9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
---|
10 | * and/or sell copies of the Software, and to permit persons to whom the |
---|
11 | * Software is furnished to do so, subject to the following conditions: |
---|
12 | * |
---|
13 | * The above copyright notice and this permission notice shall be included in |
---|
14 | * all copies or substantial portions of the Software. |
---|
15 | * |
---|
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
---|
21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
---|
22 | * DEALINGS IN THE SOFTWARE. |
---|
23 | *****************************************************************************/ |
---|
24 | |
---|
25 | #ifndef _TR_PTR_ARRAY_H_ |
---|
26 | #define _TR_PTR_ARRAY_H_ |
---|
27 | |
---|
28 | /** |
---|
29 | * A simple pointer array that resizes itself dynamically. |
---|
30 | */ |
---|
31 | typedef struct tr_ptrArray tr_ptrArray; |
---|
32 | |
---|
33 | typedef void ( *PtrArrayForeachFunc )( void * ); |
---|
34 | |
---|
35 | tr_ptrArray * tr_ptrArrayNew( void ); |
---|
36 | |
---|
37 | tr_ptrArray * tr_ptrArrayDup( tr_ptrArray* ); |
---|
38 | |
---|
39 | void tr_ptrArrayForeach( |
---|
40 | tr_ptrArray*, |
---|
41 | PtrArrayForeachFunc func ); |
---|
42 | |
---|
43 | void tr_ptrArrayFree( tr_ptrArray * array, |
---|
44 | PtrArrayForeachFunc func ); |
---|
45 | |
---|
46 | void* tr_ptrArrayNth( tr_ptrArray * array, |
---|
47 | int nth ); |
---|
48 | |
---|
49 | void* tr_ptrArrayBack( tr_ptrArray * array ); |
---|
50 | |
---|
51 | void** tr_ptrArrayPeek( tr_ptrArray * array, |
---|
52 | int * size ); |
---|
53 | |
---|
54 | void** tr_ptrArrayBase( tr_ptrArray * array ); |
---|
55 | |
---|
56 | void tr_ptrArrayClear( tr_ptrArray * array ); |
---|
57 | |
---|
58 | int tr_ptrArrayInsert( tr_ptrArray * array, |
---|
59 | void * insertMe, |
---|
60 | int pos ); |
---|
61 | |
---|
62 | int tr_ptrArrayAppend( tr_ptrArray * array, |
---|
63 | void * appendMe ); |
---|
64 | |
---|
65 | void* tr_ptrArrayPop( tr_ptrArray * array ); |
---|
66 | |
---|
67 | void tr_ptrArrayErase( tr_ptrArray * array, |
---|
68 | int begin, |
---|
69 | int end ); |
---|
70 | |
---|
71 | int tr_ptrArraySize( const tr_ptrArray* ); |
---|
72 | |
---|
73 | int tr_ptrArrayEmpty( const tr_ptrArray* ); |
---|
74 | |
---|
75 | int tr_ptrArrayInsertSorted( tr_ptrArray * array, |
---|
76 | void * value, |
---|
77 | int compare(const void*, const void*) ); |
---|
78 | |
---|
79 | void* tr_ptrArrayRemoveSorted( tr_ptrArray * array, |
---|
80 | void * value, |
---|
81 | int compare(const void*, const void*) ); |
---|
82 | |
---|
83 | void* tr_ptrArrayFindSorted( tr_ptrArray * array, |
---|
84 | const void * key, |
---|
85 | int compare(const void*, const void*) ); |
---|
86 | |
---|
87 | #endif |
---|