116 lines
3.3 KiB
C
116 lines
3.3 KiB
C
#include <fx/core/iterator.h>
|
|
|
|
/*** PRIVATE DATA *************************************************************/
|
|
|
|
struct fx_iterator_p {
|
|
enum fx_status it_status;
|
|
};
|
|
|
|
/*** PRIVATE FUNCTIONS ********************************************************/
|
|
|
|
static enum fx_status iterator_get_status(const struct fx_iterator_p *it)
|
|
{
|
|
return it->it_status;
|
|
}
|
|
|
|
static enum fx_status iterator_set_status(struct fx_iterator_p *it, fx_status status)
|
|
{
|
|
it->it_status = status;
|
|
return FX_SUCCESS;
|
|
}
|
|
|
|
/*** PUBLIC FUNCTIONS *********************************************************/
|
|
|
|
fx_iterator *fx_iterator_begin(fx_iterable *it)
|
|
{
|
|
FX_CLASS_DISPATCH_VIRTUAL_0(fx_iterable, FX_TYPE_ITERABLE, NULL, it_begin, it);
|
|
}
|
|
|
|
const fx_iterator *fx_iterator_cbegin(const fx_iterable *it)
|
|
{
|
|
FX_CLASS_DISPATCH_VIRTUAL_0(fx_iterable, FX_TYPE_ITERABLE, NULL, it_cbegin, it);
|
|
}
|
|
|
|
enum fx_status fx_iterator_get_status(const fx_iterator *it)
|
|
{
|
|
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_ITERATOR, iterator_get_status, it);
|
|
}
|
|
|
|
enum fx_status fx_iterator_set_status(const fx_iterator *it, fx_status status)
|
|
{
|
|
FX_CLASS_DISPATCH_STATIC(FX_TYPE_ITERATOR, iterator_set_status, it, status);
|
|
}
|
|
|
|
enum fx_status fx_iterator_move_next(const fx_iterator *it)
|
|
{
|
|
enum fx_status status = FX_ERR_NOT_SUPPORTED;
|
|
|
|
fx_iterator_class *iface = fx_object_get_interface(it, FX_TYPE_ITERATOR);
|
|
if (iface && iface->it_move_next) {
|
|
status = iface->it_move_next(it);
|
|
}
|
|
|
|
struct fx_iterator_p *p = fx_object_get_private(it, FX_TYPE_ITERATOR);
|
|
p->it_status = status;
|
|
|
|
return status;
|
|
}
|
|
|
|
fx_iterator_value fx_iterator_get_value(fx_iterator *it)
|
|
{
|
|
FX_CLASS_DISPATCH_VIRTUAL_0(
|
|
fx_iterator, FX_TYPE_ITERATOR, FX_ITERATOR_VALUE_NULL,
|
|
it_get_value, it);
|
|
}
|
|
|
|
const fx_iterator_value fx_iterator_get_cvalue(const fx_iterator *it)
|
|
{
|
|
FX_CLASS_DISPATCH_VIRTUAL_0(
|
|
fx_iterator, FX_TYPE_ITERATOR, FX_ITERATOR_VALUE_NULL,
|
|
it_get_cvalue, it);
|
|
}
|
|
|
|
fx_status fx_iterator_erase(fx_iterator *it)
|
|
{
|
|
enum fx_status status = FX_ERR_NOT_SUPPORTED;
|
|
|
|
fx_iterator_class *iface = fx_object_get_interface(it, FX_TYPE_ITERATOR);
|
|
if (iface && iface->it_erase) {
|
|
status = iface->it_erase(it);
|
|
}
|
|
|
|
struct fx_iterator_p *p = fx_object_get_private(it, FX_TYPE_ITERATOR);
|
|
p->it_status = status;
|
|
|
|
return status;
|
|
}
|
|
|
|
/*** CLASS DEFINITION *********************************************************/
|
|
|
|
// ---- fx_iterator DEFINITION
|
|
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_iterator)
|
|
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
|
FX_INTERFACE_ENTRY(to_string) = NULL;
|
|
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
|
FX_TYPE_CLASS_DEFINITION_END(fx_iterator)
|
|
|
|
FX_TYPE_DEFINITION_BEGIN(fx_iterator)
|
|
FX_TYPE_FLAGS(FX_TYPE_F_ABSTRACT);
|
|
FX_TYPE_ID(0xfd40b67f, 0x7087, 0x40a9, 0x8fd8, 0x8ae27bd58c9e);
|
|
FX_TYPE_CLASS(fx_iterator_class);
|
|
FX_TYPE_INSTANCE_PRIVATE(struct fx_iterator_p);
|
|
FX_TYPE_DEFINITION_END(fx_iterator)
|
|
|
|
// ---- fx_iterable DEFINITION
|
|
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_iterable)
|
|
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
|
FX_INTERFACE_ENTRY(to_string) = NULL;
|
|
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
|
FX_TYPE_CLASS_DEFINITION_END(fx_iterable)
|
|
|
|
FX_TYPE_DEFINITION_BEGIN(fx_iterable)
|
|
FX_TYPE_FLAGS(FX_TYPE_F_ABSTRACT);
|
|
FX_TYPE_ID(0x4bbabf2d, 0xfc5d, 0x40cc, 0x89fc, 0x164085e47f73);
|
|
FX_TYPE_CLASS(fx_iterable_class);
|
|
FX_TYPE_DEFINITION_END(fx_iterable)
|