2009-06-06 17:39:04 +00:00
|
|
|
/*
|
|
|
|
* This file Copyright (C) 2008-2009 Charles Kerr <charles@transmissionbt.com>
|
2007-08-18 17:05:51 +00:00
|
|
|
*
|
2009-06-06 17:39:04 +00:00
|
|
|
* This file is licensed by the GPL version 2. Works owned by the
|
|
|
|
* Transmission project are granted a special exemption to clause 2(b)
|
|
|
|
* so that the bulk of its code can remain under the MIT license.
|
|
|
|
* This exemption does not extend to derived works not owned by
|
|
|
|
* the Transmission project.
|
2008-03-25 19:49:32 +00:00
|
|
|
*
|
2009-06-06 17:39:04 +00:00
|
|
|
* $Id$
|
|
|
|
*/
|
2007-08-14 20:45:23 +00:00
|
|
|
|
2008-11-24 20:17:36 +00:00
|
|
|
#ifndef __TRANSMISSION__
|
2009-06-06 17:39:04 +00:00
|
|
|
#error only libtransmission should #include this header.
|
2008-11-24 20:17:36 +00:00
|
|
|
#endif
|
|
|
|
|
2008-03-25 19:49:32 +00:00
|
|
|
#ifndef _TR_PTR_ARRAY_H_
|
|
|
|
#define _TR_PTR_ARRAY_H_
|
2007-08-14 20:45:23 +00:00
|
|
|
|
2009-01-02 20:19:10 +00:00
|
|
|
#include "transmission.h"
|
|
|
|
|
2009-05-29 19:17:12 +00:00
|
|
|
/**
|
|
|
|
* @addtogroup utils Utilities
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2007-08-14 20:45:23 +00:00
|
|
|
/**
|
|
|
|
* A simple pointer array that resizes itself dynamically.
|
|
|
|
*/
|
2008-12-29 08:54:36 +00:00
|
|
|
typedef struct tr_ptrArray
|
|
|
|
{
|
|
|
|
void ** items;
|
|
|
|
int n_items;
|
|
|
|
int n_alloc;
|
|
|
|
}
|
|
|
|
tr_ptrArray;
|
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
typedef void ( *PtrArrayForeachFunc )( void * );
|
|
|
|
|
2008-12-29 08:54:36 +00:00
|
|
|
extern const tr_ptrArray TR_PTR_ARRAY_INIT;
|
|
|
|
|
|
|
|
void tr_ptrArrayDestruct( tr_ptrArray*, PtrArrayForeachFunc func );
|
|
|
|
|
2008-11-23 16:30:09 +00:00
|
|
|
void tr_ptrArrayForeach( tr_ptrArray * array,
|
|
|
|
PtrArrayForeachFunc func );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-10-25 02:15:37 +00:00
|
|
|
void* tr_ptrArrayNth( tr_ptrArray * array,
|
|
|
|
int nth );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-10-25 02:15:37 +00:00
|
|
|
void* tr_ptrArrayBack( tr_ptrArray * array );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-10-25 02:15:37 +00:00
|
|
|
void** tr_ptrArrayPeek( tr_ptrArray * array,
|
|
|
|
int * size );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2009-01-11 17:02:04 +00:00
|
|
|
static TR_INLINE void tr_ptrArrayClear( tr_ptrArray * a ) { a->n_items = 0; }
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-10-25 02:15:37 +00:00
|
|
|
int tr_ptrArrayInsert( tr_ptrArray * array,
|
|
|
|
void * insertMe,
|
|
|
|
int pos );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2009-01-11 17:02:04 +00:00
|
|
|
static TR_INLINE int tr_ptrArrayAppend( tr_ptrArray * array, void * appendMe )
|
2009-01-02 20:19:10 +00:00
|
|
|
{
|
|
|
|
return tr_ptrArrayInsert( array, appendMe, -1 );
|
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-10-25 02:15:37 +00:00
|
|
|
void* tr_ptrArrayPop( tr_ptrArray * array );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2009-01-11 17:02:04 +00:00
|
|
|
static TR_INLINE void** tr_ptrArrayBase( const tr_ptrArray * a )
|
2009-01-04 16:59:15 +00:00
|
|
|
{
|
|
|
|
return a->items;
|
|
|
|
}
|
|
|
|
|
2009-01-11 17:02:04 +00:00
|
|
|
static TR_INLINE int tr_ptrArraySize( const tr_ptrArray * a )
|
2009-01-02 20:19:10 +00:00
|
|
|
{
|
|
|
|
return a->n_items;
|
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2009-01-11 17:02:04 +00:00
|
|
|
static TR_INLINE tr_bool tr_ptrArrayEmpty( const tr_ptrArray * a )
|
2009-01-02 20:19:10 +00:00
|
|
|
{
|
|
|
|
return tr_ptrArraySize(a) == 0;
|
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-10-25 02:15:37 +00:00
|
|
|
int tr_ptrArrayInsertSorted( tr_ptrArray * array,
|
|
|
|
void * value,
|
|
|
|
int compare(const void*, const void*) );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-10-25 02:15:37 +00:00
|
|
|
void* tr_ptrArrayRemoveSorted( tr_ptrArray * array,
|
|
|
|
void * value,
|
|
|
|
int compare(const void*, const void*) );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-10-25 02:15:37 +00:00
|
|
|
void* tr_ptrArrayFindSorted( tr_ptrArray * array,
|
|
|
|
const void * key,
|
|
|
|
int compare(const void*, const void*) );
|
2007-08-14 20:45:23 +00:00
|
|
|
|
2009-05-29 19:17:12 +00:00
|
|
|
/* @} */
|
2007-08-14 20:45:23 +00:00
|
|
|
#endif
|