Project

General

Profile

Statistics
| Revision:

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

History | View | Annotate | Download (4.16 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
struct list_node;
27
typedef struct list_node list_node_t;
28

    
29
/**
30
 * @brief Construct list node.
31
 * @param   p   Pointer to previous list node
32
 * @param   n   Pointer to next list node
33
 * @param   val Value to be stored in the list node
34
 * @return      Pointer to created list node
35
 */
36
list_node_t* (list_node_ctor)(list_node_t *p, list_node_t *n, void *val);
37
/**
38
 * @brief Destruct list node.
39
 * @param   p   Pointer to list node to be destroyed
40
 */
41
void         (list_node_dtor)(list_node_t *p);
42
/**
43
 * @brief Get next node.
44
 * @param   p   Pointer to list node
45
 * @return      Pointer to next list node
46
 */
47
list_node_t* (list_node_next)(const list_node_t *p);
48
/**
49
 * @brief Get previous node.
50
 * @param   p   Pointer to list node
51
 * @return      Pointer to previous list node
52
 */
53
list_node_t* (list_node_prev)(const list_node_t *p);
54
/**
55
 * @brief Get value stored in the node.
56
 * @param   p   Pointer to list node
57
 * @return      Pointer to the stored value (which is in turn a void*).
58
 */
59
void**       (list_node_val )(list_node_t *p);
60

    
61
/**
62
 * @}
63
 */
64

    
65
struct list;
66

    
67
typedef struct list list_t;
68

    
69
/**
70
 * @brief Construct empty list.
71
 * @return  Pointer to created list
72
 */
73
list_t*      (list_ctor)     (void);
74
/**
75
 * @brief Destruct list.
76
 *
77
 * A list can only be destroyed once it is empty.
78
 * This is because a list stores void*, whose memory most likely need to be free'd.
79
 * @param   l   Pointer to list to be destroyed
80
 * @return      SUCCESS if the destruction was successful, other value otherwise.
81
 */
82
int          (list_dtor)     (list_t *l);
83
/**
84
 * @brief Get pointer to the first node of the list.
85
 * @param   l   Pointer to list
86
 * @return      Pointer to first node of the list.
87
 */
88
list_node_t* (list_begin)    (list_t *l);
89
/**
90
 * @brief Get pointer to the past-the-end node of the list.
91
 * @param   l   Pointer to list
92
 * @return      Pointer to past-the-end node of the list
93
 */
94
list_node_t* (list_end)      (list_t *l);
95
/**
96
 * @brief Get size of the list.
97
 * @param   l   Pointer to list
98
 * @return      Size of the list
99
 */
100
size_t       (list_size)     (const list_t *l);
101
/**
102
 * @brief Know if list is empty or not.
103
 * @param   l   Pointer to list
104
 * @return      true if the list is empty (size is zero), false otherwise
105
 */
106
int          (list_empty)    (const list_t *l);
107
/**
108
 * @brief Insert value in list.
109
 * @param   l           Pointer to list
110
 * @param   position    Pointer to node, before which the new value will be inserted
111
 * @param   val         Value to be inserted before position
112
 * @return              Pointer to newly-created node
113
 */
114
list_node_t* (list_insert)   (list_t *l, list_node_t *position, void *val);
115
/**
116
 * @brief Erase value in list.
117
 * @param   l           Pointer to list
118
 * @param   position    Node to be deleted
119
 * @return  Value contained in the deleted node, which must be free'd if appropriate
120
 */
121
void*        (list_erase)    (list_t *l, list_node_t *position);
122
/**
123
 * @brief Insert new value at the end of the list.
124
 * @param   l   Pointer to list
125
 * @param   val Value to be inserted
126
 */
127
void         (list_push_back)(list_t *l, void *val);
128
/**
129
 * @brief Get first element of the list.
130
 * @param   l   Pointer to list
131
 * @return      Pointer to value at the beginning of the list
132
 */
133
void**       (list_front)    (list_t *l);
134
/**
135
 * @brief Erase first element of the list.
136
 * @param   l   Pointer to list
137
 */
138
void         (list_pop_front)(list_t *l);
139
/**
140
 * @brief Find value in list.
141
 *
142
 * Values are found by direct comparison of void*
143
 * @param   l   Pointer to list
144
 * @param   val Pointer to value to be found in the list
145
 * @return  Node whose value compares equal to val, or past-the-end node if not found
146
 */
147
list_node_t* (list_find)     (list_t *l, void *val);
148

    
149
/**
150
 * @}
151
 */
152

    
153
#endif //LIST_H_INCLUDED