core: queue: replace legacy iterator interface
This commit is contained in:
@@ -1,22 +1,24 @@
|
||||
#ifndef BLUELIB_CORE_QUEUE_H_
|
||||
#define BLUELIB_CORE_QUEUE_H_
|
||||
#ifndef BLUE_CORE_QUEUE_H_
|
||||
#define BLUE_CORE_QUEUE_H_
|
||||
|
||||
#include <blue/core/iterator.h>
|
||||
#include <blue/core/macros.h>
|
||||
#include <blue/core/status.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
B_DECLS_BEGIN;
|
||||
|
||||
#define B_TYPE_QUEUE_ITERATOR (b_queue_iterator_get_type())
|
||||
|
||||
B_DECLARE_TYPE(b_queue_iterator);
|
||||
|
||||
B_TYPE_CLASS_DECLARATION_BEGIN(b_queue_iterator)
|
||||
B_TYPE_CLASS_DECLARATION_END(b_queue_iterator)
|
||||
|
||||
#define B_QUEUE_INIT ((b_queue) {.q_first = NULL, .q_last = NULL})
|
||||
#define B_QUEUE_ENTRY_INIT ((b_queue_entry) {.qe_next = NULL, .qe_prev = NULL})
|
||||
|
||||
#define b_queue_foreach(it, q) \
|
||||
for (int z__b_unique_name() = b_queue_iterator_begin(q, it); \
|
||||
(it)->entry != NULL; b_queue_iterator_next(it))
|
||||
|
||||
typedef struct b_queue_entry {
|
||||
struct b_queue_entry *qe_next;
|
||||
struct b_queue_entry *qe_prev;
|
||||
@@ -27,13 +29,6 @@ typedef struct b_queue {
|
||||
b_queue_entry *q_last;
|
||||
} b_queue;
|
||||
|
||||
typedef struct b_queue_iterator {
|
||||
b_iterator _base;
|
||||
size_t i;
|
||||
b_queue_entry *entry;
|
||||
b_queue *_q;
|
||||
} b_queue_iterator;
|
||||
|
||||
static inline void b_queue_init(b_queue *q)
|
||||
{
|
||||
memset(q, 0x00, sizeof *q);
|
||||
@@ -60,6 +55,8 @@ static inline b_queue_entry *b_queue_prev(const b_queue_entry *entry)
|
||||
return entry->qe_prev;
|
||||
}
|
||||
|
||||
BLUE_API b_type b_queue_iterator_get_type(void);
|
||||
|
||||
BLUE_API size_t b_queue_length(const b_queue *q);
|
||||
|
||||
BLUE_API void b_queue_insert_before(
|
||||
@@ -76,13 +73,9 @@ BLUE_API b_queue_entry *b_queue_pop_back(b_queue *q);
|
||||
BLUE_API void b_queue_delete(b_queue *q, b_queue_entry *entry);
|
||||
BLUE_API void b_queue_delete_all(b_queue *q);
|
||||
|
||||
BLUE_API int b_queue_iterator_begin(const b_queue *q, b_queue_iterator *it);
|
||||
BLUE_API bool b_queue_iterator_next(b_queue_iterator *it);
|
||||
BLUE_API b_status b_queue_iterator_erase(b_queue_iterator *it);
|
||||
BLUE_API bool b_queue_iterator_is_valid(const b_queue_iterator *it);
|
||||
BLUE_API b_iterator *b_queue_begin(b_queue *q);
|
||||
BLUE_API b_iterator *b_queue_cbegin(const b_queue *q);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
B_DECLS_END;
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user