Added flags to queue, sortedlist and stack
This commit is contained in:
1 parent
0d665c46d0
commit
ee1174d1b5
6 files changed
+296
-13
No files matched your search
+27
-5
@@ -359,6 +359,9 @@ static const char *cmc_string_fmt_queue = "struct %s<%s> "
|
||||
_queue_->count++; \
|
||||
_queue_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_queue_->callbacks && _queue_->callbacks->create) \
|
||||
_queue_->callbacks->create(); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
@@ -378,6 +381,9 @@ static const char *cmc_string_fmt_queue = "struct %s<%s> "
|
||||
_queue_->count--; \
|
||||
_queue_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_queue_->callbacks && _queue_->callbacks->delete) \
|
||||
_queue_->callbacks->delete (); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
@@ -391,6 +397,9 @@ static const char *cmc_string_fmt_queue = "struct %s<%s> "
|
||||
\
|
||||
_queue_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_queue_->callbacks && _queue_->callbacks->read) \
|
||||
_queue_->callbacks->read(); \
|
||||
\
|
||||
return _queue_->buffer[_queue_->front]; \
|
||||
} \
|
||||
\
|
||||
@@ -398,15 +407,23 @@ static const char *cmc_string_fmt_queue = "struct %s<%s> "
|
||||
{ \
|
||||
_queue_->flag = cmc_flags.OK; \
|
||||
\
|
||||
bool result = false; \
|
||||
\
|
||||
for (size_t i = _queue_->front, j = 0; j < _queue_->count; j++) \
|
||||
{ \
|
||||
if (_queue_->f_val->cmp(_queue_->buffer[i], element) == 0) \
|
||||
return true; \
|
||||
{ \
|
||||
result = true; \
|
||||
break; \
|
||||
} \
|
||||
\
|
||||
i = (i + 1) % _queue_->capacity; \
|
||||
} \
|
||||
\
|
||||
return false; \
|
||||
if (_queue_->callbacks && _queue_->callbacks->read) \
|
||||
_queue_->callbacks->read(); \
|
||||
\
|
||||
return result; \
|
||||
} \
|
||||
\
|
||||
bool PFX##_empty(struct SNAME *_queue_) \
|
||||
@@ -436,10 +453,8 @@ static const char *cmc_string_fmt_queue = "struct %s<%s> "
|
||||
\
|
||||
bool PFX##_resize(struct SNAME *_queue_, size_t capacity) \
|
||||
{ \
|
||||
_queue_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_queue_->capacity == capacity) \
|
||||
return true; \
|
||||
goto success; \
|
||||
\
|
||||
if (capacity < _queue_->count) \
|
||||
{ \
|
||||
@@ -469,6 +484,13 @@ static const char *cmc_string_fmt_queue = "struct %s<%s> "
|
||||
_queue_->front = 0; \
|
||||
_queue_->back = _queue_->count; \
|
||||
\
|
||||
success: \
|
||||
\
|
||||
_queue_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_queue_->callbacks && _queue_->callbacks->resize) \
|
||||
_queue_->callbacks->resize(); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
|
||||
+29
-3
@@ -325,6 +325,9 @@ static const char *cmc_string_fmt_sortedlist = "struct %s<%s> "
|
||||
_list_->is_sorted = false; \
|
||||
_list_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_list_->callbacks && _list_->callbacks->create) \
|
||||
_list_->callbacks->create(); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
@@ -349,6 +352,9 @@ static const char *cmc_string_fmt_sortedlist = "struct %s<%s> "
|
||||
\
|
||||
_list_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_list_->callbacks && _list_->callbacks->delete) \
|
||||
_list_->callbacks->delete (); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
@@ -364,6 +370,9 @@ static const char *cmc_string_fmt_sortedlist = "struct %s<%s> "
|
||||
\
|
||||
_list_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_list_->callbacks && _list_->callbacks->read) \
|
||||
_list_->callbacks->read(); \
|
||||
\
|
||||
return _list_->buffer[_list_->count - 1]; \
|
||||
} \
|
||||
\
|
||||
@@ -379,6 +388,9 @@ static const char *cmc_string_fmt_sortedlist = "struct %s<%s> "
|
||||
\
|
||||
_list_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_list_->callbacks && _list_->callbacks->read) \
|
||||
_list_->callbacks->read(); \
|
||||
\
|
||||
return _list_->buffer[0]; \
|
||||
} \
|
||||
\
|
||||
@@ -400,6 +412,9 @@ static const char *cmc_string_fmt_sortedlist = "struct %s<%s> "
|
||||
\
|
||||
_list_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_list_->callbacks && _list_->callbacks->read) \
|
||||
_list_->callbacks->read(); \
|
||||
\
|
||||
return _list_->buffer[index]; \
|
||||
} \
|
||||
\
|
||||
@@ -409,6 +424,9 @@ static const char *cmc_string_fmt_sortedlist = "struct %s<%s> "
|
||||
\
|
||||
PFX##_sort(_list_); \
|
||||
\
|
||||
if (_list_->callbacks && _list_->callbacks->read) \
|
||||
_list_->callbacks->read(); \
|
||||
\
|
||||
if (from_start) \
|
||||
{ \
|
||||
return PFX##_impl_binary_search_first(_list_, element); \
|
||||
@@ -426,6 +444,9 @@ static const char *cmc_string_fmt_sortedlist = "struct %s<%s> "
|
||||
\
|
||||
PFX##_sort(_list_); \
|
||||
\
|
||||
if (_list_->callbacks && _list_->callbacks->read) \
|
||||
_list_->callbacks->read(); \
|
||||
\
|
||||
return PFX##_impl_binary_search_first(_list_, element) < \
|
||||
_list_->count; \
|
||||
} \
|
||||
@@ -457,10 +478,8 @@ static const char *cmc_string_fmt_sortedlist = "struct %s<%s> "
|
||||
\
|
||||
bool PFX##_resize(struct SNAME *_list_, size_t capacity) \
|
||||
{ \
|
||||
_list_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_list_->capacity == capacity) \
|
||||
return true; \
|
||||
goto success; \
|
||||
\
|
||||
if (capacity < _list_->count) \
|
||||
{ \
|
||||
@@ -482,6 +501,13 @@ static const char *cmc_string_fmt_sortedlist = "struct %s<%s> "
|
||||
_list_->buffer = new_buffer; \
|
||||
_list_->capacity = capacity; \
|
||||
\
|
||||
success: \
|
||||
\
|
||||
_list_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_list_->callbacks && _list_->callbacks->resize) \
|
||||
_list_->callbacks->resize(); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
|
||||
+27
-5
@@ -315,6 +315,9 @@ static const char *cmc_string_fmt_stack = "struct %s<%s> "
|
||||
\
|
||||
_stack_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_stack_->callbacks && _stack_->callbacks->create) \
|
||||
_stack_->callbacks->create(); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
@@ -330,6 +333,9 @@ static const char *cmc_string_fmt_stack = "struct %s<%s> "
|
||||
\
|
||||
_stack_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_stack_->callbacks && _stack_->callbacks->delete) \
|
||||
_stack_->callbacks->delete (); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
@@ -343,6 +349,9 @@ static const char *cmc_string_fmt_stack = "struct %s<%s> "
|
||||
\
|
||||
_stack_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_stack_->callbacks && _stack_->callbacks->read) \
|
||||
_stack_->callbacks->read(); \
|
||||
\
|
||||
return _stack_->buffer[_stack_->count - 1]; \
|
||||
} \
|
||||
\
|
||||
@@ -350,13 +359,21 @@ static const char *cmc_string_fmt_stack = "struct %s<%s> "
|
||||
{ \
|
||||
_stack_->flag = cmc_flags.OK; \
|
||||
\
|
||||
bool result = false; \
|
||||
\
|
||||
for (size_t i = 0; i < _stack_->count; i++) \
|
||||
{ \
|
||||
if (_stack_->f_val->cmp(_stack_->buffer[i], element) == 0) \
|
||||
return true; \
|
||||
{ \
|
||||
result = true; \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
return false; \
|
||||
if (_stack_->callbacks && _stack_->callbacks->read) \
|
||||
_stack_->callbacks->read(); \
|
||||
\
|
||||
return result; \
|
||||
} \
|
||||
\
|
||||
bool PFX##_empty(struct SNAME *_stack_) \
|
||||
@@ -386,10 +403,8 @@ static const char *cmc_string_fmt_stack = "struct %s<%s> "
|
||||
\
|
||||
bool PFX##_resize(struct SNAME *_stack_, size_t capacity) \
|
||||
{ \
|
||||
_stack_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_stack_->capacity == capacity) \
|
||||
return true; \
|
||||
goto success; \
|
||||
\
|
||||
if (capacity < _stack_->count) \
|
||||
{ \
|
||||
@@ -411,6 +426,13 @@ static const char *cmc_string_fmt_stack = "struct %s<%s> "
|
||||
_stack_->buffer = new_buffer; \
|
||||
_stack_->capacity = capacity; \
|
||||
\
|
||||
success: \
|
||||
\
|
||||
_stack_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_stack_->callbacks && _stack_->callbacks->resize) \
|
||||
_stack_->callbacks->resize(); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
|
||||
Reference in new issue
Block a user