Added enabled flag to cmc_callbacks

This commit is contained in:
Leonardo committed 2020-03-21 23:39:51 -03:00
1 parent 1e861383e7
commit fcb8f3a005
10 files changed
+194 -148

No files matched your search

+20 -10
View File
@@ -459,7 +459,8 @@ static const char *cmc_string_fmt_bidimap = "struct %s<%s, %s> "
_map_->count++; \
_map_->flag = cmc_flags.OK; \
\
if (_map_->callbacks && _map_->callbacks->create) \
if (_map_->callbacks && _map_->callbacks->enabled && \
_map_->callbacks->create) \
_map_->callbacks->create(); \
\
return true; \
@@ -517,7 +518,8 @@ static const char *cmc_string_fmt_bidimap = "struct %s<%s, %s> "
\
_map_->flag = cmc_flags.OK; \
\
if (_map_->callbacks && _map_->callbacks->update) \
if (_map_->callbacks && _map_->callbacks->enabled && \
_map_->callbacks->update) \
_map_->callbacks->update(); \
\
return true; \
@@ -576,7 +578,8 @@ static const char *cmc_string_fmt_bidimap = "struct %s<%s, %s> "
\
_map_->flag = cmc_flags.OK; \
\
if (_map_->callbacks && _map_->callbacks->update) \
if (_map_->callbacks && _map_->callbacks->enabled && \
_map_->callbacks->update) \
_map_->callbacks->update(); \
\
return true; \
@@ -623,7 +626,8 @@ static const char *cmc_string_fmt_bidimap = "struct %s<%s, %s> "
_map_->count--; \
_map_->flag = cmc_flags.OK; \
\
if (_map_->callbacks && _map_->callbacks->delete) \
if (_map_->callbacks && _map_->callbacks->enabled && \
_map_->callbacks->delete) \
_map_->callbacks->delete (); \
\
return true; \
@@ -670,7 +674,8 @@ static const char *cmc_string_fmt_bidimap = "struct %s<%s, %s> "
_map_->count--; \
_map_->flag = cmc_flags.OK; \
\
if (_map_->callbacks && _map_->callbacks->delete) \
if (_map_->callbacks && _map_->callbacks->enabled && \
_map_->callbacks->delete) \
_map_->callbacks->delete (); \
\
return true; \
@@ -689,7 +694,8 @@ static const char *cmc_string_fmt_bidimap = "struct %s<%s, %s> "
\
_map_->flag = cmc_flags.OK; \
\
if (_map_->callbacks && _map_->callbacks->read) \
if (_map_->callbacks && _map_->callbacks->enabled && \
_map_->callbacks->read) \
_map_->callbacks->read(); \
\
return (*entry)->key; \
@@ -708,7 +714,8 @@ static const char *cmc_string_fmt_bidimap = "struct %s<%s, %s> "
\
_map_->flag = cmc_flags.OK; \
\
if (_map_->callbacks && _map_->callbacks->read) \
if (_map_->callbacks && _map_->callbacks->enabled && \
_map_->callbacks->read) \
_map_->callbacks->read(); \
\
return (*entry)->value; \
@@ -720,7 +727,8 @@ static const char *cmc_string_fmt_bidimap = "struct %s<%s, %s> "
\
bool result = PFX##_impl_get_entry_by_key(_map_, key) != NULL; \
\
if (_map_->callbacks && _map_->callbacks->read) \
if (_map_->callbacks && _map_->callbacks->enabled && \
_map_->callbacks->read) \
_map_->callbacks->read(); \
\
return result; \
@@ -732,7 +740,8 @@ static const char *cmc_string_fmt_bidimap = "struct %s<%s, %s> "
\
bool result = PFX##_impl_get_entry_by_val(_map_, val) != NULL; \
\
if (_map_->callbacks && _map_->callbacks->read) \
if (_map_->callbacks && _map_->callbacks->enabled && \
_map_->callbacks->read) \
_map_->callbacks->read(); \
\
return result; \
@@ -850,7 +859,8 @@ static const char *cmc_string_fmt_bidimap = "struct %s<%s, %s> "
\
success: \
\
if (_map_->callbacks && _map_->callbacks->resize) \
if (_map_->callbacks && _map_->callbacks->enabled && \
_map_->callbacks->resize) \
_map_->callbacks->resize(); \
\
return true; \
+16 -8
View File
@@ -349,7 +349,8 @@ static const char *cmc_string_fmt_deque = "struct %s<%s> "
_deque_->count++; \
_deque_->flag = cmc_flags.OK; \
\
if (_deque_->callbacks && _deque_->callbacks->create) \
if (_deque_->callbacks && _deque_->callbacks->enabled && \
_deque_->callbacks->create) \
_deque_->callbacks->create(); \
\
return true; \
@@ -371,7 +372,8 @@ static const char *cmc_string_fmt_deque = "struct %s<%s> "
_deque_->count++; \
_deque_->flag = cmc_flags.OK; \
\
if (_deque_->callbacks && _deque_->callbacks->create) \
if (_deque_->callbacks && _deque_->callbacks->enabled && \
_deque_->callbacks->create) \
_deque_->callbacks->create(); \
\
return true; \
@@ -394,7 +396,8 @@ static const char *cmc_string_fmt_deque = "struct %s<%s> "
_deque_->count--; \
_deque_->flag = cmc_flags.OK; \
\
if (_deque_->callbacks && _deque_->callbacks->delete) \
if (_deque_->callbacks && _deque_->callbacks->enabled && \
_deque_->callbacks->delete) \
_deque_->callbacks->delete (); \
\
return true; \
@@ -416,7 +419,8 @@ static const char *cmc_string_fmt_deque = "struct %s<%s> "
_deque_->count--; \
_deque_->flag = cmc_flags.OK; \
\
if (_deque_->callbacks && _deque_->callbacks->delete) \
if (_deque_->callbacks && _deque_->callbacks->enabled && \
_deque_->callbacks->delete) \
_deque_->callbacks->delete (); \
\
return true; \
@@ -432,7 +436,8 @@ static const char *cmc_string_fmt_deque = "struct %s<%s> "
\
_deque_->flag = cmc_flags.OK; \
\
if (_deque_->callbacks && _deque_->callbacks->read) \
if (_deque_->callbacks && _deque_->callbacks->enabled && \
_deque_->callbacks->read) \
_deque_->callbacks->read(); \
\
return _deque_->buffer[_deque_->front]; \
@@ -448,7 +453,8 @@ static const char *cmc_string_fmt_deque = "struct %s<%s> "
\
_deque_->flag = cmc_flags.OK; \
\
if (_deque_->callbacks && _deque_->callbacks->read) \
if (_deque_->callbacks && _deque_->callbacks->enabled && \
_deque_->callbacks->read) \
_deque_->callbacks->read(); \
\
return _deque_->buffer[(_deque_->back == 0) ? _deque_->capacity - 1 \
@@ -472,7 +478,8 @@ static const char *cmc_string_fmt_deque = "struct %s<%s> "
i = (i + 1) % _deque_->capacity; \
} \
\
if (_deque_->callbacks && _deque_->callbacks->read) \
if (_deque_->callbacks && _deque_->callbacks->enabled && \
_deque_->callbacks->read) \
_deque_->callbacks->read(); \
\
return result; \
@@ -540,7 +547,8 @@ static const char *cmc_string_fmt_deque = "struct %s<%s> "
\
success: \
\
if (_deque_->callbacks && _deque_->callbacks->resize) \
if (_deque_->callbacks && _deque_->callbacks->enabled && \
_deque_->callbacks->resize) \
_deque_->callbacks->resize(); \
\
return true; \
+18 -9
View File
@@ -431,7 +431,8 @@ static const char *cmc_string_fmt_hashmap = "struct %s<%s, %s> "
return false; \
} \
\
if (_map_->callbacks && _map_->callbacks->create) \
if (_map_->callbacks && _map_->callbacks->enabled && \
_map_->callbacks->create) \
_map_->callbacks->create(); \
\
_map_->count++; \
@@ -463,7 +464,8 @@ static const char *cmc_string_fmt_hashmap = "struct %s<%s, %s> "
\
_map_->flag = cmc_flags.OK; \
\
if (_map_->callbacks && _map_->callbacks->update) \
if (_map_->callbacks && _map_->callbacks->enabled && \
_map_->callbacks->update) \
_map_->callbacks->update(); \
\
return true; \
@@ -496,7 +498,8 @@ static const char *cmc_string_fmt_hashmap = "struct %s<%s, %s> "
_map_->count--; \
_map_->flag = cmc_flags.OK; \
\
if (_map_->callbacks && _map_->callbacks->delete) \
if (_map_->callbacks && _map_->callbacks->enabled && \
_map_->callbacks->delete) \
_map_->callbacks->delete (); \
\
return true; \
@@ -536,7 +539,8 @@ static const char *cmc_string_fmt_hashmap = "struct %s<%s, %s> "
if (value) \
*value = max_val; \
\
if (_map_->callbacks && _map_->callbacks->read) \
if (_map_->callbacks && _map_->callbacks->enabled && \
_map_->callbacks->read) \
_map_->callbacks->read(); \
\
return true; \
@@ -576,7 +580,8 @@ static const char *cmc_string_fmt_hashmap = "struct %s<%s, %s> "
if (value) \
*value = min_val; \
\
if (_map_->callbacks && _map_->callbacks->read) \
if (_map_->callbacks && _map_->callbacks->enabled && \
_map_->callbacks->read) \
_map_->callbacks->read(); \
\
return true; \
@@ -600,7 +605,8 @@ static const char *cmc_string_fmt_hashmap = "struct %s<%s, %s> "
\
_map_->flag = cmc_flags.OK; \
\
if (_map_->callbacks && _map_->callbacks->read) \
if (_map_->callbacks && _map_->callbacks->enabled && \
_map_->callbacks->read) \
_map_->callbacks->read(); \
\
return entry->value; \
@@ -624,7 +630,8 @@ static const char *cmc_string_fmt_hashmap = "struct %s<%s, %s> "
\
_map_->flag = cmc_flags.OK; \
\
if (_map_->callbacks && _map_->callbacks->read) \
if (_map_->callbacks && _map_->callbacks->enabled && \
_map_->callbacks->read) \
_map_->callbacks->read(); \
\
return &(entry->value); \
@@ -636,7 +643,8 @@ static const char *cmc_string_fmt_hashmap = "struct %s<%s, %s> "
\
bool result = PFX##_impl_get_entry(_map_, key) != NULL; \
\
if (_map_->callbacks && _map_->callbacks->read) \
if (_map_->callbacks && _map_->callbacks->enabled && \
_map_->callbacks->read) \
_map_->callbacks->read(); \
\
return result; \
@@ -743,7 +751,8 @@ static const char *cmc_string_fmt_hashmap = "struct %s<%s, %s> "
\
success: \
\
if (_map_->callbacks && _map_->callbacks->resize) \
if (_map_->callbacks && _map_->callbacks->enabled && \
_map_->callbacks->resize) \
_map_->callbacks->resize(); \
\
return true; \
+49 -77
View File
@@ -227,8 +227,6 @@ static const char *cmc_string_fmt_hashset = "struct %s<%s> "
#define CMC_GENERATE_HASHSET_SOURCE(PFX, SNAME, V) \
\
/* Implementation Detail Functions */ \
static struct SNAME##_entry *PFX##_impl_insert(struct SNAME *_set_, \
V element); \
static struct SNAME##_entry *PFX##_impl_get_entry(struct SNAME *_set_, \
V element); \
static size_t PFX##_impl_calculate_size(size_t required); \
@@ -437,7 +435,8 @@ static const char *cmc_string_fmt_hashset = "struct %s<%s> "
_set_->count++; \
_set_->flag = cmc_flags.OK; \
\
if (_set_->callbacks && _set_->callbacks->create) \
if (_set_->callbacks && _set_->callbacks->enabled && \
_set_->callbacks->create) \
_set_->callbacks->create(); \
\
return true; \
@@ -466,7 +465,8 @@ static const char *cmc_string_fmt_hashset = "struct %s<%s> "
_set_->count--; \
_set_->flag = cmc_flags.OK; \
\
if (_set_->callbacks && _set_->callbacks->delete) \
if (_set_->callbacks && _set_->callbacks->enabled && \
_set_->callbacks->delete) \
_set_->callbacks->delete (); \
\
return true; \
@@ -501,7 +501,8 @@ static const char *cmc_string_fmt_hashset = "struct %s<%s> "
\
_set_->flag = cmc_flags.OK; \
\
if (_set_->callbacks && _set_->callbacks->read) \
if (_set_->callbacks && _set_->callbacks->enabled && \
_set_->callbacks->read) \
_set_->callbacks->read(); \
\
return true; \
@@ -536,7 +537,8 @@ static const char *cmc_string_fmt_hashset = "struct %s<%s> "
\
_set_->flag = cmc_flags.OK; \
\
if (_set_->callbacks && _set_->callbacks->read) \
if (_set_->callbacks && _set_->callbacks->enabled && \
_set_->callbacks->read) \
_set_->callbacks->read(); \
\
return true; \
@@ -548,7 +550,8 @@ static const char *cmc_string_fmt_hashset = "struct %s<%s> "
\
bool result = PFX##_impl_get_entry(_set_, element) != NULL; \
\
if (_set_->callbacks && _set_->callbacks->read) \
if (_set_->callbacks && _set_->callbacks->enabled && \
_set_->callbacks->read) \
_set_->callbacks->read(); \
\
return result; \
@@ -623,6 +626,9 @@ static const char *cmc_string_fmt_hashset = "struct %s<%s> "
\
struct SNAME##_iter iter; \
\
if (_set_->callbacks) \
_set_->callbacks->enabled = false; \
\
/* TODO turn this into a normal loop */ \
for (PFX##_iter_init(&iter, _set_); !PFX##_iter_end(&iter); \
PFX##_iter_next(&iter)) \
@@ -630,9 +636,12 @@ static const char *cmc_string_fmt_hashset = "struct %s<%s> "
V value = PFX##_iter_value(&iter); \
\
/* TODO check for error */ \
PFX##_impl_insert(_new_set_, value); \
PFX##_insert(_new_set_, value); \
} \
\
if (_set_->callbacks) \
_set_->callbacks->enabled = true; \
\
if (_set_->count != _new_set_->count) \
{ \
PFX##_free(_new_set_); \
@@ -651,7 +660,8 @@ static const char *cmc_string_fmt_hashset = "struct %s<%s> "
\
success: \
\
if (_set_->callbacks && _set_->callbacks->resize) \
if (_set_->callbacks && _set_->callbacks->enabled && \
_set_->callbacks->resize) \
_set_->callbacks->resize(); \
\
return true; \
@@ -773,19 +783,25 @@ static const char *cmc_string_fmt_hashset = "struct %s<%s> "
PFX##_iter_init(&iter1, _set1_); \
PFX##_iter_init(&iter2, _set2_); \
\
if (_set_r_->callbacks) \
_set_r_->callbacks->enabled = false; \
\
/* TODO turn this into a normal loop and check for errors */ \
for (PFX##_iter_to_start(&iter1); !PFX##_iter_end(&iter1); \
PFX##_iter_next(&iter1)) \
{ \
PFX##_impl_insert(_set_r_, PFX##_iter_value(&iter1)); \
PFX##_insert(_set_r_, PFX##_iter_value(&iter1)); \
} \
\
for (PFX##_iter_to_start(&iter2); !PFX##_iter_end(&iter2); \
PFX##_iter_next(&iter2)) \
{ \
PFX##_impl_insert(_set_r_, PFX##_iter_value(&iter2)); \
PFX##_insert(_set_r_, PFX##_iter_value(&iter2)); \
} \
\
if (_set_r_->callbacks) \
_set_r_->callbacks->enabled = true; \
\
return _set_r_; \
} \
\
@@ -810,15 +826,21 @@ static const char *cmc_string_fmt_hashset = "struct %s<%s> "
struct SNAME##_iter iter; \
PFX##_iter_init(&iter, _set_A_); \
\
if (_set_r_->callbacks) \
_set_r_->callbacks->enabled = false; \
\
for (PFX##_iter_to_start(&iter); !PFX##_iter_end(&iter); \
PFX##_iter_next(&iter)) \
{ \
V value = PFX##_iter_value(&iter); \
\
if (PFX##_impl_get_entry(_set_B_, value) != NULL) \
PFX##_impl_insert(_set_r_, value); \
PFX##_insert(_set_r_, value); \
} \
\
if (_set_r_->callbacks) \
_set_r_->callbacks->enabled = true; \
\
return _set_r_; \
} \
\
@@ -838,15 +860,21 @@ static const char *cmc_string_fmt_hashset = "struct %s<%s> "
struct SNAME##_iter iter; \
PFX##_iter_init(&iter, _set1_); \
\
if (_set_r_->callbacks) \
_set_r_->callbacks->enabled = false; \
\
for (PFX##_iter_to_start(&iter); !PFX##_iter_end(&iter); \
PFX##_iter_next(&iter)) \
{ \
V value = PFX##_iter_value(&iter); \
\
if (PFX##_impl_get_entry(_set2_, value) == NULL) \
PFX##_impl_insert(_set_r_, value); \
PFX##_insert(_set_r_, value); \
} \
\
if (_set_r_->callbacks) \
_set_r_->callbacks->enabled = true; \
\
return _set_r_; \
} \
\
@@ -869,13 +897,16 @@ static const char *cmc_string_fmt_hashset = "struct %s<%s> "
PFX##_iter_init(&iter1, _set1_); \
PFX##_iter_init(&iter2, _set2_); \
\
if (_set_r_->callbacks) \
_set_r_->callbacks->enabled = false; \
\
for (PFX##_iter_to_start(&iter1); !PFX##_iter_end(&iter1); \
PFX##_iter_next(&iter1)) \
{ \
V value = PFX##_iter_value(&iter1); \
\
if (PFX##_impl_get_entry(_set2_, value) == NULL) \
PFX##_impl_insert(_set_r_, value); \
PFX##_insert(_set_r_, value); \
} \
\
for (PFX##_iter_to_start(&iter2); !PFX##_iter_end(&iter2); \
@@ -884,9 +915,12 @@ static const char *cmc_string_fmt_hashset = "struct %s<%s> "
V value = PFX##_iter_value(&iter2); \
\
if (PFX##_impl_get_entry(_set1_, value) == NULL) \
PFX##_impl_insert(_set_r_, value); \
PFX##_insert(_set_r_, value); \
} \
\
if (_set_r_->callbacks) \
_set_r_->callbacks->enabled = true; \
\
return _set_r_; \
} \
\
@@ -1219,68 +1253,6 @@ static const char *cmc_string_fmt_hashset = "struct %s<%s> "
return iter->index; \
} \
\
static struct SNAME##_entry *PFX##_impl_insert(struct SNAME *_set_, \
V element) \
{ \
if (PFX##_full(_set_)) \
{ \
if (!PFX##_resize(_set_, _set_->capacity + 1)) \
return NULL; \
} \
\
if (PFX##_impl_get_entry(_set_, element) != NULL) \
{ \
_set_->flag = cmc_flags.DUPLICATE; \
return NULL; \
} \
\
size_t hash = _set_->f_val->hash(element); \
size_t original_pos = hash % _set_->capacity; \
size_t pos = original_pos; \
\
struct SNAME##_entry *target = &(_set_->buffer[pos]); \
\
if (target->state == CMC_ES_EMPTY || target->state == CMC_ES_DELETED) \
{ \
target->value = element; \
target->dist = 0; \
target->state = CMC_ES_FILLED; \
} \
else \
{ \
while (true) \
{ \
pos++; \
target = &(_set_->buffer[pos % _set_->capacity]); \
\
if (target->state == CMC_ES_EMPTY || \
target->state == CMC_ES_DELETED) \
{ \
target->value = element; \
target->dist = pos - original_pos; \
target->state = CMC_ES_FILLED; \
\
break; \
} \
else if (target->dist < pos - original_pos) \
{ \
V tmp = target->value; \
size_t tmp_dist = target->dist; \
\
target->value = element; \
target->dist = pos - original_pos; \
\
element = tmp; \
original_pos = pos - tmp_dist; \
} \
} \
} \
\
_set_->count++; \
\
return target; \
} \
\
static struct SNAME##_entry *PFX##_impl_get_entry(struct SNAME *_set_, \
V element) \
{ \
+10 -5
View File
@@ -359,7 +359,8 @@ static const char *cmc_string_fmt_heap = "struct %s<%s> "
\
_heap_->flag = cmc_flags.OK; \
\
if (_heap_->callbacks && _heap_->callbacks->create) \
if (_heap_->callbacks && _heap_->callbacks->enabled && \
_heap_->callbacks->create) \
_heap_->callbacks->create(); \
\
return true; \
@@ -382,7 +383,8 @@ static const char *cmc_string_fmt_heap = "struct %s<%s> "
\
_heap_->flag = cmc_flags.OK; \
\
if (_heap_->callbacks && _heap_->callbacks->delete) \
if (_heap_->callbacks && _heap_->callbacks->enabled && \
_heap_->callbacks->delete) \
_heap_->callbacks->delete (); \
\
return true; \
@@ -398,7 +400,8 @@ static const char *cmc_string_fmt_heap = "struct %s<%s> "
\
_heap_->flag = cmc_flags.OK; \
\
if (_heap_->callbacks && _heap_->callbacks->read) \
if (_heap_->callbacks && _heap_->callbacks->enabled && \
_heap_->callbacks->read) \
_heap_->callbacks->read(); \
\
return _heap_->buffer[0]; \
@@ -419,7 +422,8 @@ static const char *cmc_string_fmt_heap = "struct %s<%s> "
} \
} \
\
if (_heap_->callbacks && _heap_->callbacks->read) \
if (_heap_->callbacks && _heap_->callbacks->enabled && \
_heap_->callbacks->read) \
_heap_->callbacks->read(); \
\
return result; \
@@ -479,7 +483,8 @@ static const char *cmc_string_fmt_heap = "struct %s<%s> "
\
success: \
\
if (_heap_->callbacks && _heap_->callbacks->resize) \
if (_heap_->callbacks && _heap_->callbacks->enabled && \
_heap_->callbacks->resize) \
_heap_->callbacks->resize(); \
\
return true; \
+18 -9
View File
@@ -385,7 +385,8 @@ static const char *cmc_string_fmt_intervalheap = "struct %s<%s> "
/* else no float up required */ \
} \
\
if (_heap_->callbacks && _heap_->callbacks->create) \
if (_heap_->callbacks && _heap_->callbacks->enabled && \
_heap_->callbacks->create) \
_heap_->callbacks->create(); \
\
return true; \
@@ -438,7 +439,8 @@ static const char *cmc_string_fmt_intervalheap = "struct %s<%s> "
\
_heap_->flag = cmc_flags.OK; \
\
if (_heap_->callbacks && _heap_->callbacks->delete) \
if (_heap_->callbacks && _heap_->callbacks->enabled && \
_heap_->callbacks->delete) \
_heap_->callbacks->delete (); \
\
return true; \
@@ -491,7 +493,8 @@ static const char *cmc_string_fmt_intervalheap = "struct %s<%s> "
\
_heap_->flag = cmc_flags.OK; \
\
if (_heap_->callbacks && _heap_->callbacks->delete) \
if (_heap_->callbacks && _heap_->callbacks->enabled && \
_heap_->callbacks->delete) \
_heap_->callbacks->delete (); \
\
return true; \
@@ -528,7 +531,8 @@ static const char *cmc_string_fmt_intervalheap = "struct %s<%s> "
\
_heap_->flag = cmc_flags.OK; \
\
if (_heap_->callbacks && _heap_->callbacks->update) \
if (_heap_->callbacks && _heap_->callbacks->enabled && \
_heap_->callbacks->update) \
_heap_->callbacks->update(); \
\
return true; \
@@ -565,7 +569,8 @@ static const char *cmc_string_fmt_intervalheap = "struct %s<%s> "
\
_heap_->flag = cmc_flags.OK; \
\
if (_heap_->callbacks && _heap_->callbacks->update) \
if (_heap_->callbacks && _heap_->callbacks->enabled && \
_heap_->callbacks->update) \
_heap_->callbacks->update(); \
\
return true; \
@@ -581,7 +586,8 @@ static const char *cmc_string_fmt_intervalheap = "struct %s<%s> "
\
_heap_->flag = cmc_flags.OK; \
\
if (_heap_->callbacks && _heap_->callbacks->read) \
if (_heap_->callbacks && _heap_->callbacks->enabled && \
_heap_->callbacks->read) \
_heap_->callbacks->read(); \
\
/* If there is only one element, then the maximum element is the */ \
@@ -602,7 +608,8 @@ static const char *cmc_string_fmt_intervalheap = "struct %s<%s> "
\
_heap_->flag = cmc_flags.OK; \
\
if (_heap_->callbacks && _heap_->callbacks->read) \
if (_heap_->callbacks && _heap_->callbacks->enabled && \
_heap_->callbacks->read) \
_heap_->callbacks->read(); \
\
return _heap_->buffer[0].data[0]; \
@@ -624,7 +631,8 @@ static const char *cmc_string_fmt_intervalheap = "struct %s<%s> "
} \
} \
\
if (_heap_->callbacks && _heap_->callbacks->read) \
if (_heap_->callbacks && _heap_->callbacks->enabled && \
_heap_->callbacks->read) \
_heap_->callbacks->read(); \
\
return result; \
@@ -699,7 +707,8 @@ static const char *cmc_string_fmt_intervalheap = "struct %s<%s> "
\
_heap_->flag = cmc_flags.OK; \
\
if (_heap_->callbacks && _heap_->callbacks->resize) \
if (_heap_->callbacks && _heap_->callbacks->enabled && \
_heap_->callbacks->resize) \
_heap_->callbacks->resize(); \
\
return true; \
+22 -11
View File
@@ -351,7 +351,8 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
_list_->count++; \
_list_->flag = cmc_flags.OK; \
\
if (_list_->callbacks && _list_->callbacks->create) \
if (_list_->callbacks && _list_->callbacks->enabled && \
_list_->callbacks->create) \
_list_->callbacks->create(); \
\
return true; \
@@ -389,7 +390,8 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
_list_->count++; \
_list_->flag = cmc_flags.OK; \
\
if (_list_->callbacks && _list_->callbacks->create) \
if (_list_->callbacks && _list_->callbacks->enabled && \
_list_->callbacks->create) \
_list_->callbacks->create(); \
\
return true; \
@@ -417,7 +419,8 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
_list_->count++; \
_list_->flag = cmc_flags.OK; \
\
if (_list_->callbacks && _list_->callbacks->create) \
if (_list_->callbacks && _list_->callbacks->enabled && \
_list_->callbacks->create) \
_list_->callbacks->create(); \
\
return true; \
@@ -444,7 +447,8 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
_list_->count--; \
_list_->flag = cmc_flags.OK; \
\
if (_list_->callbacks && _list_->callbacks->delete) \
if (_list_->callbacks && _list_->callbacks->enabled && \
_list_->callbacks->delete) \
_list_->callbacks->delete (); \
\
return true; \
@@ -486,7 +490,8 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
_list_->count--; \
_list_->flag = cmc_flags.OK; \
\
if (_list_->callbacks && _list_->callbacks->delete) \
if (_list_->callbacks && _list_->callbacks->enabled && \
_list_->callbacks->delete) \
_list_->callbacks->delete (); \
\
return true; \
@@ -513,7 +518,8 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
_list_->count--; \
_list_->flag = cmc_flags.OK; \
\
if (_list_->callbacks && _list_->callbacks->delete) \
if (_list_->callbacks && _list_->callbacks->enabled && \
_list_->callbacks->delete) \
_list_->callbacks->delete (); \
\
return true; \
@@ -529,7 +535,8 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
\
_list_->flag = cmc_flags.OK; \
\
if (_list_->callbacks && _list_->callbacks->read) \
if (_list_->callbacks && _list_->callbacks->enabled && \
_list_->callbacks->read) \
_list_->callbacks->read(); \
\
return _list_->head->value; \
@@ -554,7 +561,8 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
if (scan == NULL) \
return (V){ 0 }; \
\
if (_list_->callbacks && _list_->callbacks->read) \
if (_list_->callbacks && _list_->callbacks->enabled && \
_list_->callbacks->read) \
_list_->callbacks->read(); \
\
return scan->value; \
@@ -579,7 +587,8 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
if (scan == NULL) \
return NULL; \
\
if (_list_->callbacks && _list_->callbacks->read) \
if (_list_->callbacks && _list_->callbacks->enabled && \
_list_->callbacks->read) \
_list_->callbacks->read(); \
\
return &(scan->value); \
@@ -595,7 +604,8 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
\
_list_->flag = cmc_flags.OK; \
\
if (_list_->callbacks && _list_->callbacks->read) \
if (_list_->callbacks && _list_->callbacks->enabled && \
_list_->callbacks->read) \
_list_->callbacks->read(); \
\
return _list_->tail->value; \
@@ -620,7 +630,8 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
scan = scan->next; \
} \
\
if (_list_->callbacks && _list_->callbacks->read) \
if (_list_->callbacks && _list_->callbacks->enabled && \
_list_->callbacks->read) \
_list_->callbacks->read(); \
\
return result; \
+36 -18
View File
@@ -351,7 +351,8 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
_list_->count++; \
_list_->flag = cmc_flags.OK; \
\
if (_list_->callbacks && _list_->callbacks->create) \
if (_list_->callbacks && _list_->callbacks->enabled && \
_list_->callbacks->create) \
_list_->callbacks->create(); \
\
return true; \
@@ -378,7 +379,8 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
_list_->count++; \
_list_->flag = cmc_flags.OK; \
\
if (_list_->callbacks && _list_->callbacks->create) \
if (_list_->callbacks && _list_->callbacks->enabled && \
_list_->callbacks->create) \
_list_->callbacks->create(); \
\
return true; \
@@ -395,7 +397,8 @@ 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) \
if (_list_->callbacks && _list_->callbacks->enabled && \
_list_->callbacks->create) \
_list_->callbacks->create(); \
\
return true; \
@@ -415,7 +418,8 @@ 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) \
if (_list_->callbacks && _list_->callbacks->enabled && \
_list_->callbacks->delete) \
_list_->callbacks->delete (); \
\
return true; \
@@ -441,7 +445,8 @@ 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) \
if (_list_->callbacks && _list_->callbacks->enabled && \
_list_->callbacks->delete) \
_list_->callbacks->delete (); \
\
return true; \
@@ -455,7 +460,8 @@ 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) \
if (_list_->callbacks && _list_->callbacks->enabled && \
_list_->callbacks->delete) \
_list_->callbacks->delete (); \
\
return true; \
@@ -483,7 +489,8 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
_list_->count += size; \
_list_->flag = cmc_flags.OK; \
\
if (_list_->callbacks && _list_->callbacks->create) \
if (_list_->callbacks && _list_->callbacks->enabled && \
_list_->callbacks->create) \
_list_->callbacks->create(); \
\
return true; \
@@ -523,7 +530,8 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
_list_->count += size; \
_list_->flag = cmc_flags.OK; \
\
if (_list_->callbacks && _list_->callbacks->create) \
if (_list_->callbacks && _list_->callbacks->enabled && \
_list_->callbacks->create) \
_list_->callbacks->create(); \
\
return true; \
@@ -548,7 +556,8 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
_list_->count += size; \
_list_->flag = cmc_flags.OK; \
\
if (_list_->callbacks && _list_->callbacks->create) \
if (_list_->callbacks && _list_->callbacks->enabled && \
_list_->callbacks->create) \
_list_->callbacks->create(); \
\
return true; \
@@ -579,7 +588,8 @@ 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) \
if (_list_->callbacks && _list_->callbacks->enabled && \
_list_->callbacks->delete) \
_list_->callbacks->delete (); \
\
return true; \
@@ -624,7 +634,8 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
\
_list_->flag = cmc_flags.OK; \
\
if (_list_->callbacks && _list_->callbacks->delete) \
if (_list_->callbacks && _list_->callbacks->enabled && \
_list_->callbacks->enabled && _list_->callbacks->delete) \
_list_->callbacks->delete (); \
\
return result; \
@@ -640,7 +651,8 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
\
_list_->flag = cmc_flags.OK; \
\
if (_list_->callbacks && _list_->callbacks->read) \
if (_list_->callbacks && _list_->callbacks->enabled && \
_list_->callbacks->read) \
_list_->callbacks->read(); \
\
return _list_->buffer[0]; \
@@ -662,7 +674,8 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
\
_list_->flag = cmc_flags.OK; \
\
if (_list_->callbacks && _list_->callbacks->read) \
if (_list_->callbacks && _list_->callbacks->enabled && \
_list_->callbacks->read) \
_list_->callbacks->read(); \
\
return _list_->buffer[index]; \
@@ -684,7 +697,8 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
\
_list_->flag = cmc_flags.OK; \
\
if (_list_->callbacks && _list_->callbacks->read) \
if (_list_->callbacks && _list_->callbacks->enabled && \
_list_->callbacks->read) \
_list_->callbacks->read(); \
\
return &(_list_->buffer[index]); \
@@ -700,7 +714,8 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
\
_list_->flag = cmc_flags.OK; \
\
if (_list_->callbacks && _list_->callbacks->read) \
if (_list_->callbacks && _list_->callbacks->enabled && \
_list_->callbacks->read) \
_list_->callbacks->read(); \
\
return _list_->buffer[_list_->count - 1]; \
@@ -735,7 +750,8 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
} \
} \
\
if (_list_->callbacks && _list_->callbacks->read) \
if (_list_->callbacks && _list_->callbacks->enabled && \
_list_->callbacks->read) \
_list_->callbacks->read(); \
\
return result; \
@@ -756,7 +772,8 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
} \
} \
\
if (_list_->callbacks && _list_->callbacks->read) \
if (_list_->callbacks && _list_->callbacks->enabled && \
_list_->callbacks->read) \
_list_->callbacks->read(); \
\
return result; \
@@ -819,7 +836,8 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
_list_->buffer = new_buffer; \
_list_->capacity = capacity; \
\
if (_list_->callbacks && _list_->callbacks->resize) \
if (_list_->callbacks && _list_->callbacks->enabled && \
_list_->callbacks->resize) \
_list_->callbacks->resize(); \
\
return true; \
+3
View File
@@ -62,9 +62,12 @@ static struct cmc_alloc_node
* - update : an element in the collection was successfully updated
* - delete : an element was successfully removed from the collection
* - resize : the collection was full and successfully resized
*
* enabled : if true, callbacks will be called.
*/
struct cmc_callbacks
{
bool enabled;
void (*create)(void);
void (*read)(void);
void (*update)(void);
+2 -1
View File
@@ -99,7 +99,8 @@ void callback_resize(void)
}
struct cmc_callbacks *callbacks =
&(struct cmc_callbacks){ .create = callback_create,
&(struct cmc_callbacks){ .enabled = true,
.create = callback_create,
.read = callback_read,
.update = callback_update,
.delete = callback_delete,