libuproc  1.2.0
list.h
Go to the documentation of this file.
1 /* Copyright 2014 Peter Meinicke, Robin Martinjak
2  *
3  * This file is part of libuproc.
4  *
5  * libuproc is free software: you can redistribute it and/or modify it under
6  * the terms of the GNU Lesser General Public License as published by the Free
7  * Software Foundation, either version 3 of the License, or (at your option)
8  * any later version.
9  *
10  * libuproc is distributed in the hope that it will be useful, but WITHOUT ANY
11  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with libuproc. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
33 #ifndef UPROC_LIST_H
34 #define UPROC_LIST_H
35 
36 #include <stdlib.h>
37 #include <string.h>
38 
51 typedef struct uproc_list_s uproc_list;
52 
57 uproc_list *uproc_list_create(size_t value_size);
58 
60 void uproc_list_destroy(uproc_list *list);
61 
63 void uproc_list_clear(uproc_list *list);
64 
65 int uproc_list_get_safe(const uproc_list *list, long index, void *value,
66  size_t value_size);
67 
68 /* Get item at index
69  *
70  * Copies the data of the item at \c index into \c *value.
71  * NOTE: \c value WILL BE EVALUATED TWICE.
72  */
73 #define uproc_list_get(list, index, value) \
74  uproc_list_get_safe((list), (index), (value), sizeof *(value))
75 
76 size_t uproc_list_get_all_safe(const uproc_list *list, void *buf, size_t sz,
77  size_t value_size);
92 #define uproc_list_get_all(list, buf, sz) \
93  uproc_list_get_all_safe((list), (buf), (sz), sizeof *(buf))
94 
95 int uproc_list_set_safe(uproc_list *list, long index, const void *value,
96  size_t value_size);
97 
104 #define uproc_list_set(list, index, value) \
105  uproc_list_set_safe((list), (index), (value), sizeof *(value))
106 
107 int uproc_list_append_safe(uproc_list *list, const void *value,
108  size_t value_size);
109 
115 #define uproc_list_append(list, value) \
116  uproc_list_append_safe((list), (value), sizeof *(value))
117 
118 int uproc_list_extend_safe(uproc_list *list, const void *values, long n,
119  size_t value_size);
120 
127 #define uproc_list_extend(list, values, n) \
128  uproc_list_extend_safe((list), (values), (n), sizeof *(values))
129 
135 int uproc_list_add(uproc_list *list, const uproc_list *src);
136 
137 int uproc_list_pop_safe(uproc_list *list, void *value, size_t value_size);
138 
144 #define uproc_list_pop(list, value) \
145  uproc_list_pop_safe((list), (value), sizeof *(value))
146 
148 long uproc_list_size(const uproc_list *list);
149 
160 void uproc_list_map(const uproc_list *list, void (*func)(void *, void *),
161  void *opaque);
168 #endif
List of homogenous items (also known as "vector" or "arraylist")
void uproc_list_clear(uproc_list *list)
Remove all items.
int uproc_list_add(uproc_list *list, const uproc_list *src)
Append all elements of another list.
void uproc_list_map(const uproc_list *list, void(*func)(void *, void *), void *opaque)
Apply function to all items.
void uproc_list_destroy(uproc_list *list)
Destroy list object.
uproc_list * uproc_list_create(size_t value_size)
Create an empty list.
long uproc_list_size(const uproc_list *list)
Returns the number of items.