root / proj / libs / classes / include / list.h @ 351
History | View | Annotate | Download (4.18 KB)
1 | 226 | up20180642 | #ifndef LIST_H_INCLUDED
|
---|---|---|---|
2 | #define LIST_H_INCLUDED
|
||
3 | |||
4 | 316 | up20180642 | /**
|
5 | 328 | up20180642 | * @defgroup list_t list_t
|
6 | 331 | up20180642 | * @ingroup classes
|
7 | 328 | up20180642 | * @brief List module
|
8 | 316 | up20180642 | *
|
9 | 328 | up20180642 | * 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 | 316 | up20180642 | * Can be used like a C++ std::list iterator.
|
21 | * A list node stores a void* to allow for more flexibility.
|
||
22 | 328 | up20180642 | *
|
23 | * @{
|
||
24 | 316 | up20180642 | */
|
25 | 328 | up20180642 | |
26 | 336 | up20180642 | /**
|
27 | * @brief List node.
|
||
28 | */
|
||
29 | 226 | up20180642 | typedef struct list_node list_node_t; |
30 | |||
31 | 316 | up20180642 | /**
|
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 | 226 | up20180642 | list_node_t* (list_node_ctor)(list_node_t *p, list_node_t *n, void *val);
|
39 | 316 | up20180642 | /**
|
40 | * @brief Destruct list node.
|
||
41 | * @param p Pointer to list node to be destroyed
|
||
42 | */
|
||
43 | 226 | up20180642 | void (list_node_dtor)(list_node_t *p);
|
44 | 316 | up20180642 | /**
|
45 | * @brief Get next node.
|
||
46 | * @param p Pointer to list node
|
||
47 | * @return Pointer to next list node
|
||
48 | */
|
||
49 | 226 | up20180642 | list_node_t* (list_node_next)(const list_node_t *p);
|
50 | 316 | up20180642 | /**
|
51 | * @brief Get previous node.
|
||
52 | * @param p Pointer to list node
|
||
53 | * @return Pointer to previous list node
|
||
54 | */
|
||
55 | 226 | up20180642 | list_node_t* (list_node_prev)(const list_node_t *p);
|
56 | 316 | up20180642 | /**
|
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 | 226 | up20180642 | void** (list_node_val )(list_node_t *p);
|
62 | |||
63 | 316 | up20180642 | /**
|
64 | 328 | up20180642 | * @}
|
65 | 316 | up20180642 | */
|
66 | 328 | up20180642 | |
67 | 336 | up20180642 | /**
|
68 | * @brief List.
|
||
69 | */
|
||
70 | 226 | up20180642 | typedef struct list list_t; |
71 | |||
72 | 316 | up20180642 | /**
|
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 | 275 | up20180642 | void (list_push_back)(list_t *l, void *val); |
131 | 316 | up20180642 | /**
|
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 | 275 | up20180642 | void (list_pop_front)(list_t *l);
|
142 | 316 | up20180642 | /**
|
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 | 226 | up20180642 | |
152 | 328 | up20180642 | /**
|
153 | * @}
|
||
154 | */
|
||
155 | |||
156 | 226 | up20180642 | #endif //LIST_H_INCLUDED |