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