1 /* EINA - EFL data type library
2 * Copyright (C) 2002-2008 Cedric Bail
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.
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.
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/>.
25 #include "eina_config.h"
26 #include "eina_private.h"
28 /* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
29 #include "eina_safety_checks.h"
30 #include "eina_accessor.h"
32 /*============================================================================*
34 *============================================================================*/
40 static const char EINA_MAGIC_ACCESSOR_STR[] = "Eina Accessor";
42 #define EINA_MAGIC_CHECK_ACCESSOR(d) \
44 if (!EINA_MAGIC_CHECK(d, EINA_MAGIC_ACCESSOR)) { \
45 EINA_MAGIC_FAIL(d, EINA_MAGIC_ACCESSOR); } \
52 /*============================================================================*
54 *============================================================================*/
58 * @brief Initialize the accessor module.
60 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
62 * This function sets up the accessor module of Eina. It is called by
68 eina_accessor_init(void)
70 return eina_magic_string_set(EINA_MAGIC_ACCESSOR, EINA_MAGIC_ACCESSOR_STR);
75 * @brief Shut down the accessor module.
77 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
79 * This function shuts down the accessor module set up by
80 * eina_accessor_init(). It is called by eina_shutdown().
82 * @see eina_shutdown()
85 eina_accessor_shutdown(void)
90 /*============================================================================*
92 *============================================================================*/
96 eina_accessor_free(Eina_Accessor *accessor)
101 EINA_MAGIC_CHECK_ACCESSOR(accessor);
102 EINA_SAFETY_ON_NULL_RETURN(accessor->free);
103 accessor->free(accessor);
107 eina_accessor_container_get(Eina_Accessor *accessor)
109 EINA_MAGIC_CHECK_ACCESSOR(accessor);
110 EINA_SAFETY_ON_NULL_RETURN_VAL(accessor, NULL);
111 EINA_SAFETY_ON_NULL_RETURN_VAL(accessor->get_container, NULL);
112 return accessor->get_container(accessor);
116 eina_accessor_data_get(Eina_Accessor *accessor,
117 unsigned int position,
120 EINA_MAGIC_CHECK_ACCESSOR(accessor);
121 EINA_SAFETY_ON_NULL_RETURN_VAL(accessor, EINA_FALSE);
122 EINA_SAFETY_ON_NULL_RETURN_VAL(accessor->get_at, EINA_FALSE);
123 EINA_SAFETY_ON_NULL_RETURN_VAL(data, EINA_FALSE);
124 return accessor->get_at(accessor, position, data);
128 eina_accessor_over(Eina_Accessor *accessor,
134 const void *container;
138 if (!accessor) return ;
140 EINA_MAGIC_CHECK_ACCESSOR(accessor);
141 EINA_SAFETY_ON_NULL_RETURN(accessor->get_container);
142 EINA_SAFETY_ON_NULL_RETURN(accessor->get_at);
143 EINA_SAFETY_ON_NULL_RETURN(cb);
144 EINA_SAFETY_ON_FALSE_RETURN(start < end);
146 if (!eina_accessor_lock(accessor))
149 container = accessor->get_container(accessor);
150 for (i = start; i < end && accessor->get_at(accessor, i, &data) == EINA_TRUE;
152 if (cb(container, data, (void *)fdata) != EINA_TRUE)
156 (void) eina_accessor_unlock(accessor);
160 eina_accessor_lock(Eina_Accessor *accessor)
162 EINA_MAGIC_CHECK_ACCESSOR(accessor);
163 EINA_SAFETY_ON_NULL_RETURN_VAL(accessor, EINA_FALSE);
166 return accessor->lock(accessor);
171 eina_accessor_unlock(Eina_Accessor *accessor)
173 EINA_MAGIC_CHECK_ACCESSOR(accessor);
174 EINA_SAFETY_ON_NULL_RETURN_VAL(accessor, EINA_FALSE);
176 if (accessor->unlock)
177 return accessor->unlock(accessor);