ds: list: update iterator interface
This commit is contained in:
@@ -56,7 +56,7 @@ BLUE_API void b_list_delete_all(b_list *q);
|
|||||||
BLUE_API void *b_list_entry_value(const b_list_entry *entry);
|
BLUE_API void *b_list_entry_value(const b_list_entry *entry);
|
||||||
|
|
||||||
BLUE_API b_iterator *b_list_begin(b_list *q);
|
BLUE_API b_iterator *b_list_begin(b_list *q);
|
||||||
BLUE_API b_iterator *b_list_cbegin(const b_list *q);
|
BLUE_API const b_iterator *b_list_cbegin(const b_list *q);
|
||||||
|
|
||||||
B_DECLS_END;
|
B_DECLS_END;
|
||||||
|
|
||||||
|
|||||||
38
ds/list.c
38
ds/list.c
@@ -365,22 +365,7 @@ void *b_list_entry_value(const struct b_list_entry *entry)
|
|||||||
return entry ? entry->e_data : NULL;
|
return entry ? entry->e_data : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*** VIRTUAL FUNCTIONS ********************************************************/
|
b_iterator *b_list_begin(b_list *q)
|
||||||
|
|
||||||
static void list_init(b_object *obj, void *priv)
|
|
||||||
{
|
|
||||||
struct b_list_p *list = priv;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void list_fini(b_object *obj, void *priv)
|
|
||||||
{
|
|
||||||
struct b_list_p *list = priv;
|
|
||||||
list_delete_all(list);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*** ITERATOR FUNCTIONS *******************************************************/
|
|
||||||
|
|
||||||
static b_iterator *iterable_begin(b_list *q)
|
|
||||||
{
|
{
|
||||||
b_list_iterator *it_obj = b_object_create(B_TYPE_LIST_ITERATOR);
|
b_list_iterator *it_obj = b_object_create(B_TYPE_LIST_ITERATOR);
|
||||||
struct b_list_iterator_p *it
|
struct b_list_iterator_p *it
|
||||||
@@ -399,7 +384,7 @@ static b_iterator *iterable_begin(b_list *q)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const b_iterator *iterable_cbegin(const b_list *q)
|
const b_iterator *b_list_cbegin(const b_list *q)
|
||||||
{
|
{
|
||||||
b_list_iterator *it_obj = b_object_create(B_TYPE_LIST_ITERATOR);
|
b_list_iterator *it_obj = b_object_create(B_TYPE_LIST_ITERATOR);
|
||||||
struct b_list_iterator_p *it
|
struct b_list_iterator_p *it
|
||||||
@@ -418,6 +403,21 @@ static const b_iterator *iterable_cbegin(const b_list *q)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*** VIRTUAL FUNCTIONS ********************************************************/
|
||||||
|
|
||||||
|
static void list_init(b_object *obj, void *priv)
|
||||||
|
{
|
||||||
|
struct b_list_p *list = priv;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void list_fini(b_object *obj, void *priv)
|
||||||
|
{
|
||||||
|
struct b_list_p *list = priv;
|
||||||
|
list_delete_all(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*** ITERATOR FUNCTIONS *******************************************************/
|
||||||
|
|
||||||
static enum b_status iterator_move_next(const b_iterator *obj)
|
static enum b_status iterator_move_next(const b_iterator *obj)
|
||||||
{
|
{
|
||||||
struct b_list_iterator_p *it
|
struct b_list_iterator_p *it
|
||||||
@@ -493,8 +493,8 @@ B_TYPE_CLASS_DEFINITION_BEGIN(b_list)
|
|||||||
B_TYPE_CLASS_INTERFACE_END(b_object, B_TYPE_OBJECT)
|
B_TYPE_CLASS_INTERFACE_END(b_object, B_TYPE_OBJECT)
|
||||||
|
|
||||||
B_TYPE_CLASS_INTERFACE_BEGIN(b_iterable, B_TYPE_ITERABLE)
|
B_TYPE_CLASS_INTERFACE_BEGIN(b_iterable, B_TYPE_ITERABLE)
|
||||||
B_INTERFACE_ENTRY(it_begin) = iterable_begin;
|
B_INTERFACE_ENTRY(it_begin) = b_list_begin;
|
||||||
B_INTERFACE_ENTRY(it_cbegin) = iterable_cbegin;
|
B_INTERFACE_ENTRY(it_cbegin) = b_list_cbegin;
|
||||||
B_TYPE_CLASS_INTERFACE_END(b_iterable, B_TYPE_ITERABLE)
|
B_TYPE_CLASS_INTERFACE_END(b_iterable, B_TYPE_ITERABLE)
|
||||||
B_TYPE_CLASS_DEFINITION_END(b_list)
|
B_TYPE_CLASS_DEFINITION_END(b_list)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user