- Linked List programmed but not tested
[strongswan.git] / Source / charon / linked_list.h
1 /**
2 * @file linked_list.h
3 *
4 * @brief Generic Double Linked List
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #ifndef LINKED_LIST_H_
24 #define LINKED_LIST_H_
25
26 #include "types.h"
27
28
29 /**
30 * @brief Double Linked List Element type
31 */
32 typedef struct linked_list_element_s linked_list_element_t;
33
34 struct linked_list_element_s {
35 linked_list_element_t *previous;
36 linked_list_element_t *next;
37 /* value of a list item */
38 void *value;
39
40 /**
41 * @brief Destroys a linked_list_element object
42 *
43 * @param linked_list_element_t calling object
44 * @returns SUCCESS if succeeded, FAILED otherwise
45 */
46 status_t (*destroy) (linked_list_element_t *this);
47 };
48
49 /**
50 * @brief Creates an empty linked list object
51 *
52 * @param value value of item
53 *
54 * @return linked_list_element object
55 */
56 linked_list_element_t *linked_list_element_create(void *value);
57
58
59 /**
60 * @brief Double Linked List type
61 */
62 typedef struct linked_list_s linked_list_t;
63
64
65 struct linked_list_s {
66 /* item count */
67 int count;
68 linked_list_element_t *first;
69 linked_list_element_t *last;
70
71 /**
72 * @brief inserts a new item at the beginning of the list
73 *
74 * @param linked_list calling object
75 * @param item value to insert in list
76 * @returns SUCCESS if succeeded, FAILED otherwise
77 */
78 status_t (*insert_first) (linked_list_t *linked_list, void *item);
79
80 /**
81 * @brief removes the first item in the list and returns its value
82 *
83 * @param linked_list calling object
84 * @param item returned value of first item
85 * @returns SUCCESS if succeeded, FAILED otherwise
86 */
87 status_t (*remove_first) (linked_list_t *linked_list, void **item);
88
89 /**
90 * @brief Returns the value of the first list item without removing it
91 *
92 * @param linked_list calling object
93 * @param item returned value of first item
94 * @returns SUCCESS if succeeded, FAILED otherwise
95 */
96 status_t (*get_first) (linked_list_t *linked_list, void **item);
97
98 /**
99 * @brief inserts a new item at the end of the list
100 *
101 * @param linked_list calling object
102 * @param item value to insert in list
103 * @returns SUCCESS if succeeded, FAILED otherwise
104 */
105 status_t (*insert_last) (linked_list_t *linked_list, void *item);
106
107 /**
108 * @brief removes the last item in the list and returns its value
109 *
110 * @param linked_list calling object
111 * @param item returned value of last item
112 * @returns SUCCESS if succeeded, FAILED otherwise
113 */
114 status_t (*remove_last) (linked_list_t *linked_list, void **item);
115
116 /**
117 * @brief Returns the value of the last list item without removing it
118 *
119 * @param linked_list calling object
120 * @param item returned value of last item
121 * @returns SUCCESS if succeeded, FAILED otherwise
122 */
123 status_t (*get_last) (linked_list_t *linked_list, void **item);
124
125 /**
126 * @brief Destroys a linked_list object
127 *
128 * @param linked_list calling object
129 * @returns SUCCESS if succeeded, FAILED otherwise
130 */
131 status_t (*destroy) (linked_list_t *linked_list);
132 };
133
134 /**
135 * @brief
136 *
137 * Creates an empty linked list object
138 */
139 linked_list_t *linked_list_create(void);
140
141
142 #endif /*LINKED_LIST_H_*/