source: trunk/libtransmission/ptrarray.h @ 8561

Last change on this file since 8561 was 8561, checked in by charles, 13 years ago

(trunk libT) re-start work on making libT doxygen friendly. still a long ways to go on this.

  • Property svn:keywords set to Date Rev Author Id
File size: 3.9 KB
Line 
1/******************************************************************************
2 * $Id: ptrarray.h 8561 2009-05-29 19:17:12Z charles $
3 *
4 * This file Copyright (C) 2007-2009 Charles Kerr <charles@transmissionbt.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 __TRANSMISSION__
26#error only libtransmission should #include this header.
27#endif
28
29#ifndef _TR_PTR_ARRAY_H_
30#define _TR_PTR_ARRAY_H_
31
32#include "transmission.h"
33
34/**
35 * @addtogroup utils Utilities
36 * @{
37 */
38
39/**
40 * A simple pointer array that resizes itself dynamically.
41 */
42typedef struct tr_ptrArray
43{
44    void ** items;
45    int     n_items;
46    int     n_alloc;
47}
48tr_ptrArray;
49
50typedef void ( *PtrArrayForeachFunc )( void * );
51
52extern const tr_ptrArray TR_PTR_ARRAY_INIT;
53
54void          tr_ptrArrayDestruct( tr_ptrArray*, PtrArrayForeachFunc func );
55
56tr_ptrArray * tr_ptrArrayNew( void );
57
58tr_ptrArray * tr_ptrArrayDup( tr_ptrArray* );
59
60void          tr_ptrArrayForeach( tr_ptrArray         * array,
61                                  PtrArrayForeachFunc   func );
62
63void          tr_ptrArrayFree( tr_ptrArray         * array,
64                               PtrArrayForeachFunc   func );
65
66void*         tr_ptrArrayNth( tr_ptrArray   * array,
67                              int             nth );
68
69void*         tr_ptrArrayBack( tr_ptrArray  * array );
70
71void**        tr_ptrArrayPeek( tr_ptrArray  * array,
72                               int          * size );
73
74static TR_INLINE void  tr_ptrArrayClear( tr_ptrArray * a ) { a->n_items = 0; }
75
76int           tr_ptrArrayInsert( tr_ptrArray * array,
77                                 void        * insertMe,
78                                 int           pos );
79
80static TR_INLINE int tr_ptrArrayAppend( tr_ptrArray * array, void * appendMe )
81{
82    return tr_ptrArrayInsert( array, appendMe, -1 );
83}
84
85void*         tr_ptrArrayPop( tr_ptrArray    * array );
86
87void          tr_ptrArrayErase( tr_ptrArray  * array,
88                                int            begin,
89                                int            end );
90
91static TR_INLINE void** tr_ptrArrayBase( const tr_ptrArray * a )
92{
93    return a->items;
94}
95
96static TR_INLINE int tr_ptrArraySize( const tr_ptrArray *  a )
97{
98    return a->n_items;
99}
100
101static TR_INLINE tr_bool tr_ptrArrayEmpty( const tr_ptrArray * a )
102{
103    return tr_ptrArraySize(a) == 0;
104}
105
106int           tr_ptrArrayInsertSorted( tr_ptrArray * array,
107                                       void        * value,
108                                       int compare(const void*, const void*) );
109
110void*         tr_ptrArrayRemoveSorted( tr_ptrArray * array,
111                                       void        * value,
112                                       int compare(const void*, const void*) );
113
114void*         tr_ptrArrayFindSorted( tr_ptrArray * array,
115                                     const void  * key,
116                                     int compare(const void*, const void*) );
117
118/* @} */
119#endif
Note: See TracBrowser for help on using the repository browser.