summaryrefslogtreecommitdiff
path: root/tests/suite/ecore/src/include/eina_inlist.h
blob: 6e55de38eaf46ad3fe733df1836f6cdef0d6483c (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/* EINA - EFL data type library
 * Copyright (C) 2002-2008 Carsten Haitzler, Vincent Torri
 *
 * 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_INLIST_H_
#define EINA_INLIST_H_

#include "eina_types.h"
#include "eina_iterator.h"
#include "eina_accessor.h"
#include <stddef.h>

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

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

/**
 * @defgroup Eina_Inline_List_Group Inline List
 *
 * @{
 */

/**
 * @typedef Eina_Inlist
 * Inlined list type.
 */
typedef struct _Eina_Inlist Eina_Inlist;

/**
 * @struct _Eina_Inlist
 * Inlined list type.
 */
struct _Eina_Inlist {
	Eina_Inlist *next;
		      /**< next node */
	Eina_Inlist *prev;
		      /**< previous node */
	Eina_Inlist *last;
		      /**< last node */
};

#define EINA_INLIST Eina_Inlist __in_list
#define EINA_INLIST_GET(Inlist) (& ((Inlist)->__in_list))
#define EINA_INLIST_CONTAINER_GET(ptr, \
                                  type) ((type *)((char *)ptr - \
                                                  offsetof(type, __in_list)))

EAPI Eina_Inlist *eina_inlist_append(Eina_Inlist * in_list,
				     Eina_Inlist *
				     in_item) EINA_ARG_NONNULL(2)
    EINA_WARN_UNUSED_RESULT;
EAPI Eina_Inlist *eina_inlist_prepend(Eina_Inlist * in_list,
				      Eina_Inlist *
				      in_item) EINA_ARG_NONNULL(2)
    EINA_WARN_UNUSED_RESULT;
EAPI Eina_Inlist *eina_inlist_append_relative(Eina_Inlist * in_list,
					      Eina_Inlist * in_item,
					      Eina_Inlist *
					      in_relative)
EINA_ARG_NONNULL(2) EINA_WARN_UNUSED_RESULT;
EAPI Eina_Inlist *eina_inlist_prepend_relative(Eina_Inlist * in_list,
					       Eina_Inlist * in_item,
					       Eina_Inlist *
					       in_relative)
EINA_ARG_NONNULL(2) EINA_WARN_UNUSED_RESULT;
EAPI Eina_Inlist *eina_inlist_remove(Eina_Inlist * in_list,
				     Eina_Inlist *
				     in_item) EINA_ARG_NONNULL(1,
							       2)
    EINA_WARN_UNUSED_RESULT;
EAPI Eina_Inlist *eina_inlist_find(Eina_Inlist * in_list,
				   Eina_Inlist *
				   in_item) EINA_ARG_NONNULL(2)
    EINA_WARN_UNUSED_RESULT;
EAPI Eina_Inlist *eina_inlist_promote(Eina_Inlist * list,
				      Eina_Inlist *
				      item) EINA_ARG_NONNULL(1,
							     2)
    EINA_WARN_UNUSED_RESULT;
EAPI Eina_Inlist *eina_inlist_demote(Eina_Inlist * list,
				     Eina_Inlist *
				     item) EINA_ARG_NONNULL(1,
							    2)
    EINA_WARN_UNUSED_RESULT;
EAPI unsigned int eina_inlist_count(const Eina_Inlist *
				    list) EINA_WARN_UNUSED_RESULT;

EAPI Eina_Iterator *eina_inlist_iterator_new(const Eina_Inlist * in_list)
EINA_MALLOC EINA_WARN_UNUSED_RESULT;
EAPI Eina_Accessor *eina_inlist_accessor_new(const Eina_Inlist * in_list)
EINA_MALLOC EINA_WARN_UNUSED_RESULT;

/* This two macros are helpers for the _FOREACH ones, don't use them */
#define _EINA_INLIST_OFFSET(ref) ((char *)&(ref)->__in_list - (char *)(ref))
#define _EINA_INLIST_CONTAINER(ref, ptr) (void *)((char *)(ptr) - \
                                                  _EINA_INLIST_OFFSET(ref))

#define EINA_INLIST_FOREACH(list, l) \
   for (l = NULL, l = (list ? _EINA_INLIST_CONTAINER(l, list) : NULL); l; \
        l = (EINA_INLIST_GET(l)->next ? _EINA_INLIST_CONTAINER(l, EINA_INLIST_GET(l)->next) : NULL))
#define EINA_INLIST_REVERSE_FOREACH(list, l) \
   for (l = NULL, l = (list ? _EINA_INLIST_CONTAINER(l, list->last) : NULL); \
        l; l = (EINA_INLIST_GET(l)->prev ? _EINA_INLIST_CONTAINER(l, EINA_INLIST_GET(l)->prev) : NULL))

/**
 * @}
 */

/**
 * @}
 */

/**
 * @}
 */

#endif				/*EINA_INLIST_H_ */