summaryrefslogtreecommitdiff
path: root/tests/suite/ecore/src/include/eina_trash.h
blob: c7088e4f8a0a531f00c440ef308f0b2cb0ec9f48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* EINA - EFL data type library
 * Copyright (C) 2002-2008 Carsten Haitzler, Vincent Torri, Jorge Luis Zapata Muga
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library;
 * if not, see <http://www.gnu.org/licenses/>.
 */

#ifndef EINA_TRASH_H__
#define EINA_TRASH_H__

/**
 * @addtogroup Eina_Data_Types_Group Data Types
 *
 * @{
 */

/**
 * @addtogroup Eina_Containers_Group Containers
 *
 * @{
 */

/**
 * @defgroup Eina_Trash_Group Trash
 *
 * @{
 */

/**
 * @typedef Eina_Trash
 * Type for a generic container of unused allocated pointer.
 */
typedef struct _Eina_Trash Eina_Trash;

/**
 * @struct _Eina_Trash
 * Type for a generic container of unused allocated pointer.
 */
struct _Eina_Trash {
	Eina_Trash *next;
		     /**< next item in trash. */
};

static inline void eina_trash_init(Eina_Trash **
				   trash) EINA_ARG_NONNULL(1);
static inline void eina_trash_push(Eina_Trash ** trash,
				   void *data) EINA_ARG_NONNULL(1);
static inline void *eina_trash_pop(Eina_Trash **
				   trash) EINA_ARG_NONNULL(1)
    EINA_WARN_UNUSED_RESULT;

/**
 * @def EINA_TRASH_CLEAN
 * @brief Macro to remove all pointer from the trash.
 *
 * @param trash The trash to clean.
 * @param data The pointer extracted from the trash.
 *
 * This macro allow the cleaning of @p trash in an easy way. It will
 * remove all pointers from @p trash until it's empty.
 *
 * This macro can be used for freeing the data in the trash, like in
 * the following example:
 *
 * @code
 * Eina_Trash *trash = NULL;
 * char *data;
 *
 * // trash is filled with pointer to some duped strings.
 *
 * EINA_TRASH_CLEAN(&trash, data)
 *   free(data);
 * @endcode
 *
 * @note this macro is useful when you implement some memory pool.
 */
#define EINA_TRASH_CLEAN(trash, data) while ((data = eina_trash_pop(trash))

#include "eina_inline_trash.x"

/**
 * @}
 */

/**
 * @}
 */

/**
 * @}
 */

#endif				/* EINA_TRASH_H_ */