1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-26 09:37:56 +00:00
transmission/libtransmission/list.h
2008-12-22 19:16:06 +00:00

131 lines
2.9 KiB
C

/*
* This file Copyright (C) 2007-2008 Charles Kerr <charles@transmissionbt.com>
*
* 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.
*
* $Id$
*/
#ifndef __TRANSMISSION__
#error only libtransmission should #include this header.
#endif
#ifndef TR_LIST_H
#define TR_LIST_H
typedef struct tr_list
{
void * data;
struct tr_list * next;
struct tr_list * prev;
}
tr_list;
typedef int ( *TrListCompareFunc )( const void * a, const void * b );
typedef void ( *TrListForeachFunc )( void * );
int tr_list_size( const tr_list * list );
void tr_list_free( tr_list ** list,
TrListForeachFunc data_free_func );
void tr_list_append( tr_list ** list,
void * data );
void tr_list_prepend( tr_list ** list,
void * data );
void* tr_list_pop_front( tr_list ** list );
void* tr_list_remove_data( tr_list ** list,
const void * data );
void* tr_list_remove( tr_list ** list,
const void * b,
TrListCompareFunc compare_func );
tr_list* tr_list_find( tr_list * list,
const void * b,
TrListCompareFunc compare_func );
/*
* Double-linked list with easy memory management and fast
* insert/remove operations
*/
struct __tr_list
{
struct __tr_list * next, * prev;
};
#define __tr_list_entry(ptr, type, member) ({ \
const struct __tr_list *__mptr = (ptr); \
(void *)( (char *)__mptr - offsetof(type,member) ); \
})
typedef int ( *__tr_list_cmp_t ) ( const void * a, const void * b );
typedef void ( *__tr_list_free_t )( void * );
/**
* __tr_list_init()
*
* Init @head as an empty list.
*/
void
__tr_list_init( struct __tr_list * head );
/**
* __tr_list_insert()
*
* Insert @list between @prev and @next.
*/
void
__tr_list_insert( struct __tr_list * list,
struct __tr_list * prev,
struct __tr_list * next);
/**
* __tr_list_splice()
*
* Connect @prev with @next, removing any nodes that were
* in between.
*/
void
__tr_list_splice( struct __tr_list * prev,
struct __tr_list * next);
/**
* __tr_list_append()
*
* Append @list to the end of @head.
*/
void
__tr_list_append( struct __tr_list * head,
struct __tr_list * list);
/**
* __tr_list_remove()
*
* Remove @head from the list it is in.
*/
void
__tr_list_remove( struct __tr_list * head );
/**
* __tr_list_destroy()
*
* Destroy the list and free all nodes
*/
void
__tr_list_destroy( struct __tr_list * head,
__tr_list_free_t func);
#endif /* TR_LIST_H */