Updating linkedlist iterator
This commit is contained in:
1 parent
2f59d5fcaf
commit
8fc432b76c
3 files changed
+522
-103
No files matched your search
+39
-56
@@ -202,17 +202,15 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
|
||||
struct SNAME##_node *PFX##_prev_node(struct SNAME##_node *_node_); \
|
||||
\
|
||||
/* Iterator Functions */ \
|
||||
/* Iterator Allocation and Deallocation */ \
|
||||
struct SNAME##_iter *PFX##_iter_new(struct SNAME *target); \
|
||||
void PFX##_iter_free(struct SNAME##_iter *iter); \
|
||||
/* Iterator Initialization */ \
|
||||
void PFX##_iter_init(struct SNAME##_iter *iter, struct SNAME *target); \
|
||||
struct SNAME##_iter PFX##_iter_start(struct SNAME *target); \
|
||||
struct SNAME##_iter PFX##_iter_end(struct SNAME *target); \
|
||||
/* Iterator State */ \
|
||||
bool PFX##_iter_start(struct SNAME##_iter *iter); \
|
||||
bool PFX##_iter_end(struct SNAME##_iter *iter); \
|
||||
bool PFX##_iter_at_start(struct SNAME##_iter *iter); \
|
||||
bool PFX##_iter_at_end(struct SNAME##_iter *iter); \
|
||||
/* Iterator Movement */ \
|
||||
void PFX##_iter_to_start(struct SNAME##_iter *iter); \
|
||||
void PFX##_iter_to_end(struct SNAME##_iter *iter); \
|
||||
bool PFX##_iter_to_start(struct SNAME##_iter *iter); \
|
||||
bool PFX##_iter_to_end(struct SNAME##_iter *iter); \
|
||||
bool PFX##_iter_next(struct SNAME##_iter *iter); \
|
||||
bool PFX##_iter_prev(struct SNAME##_iter *iter); \
|
||||
bool PFX##_iter_advance(struct SNAME##_iter *iter, size_t steps); \
|
||||
@@ -230,8 +228,7 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
|
||||
#define CMC_GENERATE_LINKEDLIST_SOURCE(PFX, SNAME, V) \
|
||||
\
|
||||
/* Implementation Detail Functions */ \
|
||||
static struct SNAME##_iter PFX##_impl_it_start(struct SNAME *_list_); \
|
||||
static struct SNAME##_iter PFX##_impl_it_end(struct SNAME *_list_); \
|
||||
/* None */ \
|
||||
\
|
||||
struct SNAME *PFX##_new(struct SNAME##_fval *f_val) \
|
||||
{ \
|
||||
@@ -252,8 +249,6 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
|
||||
_list_->f_val = f_val; \
|
||||
_list_->alloc = alloc; \
|
||||
_list_->callbacks = NULL; \
|
||||
_list_->it_start = PFX##_impl_it_start; \
|
||||
_list_->it_end = PFX##_impl_it_end; \
|
||||
\
|
||||
return _list_; \
|
||||
} \
|
||||
@@ -280,8 +275,6 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
|
||||
_list_->f_val = f_val; \
|
||||
_list_->alloc = alloc; \
|
||||
_list_->callbacks = callbacks; \
|
||||
_list_->it_start = PFX##_impl_it_start; \
|
||||
_list_->it_end = PFX##_impl_it_end; \
|
||||
\
|
||||
return _list_; \
|
||||
} \
|
||||
@@ -935,44 +928,46 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
|
||||
return _node_->prev; \
|
||||
} \
|
||||
\
|
||||
struct SNAME##_iter *PFX##_iter_new(struct SNAME *target) \
|
||||
struct SNAME##_iter PFX##_iter_start(struct SNAME *target) \
|
||||
{ \
|
||||
struct SNAME##_iter *iter = \
|
||||
target->alloc->malloc(sizeof(struct SNAME##_iter)); \
|
||||
struct SNAME##_iter iter; \
|
||||
\
|
||||
if (!iter) \
|
||||
return NULL; \
|
||||
\
|
||||
PFX##_iter_init(iter, target); \
|
||||
iter.target = target; \
|
||||
iter.cursor = target->head; \
|
||||
iter.index = 0; \
|
||||
iter.start = true; \
|
||||
iter.end = PFX##_empty(target); \
|
||||
\
|
||||
return iter; \
|
||||
} \
|
||||
\
|
||||
void PFX##_iter_free(struct SNAME##_iter *iter) \
|
||||
struct SNAME##_iter PFX##_iter_end(struct SNAME *target) \
|
||||
{ \
|
||||
iter->target->alloc->free(iter); \
|
||||
struct SNAME##_iter iter; \
|
||||
\
|
||||
iter.target = target; \
|
||||
iter.cursor = target->tail; \
|
||||
iter.index = 0; \
|
||||
iter.start = PFX##_empty(target); \
|
||||
iter.end = true; \
|
||||
\
|
||||
if (!PFX##_empty(target)) \
|
||||
iter.index = target->count - 1; \
|
||||
\
|
||||
return iter; \
|
||||
} \
|
||||
\
|
||||
void PFX##_iter_init(struct SNAME##_iter *iter, struct SNAME *target) \
|
||||
{ \
|
||||
iter->target = target; \
|
||||
iter->cursor = target->head; \
|
||||
iter->index = 0; \
|
||||
iter->start = true; \
|
||||
iter->end = PFX##_empty(target); \
|
||||
} \
|
||||
\
|
||||
bool PFX##_iter_start(struct SNAME##_iter *iter) \
|
||||
bool PFX##_iter_at_start(struct SNAME##_iter *iter) \
|
||||
{ \
|
||||
return PFX##_empty(iter->target) || iter->start; \
|
||||
} \
|
||||
\
|
||||
bool PFX##_iter_end(struct SNAME##_iter *iter) \
|
||||
bool PFX##_iter_at_end(struct SNAME##_iter *iter) \
|
||||
{ \
|
||||
return PFX##_empty(iter->target) || iter->end; \
|
||||
} \
|
||||
\
|
||||
void PFX##_iter_to_start(struct SNAME##_iter *iter) \
|
||||
bool PFX##_iter_to_start(struct SNAME##_iter *iter) \
|
||||
{ \
|
||||
if (!PFX##_empty(iter->target)) \
|
||||
{ \
|
||||
@@ -980,10 +975,14 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
|
||||
iter->index = 0; \
|
||||
iter->start = true; \
|
||||
iter->end = PFX##_empty(iter->target); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
void PFX##_iter_to_end(struct SNAME##_iter *iter) \
|
||||
bool PFX##_iter_to_end(struct SNAME##_iter *iter) \
|
||||
{ \
|
||||
if (!PFX##_empty(iter->target)) \
|
||||
{ \
|
||||
@@ -991,7 +990,11 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
|
||||
iter->index = iter->target->count - 1; \
|
||||
iter->start = PFX##_empty(iter->target); \
|
||||
iter->end = true; \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
bool PFX##_iter_next(struct SNAME##_iter *iter) \
|
||||
@@ -1121,26 +1124,6 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
|
||||
struct SNAME##_node *PFX##_iter_node(struct SNAME##_iter *iter) \
|
||||
{ \
|
||||
return iter->cursor; \
|
||||
} \
|
||||
\
|
||||
static struct SNAME##_iter PFX##_impl_it_start(struct SNAME *_list_) \
|
||||
{ \
|
||||
struct SNAME##_iter iter; \
|
||||
\
|
||||
PFX##_iter_init(&iter, _list_); \
|
||||
PFX##_iter_to_start(&iter); \
|
||||
\
|
||||
return iter; \
|
||||
} \
|
||||
\
|
||||
static struct SNAME##_iter PFX##_impl_it_end(struct SNAME *_list_) \
|
||||
{ \
|
||||
struct SNAME##_iter iter; \
|
||||
\
|
||||
PFX##_iter_init(&iter, _list_); \
|
||||
PFX##_iter_to_end(&iter); \
|
||||
\
|
||||
return iter; \
|
||||
}
|
||||
|
||||
#endif /* CMC_LINKEDLIST_H */
|
||||
Reference in new issue
Block a user