2007-07-09 04:37:16 +00:00
|
|
|
/*
|
2014-01-19 01:09:44 +00:00
|
|
|
* This file Copyright (C) 2007-2014 Mnemosyne LLC
|
2007-07-09 04:37:16 +00:00
|
|
|
*
|
2014-01-21 03:10:30 +00:00
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
2014-01-19 01:09:44 +00:00
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
2007-08-18 17:05:51 +00:00
|
|
|
*
|
2007-07-09 04:37:16 +00:00
|
|
|
*/
|
|
|
|
|
2008-11-24 20:17:36 +00:00
|
|
|
#ifndef __TRANSMISSION__
|
2017-04-19 12:04:45 +00:00
|
|
|
#error only libtransmission should #include this header.
|
2008-11-24 20:17:36 +00:00
|
|
|
#endif
|
|
|
|
|
2016-03-29 16:37:21 +00:00
|
|
|
#pragma once
|
2007-07-09 04:37:16 +00:00
|
|
|
|
2010-01-06 00:18:33 +00:00
|
|
|
/**
|
|
|
|
* @addtogroup utils Utilities
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2010-01-01 22:26:35 +00:00
|
|
|
#include "transmission.h" /* inline */
|
2009-06-30 16:40:34 +00:00
|
|
|
|
2010-01-06 00:18:33 +00:00
|
|
|
/** @brief simple list structure similar to glib's GList */
|
2007-09-20 16:32:01 +00:00
|
|
|
typedef struct tr_list
|
2007-07-09 04:37:16 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
void* data;
|
|
|
|
struct tr_list* next;
|
|
|
|
struct tr_list* prev;
|
2007-07-09 04:37:16 +00:00
|
|
|
}
|
2007-09-20 16:32:01 +00:00
|
|
|
tr_list;
|
2007-07-09 04:37:16 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
typedef int (* TrListCompareFunc)(void const* a, void const* b);
|
2017-04-19 12:04:45 +00:00
|
|
|
typedef void (* TrListForeachFunc)(void*);
|
2007-08-14 14:18:54 +00:00
|
|
|
|
2010-01-06 00:18:33 +00:00
|
|
|
/**
|
|
|
|
* @brief return the number of items in the list
|
|
|
|
* @return the number of items in the list
|
|
|
|
*/
|
2017-04-20 16:02:19 +00:00
|
|
|
int tr_list_size(tr_list const* list);
|
2007-08-14 14:18:54 +00:00
|
|
|
|
2010-01-06 00:18:33 +00:00
|
|
|
/**
|
|
|
|
* @brief free the specified list and set its pointer to NULL
|
|
|
|
* @param list pointer to the list to be freed
|
|
|
|
* @param func optional function to invoke on each item in the list
|
|
|
|
*/
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_list_free(tr_list** list, TrListForeachFunc data_free_func);
|
2007-08-14 14:18:54 +00:00
|
|
|
|
2010-01-06 00:18:33 +00:00
|
|
|
/**
|
|
|
|
* @brief append an item to the specified list
|
|
|
|
* @param list pointer to the list
|
|
|
|
* @param item the item to append
|
|
|
|
*/
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_list_append(tr_list** list, void* data);
|
2007-08-14 14:18:54 +00:00
|
|
|
|
2010-01-06 00:18:33 +00:00
|
|
|
/**
|
|
|
|
* @brief prepend an item to the specified list
|
|
|
|
* @param list pointer to the list
|
|
|
|
* @param item the item to prepend
|
|
|
|
*/
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_list_prepend(tr_list** list, void* data);
|
2007-08-14 14:18:54 +00:00
|
|
|
|
2010-01-06 00:18:33 +00:00
|
|
|
/**
|
|
|
|
* @brief remove the next item in the list
|
|
|
|
* @return the next item in the list, or NULL if the list is empty
|
|
|
|
* @param list pointer to the list
|
|
|
|
*/
|
2017-04-19 12:04:45 +00:00
|
|
|
void* tr_list_pop_front(tr_list** list);
|
2007-08-14 14:18:54 +00:00
|
|
|
|
2010-01-06 00:18:33 +00:00
|
|
|
/**
|
|
|
|
* @brief remove the list's node that contains the specified data pointer
|
|
|
|
* @param list pointer to the list
|
|
|
|
* @param data data to remove
|
|
|
|
* @return the removed data pointer, or NULL if no match was found
|
|
|
|
*/
|
2017-04-20 16:02:19 +00:00
|
|
|
void* tr_list_remove_data(tr_list** list, void const* data);
|
2007-08-14 14:18:54 +00:00
|
|
|
|
2010-01-06 00:18:33 +00:00
|
|
|
/**
|
|
|
|
* @brief remove the list's node that compares equal to "b" when compared with "compare_func"
|
|
|
|
* @param list pointer to the list
|
|
|
|
* @param b the comparison key
|
2010-12-27 19:18:17 +00:00
|
|
|
* @param compare_func the comparison function. The arguments passed to it will be the list's pointers and the comparison key "b"
|
2010-01-06 00:18:33 +00:00
|
|
|
* @return the removed data pointer, or NULL if no match was found
|
|
|
|
*/
|
2017-04-20 16:02:19 +00:00
|
|
|
void* tr_list_remove(tr_list** list, void const* b, TrListCompareFunc compare_func);
|
2007-08-14 14:18:54 +00:00
|
|
|
|
2010-01-06 00:18:33 +00:00
|
|
|
/**
|
|
|
|
* @brief find the list node whose data that compares equal to "b" when compared with "compare_func"
|
|
|
|
* @param list pointer to the list
|
|
|
|
* @param b the comparison key
|
2010-12-27 19:18:17 +00:00
|
|
|
* @param compare_func the comparison function. The arguments passed to it will be the list's pointers and the comparison key "b"
|
2010-01-06 00:18:33 +00:00
|
|
|
* @return the matching list node, or NULL if not match was found
|
|
|
|
*/
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_list* tr_list_find(tr_list* list, void const* b, TrListCompareFunc compare_func);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2010-12-12 16:43:19 +00:00
|
|
|
/**
|
|
|
|
* @brief Insert in an ordered list
|
|
|
|
* @param list pointer to the list
|
|
|
|
* @param item the item to be inserted
|
|
|
|
* @param compare the comparison function.
|
|
|
|
*/
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_list_insert_sorted(tr_list** list, void* data, TrListCompareFunc compare);
|
2008-12-22 19:16:06 +00:00
|
|
|
|
2010-01-06 00:18:33 +00:00
|
|
|
/* @} */
|