fx.io: update iterator semantics
This commit is contained in:
@@ -35,6 +35,7 @@ struct fx_directory_iterator_p {
|
||||
fx_directory *root;
|
||||
|
||||
fx_directory_entry entry;
|
||||
fx_value entry_value;
|
||||
};
|
||||
|
||||
/*** PRIVATE FUNCTIONS ********************************************************/
|
||||
@@ -375,8 +376,6 @@ fx_result fx_directory_open_temp(fx_directory **out)
|
||||
|
||||
fx_path_unlink(rpath);
|
||||
fx_path_unref(rpath);
|
||||
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -512,6 +511,8 @@ static void update_iterator_data(struct fx_directory_iterator_p *it)
|
||||
fx_path *path = fx_path_create_from_cstr(
|
||||
ent->fts_path + fx_path_length(it->_p->d_path_abs) + 1);
|
||||
|
||||
fx_value_unset(&it->entry_value);
|
||||
it->entry_value = FX_POINTER(&it->entry);
|
||||
it->entry.filename = ent->fts_name;
|
||||
it->entry.filepath = path;
|
||||
|
||||
@@ -619,12 +620,7 @@ fx_iterator *fx_directory_begin(
|
||||
return it_obj;
|
||||
}
|
||||
|
||||
static fx_iterator *iterator_begin(fx_object *obj)
|
||||
{
|
||||
return fx_directory_begin(obj, FX_DIRECTORY_ITERATE_PARENT_FIRST);
|
||||
}
|
||||
|
||||
static const fx_iterator *iterator_cbegin(const fx_object *obj)
|
||||
static const fx_iterator *iterator_begin(const fx_object *obj)
|
||||
{
|
||||
return fx_directory_begin(
|
||||
(fx_object *)obj,
|
||||
@@ -698,13 +694,13 @@ static enum fx_status iterator_erase(fx_iterator *obj)
|
||||
return iterator_move_next(obj);
|
||||
}
|
||||
|
||||
static fx_value iterator_get_value(const fx_iterator *obj)
|
||||
static const fx_value *iterator_get_value(const fx_iterator *obj)
|
||||
{
|
||||
struct fx_directory_iterator_p *it = fx_object_get_private(
|
||||
obj,
|
||||
FX_TYPE_DIRECTORY_ITERATOR);
|
||||
|
||||
return FX_POINTER(&it->entry);
|
||||
return &it->entry_value;
|
||||
}
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
@@ -717,7 +713,6 @@ FX_TYPE_CLASS_BEGIN(fx_directory)
|
||||
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_INTERFACE_ENTRY(it_begin) = iterator_begin;
|
||||
FX_INTERFACE_ENTRY(it_cbegin) = iterator_cbegin;
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_TYPE_CLASS_END(fx_directory)
|
||||
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ int main(int argc, const char **argv)
|
||||
fx_foreach(val, it)
|
||||
{
|
||||
fx_directory_entry *entry = NULL;
|
||||
fx_value_get_pointer(&val, (void **)&entry);
|
||||
fx_value_get_pointer(val, (void **)&entry);
|
||||
printf("%s\n", fx_path_ptr(entry->filepath));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user