forked from jankaluza/hamlog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.h
111 lines (93 loc) · 2.81 KB
/
list.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
* @file list.h List API
* @ingroup core
*/
/*
* Hamlog
*
* Copyright (C) 2011, Jan Kaluza <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
*/
#ifndef _HAMLOG_LIST_H
#define _HAMLOG_LIST_H
#ifdef __cplusplus
extern "C" {
#endif
typedef void (*HAMListItemDataFree) (void *data);
typedef struct _HAMListItem {
void *data;
struct _HAMListItem *lptr;
struct _HAMListItem *rptr;
} HAMListItem;
typedef struct _HAMList {
HAMListItem *first;
HAMListItem *last;
HAMListItemDataFree free_func;
} HAMList;
/**
* Creates new empy list.
* @return Empty list which has to be destroyed by ham_list_destroy() method.
*/
HAMList *ham_list_new();
/**
* Destroys the list and also frees the data.
* @param list List.
*/
void ham_list_destroy(HAMList *list);
void ham_list_set_free_func(HAMList *list, HAMListItemDataFree func);
/**
* Inserts new data as first element in list.
* @param list List.
* @param data Data.
*/
void ham_list_insert_first(HAMList *list, void *data);
/**
* Inserts new data as last element in list.
* @param list List.
* @param data Data.
*/
void ham_list_insert_last(HAMList *list, void *data);
/**
* Removes data, but does not free it.
* @param list List.
* @param data Data.
*/
void ham_list_remove(HAMList *list, void *data);
/**
* Returns data of first element in list.
* @param list List.
* @return Data.
*/
void *ham_list_get_first(HAMList *list);
HAMListItem *ham_list_get_first_item(HAMList *list);
HAMListItem *ham_list_get_next_item(HAMListItem *item);
void *ham_list_item_get_data(HAMListItem *item);
/**
* Returns data of free element in list and removes it from list.
* @param list List.
* @return Data.
*/
void *ham_list_pop_first(HAMList *list);
/**
* Returns data of last element in list.
* @param list List.
* @return Data.
*/
void *ham_list_get_last(HAMList *list);
#ifdef __cplusplus
}
#endif
#endif