2008-08-11 09:30:16 -07:00
|
|
|
/*
|
|
|
|
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
|
|
|
|
*/
|
|
|
|
/* EINA - EFL data type library
|
2008-09-01 05:42:16 -07:00
|
|
|
* Copyright (C) 2002-2008 Cedric Bail
|
2008-08-11 09:30:16 -07:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2008-08-28 00:46:42 -07:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2008-08-11 09:30:16 -07:00
|
|
|
#include "eina_private.h"
|
|
|
|
|
2008-12-09 05:06:17 -08:00
|
|
|
#include "eina_accessor.h"
|
Make it possible to create iterators outside Eina.
Many places in EFL we just create walk something, create a list with
walked data, return, then the user walks it again and then deletes
(which will walk again). For such cases it's way better to define
iterators or accessors.
I'm not moving any EFL code to it now, but if people are interested,
things like evas_render_method_list(), evas_font_available_list(),
evas_objects_at_xy_get(), evas_objects_in_rectangle_get(),
evas_object_smart_members_get() are good candidates. If the subject is
already using Eina list, then you can just use
eina_list_iterator_new() and return it, otherwise you can define your
own iterator, which is very easy.
SVN revision: 37956
2008-12-05 19:41:03 -08:00
|
|
|
|
|
|
|
/*============================================================================*
|
|
|
|
* Local *
|
|
|
|
*============================================================================*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @cond LOCAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define EINA_MAGIC_CHECK_ACCESSOR(d) \
|
|
|
|
do { \
|
|
|
|
if (!EINA_MAGIC_CHECK(d, EINA_MAGIC_ACCESSOR)) \
|
|
|
|
EINA_MAGIC_FAIL(d, EINA_MAGIC_ACCESSOR); \
|
|
|
|
} while(0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @endcond
|
|
|
|
*/
|
|
|
|
|
2008-08-28 00:46:42 -07:00
|
|
|
/*============================================================================*
|
|
|
|
* Global *
|
|
|
|
*============================================================================*/
|
|
|
|
|
|
|
|
/*============================================================================*
|
|
|
|
* API *
|
|
|
|
*============================================================================*/
|
|
|
|
|
2008-09-07 00:19:19 -07:00
|
|
|
/**
|
|
|
|
* @addtogroup Eina_Content_Access_Group Content Access
|
|
|
|
*
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2008-09-15 12:58:36 -07:00
|
|
|
* @addtogroup Eina_Accessor_Group Accessor Functions
|
2008-09-07 00:19:19 -07:00
|
|
|
*
|
|
|
|
* @brief These functions manage accessor on containers.
|
|
|
|
*
|
|
|
|
* These functions allow to access elements of a container in a
|
|
|
|
* generic way, without knowing which container is used (a bit like
|
|
|
|
* iterators in the C++ STL). Accessors allows random access (that is, any
|
|
|
|
* element in the container). For sequential access, see
|
|
|
|
* @ref Eina_Iterator_Group.
|
|
|
|
*
|
|
|
|
* An accessor is created from container data types, so no creation
|
|
|
|
* function is available here. An accessor is deleted with
|
|
|
|
* eina_accessor_free(). To get the data of an element at a given
|
|
|
|
* position, use eina_accessor_data_get(). To call a function on
|
|
|
|
* chosen elements of a container, use eina_accessor_over().
|
|
|
|
*
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Free an accessor.
|
|
|
|
*
|
|
|
|
* @param accessor The accessor to free.
|
|
|
|
*
|
|
|
|
* This function frees @p accessor if it is not @c NULL;
|
|
|
|
*/
|
2008-08-11 09:30:16 -07:00
|
|
|
EAPI void
|
|
|
|
eina_accessor_free(Eina_Accessor *accessor)
|
|
|
|
{
|
Make it possible to create iterators outside Eina.
Many places in EFL we just create walk something, create a list with
walked data, return, then the user walks it again and then deletes
(which will walk again). For such cases it's way better to define
iterators or accessors.
I'm not moving any EFL code to it now, but if people are interested,
things like evas_render_method_list(), evas_font_available_list(),
evas_objects_at_xy_get(), evas_objects_in_rectangle_get(),
evas_object_smart_members_get() are good candidates. If the subject is
already using Eina list, then you can just use
eina_list_iterator_new() and return it, otherwise you can define your
own iterator, which is very easy.
SVN revision: 37956
2008-12-05 19:41:03 -08:00
|
|
|
EINA_MAGIC_CHECK_ACCESSOR(accessor);
|
2008-08-11 09:30:16 -07:00
|
|
|
if (accessor) accessor->free(accessor);
|
|
|
|
}
|
|
|
|
|
2008-09-07 00:19:19 -07:00
|
|
|
/**
|
|
|
|
* @brief Return the container of an accessor.
|
|
|
|
*
|
|
|
|
* @param accessor The accessor.
|
|
|
|
* @return The container which created the accessor.
|
|
|
|
*
|
|
|
|
* This function returns the container which created @p accessor. If
|
|
|
|
* @p accessor is @c NULL, this function returns @c NULL.
|
|
|
|
*/
|
2008-08-11 09:30:16 -07:00
|
|
|
EAPI void *
|
|
|
|
eina_accessor_container_get(Eina_Accessor *accessor)
|
|
|
|
{
|
Make it possible to create iterators outside Eina.
Many places in EFL we just create walk something, create a list with
walked data, return, then the user walks it again and then deletes
(which will walk again). For such cases it's way better to define
iterators or accessors.
I'm not moving any EFL code to it now, but if people are interested,
things like evas_render_method_list(), evas_font_available_list(),
evas_objects_at_xy_get(), evas_objects_in_rectangle_get(),
evas_object_smart_members_get() are good candidates. If the subject is
already using Eina list, then you can just use
eina_list_iterator_new() and return it, otherwise you can define your
own iterator, which is very easy.
SVN revision: 37956
2008-12-05 19:41:03 -08:00
|
|
|
EINA_MAGIC_CHECK_ACCESSOR(accessor);
|
2008-08-11 09:30:16 -07:00
|
|
|
if (!accessor) return NULL;
|
|
|
|
return accessor->get_container(accessor);
|
|
|
|
}
|
|
|
|
|
2008-09-07 00:19:19 -07:00
|
|
|
/**
|
|
|
|
* @brief Retrieve the data of an accessor at a given position.
|
|
|
|
*
|
|
|
|
* @param accessor The accessor.
|
|
|
|
* @param position The position of the element.
|
|
|
|
* @param data The pointer that stores the data to retrieve.
|
2008-09-17 11:55:54 -07:00
|
|
|
* @return #EINA_TRUE on success, #EINA_FALSE otherwise.
|
2008-09-07 00:19:19 -07:00
|
|
|
*
|
|
|
|
* This function retrieves the data of the element pointed by
|
|
|
|
* @p accessor at the porition @p position, and stores it in
|
|
|
|
* @p data. If @p accessor is @c NULL or if an error occurred,
|
|
|
|
* #EINA_FALSE is returned, otherwise EINA_TRUE is returned.
|
|
|
|
*/
|
|
|
|
EAPI Eina_Bool
|
|
|
|
eina_accessor_data_get(Eina_Accessor *accessor, unsigned int position, void **data)
|
|
|
|
{
|
Make it possible to create iterators outside Eina.
Many places in EFL we just create walk something, create a list with
walked data, return, then the user walks it again and then deletes
(which will walk again). For such cases it's way better to define
iterators or accessors.
I'm not moving any EFL code to it now, but if people are interested,
things like evas_render_method_list(), evas_font_available_list(),
evas_objects_at_xy_get(), evas_objects_in_rectangle_get(),
evas_object_smart_members_get() are good candidates. If the subject is
already using Eina list, then you can just use
eina_list_iterator_new() and return it, otherwise you can define your
own iterator, which is very easy.
SVN revision: 37956
2008-12-05 19:41:03 -08:00
|
|
|
EINA_MAGIC_CHECK_ACCESSOR(accessor);
|
2008-09-07 00:19:19 -07:00
|
|
|
if (!accessor) return EINA_FALSE;
|
|
|
|
return accessor->get_at(accessor, position, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Iterate over the container and execute a callback on chosen elements.
|
|
|
|
*
|
|
|
|
* @param accessor The accessor.
|
|
|
|
* @param cb The callback called on the chosen elements.
|
|
|
|
* @param start The position of the first element.
|
|
|
|
* @param end The position of the last element.
|
|
|
|
* @param fdata The data passed to the callback.
|
|
|
|
*
|
|
|
|
* This function iterates over the elements pointed by @p accessor,
|
|
|
|
* starting from the element at position @p start and ending to the
|
|
|
|
* element at position @p end. For Each element, the callback
|
|
|
|
* @p cb is called with the data @p fdata. If @p accessor is @c NULL
|
|
|
|
* or if @p start is greter or equal than @p end, the function returns
|
|
|
|
* immediatly.
|
|
|
|
*/
|
2008-08-11 09:30:16 -07:00
|
|
|
EAPI void
|
|
|
|
eina_accessor_over(Eina_Accessor *accessor,
|
|
|
|
Eina_Each cb,
|
|
|
|
unsigned int start,
|
|
|
|
unsigned int end,
|
|
|
|
const void *fdata)
|
|
|
|
{
|
|
|
|
void *container;
|
|
|
|
void *data;
|
|
|
|
unsigned int i = start;
|
|
|
|
|
Make it possible to create iterators outside Eina.
Many places in EFL we just create walk something, create a list with
walked data, return, then the user walks it again and then deletes
(which will walk again). For such cases it's way better to define
iterators or accessors.
I'm not moving any EFL code to it now, but if people are interested,
things like evas_render_method_list(), evas_font_available_list(),
evas_objects_at_xy_get(), evas_objects_in_rectangle_get(),
evas_object_smart_members_get() are good candidates. If the subject is
already using Eina list, then you can just use
eina_list_iterator_new() and return it, otherwise you can define your
own iterator, which is very easy.
SVN revision: 37956
2008-12-05 19:41:03 -08:00
|
|
|
EINA_MAGIC_CHECK_ACCESSOR(accessor);
|
|
|
|
|
2008-08-11 09:30:16 -07:00
|
|
|
if (!accessor) return ;
|
|
|
|
if (!(start < end)) return ;
|
|
|
|
|
2008-08-27 10:13:58 -07:00
|
|
|
container = eina_accessor_container_get(accessor);
|
2008-08-12 01:41:39 -07:00
|
|
|
for (i = start; i < end && accessor->get_at(accessor, i, &data) == EINA_TRUE; ++i)
|
2008-08-11 09:30:16 -07:00
|
|
|
if (cb(container, data, (void*) fdata) != EINA_TRUE) return ;
|
|
|
|
}
|
|
|
|
|
2008-09-07 00:19:19 -07:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
2008-08-11 09:30:16 -07:00
|
|
|
|
2008-09-07 00:19:19 -07:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|