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