libBLOC
Barry Adding object metadata functions c5a8d16 (2 years, 11 months ago)
/*
* Copyright (C) 2023 Barry
*
* This file is part of Barry's Little Objects in C Library (libBLOC).
*
* libBLOC is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* libBLOC is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTIBILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* libBLOC. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stddef.h>
#include <BLOC/iterator.h>
#include "iterator.h"
/* Get the next iterable element */
void *
iterator_next(Iterator *iter)
{
iter->entry = iter->next;
if (!iter->entry)
return NULL;
iter->prev = iter->entry->prev;
iter->next = iter->entry->next;
iter->pos++;
return iter->entry->obj;
}
/* Get the previous iterable element */
void *
iterator_prev(Iterator *iter)
{
iter->entry = iter->prev;
if (!iter->entry)
return NULL;
iter->prev = iter->entry->prev;
iter->next = iter->entry->next;
iter->pos--;
return iter->entry->obj;
}