Project

General

Profile

Statistics
| Revision:

root / proj / libs / classes / include / list.h @ 330

History | View | Annotate | Download (4.14 KB)

1
#ifndef LIST_H_INCLUDED
2
#define LIST_H_INCLUDED
3

    
4
/**
5
 * @defgroup    list_t    list_t
6
 * @brief List module
7
 *
8
 * 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
 * Can be used like a C++ std::list iterator.
20
 * A list node stores a void* to allow for more flexibility.
21
 *
22
 * @{
23
 */
24

    
25
struct list_node;
26
typedef struct list_node list_node_t;
27

    
28
/**
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
list_node_t* (list_node_ctor)(list_node_t *p, list_node_t *n, void *val);
36
/**
37
 * @brief Destruct list node.
38
 * @param   p   Pointer to list node to be destroyed
39
 */
40
void         (list_node_dtor)(list_node_t *p);
41
/**
42
 * @brief Get next node.
43
 * @param   p   Pointer to list node
44
 * @return      Pointer to next list node
45
 */
46
list_node_t* (list_node_next)(const list_node_t *p);
47
/**
48
 * @brief Get previous node.
49
 * @param   p   Pointer to list node
50
 * @return      Pointer to previous list node
51
 */
52
list_node_t* (list_node_prev)(const list_node_t *p);
53
/**
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
void**       (list_node_val )(list_node_t *p);
59

    
60
/**
61
 * @}
62
 */
63

    
64
struct list;
65

    
66
typedef struct list list_t;
67

    
68
/**
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
void         (list_push_back)(list_t *l, void *val);
127
/**
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
void         (list_pop_front)(list_t *l);
138
/**
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

    
148
/**
149
 * @}
150
 */
151

    
152
#endif //LIST_H_INCLUDED