From 7014e5e2dae890d8f64e1861d04d8a010aa73ddf Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sat, 26 Feb 2022 19:31:19 -0600 Subject: [PATCH] Feature: Maps and Multi-Maps should support appending a single map rather than just an entire set. This is really an oversight on my part. The append should by default append a single item. To append an entire set, a new function should be used (an append all function). This should be done for all of the string types that are applicable. Such changes are left for the next release and are not planed for the 0.5.8 release. This functionality is necessary for bug fixes in the controller program. --- level_0/f_string/c/private-string.c | 66 ++++++++++++++++++-- level_0/f_string/c/private-string.h | 64 +++++++++++++++++-- level_0/f_string/c/string/map.c | 118 ++++++++++++++++++++++++++++++++---- level_0/f_string/c/string/map.h | 78 +++++++++++++++++++++--- 4 files changed, 296 insertions(+), 30 deletions(-) diff --git a/level_0/f_string/c/private-string.c b/level_0/f_string/c/private-string.c index cb17f2e..9d046b5 100644 --- a/level_0/f_string/c/private-string.c +++ b/level_0/f_string/c/private-string.c @@ -318,7 +318,36 @@ extern "C" { #endif // !defined(_di_f_string_map_multis_adjust_) || !defined(_di_f_string_map_multis_decimate_by_) #if !defined(_di_f_string_map_multiss_append_) || !defined(_di_f_string_map_multis_append_) - f_status_t private_f_string_map_multis_append(const f_string_map_multis_t source, f_string_map_multis_t * const destination) { + f_status_t private_f_string_map_multis_append(const f_string_map_multi_t source, f_string_map_multis_t * const destination) { + + f_status_t status = F_none; + + if (destination->used + 1 > destination->size) { + status = private_f_string_map_multis_resize(destination->used + F_memory_default_allocation_small_d, destination); + if (F_status_is_error(status)) return status; + } + + destination->array[destination->used].name.used = 0; + destination->array[destination->used].value.used = 0; + + if (source.name.used) { + status = private_f_string_append(source.name.string, source.name.used, &destination->array[destination->used].name); + if (F_status_is_error(status)) return status; + } + + if (source.value.used) { + status = private_f_string_dynamics_append(source.value, &destination->array[destination->used].value); + if (F_status_is_error(status)) return status; + } + + ++destination->used; + + return F_none; + } +#endif // !defined(_di_f_string_map_multiss_append_) || !defined(_di_f_string_map_multis_append_) + +#if !defined(_di_f_string_map_multiss_append_all_) || !defined(_di_f_string_map_multis_append_all_) + f_status_t private_f_string_map_multis_append_all(const f_string_map_multis_t source, f_string_map_multis_t * const destination) { f_status_t status = F_none; @@ -345,7 +374,7 @@ extern "C" { return F_none; } -#endif // !defined(_di_f_string_map_multiss_append_) || !defined(_di_f_string_map_multis_append_) +#endif // !defined(_di_f_string_map_multiss_append_all_) || !defined(_di_f_string_map_multis_append_all_) #if !defined(_di_f_string_map_multis_decrease_by_) || !defined(_di_f_string_map_multis_increase_) || !defined(_di_f_string_map_multis_increase_by_) || !defined(_di_f_string_map_multis_terminate_) || !defined(_di_f_string_map_multis_terminate_after_) f_status_t private_f_string_map_multis_resize(const f_array_length_t length, f_string_map_multis_t * const map_multis) { @@ -470,7 +499,36 @@ extern "C" { #endif // !defined(_di_f_string_maps_adjust_) || !defined(_di_f_string_maps_decimate_by_) #if !defined(_di_f_string_mapss_append_) || !defined(_di_f_string_maps_append_) - f_status_t private_f_string_maps_append(const f_string_maps_t source, f_string_maps_t * const destination) { + f_status_t private_f_string_maps_append(const f_string_map_t source, f_string_maps_t * const destination) { + + f_status_t status = F_none; + + if (destination->used + 1 > destination->size) { + status = private_f_string_maps_resize(destination->used + F_memory_default_allocation_small_d, destination); + if (F_status_is_error(status)) return status; + } + + destination->array[destination->used].name.used = 0; + destination->array[destination->used].value.used = 0; + + if (source.name.used) { + status = private_f_string_append(source.name.string, source.name.used, &destination->array[destination->used].name); + if (F_status_is_error(status)) return status; + } + + if (source.value.used) { + status = private_f_string_append(source.value.string, source.value.used, &destination->array[destination->used].value); + if (F_status_is_error(status)) return status; + } + + ++destination->used; + + return F_none; + } +#endif // !defined(_di_f_string_mapss_append_) || !defined(_di_f_string_maps_append_) + +#if !defined(_di_f_string_mapss_append_all_) || !defined(_di_f_string_maps_append_all_) + f_status_t private_f_string_maps_append_all(const f_string_maps_t source, f_string_maps_t * const destination) { f_status_t status = F_none; @@ -497,7 +555,7 @@ extern "C" { return F_none; } -#endif // !defined(_di_f_string_mapss_append_) || !defined(_di_f_string_maps_append_) +#endif // !defined(_di_f_string_mapss_append_all_) || !defined(_di_f_string_maps_append_all_) #if !defined(_di_f_string_maps_decrease_by_) || !defined(_di_f_string_maps_increase_) || !defined(_di_f_string_maps_increase_by_) || !defined(_di_f_string_maps_terminate_) || !defined(_di_f_string_maps_terminate_after_) f_status_t private_f_string_maps_resize(const f_array_length_t length, f_string_maps_t * const maps) { diff --git a/level_0/f_string/c/private-string.h b/level_0/f_string/c/private-string.h index 0b13cab..c76fce0 100644 --- a/level_0/f_string/c/private-string.h +++ b/level_0/f_string/c/private-string.h @@ -401,9 +401,9 @@ extern "C" { * Intended to be shared to each of the different implementation variations. * * @param source - * The source strings to append. + * The source multi-map to append. * @param destination - * The destination strings the source is appended onto. + * The destination multi-maps the source is appended onto. * * @return * F_none on success. @@ -419,10 +419,37 @@ extern "C" { * @see f_string_map_multiss_append() */ #if !defined(_di_f_string_map_multiss_append_) || !defined(_di_f_string_map_multis_append_) - extern f_status_t private_f_string_map_multis_append(const f_string_map_multis_t source, f_string_map_multis_t * const destination) F_attribute_visibility_internal_d; + extern f_status_t private_f_string_map_multis_append(const f_string_map_multi_t source, f_string_map_multis_t * const destination) F_attribute_visibility_internal_d; #endif // !defined(_di_f_string_map_multiss_append_) || !defined(_di_f_string_map_multis_append_) /** + * Private implementation for appending. + * + * Intended to be shared to each of the different implementation variations. + * + * @param source + * The source multi-maps to append. + * @param destination + * The destination multi-maps the source is appended onto. + * + * @return + * F_none on success. + * + * F_array_too_large (with error bit) if the combined array is too large. + * + * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_string_map_multis_append(). + * Errors (with error bit) from: f_string_map_multiss_append(). + * + * @see f_memory_resize() + * @see f_string_map_multis_append() + * @see f_string_map_multiss_append() + */ +#if !defined(_di_f_string_map_multiss_append_all_) || !defined(_di_f_string_map_multis_append_all_) + extern f_status_t private_f_string_map_multis_append_all(const f_string_map_multis_t source, f_string_map_multis_t * const destination) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_string_map_multiss_append_all_) || !defined(_di_f_string_map_multis_append_all_) + +/** * Private implementation for resizing. * * Intended to be shared to each of the different implementation variations. @@ -532,9 +559,9 @@ extern "C" { * Intended to be shared to each of the different implementation variations. * * @param source - * The source strings to append. + * The source map to append. * @param destination - * The destination strings the source is appended onto. + * The destination maps the source is appended onto. * * @return * F_none on success. @@ -548,10 +575,35 @@ extern "C" { * @see f_string_mapss_append() */ #if !defined(_di_f_string_mapss_append_) || !defined(_di_f_string_maps_append_) - extern f_status_t private_f_string_maps_append(const f_string_maps_t source, f_string_maps_t * const destination) F_attribute_visibility_internal_d; + extern f_status_t private_f_string_maps_append(const f_string_map_t source, f_string_maps_t * const destination) F_attribute_visibility_internal_d; #endif // !defined(_di_f_string_mapss_append_) || !defined(_di_f_string_maps_append_) /** + * Private implementation for appending. + * + * Intended to be shared to each of the different implementation variations. + * + * @param source + * The source maps to append. + * @param destination + * The destination maps the source is appended onto. + * + * @return + * F_none on success. + * + * F_array_too_large (with error bit) if the combined array is too large. + * + * Errors (with error bit) from: f_memory_resize(). + * + * @see f_memory_resize() + * @see f_string_maps_append() + * @see f_string_mapss_append() + */ +#if !defined(_di_f_string_mapss_append_all_) || !defined(_di_f_string_maps_append_all_) + extern f_status_t private_f_string_maps_append_all(const f_string_maps_t source, f_string_maps_t * const destination) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_string_mapss_append_all_) || !defined(_di_f_string_maps_append_all_) + +/** * Private implementation for resizing. * * Intended to be shared to each of the different implementation variations. diff --git a/level_0/f_string/c/string/map.c b/level_0/f_string/c/string/map.c index 94d0be9..7bcfb7d 100644 --- a/level_0/f_string/c/string/map.c +++ b/level_0/f_string/c/string/map.c @@ -16,7 +16,39 @@ extern "C" { #endif // _di_f_string_map_multis_adjust_ #ifndef _di_f_string_map_multis_append_ - f_status_t f_string_map_multis_append(const f_string_map_multis_t source, f_string_map_multis_t * const destination) { + f_status_t f_string_map_multis_append(const f_string_map_multi_t source, f_string_map_multis_t * const destination) { + #ifndef _di_level_0_parameter_checking_ + if (!destination) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + f_status_t status = F_none; + + if (destination->used + 1 > destination->size) { + status = private_f_string_map_multis_resize(destination->used + F_memory_default_allocation_small_d, destination); + if (F_status_is_error(status)) return status; + } + + destination->array[destination->used].name.used = 0; + destination->array[destination->used].value.used = 0; + + if (source.name.used) { + status = private_f_string_append(source.name.string, source.name.used, &destination->array[destination->used].name); + if (F_status_is_error(status)) return status; + } + + if (source.value.used) { + status = private_f_string_dynamics_append(source.value, &destination->array[destination->used].value); + if (F_status_is_error(status)) return status; + } + + ++destination->used; + + return F_none; + } +#endif // _di_f_string_map_multis_append_ + +#ifndef _di_f_string_map_multis_append_all_ + f_status_t f_string_map_multis_append_all(const f_string_map_multis_t source, f_string_map_multis_t * const destination) { #ifndef _di_level_0_parameter_checking_ if (!destination) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ @@ -46,7 +78,7 @@ extern "C" { return F_none; } -#endif // _di_f_string_map_multis_append_ +#endif // _di_f_string_map_multis_append_all_ #ifndef _di_f_string_map_multis_decimate_by_ f_status_t f_string_map_multis_decimate_by(const f_array_length_t amount, f_string_map_multis_t * const map_multis) { @@ -151,7 +183,33 @@ extern "C" { #endif // _di_f_string_map_multiss_adjust_ #ifndef _di_f_string_map_multiss_append_ - f_status_t f_string_map_multiss_append(const f_string_map_multiss_t source, f_string_map_multiss_t * const destination) { + f_status_t f_string_map_multiss_append(const f_string_map_multis_t source, f_string_map_multiss_t * const destination) { + #ifndef _di_level_0_parameter_checking_ + if (!destination) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + f_status_t status = F_none; + + if (destination->used + 1 > destination->size) { + status = private_f_string_map_multiss_resize(destination->used + F_memory_default_allocation_small_d, destination); + if (F_status_is_error(status)) return status; + } + + destination->array[destination->used].used = 0; + + if (source.used) { + status = private_f_string_map_multis_append_all(source, &destination->array[destination->used]); + if (F_status_is_error(status)) return status; + } + + ++destination->used; + + return F_none; + } +#endif // _di_f_string_map_multiss_append_ + +#ifndef _di_f_string_map_multiss_append_all_ + f_status_t f_string_map_multiss_append_all(const f_string_map_multiss_t source, f_string_map_multiss_t * const destination) { #ifndef _di_level_0_parameter_checking_ if (!destination) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ @@ -168,14 +226,14 @@ extern "C" { destination->array[destination->used].used = 0; if (source.array[i].used) { - status = private_f_string_map_multis_append(source.array[i], &destination->array[destination->used]); + status = private_f_string_map_multis_append_all(source.array[i], &destination->array[destination->used]); if (F_status_is_error(status)) return status; } } // for return F_none; } -#endif // _di_f_string_map_multiss_append_ +#endif // _di_f_string_map_multiss_append_all_ #ifndef _di_f_string_map_multiss_decimate_by_ f_status_t f_string_map_multiss_decimate_by(const f_array_length_t amount, f_string_map_multiss_t * const map_multiss) { @@ -280,17 +338,27 @@ extern "C" { #endif // _di_f_string_maps_adjust_ #ifndef _di_f_string_maps_append_ - f_status_t f_string_maps_append(const f_string_maps_t source, f_string_maps_t * const destination) { + f_status_t f_string_maps_append(const f_string_map_t source, f_string_maps_t * const destination) { #ifndef _di_level_0_parameter_checking_ if (!destination) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (!source.used) return F_data_not; - return private_f_string_maps_append(source, destination); } #endif // _di_f_string_maps_append_ +#ifndef _di_f_string_maps_append_all_ + f_status_t f_string_maps_append_all(const f_string_maps_t source, f_string_maps_t * const destination) { + #ifndef _di_level_0_parameter_checking_ + if (!destination) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!source.used) return F_data_not; + + return private_f_string_maps_append_all(source, destination); + } +#endif // _di_f_string_maps_append_all_ + #ifndef _di_f_string_maps_decimate_by_ f_status_t f_string_maps_decimate_by(const f_array_length_t amount, f_string_maps_t * const maps) { #ifndef _di_level_0_parameter_checking_ @@ -394,7 +462,35 @@ extern "C" { #endif // _di_f_string_mapss_adjust_ #ifndef _di_f_string_mapss_append_ - f_status_t f_string_mapss_append(const f_string_mapss_t source, f_string_mapss_t * const destination) { + f_status_t f_string_mapss_append(const f_string_maps_t source, f_string_mapss_t * const destination) { + #ifndef _di_level_0_parameter_checking_ + if (!destination) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!source.used) return F_data_not; + + f_status_t status = F_none; + + if (destination->used + 1 > destination->size) { + status = private_f_string_mapss_resize(destination->used + F_memory_default_allocation_small_d, destination); + if (F_status_is_error(status)) return status; + } + + destination->array[destination->used].used = 0; + + if (source.used) { + status = private_f_string_maps_append_all(source, &destination->array[destination->used]); + if (F_status_is_error(status)) return status; + } + + ++destination->used; + + return F_none; + } +#endif // _di_f_string_mapss_append_ + +#ifndef _di_f_string_mapss_append_all_ + f_status_t f_string_mapss_append_all(const f_string_mapss_t source, f_string_mapss_t * const destination) { #ifndef _di_level_0_parameter_checking_ if (!destination) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ @@ -413,14 +509,14 @@ extern "C" { destination->array[destination->used].used = 0; if (source.array[i].used) { - status = private_f_string_maps_append(source.array[i], &destination->array[destination->used]); + status = private_f_string_maps_append_all(source.array[i], &destination->array[destination->used]); if (F_status_is_error(status)) return status; } } // for return F_none; } -#endif // _di_f_string_mapss_append_ +#endif // _di_f_string_mapss_append_all_ #ifndef _di_f_string_mapss_decimate_by_ f_status_t f_string_mapss_decimate_by(const f_array_length_t amount, f_string_mapss_t * const mapss) { diff --git a/level_0/f_string/c/string/map.h b/level_0/f_string/c/string/map.h index 8e814a0..db983f5 100644 --- a/level_0/f_string/c/string/map.h +++ b/level_0/f_string/c/string/map.h @@ -214,7 +214,7 @@ extern "C" { #endif // _di_f_string_map_multis_adjust_ /** - * Append the source map_multis onto the destination. + * Append a single source map_multi onto the destination. * * @param source * The source maps to append. @@ -223,7 +223,6 @@ extern "C" { * * @return * F_none on success. - * F_data_not on success, but there is nothing to append (size == 0). * * F_parameter (with error bit) if a parameter is invalid. * F_string_too_large (with error bit) if the combined string is too large. @@ -231,10 +230,31 @@ extern "C" { * Errors (with error bit) from: f_memory_resize(). */ #ifndef _di_f_string_map_multis_append_ - f_status_t f_string_map_multis_append(const f_string_map_multis_t source, f_string_map_multis_t *destination); + f_status_t f_string_map_multis_append(const f_string_map_multi_t source, f_string_map_multis_t *destination); #endif // _di_f_string_map_multis_append_ /** + * Append the source map_multis onto the destination. + * + * @param source + * The source maps to append. + * @param destination + * The destination maps the source is appended onto. + * + * @return + * F_none on success. + * F_data_not on success, but there is nothing to append (size == 0). + * + * F_parameter (with error bit) if a parameter is invalid. + * F_string_too_large (with error bit) if the combined string is too large. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_map_multis_append_all_ + f_status_t f_string_map_multis_append_all(const f_string_map_multis_t source, f_string_map_multis_t *destination); +#endif // _di_f_string_map_multis_append_all_ + +/** * Resize the map_multis array to a smaller size. * * This will resize making the array smaller based on (size - given length). @@ -370,7 +390,7 @@ extern "C" { #endif // _di_f_string_maps_adjust_ /** - * Append the source maps onto the destination. + * Append a single source map onto the destination. * * @param source * The source maps to append. @@ -379,7 +399,6 @@ extern "C" { * * @return * F_none on success. - * F_data_not on success, but there is nothing to append (size == 0). * * F_parameter (with error bit) if a parameter is invalid. * F_string_too_large (with error bit) if the combined string is too large. @@ -387,10 +406,31 @@ extern "C" { * Errors (with error bit) from: f_memory_resize(). */ #ifndef _di_f_string_maps_append_ - extern f_status_t f_string_maps_append(const f_string_maps_t source, f_string_maps_t * const destination); + extern f_status_t f_string_maps_append(const f_string_map_t source, f_string_maps_t * const destination); #endif // _di_f_string_maps_append_ /** + * Append the source maps onto the destination. + * + * @param source + * The source maps to append. + * @param destination + * The destination maps the source is appended onto. + * + * @return + * F_none on success. + * F_data_not on success, but there is nothing to append (size == 0). + * + * F_parameter (with error bit) if a parameter is invalid. + * F_string_too_large (with error bit) if the combined string is too large. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_maps_append_all_ + extern f_status_t f_string_maps_append_all(const f_string_maps_t source, f_string_maps_t * const destination); +#endif // _di_f_string_maps_append_all_ + +/** * Resize the string maps array to a smaller size. * * This will resize making the array smaller based on (size - given length). @@ -526,7 +566,7 @@ extern "C" { #endif // _di_f_string_mapss_adjust_ /** - * Append the source mapss onto the destination. + * Append a single source maps onto the destination. * * @param source * The source mapss to append. @@ -535,7 +575,6 @@ extern "C" { * * @return * F_none on success. - * F_data_not on success, but there is nothing to append (size == 0). * * F_parameter (with error bit) if a parameter is invalid. * F_string_too_large (with error bit) if the combined string is too large. @@ -543,10 +582,31 @@ extern "C" { * Errors (with error bit) from: f_memory_resize(). */ #ifndef _di_f_string_mapss_append_ - extern f_status_t f_string_mapss_append(const f_string_mapss_t source, f_string_mapss_t * const destination); + extern f_status_t f_string_mapss_append(const f_string_maps_t source, f_string_mapss_t * const destination); #endif // _di_f_string_mapss_append_ /** + * Append the source mapss onto the destination. + * + * @param source + * The source mapss to append. + * @param destination + * The destination mapss the source is appended onto. + * + * @return + * F_none on success. + * F_data_not on success, but there is nothing to append (size == 0). + * + * F_parameter (with error bit) if a parameter is invalid. + * F_string_too_large (with error bit) if the combined string is too large. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_mapss_append_all_ + extern f_status_t f_string_mapss_append_all(const f_string_mapss_t source, f_string_mapss_t * const destination); +#endif // _di_f_string_mapss_append_all_ + +/** * Resize the string mapss array to a smaller size. * * This will resize making the array smaller based on (size - given length). -- 1.8.3.1