Added callbacks to linkedlist and list
This commit is contained in:
1 parent
5b8f64b421
commit
701a24f47c
4 files changed
+225
-8
No files matched your search
+40
-2
@@ -351,6 +351,9 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
|
||||
_list_->count++; \
|
||||
_list_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_list_->callbacks && _list_->callbacks->create) \
|
||||
_list_->callbacks->create(); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
@@ -386,6 +389,9 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
|
||||
_list_->count++; \
|
||||
_list_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_list_->callbacks && _list_->callbacks->create) \
|
||||
_list_->callbacks->create(); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
@@ -411,6 +417,9 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
|
||||
_list_->count++; \
|
||||
_list_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_list_->callbacks && _list_->callbacks->create) \
|
||||
_list_->callbacks->create(); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
@@ -435,6 +444,9 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
|
||||
_list_->count--; \
|
||||
_list_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_list_->callbacks && _list_->callbacks->delete) \
|
||||
_list_->callbacks->delete (); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
@@ -474,6 +486,9 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
|
||||
_list_->count--; \
|
||||
_list_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_list_->callbacks && _list_->callbacks->delete) \
|
||||
_list_->callbacks->delete (); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
@@ -498,6 +513,9 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
|
||||
_list_->count--; \
|
||||
_list_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_list_->callbacks && _list_->callbacks->delete) \
|
||||
_list_->callbacks->delete (); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
@@ -511,6 +529,9 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
|
||||
\
|
||||
_list_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_list_->callbacks && _list_->callbacks->read) \
|
||||
_list_->callbacks->read(); \
|
||||
\
|
||||
return _list_->head->value; \
|
||||
} \
|
||||
\
|
||||
@@ -533,6 +554,9 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
|
||||
if (scan == NULL) \
|
||||
return (V){ 0 }; \
|
||||
\
|
||||
if (_list_->callbacks && _list_->callbacks->read) \
|
||||
_list_->callbacks->read(); \
|
||||
\
|
||||
return scan->value; \
|
||||
} \
|
||||
\
|
||||
@@ -555,6 +579,9 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
|
||||
if (scan == NULL) \
|
||||
return NULL; \
|
||||
\
|
||||
if (_list_->callbacks && _list_->callbacks->read) \
|
||||
_list_->callbacks->read(); \
|
||||
\
|
||||
return &(scan->value); \
|
||||
} \
|
||||
\
|
||||
@@ -568,6 +595,9 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
|
||||
\
|
||||
_list_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_list_->callbacks && _list_->callbacks->read) \
|
||||
_list_->callbacks->read(); \
|
||||
\
|
||||
return _list_->tail->value; \
|
||||
} \
|
||||
\
|
||||
@@ -575,17 +605,25 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
|
||||
{ \
|
||||
_list_->flag = cmc_flags.OK; \
|
||||
\
|
||||
bool result = false; \
|
||||
\
|
||||
struct SNAME##_node *scan = _list_->head; \
|
||||
\
|
||||
while (scan != NULL) \
|
||||
{ \
|
||||
if (_list_->f_val->cmp(scan->value, element) == 0) \
|
||||
return true; \
|
||||
{ \
|
||||
result = true; \
|
||||
break; \
|
||||
} \
|
||||
\
|
||||
scan = scan->next; \
|
||||
} \
|
||||
\
|
||||
return false; \
|
||||
if (_list_->callbacks && _list_->callbacks->read) \
|
||||
_list_->callbacks->read(); \
|
||||
\
|
||||
return result; \
|
||||
} \
|
||||
\
|
||||
bool PFX##_empty(struct SNAME *_list_) \
|
||||
|
||||
+73
-6
@@ -351,6 +351,9 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
|
||||
_list_->count++; \
|
||||
_list_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_list_->callbacks && _list_->callbacks->create) \
|
||||
_list_->callbacks->create(); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
@@ -375,6 +378,9 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
|
||||
_list_->count++; \
|
||||
_list_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_list_->callbacks && _list_->callbacks->create) \
|
||||
_list_->callbacks->create(); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
@@ -389,6 +395,9 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
|
||||
_list_->buffer[_list_->count++] = element; \
|
||||
_list_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_list_->callbacks && _list_->callbacks->create) \
|
||||
_list_->callbacks->create(); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
@@ -406,6 +415,9 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
|
||||
_list_->buffer[--_list_->count] = (V){ 0 }; \
|
||||
_list_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_list_->callbacks && _list_->callbacks->delete) \
|
||||
_list_->callbacks->delete (); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
@@ -429,6 +441,9 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
|
||||
_list_->buffer[--_list_->count] = (V){ 0 }; \
|
||||
_list_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_list_->callbacks && _list_->callbacks->delete) \
|
||||
_list_->callbacks->delete (); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
@@ -440,6 +455,9 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
|
||||
_list_->buffer[--_list_->count] = (V){ 0 }; \
|
||||
_list_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_list_->callbacks && _list_->callbacks->delete) \
|
||||
_list_->callbacks->delete (); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
@@ -465,6 +483,9 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
|
||||
_list_->count += size; \
|
||||
_list_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_list_->callbacks && _list_->callbacks->create) \
|
||||
_list_->callbacks->create(); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
@@ -502,6 +523,9 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
|
||||
_list_->count += size; \
|
||||
_list_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_list_->callbacks && _list_->callbacks->create) \
|
||||
_list_->callbacks->create(); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
@@ -524,6 +548,9 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
|
||||
_list_->count += size; \
|
||||
_list_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_list_->callbacks && _list_->callbacks->create) \
|
||||
_list_->callbacks->create(); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
@@ -552,6 +579,9 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
|
||||
_list_->count -= to - from + 1; \
|
||||
_list_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_list_->callbacks && _list_->callbacks->delete) \
|
||||
_list_->callbacks->delete (); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
@@ -581,7 +611,7 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
|
||||
return NULL; \
|
||||
} \
|
||||
\
|
||||
memcpy(result->buffer, _list_->buffer, _list_->count * sizeof(V)); \
|
||||
memcpy(result->buffer, _list_->buffer, length * sizeof(V)); \
|
||||
\
|
||||
memmove(_list_->buffer + from, _list_->buffer + to + 1, \
|
||||
(_list_->count - to - 1) * sizeof(V)); \
|
||||
@@ -594,6 +624,9 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
|
||||
\
|
||||
_list_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_list_->callbacks && _list_->callbacks->delete) \
|
||||
_list_->callbacks->delete (); \
|
||||
\
|
||||
return result; \
|
||||
} \
|
||||
\
|
||||
@@ -607,6 +640,9 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
|
||||
\
|
||||
_list_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_list_->callbacks && _list_->callbacks->read) \
|
||||
_list_->callbacks->read(); \
|
||||
\
|
||||
return _list_->buffer[0]; \
|
||||
} \
|
||||
\
|
||||
@@ -626,6 +662,9 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
|
||||
\
|
||||
_list_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_list_->callbacks && _list_->callbacks->read) \
|
||||
_list_->callbacks->read(); \
|
||||
\
|
||||
return _list_->buffer[index]; \
|
||||
} \
|
||||
\
|
||||
@@ -645,6 +684,9 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
|
||||
\
|
||||
_list_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_list_->callbacks && _list_->callbacks->read) \
|
||||
_list_->callbacks->read(); \
|
||||
\
|
||||
return &(_list_->buffer[index]); \
|
||||
} \
|
||||
\
|
||||
@@ -658,6 +700,9 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
|
||||
\
|
||||
_list_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_list_->callbacks && _list_->callbacks->read) \
|
||||
_list_->callbacks->read(); \
|
||||
\
|
||||
return _list_->buffer[_list_->count - 1]; \
|
||||
} \
|
||||
\
|
||||
@@ -665,12 +710,17 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
|
||||
{ \
|
||||
_list_->flag = cmc_flags.OK; \
|
||||
\
|
||||
size_t result = _list_->count; \
|
||||
\
|
||||
if (from_start) \
|
||||
{ \
|
||||
for (size_t i = 0; i < _list_->count; i++) \
|
||||
{ \
|
||||
if (_list_->f_val->cmp(_list_->buffer[i], element) == 0) \
|
||||
return i; \
|
||||
{ \
|
||||
result = i; \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
else \
|
||||
@@ -678,24 +728,38 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
|
||||
for (size_t i = _list_->count; i > 0; i--) \
|
||||
{ \
|
||||
if (_list_->f_val->cmp(_list_->buffer[i - 1], element) == 0) \
|
||||
return i - 1; \
|
||||
{ \
|
||||
result = i - 1; \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
return _list_->count; \
|
||||
if (_list_->callbacks && _list_->callbacks->read) \
|
||||
_list_->callbacks->read(); \
|
||||
\
|
||||
return result; \
|
||||
} \
|
||||
\
|
||||
bool PFX##_contains(struct SNAME *_list_, V element) \
|
||||
{ \
|
||||
_list_->flag = cmc_flags.OK; \
|
||||
\
|
||||
bool result = false; \
|
||||
\
|
||||
for (size_t i = 0; i < _list_->count; i++) \
|
||||
{ \
|
||||
if (_list_->f_val->cmp(_list_->buffer[i], element) == 0) \
|
||||
return true; \
|
||||
{ \
|
||||
result = true; \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
return false; \
|
||||
if (_list_->callbacks && _list_->callbacks->read) \
|
||||
_list_->callbacks->read(); \
|
||||
\
|
||||
return result; \
|
||||
} \
|
||||
\
|
||||
bool PFX##_empty(struct SNAME *_list_) \
|
||||
@@ -755,6 +819,9 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
|
||||
_list_->buffer = new_buffer; \
|
||||
_list_->capacity = capacity; \
|
||||
\
|
||||
if (_list_->callbacks && _list_->callbacks->resize) \
|
||||
_list_->callbacks->resize(); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
|
||||
Reference in new issue
Block a user