PengZheng commented on code in PR #721: URL: https://github.com/apache/celix/pull/721#discussion_r1537275964
########## libs/utils/src/properties.c: ########## @@ -809,11 +910,518 @@ celix_properties_setVersion(celix_properties_t* props, const char* key, const ce return celix_properties_createAndSetEntry(props, key, &prototype); } -celix_status_t celix_properties_setVersionWithoutCopy(celix_properties_t* props, const char* key, celix_version_t* version) { +celix_status_t +celix_properties_assignVersion(celix_properties_t* properties, const char* key, celix_version_t* version) { + assert(version != NULL); celix_properties_entry_t prototype = {0}; prototype.valueType = CELIX_PROPERTIES_VALUE_TYPE_VERSION; prototype.typed.versionValue = version; - return celix_properties_createAndSetEntry(props, key, &prototype); + return celix_properties_createAndSetEntry(properties, key, &prototype); +} + +celix_status_t celix_properties_getAsLongArrayList(const celix_properties_t* properties, + const char* key, + const celix_array_list_t* defaultValue, + celix_array_list_t** list) { + const celix_properties_entry_t* entry = celix_properties_getEntry(properties, key); + if (entry != NULL && entry->valueType == CELIX_PROPERTIES_VALUE_TYPE_LONG_ARRAY) { + celix_array_list_t* copy = celix_arrayList_copy(entry->typed.arrayValue); + if (!copy) { + return CELIX_ENOMEM; + } + *list = copy; + return CELIX_SUCCESS; + } + if (entry != NULL && entry->valueType == CELIX_PROPERTIES_VALUE_TYPE_STRING) { + celix_status_t convertStatus = celix_utils_convertStringToLongArrayList(entry->value, defaultValue, list); + if (convertStatus == CELIX_ILLEGAL_ARGUMENT) { + // conversion failed, but no memory error so defaultValue is copied and set + return CELIX_SUCCESS; + } + return convertStatus; + } + if (defaultValue) { + *list = celix_arrayList_copy(defaultValue); + return *list ? CELIX_SUCCESS : CELIX_ENOMEM; + } + *list = NULL; + return CELIX_SUCCESS; +} + +celix_status_t +celix_properties_setLongArrayList(celix_properties_t* properties, const char* key, const celix_array_list_t* values) { + assert(values != NULL); + celix_array_list_t* copy = celix_arrayList_copy(values); + if (!copy) { + return CELIX_ENOMEM; + } + celix_properties_entry_t prototype = {0}; + prototype.valueType = CELIX_PROPERTIES_VALUE_TYPE_LONG_ARRAY; + prototype.typed.arrayValue = copy; + return celix_properties_createAndSetEntry(properties, key, &prototype); +} + +celix_status_t +celix_properties_assignLongArrayList(celix_properties_t* properties, const char* key, celix_array_list_t* values) { + assert(values != NULL); + celix_properties_entry_t prototype = {0}; + prototype.valueType = CELIX_PROPERTIES_VALUE_TYPE_LONG_ARRAY; + prototype.typed.arrayValue = values; + return celix_properties_createAndSetEntry(properties, key, &prototype); +} + +celix_status_t +celix_properties_setLongs(celix_properties_t* properties, const char* key, const long* values, size_t nrOfValues) { + assert(values != NULL); + celix_autoptr(celix_array_list_t) copy = celix_arrayList_create(); + if (!copy) { + celix_err_push("Failed to create a long array"); + return CELIX_ENOMEM; + } + for (size_t i = 0; i < nrOfValues; ++i) { + celix_status_t status = celix_arrayList_addLong(copy, values[i]); + if (status != CELIX_SUCCESS) { + celix_err_push("Failed to add long to array list"); + return status; + } + } + + celix_properties_entry_t prototype = {0}; + prototype.valueType = CELIX_PROPERTIES_VALUE_TYPE_LONG_ARRAY; + prototype.typed.arrayValue = celix_steal_ptr(copy); + return celix_properties_createAndSetEntry(properties, key, &prototype); +} + +const celix_array_list_t* celix_properties_getLongArrayList(const celix_properties_t* properties, + const char* key, + const celix_array_list_t* defaultValue) { + const celix_properties_entry_t* entry = celix_properties_getEntry(properties, key); + if (entry != NULL && entry->valueType == CELIX_PROPERTIES_VALUE_TYPE_LONG_ARRAY) { + return entry->typed.arrayValue; + } + return defaultValue; +} + +celix_status_t +celix_properties_setDoubleArrayList(celix_properties_t* properties, const char* key, const celix_array_list_t* values) { + assert(values != NULL); + celix_array_list_t* copy = celix_arrayList_copy(values); + if (!copy) { + return CELIX_ENOMEM; + } + celix_properties_entry_t prototype = {0}; + prototype.valueType = CELIX_PROPERTIES_VALUE_TYPE_DOUBLE_ARRAY; + prototype.typed.arrayValue = copy; + return celix_properties_createAndSetEntry(properties, key, &prototype); +} + +celix_status_t +celix_properties_assignDoubleArrayList(celix_properties_t* properties, const char* key, celix_array_list_t* values) { + assert(values != NULL); + celix_properties_entry_t prototype = {0}; + prototype.valueType = CELIX_PROPERTIES_VALUE_TYPE_DOUBLE_ARRAY; + prototype.typed.arrayValue = values; + return celix_properties_createAndSetEntry(properties, key, &prototype); +} + +celix_status_t +celix_properties_setDoubles(celix_properties_t* properties, const char* key, const double* values, size_t nrOfValues) { + assert(values != NULL); + celix_autoptr(celix_array_list_t) copy = celix_arrayList_create(); + if (!copy) { + celix_err_push("Failed to create a double array"); + return CELIX_ENOMEM; + } + for (size_t i = 0; i < nrOfValues; ++i) { + celix_status_t status = celix_arrayList_addDouble(copy, values[i]); + if (status != CELIX_SUCCESS) { + celix_err_push("Failed to add double to array list"); + return status; + } + } + celix_properties_entry_t prototype = {0}; + prototype.valueType = CELIX_PROPERTIES_VALUE_TYPE_DOUBLE_ARRAY; + prototype.typed.arrayValue = celix_steal_ptr(copy); + return celix_properties_createAndSetEntry(properties, key, &prototype); +} + +celix_status_t celix_properties_getAsDoubleArrayList(const celix_properties_t* properties, + const char* key, + const celix_array_list_t* defaultValue, + celix_array_list_t** list) { + const celix_properties_entry_t* entry = celix_properties_getEntry(properties, key); + if (entry != NULL && entry->valueType == CELIX_PROPERTIES_VALUE_TYPE_DOUBLE_ARRAY) { + celix_array_list_t* copy = celix_arrayList_copy(entry->typed.arrayValue); + if (!copy) { + return CELIX_ENOMEM; + } + *list = copy; + return CELIX_SUCCESS; + } + if (entry != NULL && entry->valueType == CELIX_PROPERTIES_VALUE_TYPE_STRING) { + celix_status_t convertStatus = celix_utils_convertStringToDoubleArrayList(entry->value, defaultValue, list); + if (convertStatus == CELIX_ILLEGAL_ARGUMENT) { + // conversion failed, but no memory error so defaultValue is copied and set + return CELIX_SUCCESS; + } + return convertStatus; + } + if (defaultValue) { + *list = celix_arrayList_copy(defaultValue); + return *list ? CELIX_SUCCESS : CELIX_ENOMEM; + } + *list = NULL; + return CELIX_SUCCESS; +} + +const celix_array_list_t* celix_properties_getDoubleArrayList(const celix_properties_t* properties, + const char* key, + const celix_array_list_t* defaultValue) { + const celix_properties_entry_t* entry = celix_properties_getEntry(properties, key); + if (entry != NULL && entry->valueType == CELIX_PROPERTIES_VALUE_TYPE_DOUBLE_ARRAY) { + return entry->typed.arrayValue; + } + return defaultValue; +} + +celix_status_t celix_properties_setBoolArrayList(celix_properties_t* properties, const char* key, const celix_array_list_t* values) { + assert(values != NULL); + celix_array_list_t* copy = celix_arrayList_copy(values); + if (!copy) { + return CELIX_ENOMEM; + } + celix_properties_entry_t prototype = {0}; + prototype.valueType = CELIX_PROPERTIES_VALUE_TYPE_BOOL_ARRAY; + prototype.typed.arrayValue = copy; + return celix_properties_createAndSetEntry(properties, key, &prototype); +} + +celix_status_t +celix_properties_assignBoolArrayList(celix_properties_t* properties, const char* key, celix_array_list_t* values) { + assert(values != NULL); + celix_properties_entry_t prototype = {0}; + prototype.valueType = CELIX_PROPERTIES_VALUE_TYPE_BOOL_ARRAY; + prototype.typed.arrayValue = values; + return celix_properties_createAndSetEntry(properties, key, &prototype); +} + +celix_status_t +celix_properties_setBooleans(celix_properties_t* properties, const char* key, const bool* values, size_t nrOfValues) { + assert(values != NULL); + celix_autoptr(celix_array_list_t) copy = celix_arrayList_create(); + if (!copy) { + celix_err_push("Failed to create a bool array"); + return CELIX_ENOMEM; + } + for (size_t i = 0; i < nrOfValues; ++i) { + celix_status_t status = celix_arrayList_addBool(copy, values[i]); + if (status != CELIX_SUCCESS) { + celix_err_push("Failed to add bool to array list."); + return status; + } + } + celix_properties_entry_t prototype = {0}; + prototype.valueType = CELIX_PROPERTIES_VALUE_TYPE_BOOL_ARRAY; + prototype.typed.arrayValue = celix_steal_ptr(copy); + return celix_properties_createAndSetEntry(properties, key, &prototype); +} + +celix_status_t celix_properties_getAsBoolArrayList(const celix_properties_t* properties, + const char* key, + const celix_array_list_t* defaultValue, Review Comment: Why not `celix_properties_getAsArrayList`? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@celix.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org