source: trunk/libtransmission/list.h

Last change on this file was 14724, checked in by jordan, 5 years ago

use '#pragma once' instead of #ifndef..#define..#endif guards

  • Property svn:keywords set to Date Rev Author Id
File size: 3.2 KB
Line 
1/*
2 * This file Copyright (C) 2007-2014 Mnemosyne LLC
3 *
4 * It may be used under the GNU GPL versions 2 or 3
5 * or any future license endorsed by Mnemosyne LLC.
6 *
7 * $Id: list.h 14724 2016-03-29 16:37:21Z mikedld $
8 */
9
10#ifndef __TRANSMISSION__
11 #error only libtransmission should #include this header.
12#endif
13
14#pragma once
15
16/**
17 * @addtogroup utils Utilities
18 * @{
19 */
20
21#include "transmission.h" /* inline */
22
23/** @brief simple list structure similar to glib's GList */
24typedef struct tr_list
25{
26    void *  data;
27    struct tr_list  * next;
28    struct tr_list  * prev;
29}
30tr_list;
31
32typedef int (*TrListCompareFunc)(const void * a, const void * b);
33typedef void (*TrListForeachFunc)(void *);
34
35/**
36 * @brief return the number of items in the list
37 * @return the number of items in the list
38 */
39int      tr_list_size (const tr_list * list);
40
41/**
42 * @brief free the specified list and set its pointer to NULL
43 * @param list pointer to the list to be freed
44 * @param func optional function to invoke on each item in the list
45 */
46void     tr_list_free (tr_list ** list, TrListForeachFunc data_free_func);
47
48/**
49 * @brief append an item to the specified list
50 * @param list pointer to the list
51 * @param item the item to append
52 */
53void tr_list_append (tr_list ** list, void * data);
54
55/**
56 * @brief prepend an item to the specified list
57 * @param list pointer to the list
58 * @param item the item to prepend
59 */
60void tr_list_prepend (tr_list ** list, void * data);
61
62/**
63 * @brief remove the next item in the list
64 * @return the next item in the list, or NULL if the list is empty
65 * @param list pointer to the list
66 */
67void* tr_list_pop_front (tr_list ** list);
68
69/**
70 * @brief remove the list's node that contains the specified data pointer
71 * @param list pointer to the list
72 * @param data data to remove
73 * @return the removed data pointer, or NULL if no match was found
74 */
75void* tr_list_remove_data (tr_list ** list, const void * data);
76
77/**
78 * @brief remove the list's node that compares equal to "b" when compared with "compare_func"
79 * @param list pointer to the list
80 * @param b the comparison key
81 * @param compare_func the comparison function. The arguments passed to it will be the list's pointers and the comparison key "b"
82 * @return the removed data pointer, or NULL if no match was found
83 */
84void*    tr_list_remove (tr_list **        list,
85                         const void *      b,
86                         TrListCompareFunc compare_func);
87
88/**
89 * @brief find the list node whose data that compares equal to "b" when compared with "compare_func"
90 * @param list pointer to the list
91 * @param b the comparison key
92 * @param compare_func the comparison function. The arguments passed to it will be the list's pointers and the comparison key "b"
93 * @return the matching list node, or NULL if not match was found
94 */
95tr_list* tr_list_find (tr_list *         list,
96                       const void *      b,
97                       TrListCompareFunc compare_func);
98
99/**
100 * @brief Insert in an ordered list
101 * @param list pointer to the list
102 * @param item the item to be inserted
103 * @param compare the comparison function.
104 */
105void tr_list_insert_sorted (tr_list          ** list,
106                            void              * data,
107                            TrListCompareFunc   compare);
108
109
110
111/* @} */
112
Note: See TracBrowser for help on using the repository browser.