root / proj / libs / classes / include / list.h @ 352
History | View | Annotate | Download (4.18 KB)
1 |
#ifndef LIST_H_INCLUDED
|
---|---|
2 |
#define LIST_H_INCLUDED
|
3 |
|
4 |
/**
|
5 |
* @defgroup list_t list_t
|
6 |
* @ingroup classes
|
7 |
* @brief List module
|
8 |
*
|
9 |
* Can be used like a C++ std::list.
|
10 |
* A list_t is a sequence of list_node_t nodes, that store void* to allow for more flexibility.
|
11 |
*
|
12 |
* @{
|
13 |
*/
|
14 |
|
15 |
/**
|
16 |
* @defgroup list_node_t list_node_t
|
17 |
* @ingroup list
|
18 |
* @brief List node module
|
19 |
*
|
20 |
* Can be used like a C++ std::list iterator.
|
21 |
* A list node stores a void* to allow for more flexibility.
|
22 |
*
|
23 |
* @{
|
24 |
*/
|
25 |
|
26 |
/**
|
27 |
* @brief List node.
|
28 |
*/
|
29 |
typedef struct list_node list_node_t; |
30 |
|
31 |
/**
|
32 |
* @brief Construct list node.
|
33 |
* @param p Pointer to previous list node
|
34 |
* @param n Pointer to next list node
|
35 |
* @param val Value to be stored in the list node
|
36 |
* @return Pointer to created list node
|
37 |
*/
|
38 |
list_node_t* (list_node_ctor)(list_node_t *p, list_node_t *n, void *val);
|
39 |
/**
|
40 |
* @brief Destruct list node.
|
41 |
* @param p Pointer to list node to be destroyed
|
42 |
*/
|
43 |
void (list_node_dtor)(list_node_t *p);
|
44 |
/**
|
45 |
* @brief Get next node.
|
46 |
* @param p Pointer to list node
|
47 |
* @return Pointer to next list node
|
48 |
*/
|
49 |
list_node_t* (list_node_next)(const list_node_t *p);
|
50 |
/**
|
51 |
* @brief Get previous node.
|
52 |
* @param p Pointer to list node
|
53 |
* @return Pointer to previous list node
|
54 |
*/
|
55 |
list_node_t* (list_node_prev)(const list_node_t *p);
|
56 |
/**
|
57 |
* @brief Get value stored in the node.
|
58 |
* @param p Pointer to list node
|
59 |
* @return Pointer to the stored value (which is in turn a void*).
|
60 |
*/
|
61 |
void** (list_node_val )(list_node_t *p);
|
62 |
|
63 |
/**
|
64 |
* @}
|
65 |
*/
|
66 |
|
67 |
/**
|
68 |
* @brief List.
|
69 |
*/
|
70 |
typedef struct list list_t; |
71 |
|
72 |
/**
|
73 |
* @brief Construct empty list.
|
74 |
* @return Pointer to created list
|
75 |
*/
|
76 |
list_t* (list_ctor) (void);
|
77 |
/**
|
78 |
* @brief Destruct list.
|
79 |
*
|
80 |
* A list can only be destroyed once it is empty.
|
81 |
* This is because a list stores void*, whose memory most likely need to be free'd.
|
82 |
* @param l Pointer to list to be destroyed
|
83 |
* @return SUCCESS if the destruction was successful, other value otherwise.
|
84 |
*/
|
85 |
int (list_dtor) (list_t *l);
|
86 |
/**
|
87 |
* @brief Get pointer to the first node of the list.
|
88 |
* @param l Pointer to list
|
89 |
* @return Pointer to first node of the list.
|
90 |
*/
|
91 |
list_node_t* (list_begin) (list_t *l); |
92 |
/**
|
93 |
* @brief Get pointer to the past-the-end node of the list.
|
94 |
* @param l Pointer to list
|
95 |
* @return Pointer to past-the-end node of the list
|
96 |
*/
|
97 |
list_node_t* (list_end) (list_t *l); |
98 |
/**
|
99 |
* @brief Get size of the list.
|
100 |
* @param l Pointer to list
|
101 |
* @return Size of the list
|
102 |
*/
|
103 |
size_t (list_size) (const list_t *l);
|
104 |
/**
|
105 |
* @brief Know if list is empty or not.
|
106 |
* @param l Pointer to list
|
107 |
* @return true if the list is empty (size is zero), false otherwise
|
108 |
*/
|
109 |
int (list_empty) (const list_t *l); |
110 |
/**
|
111 |
* @brief Insert value in list.
|
112 |
* @param l Pointer to list
|
113 |
* @param position Pointer to node, before which the new value will be inserted
|
114 |
* @param val Value to be inserted before position
|
115 |
* @return Pointer to newly-created node
|
116 |
*/
|
117 |
list_node_t* (list_insert) (list_t *l, list_node_t *position, void *val);
|
118 |
/**
|
119 |
* @brief Erase value in list.
|
120 |
* @param l Pointer to list
|
121 |
* @param position Node to be deleted
|
122 |
* @return Value contained in the deleted node, which must be free'd if appropriate
|
123 |
*/
|
124 |
void* (list_erase) (list_t *l, list_node_t *position);
|
125 |
/**
|
126 |
* @brief Insert new value at the end of the list.
|
127 |
* @param l Pointer to list
|
128 |
* @param val Value to be inserted
|
129 |
*/
|
130 |
void (list_push_back)(list_t *l, void *val); |
131 |
/**
|
132 |
* @brief Get first element of the list.
|
133 |
* @param l Pointer to list
|
134 |
* @return Pointer to value at the beginning of the list
|
135 |
*/
|
136 |
void** (list_front) (list_t *l);
|
137 |
/**
|
138 |
* @brief Erase first element of the list.
|
139 |
* @param l Pointer to list
|
140 |
*/
|
141 |
void (list_pop_front)(list_t *l);
|
142 |
/**
|
143 |
* @brief Find value in list.
|
144 |
*
|
145 |
* Values are found by direct comparison of void*
|
146 |
* @param l Pointer to list
|
147 |
* @param val Pointer to value to be found in the list
|
148 |
* @return Node whose value compares equal to val, or past-the-end node if not found
|
149 |
*/
|
150 |
list_node_t* (list_find) (list_t *l, void *val);
|
151 |
|
152 |
/**
|
153 |
* @}
|
154 |
*/
|
155 |
|
156 |
#endif //LIST_H_INCLUDED |