EFL 1.7 svn doobies
[profile/ivi/eina.git] / src / include / eina_trash.h
1 /* EINA - EFL data type library
2  * Copyright (C) 2002-2008 Carsten Haitzler, Vincent Torri, Jorge Luis Zapata Muga
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library;
16  * if not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #ifndef EINA_TRASH_H__
20 #define EINA_TRASH_H__
21
22 /**
23  * @addtogroup Eina_Data_Types_Group Data Types
24  *
25  * @{
26  */
27
28 /**
29  * @addtogroup Eina_Containers_Group Containers
30  *
31  * @{
32  */
33
34 /**
35  * @defgroup Eina_Trash_Group Trash
36  *
37  * @{
38  */
39
40 /**
41  * @typedef Eina_Trash
42  * Type for a generic container of unused allocated pointer.
43  */
44 typedef struct _Eina_Trash Eina_Trash;
45
46 /**
47  * @struct _Eina_Trash
48  * Type for a generic container of unused allocated pointer.
49  */
50 struct _Eina_Trash
51 {
52    Eina_Trash *next; /**< next item in trash. */
53 };
54
55 static inline void  eina_trash_init(Eina_Trash **trash) EINA_ARG_NONNULL(1);
56 static inline void  eina_trash_push(Eina_Trash **trash, void *data) EINA_ARG_NONNULL(1);
57 static inline void *eina_trash_pop(Eina_Trash **trash) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;
58
59 /**
60  * @def EINA_TRASH_CLEAN
61  * @brief Macro to remove all pointer from the trash.
62  *
63  * @param trash The trash to clean.
64  * @param data The pointer extracted from the trash.
65  *
66  * This macro allow the cleaning of @p trash in an easy way. It will
67  * remove all pointers from @p trash until it's empty.
68  *
69  * This macro can be used for freeing the data in the trash, like in
70  * the following example:
71  *
72  * @code
73  * Eina_Trash *trash = NULL;
74  * char *data;
75  *
76  * // trash is filled with pointer to some duped strings.
77  *
78  * EINA_TRASH_CLEAN(&trash, data)
79  *   free(data);
80  * @endcode
81  *
82  * @note this macro is useful when you implement some memory pool.
83  */
84 #define EINA_TRASH_CLEAN(trash, data) while ((data = eina_trash_pop(trash)))
85
86 #include "eina_inline_trash.x"
87
88 /**
89  * @}
90  */
91
92 /**
93  * @}
94  */
95
96 /**
97  * @}
98  */
99
100 #endif /* EINA_TRASH_H_ */