b_list behaves exactly like b_queue, with two key differences:
1) it is memory-managed like other b_objects, which means it
is stored on the heap and ref-counted.
2) it is not an invasive data structure, and will automatically
create and manage list nodes that contain pointers to the
list items.
68 lines
2.1 KiB
C
68 lines
2.1 KiB
C
#ifndef BLUE_OBJECT_LIST_H_
|
|
#define BLUE_OBJECT_LIST_H_
|
|
|
|
#include <blue/core/status.h>
|
|
#include <blue/object/object.h>
|
|
|
|
#define B_LIST(p) ((b_list *)(p))
|
|
|
|
typedef struct b_list b_list;
|
|
typedef struct b_list_entry b_list_entry;
|
|
|
|
#define b_list_foreach(it, q) \
|
|
for (int z__b_unique_name() = b_list_iterator_begin(q, it); \
|
|
(it)->entry != NULL; b_list_iterator_next(it))
|
|
|
|
typedef struct b_list_iterator {
|
|
b_queue_iterator _base;
|
|
const b_list *_q;
|
|
size_t i;
|
|
void *item;
|
|
b_list_entry *entry;
|
|
} b_list_iterator;
|
|
|
|
BLUE_API b_list *b_list_create(void);
|
|
|
|
static inline b_list *b_list_retain(b_list *str)
|
|
{
|
|
return B_LIST(b_retain(B_OBJECT(str)));
|
|
}
|
|
static inline void b_list_release(b_list *str)
|
|
{
|
|
b_release(B_OBJECT(str));
|
|
}
|
|
|
|
BLUE_API bool b_list_empty(b_list *q);
|
|
BLUE_API void *b_list_first_item(const b_list *q);
|
|
BLUE_API void *b_list_last_item(const b_list *q);
|
|
BLUE_API b_list_entry *b_list_first_entry(const b_list *q);
|
|
BLUE_API b_list_entry *b_list_last_entry(const b_list *q);
|
|
BLUE_API b_list_entry *b_list_next(const b_list_entry *entry);
|
|
BLUE_API b_list_entry *b_list_prev(const b_list_entry *entry);
|
|
|
|
BLUE_API size_t b_list_length(const b_list *q);
|
|
|
|
BLUE_API b_list_entry *b_list_insert_before(
|
|
b_list *q, void *ptr, b_list_entry *before);
|
|
BLUE_API b_list_entry *b_list_insert_after(
|
|
b_list *q, void *ptr, b_list_entry *after);
|
|
|
|
BLUE_API b_list_entry *b_list_push_front(b_list *q, void *ptr);
|
|
BLUE_API b_list_entry *b_list_push_back(b_list *q, void *ptr);
|
|
|
|
BLUE_API void *b_list_pop_front(b_list *q);
|
|
BLUE_API void *b_list_pop_back(b_list *q);
|
|
|
|
BLUE_API b_status b_list_delete_item(b_list *q, void *ptr);
|
|
BLUE_API b_status b_list_delete_entry(b_list *q, b_list_entry *entry);
|
|
BLUE_API void b_list_delete_all(b_list *q);
|
|
|
|
BLUE_API int b_list_iterator_begin(const b_list *q, b_list_iterator *it);
|
|
BLUE_API bool b_list_iterator_next(b_list_iterator *it);
|
|
BLUE_API b_status b_list_iterator_erase(b_list_iterator *it);
|
|
BLUE_API bool b_list_iterator_is_valid(const b_list_iterator *it);
|
|
|
|
BLUE_API void *b_list_entry_value(const b_list_entry *entry);
|
|
|
|
#endif
|