fx.collections: update iterator semantics
This commit is contained in:
+5
-24
@@ -23,6 +23,7 @@ struct fx_list_iterator_p {
|
||||
|
||||
size_t i;
|
||||
void *item;
|
||||
fx_value item_value;
|
||||
fx_list_entry *entry;
|
||||
};
|
||||
|
||||
@@ -401,27 +402,7 @@ void *fx_list_entry_value(const struct fx_list_entry *entry)
|
||||
return entry ? entry->e_data : NULL;
|
||||
}
|
||||
|
||||
fx_iterator *fx_list_begin(fx_list *q)
|
||||
{
|
||||
fx_list_iterator *it_obj = fx_object_create(FX_TYPE_LIST_ITERATOR);
|
||||
struct fx_list_iterator_p *it = fx_object_get_private(
|
||||
it_obj,
|
||||
FX_TYPE_LIST_ITERATOR);
|
||||
|
||||
it->_q = q;
|
||||
it->_q_p = fx_object_get_private(q, FX_TYPE_LIST);
|
||||
it->_q_entry = fx_queue_first(&it->_q_p->l_queue);
|
||||
|
||||
it->i = 0;
|
||||
it->entry = fx_unbox(struct fx_list_entry, it->_q_entry, e_entry);
|
||||
if (it->entry) {
|
||||
it->item = it->entry->e_data;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const fx_iterator *fx_list_cbegin(const fx_list *q)
|
||||
const fx_iterator *fx_list_begin(const fx_list *q)
|
||||
{
|
||||
fx_list_iterator *it_obj = fx_object_create(FX_TYPE_LIST_ITERATOR);
|
||||
struct fx_list_iterator_p *it = fx_object_get_private(
|
||||
@@ -508,13 +489,14 @@ static enum fx_status iterator_erase(fx_iterator *obj)
|
||||
return FX_SUCCESS;
|
||||
}
|
||||
|
||||
static fx_value iterator_get_value(const fx_iterator *obj)
|
||||
static const fx_value *iterator_get_value(const fx_iterator *obj)
|
||||
{
|
||||
struct fx_list_iterator_p *it = fx_object_get_private(
|
||||
obj,
|
||||
FX_TYPE_LIST_ITERATOR);
|
||||
|
||||
return FX_POINTER(it->item);
|
||||
it->item_value = FX_POINTER(it->item);
|
||||
return &it->item_value;
|
||||
}
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
@@ -527,7 +509,6 @@ FX_TYPE_CLASS_BEGIN(fx_list)
|
||||
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_INTERFACE_ENTRY(it_begin) = fx_list_begin;
|
||||
FX_INTERFACE_ENTRY(it_cbegin) = fx_list_cbegin;
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_TYPE_CLASS_END(fx_list)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user