source: trunk/libtransmission/list.h @ 7658

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

(trunk) update the GPL code's copyright dates

  • Property svn:keywords set to Date Rev Author Id
File size: 3.1 KB
Line 
1/*
2 * This file Copyright (C) 2007-2009 Charles Kerr <charles@transmissionbt.com>
3 *
4 * This file is licensed by the GPL version 2.  Works owned by the
5 * Transmission project are granted a special exemption to clause 2(b)
6 * so that the bulk of its code can remain under the MIT license.
7 * This exemption does not extend to derived works not owned by
8 * the Transmission project.
9 *
10 * $Id: list.h 7658 2009-01-10 23:09:07Z charles $
11 */
12
13#ifndef __TRANSMISSION__
14#error only libtransmission should #include this header.
15#endif
16
17#ifndef TR_LIST_H
18#define TR_LIST_H
19
20typedef struct tr_list
21{
22    void *  data;
23    struct tr_list  * next;
24    struct tr_list  * prev;
25}
26tr_list;
27
28typedef int ( *TrListCompareFunc )( const void * a, const void * b );
29typedef void ( *TrListForeachFunc )( void * );
30
31int      tr_list_size( const tr_list * list );
32
33void     tr_list_free( tr_list **        list,
34                       TrListForeachFunc data_free_func );
35
36void     tr_list_append( tr_list ** list,
37                         void *     data );
38
39void     tr_list_prepend( tr_list ** list,
40                          void *     data );
41
42void*    tr_list_pop_front( tr_list ** list );
43
44void*    tr_list_remove_data( tr_list **   list,
45                              const void * data );
46
47void*    tr_list_remove( tr_list **        list,
48                         const void *      b,
49                         TrListCompareFunc compare_func );
50
51tr_list* tr_list_find( tr_list *         list,
52                       const void *      b,
53                       TrListCompareFunc compare_func );
54
55
56/*
57 * Double-linked list with easy memory management and fast
58 * insert/remove operations
59 */
60
61struct __tr_list
62{
63    struct __tr_list * next, * prev;
64};
65
66/**
67 * Given a __tr_list node that's embedded in a struct, returns a pointer to the struct.
68 * @param ptr     pointer to the embedded __tr_list
69 * @param type    struct type that has contains the __tr_list
70 * @param field   the name of the struct's _tr_list field
71 */
72#define __tr_list_entry(ptr,type,field) ((type*) (((char*)ptr) - offsetof(type,field)))
73
74typedef int  ( *__tr_list_cmp_t ) ( const void * a, const void * b );
75typedef void ( *__tr_list_free_t )( void * );
76
77
78/**
79 *    __tr_list_init()
80 *
81 * Init @head as an empty list.
82 */
83void
84__tr_list_init( struct __tr_list * head );
85
86
87/**
88 *    __tr_list_insert()
89 *
90 * Insert @list between @prev and @next.
91 */
92void
93__tr_list_insert( struct __tr_list * list,
94                  struct __tr_list * prev,
95                  struct __tr_list * next);
96
97/**
98 *    __tr_list_splice()
99 *
100 * Connect @prev with @next, removing any nodes that were
101 * in between.
102 */
103void
104__tr_list_splice( struct __tr_list * prev,
105                  struct __tr_list * next);
106
107/**
108 *    __tr_list_append()
109 *
110 * Append @list to the end of @head.
111 */
112void
113__tr_list_append( struct __tr_list * head,
114                  struct __tr_list * list);
115
116/**
117 *    __tr_list_remove()
118 *
119 * Remove @head from the list it is in.
120 */
121void
122__tr_list_remove( struct __tr_list * head );
123
124/**
125 *    __tr_list_destroy()
126 *
127 * Destroy the list and free all nodes
128 */
129void
130__tr_list_destroy( struct __tr_list * head,
131                   __tr_list_free_t   func);
132
133#endif /* TR_LIST_H */
134
Note: See TracBrowser for help on using the repository browser.