From 3989ce180c38988277276bd934990b3a450ea4ef Mon Sep 17 00:00:00 2001 From: Pepijn Noltes Date: Mon, 1 Apr 2024 14:54:43 +0200 Subject: [PATCH] gh-674: Remove defaultValue arg from props get array functions --- libs/utils/gtest/src/PropertiesTestSuite.cc | 24 ++++----- libs/utils/include/celix/Properties.h | 10 ++-- libs/utils/include/celix_properties.h | 60 +++++++++------------ libs/utils/src/properties.c | 36 +++++-------- 4 files changed, 54 insertions(+), 76 deletions(-) diff --git a/libs/utils/gtest/src/PropertiesTestSuite.cc b/libs/utils/gtest/src/PropertiesTestSuite.cc index a426bdde0..a2873c8df 100644 --- a/libs/utils/gtest/src/PropertiesTestSuite.cc +++ b/libs/utils/gtest/src/PropertiesTestSuite.cc @@ -832,9 +832,9 @@ TEST_F(PropertiesTestSuite, LongArrayListTest) { EXPECT_EQ(6, celix_arrayList_getLong(retrievedList4, 0)); celix_arrayList_destroy(retrievedList4); - auto* getList = celix_properties_getLongArrayList(props, "array2", nullptr); + auto* getList = celix_properties_getLongArrayList(props, "array2"); EXPECT_NE(longList2, getList); - getList = celix_properties_getLongArrayList(props, "array3", nullptr); + getList = celix_properties_getLongArrayList(props, "array3"); EXPECT_EQ(longList3, getList); } @@ -892,11 +892,11 @@ TEST_F(PropertiesTestSuite, GetTypedArrayListTest) { ///When the celix_properties_getArrayList is called with the array lists - const auto* retrievedStringList2 = celix_properties_getStringArrayList(props, "stringList", nullptr); - const auto* retrievedLongList2 = celix_properties_getLongArrayList(props, "longList", nullptr); - const auto* retrievedDoubleList2 = celix_properties_getDoubleArrayList(props, "doubleList", nullptr); - const auto* retrievedBoolList2 = celix_properties_getBoolArrayList(props, "boolList", nullptr); - const auto* retrievedVersionList2 = celix_properties_getVersionArrayList(props, "versionList", nullptr); + const auto* retrievedStringList2 = celix_properties_getStringArrayList(props, "stringList"); + const auto* retrievedLongList2 = celix_properties_getLongArrayList(props, "longList"); + const auto* retrievedDoubleList2 = celix_properties_getDoubleArrayList(props, "doubleList"); + const auto* retrievedBoolList2 = celix_properties_getBoolArrayList(props, "boolList"); + const auto* retrievedVersionList2 = celix_properties_getVersionArrayList(props, "versionList"); //Then the retrieved array lists pointers should be the same as the original array lists EXPECT_EQ(stringList, retrievedStringList2); @@ -906,11 +906,11 @@ TEST_F(PropertiesTestSuite, GetTypedArrayListTest) { EXPECT_EQ(versionList, retrievedVersionList2); //When using the celix_properties_getArrayList function to retrieve the array lists - const auto* retrievedStringList3 = celix_properties_getArrayList(props, "stringList", nullptr); - const auto* retrievedLongList3 = celix_properties_getArrayList(props, "longList", nullptr); - const auto* retrievedDoubleList3 = celix_properties_getArrayList(props, "doubleList", nullptr); - const auto* retrievedBoolList3 = celix_properties_getArrayList(props, "boolList", nullptr); - const auto* retrievedVersionList3 = celix_properties_getArrayList(props, "versionList", nullptr); + const auto* retrievedStringList3 = celix_properties_getArrayList(props, "stringList"); + const auto* retrievedLongList3 = celix_properties_getArrayList(props, "longList"); + const auto* retrievedDoubleList3 = celix_properties_getArrayList(props, "doubleList"); + const auto* retrievedBoolList3 = celix_properties_getArrayList(props, "boolList"); + const auto* retrievedVersionList3 = celix_properties_getArrayList(props, "versionList"); //Then the retrieved array lists should be the same as the original array lists EXPECT_TRUE(celix_arrayList_equals(stringList, retrievedStringList3)); diff --git a/libs/utils/include/celix/Properties.h b/libs/utils/include/celix/Properties.h index bc46b18e0..78e1dd6a6 100644 --- a/libs/utils/include/celix/Properties.h +++ b/libs/utils/include/celix/Properties.h @@ -476,7 +476,7 @@ namespace celix { * set or its value is not a array of longs. */ std::vector getLongVector(const std::string& key, const std::vector& defaultValue = {}) const { - const auto* list = celix_properties_getLongArrayList(cProps.get(), key.c_str(), nullptr); + const auto* list = celix_properties_getLongArrayList(cProps.get(), key.c_str()); return convertToVector(list, defaultValue, celix_arrayList_getLong); } @@ -511,7 +511,7 @@ namespace celix { * set or its value is not a array of booleans. */ std::vector getBoolVector(const std::string& key, const std::vector& defaultValue = {}) const { - const auto* list = celix_properties_getBoolArrayList(cProps.get(), key.c_str(), nullptr); + const auto* list = celix_properties_getBoolArrayList(cProps.get(), key.c_str()); return convertToVector(list, defaultValue, celix_arrayList_getBool); } @@ -548,7 +548,7 @@ namespace celix { */ std::vector getDoubleVector(const std::string& key, const std::vector& defaultValue = {}) const { - const auto* list = celix_properties_getDoubleArrayList(cProps.get(), key.c_str(), nullptr); + const auto* list = celix_properties_getDoubleArrayList(cProps.get(), key.c_str()); return convertToVector(list, defaultValue, celix_arrayList_getDouble); } @@ -597,7 +597,7 @@ namespace celix { */ std::vector getVersionVector(const std::string& key, const std::vector& defaultValue = {}) const { - const auto* list = celix_properties_getVersionArrayList(cProps.get(), key.c_str(), nullptr); + const auto* list = celix_properties_getVersionArrayList(cProps.get(), key.c_str()); if (list) { std::vector result{}; for (int i = 0; i < celix_arrayList_size(list); ++i) { @@ -653,7 +653,7 @@ namespace celix { */ std::vector getStringVector(const std::string& key, const std::vector& defaultValue = {}) const { - const auto* list = celix_properties_getStringArrayList(cProps.get(), key.c_str(), nullptr); + const auto* list = celix_properties_getStringArrayList(cProps.get(), key.c_str()); if (list) { std::vector result{}; for (int i = 0; i < celix_arrayList_size(list); ++i) { diff --git a/libs/utils/include/celix_properties.h b/libs/utils/include/celix_properties.h index 4c23f2499..3a7225afa 100644 --- a/libs/utils/include/celix_properties.h +++ b/libs/utils/include/celix_properties.h @@ -569,8 +569,7 @@ CELIX_UTILS_EXPORT celix_status_t celix_properties_assignArrayList(celix_propert * @brief Get the property value as an array without copying. * * This function provides a non-owning, read-only access to a array property value. - * It returns a const pointer to the array. If the property is not set or its value is not an array, - * the default value is returned. + * It returns a const pointer to the array. If the property is not set or its value is not an array, NULL is returned. * * The returned array will have a element type of: * - CELIX_ARRAY_LIST_ELEMENT_TYPE_STRING @@ -583,13 +582,11 @@ CELIX_UTILS_EXPORT celix_status_t celix_properties_assignArrayList(celix_propert * * @param[in] properties The property set to search. * @param[in] key The key of the property to get. - * @param[in] defaultValue The value to return if the property is not set or its value is not an array list. - * @return A const pointer to the array list property value, or the default value if the property - * is not set or its value is not an array list. The returned pointer should not be modified or freed. + * @return A const pointer to the array list property value, or NULL if the property is not set or its value is not + * an array list. The returned pointer should not be modified or freed. */ CELIX_UTILS_EXPORT const celix_array_list_t* celix_properties_getArrayList(const celix_properties_t* properties, - const char* key, - const celix_array_list_t* defaultValue); + const char* key); /** * @brief Get a property value as an array of longs. @@ -624,18 +621,16 @@ CELIX_UTILS_EXPORT celix_status_t celix_properties_getAsLongArrayList(const celi * * This function provides a non-owning, read-only access to a array of longs property value. * It returns a const pointer to the array. If the property is not set or its value is not an array of longs, - * the default value is returned. + * NULL is returned. * * * @param[in] properties The property set to search. * @param[in] key The key of the property to get. - * @param[in] defaultValue The value to return if the property is not set or its value is not an array of longs. - * @return A const pointer to the property value interpreted as an array of longs, or the default value if the property + * @return A const pointer to the property value interpreted as an array of longs, or NULL if the property * is not set or its value is not an array of longs. The returned pointer should not be modified or freed. */ CELIX_UTILS_EXPORT const celix_array_list_t* celix_properties_getLongArrayList(const celix_properties_t* properties, - const char* key, - const celix_array_list_t* defaultValue); + const char* key); /** * @brief Get a property value as an array of doubles, making a copy of the array. @@ -668,17 +663,16 @@ CELIX_UTILS_EXPORT celix_status_t celix_properties_getAsDoubleArrayList(const ce * * This function provides a non-owning, read-only access to a array of doubles property value. * It returns a const pointer to the array. If the property is not set or its value is not an array of doubles, - * the default value is returned. + * NULL is returned. * * * @param[in] properties The property set to search. * @param[in] key The key of the property to get. - * @param[in] defaultValue The value to return if the property is not set or its value is not an array of doubles. - * @return A const pointer to the property value interpreted as an array of doubles, or the default value if the + * @return A const pointer to the property value interpreted as an array of doubles, or NULL if the * property is not set or its value is not an array of doubles. The returned pointer should not be modified or freed. */ -CELIX_UTILS_EXPORT const celix_array_list_t* celix_properties_getDoubleArrayList( - const celix_properties_t* properties, const char* key, const celix_array_list_t* defaultValue); +CELIX_UTILS_EXPORT const celix_array_list_t* celix_properties_getDoubleArrayList(const celix_properties_t* properties, + const char* key); /** * @brief Get a property value as an array of booleans, making a copy of the array. @@ -713,17 +707,15 @@ CELIX_UTILS_EXPORT celix_status_t celix_properties_getAsBoolArrayList(const celi * * This function provides a non-owning, read-only access to a array of booleans property value. * It returns a const pointer to the array. If the property is not set or its value is not an array of booleans, - * the default value is returned. - * + * NULL is returned. * * @param[in] properties The property set to search. * @param[in] key The key of the property to get. - * @param[in] defaultValue The value to return if the property is not set or its value is not an array of booleans. - * @return A const pointer to the property value interpreted as an array of booleans, or the default value if the + * @return A const pointer to the property value interpreted as an array of booleans, or NULL if the * property is not set or its value is not an array of booleans. The returned pointer should not be modified or freed. */ -CELIX_UTILS_EXPORT const celix_array_list_t* celix_properties_getBoolArrayList( - const celix_properties_t* properties, const char* key, const celix_array_list_t* defaultValue); +CELIX_UTILS_EXPORT const celix_array_list_t* celix_properties_getBoolArrayList(const celix_properties_t* properties, + const char* key); /** * @brief Get a property value as an array of strings, making a copy of the array. @@ -761,17 +753,15 @@ CELIX_UTILS_EXPORT celix_status_t celix_properties_getAsStringArrayList(const ce * * This function provides a non-owning, read-only access to a array of string property value. * It returns a const pointer to the array. If the property is not set or its value is not an array of strings, - * the default value is returned. - * + * NULL is returned. * * @param[in] properties The property set to search. * @param[in] key The key of the property to get. - * @param[in] defaultValue The value to return if the property is not set or its value is not an array of strings. - * @return A const pointer to the property value interpreted as an array of strings, or the default value if the + * @return A const pointer to the property value interpreted as an array of strings, or NULL if the * property is not set or its value is not an array of strings. The returned pointer should not be modified or freed. */ -CELIX_UTILS_EXPORT const celix_array_list_t* celix_properties_getStringArrayList( - const celix_properties_t* properties, const char* key, const celix_array_list_t* defaultValue); +CELIX_UTILS_EXPORT const celix_array_list_t* celix_properties_getStringArrayList(const celix_properties_t* properties, + const char* key); /** * @brief Get a property value as an array of celix_version_t entries, making a copy of the array. @@ -811,18 +801,16 @@ CELIX_UTILS_EXPORT celix_status_t celix_properties_getAsVersionArrayList(const c * * This function provides a non-owning, read-only access to a array of celix_version_t property value. * entries. It returns a const pointer to the array. If the property is not set or its value is not an array of - * celix_version_t entries, the default value is returned. + * celix_version_t entries, NULL is returned. * * @param[in] properties The property set to search. * @param[in] key The key of the property to get. - * @param[in] defaultValue The value to return if the property is not set or its value is not an array of - * celix_version_t entries. - * @return A const pointer to the property value interpreted as an array of celix_version_t entries, or the default - * value if the property is not set or its value is not an array of celix_version_t entries. The returned pointer should + * @return A const pointer to the property value interpreted as an array of celix_version_t entries, or NULL if the + * property is not set or its value is not an array of celix_version_t entries. The returned pointer should * not be modified or freed. */ -CELIX_UTILS_EXPORT const celix_array_list_t* celix_properties_getVersionArrayList( - const celix_properties_t* properties, const char* key, const celix_array_list_t* defaultValue); +CELIX_UTILS_EXPORT const celix_array_list_t* celix_properties_getVersionArrayList(const celix_properties_t* properties, + const char* key); /** * @brief Set the value of a property based on the provided property entry, maintaining underlying type. diff --git a/libs/utils/src/properties.c b/libs/utils/src/properties.c index 1eda4d1d7..e143a03a3 100644 --- a/libs/utils/src/properties.c +++ b/libs/utils/src/properties.c @@ -956,26 +956,21 @@ celix_properties_assignArrayList(celix_properties_t* properties, const char* key } const celix_array_list_t* celix_properties_getArrayList(const celix_properties_t* properties, - const char* key, - const celix_array_list_t* defaultValue) { + const char* key) { const celix_properties_entry_t* entry = celix_properties_getEntry(properties, key); if (entry && entry->valueType == CELIX_PROPERTIES_VALUE_TYPE_ARRAY_LIST) { return entry->typed.arrayValue; } - return defaultValue; + return NULL; } static const celix_array_list_t* celix_properties_getTypedArrayList(const celix_properties_t* properties, const char* key, - celix_array_list_element_type_t elType, - const celix_array_list_t* defaultValue) { + celix_array_list_element_type_t elType) { const celix_properties_entry_t* entry = celix_properties_getArrayListEntry(properties, key, elType); if (entry) { return entry->typed.arrayValue; } - if (defaultValue) { - return celix_arrayList_getElementType(defaultValue) == elType ? defaultValue : NULL; - } return NULL; } @@ -1028,9 +1023,8 @@ celix_status_t celix_properties_getAsLongArrayList(const celix_properties_t* pro } const celix_array_list_t* celix_properties_getLongArrayList(const celix_properties_t* properties, - const char* key, - const celix_array_list_t* defaultValue) { - return celix_properties_getTypedArrayList(properties, key, CELIX_ARRAY_LIST_ELEMENT_TYPE_LONG, defaultValue); + const char* key) { + return celix_properties_getTypedArrayList(properties, key, CELIX_ARRAY_LIST_ELEMENT_TYPE_LONG); } celix_status_t celix_properties_getAsDoubleArrayList(const celix_properties_t* properties, @@ -1042,9 +1036,8 @@ celix_status_t celix_properties_getAsDoubleArrayList(const celix_properties_t* p } const celix_array_list_t* celix_properties_getDoubleArrayList(const celix_properties_t* properties, - const char* key, - const celix_array_list_t* defaultValue) { - return celix_properties_getTypedArrayList(properties, key, CELIX_ARRAY_LIST_ELEMENT_TYPE_DOUBLE, defaultValue); + const char* key) { + return celix_properties_getTypedArrayList(properties, key, CELIX_ARRAY_LIST_ELEMENT_TYPE_DOUBLE); } celix_status_t celix_properties_getAsBoolArrayList(const celix_properties_t* properties, @@ -1056,9 +1049,8 @@ celix_status_t celix_properties_getAsBoolArrayList(const celix_properties_t* pro } const celix_array_list_t* celix_properties_getBoolArrayList(const celix_properties_t* properties, - const char* key, - const celix_array_list_t* defaultValue) { - return celix_properties_getTypedArrayList(properties, key, CELIX_ARRAY_LIST_ELEMENT_TYPE_BOOL, defaultValue); + const char* key) { + return celix_properties_getTypedArrayList(properties, key, CELIX_ARRAY_LIST_ELEMENT_TYPE_BOOL); } celix_status_t celix_properties_getAsStringArrayList(const celix_properties_t* properties, @@ -1070,9 +1062,8 @@ celix_status_t celix_properties_getAsStringArrayList(const celix_properties_t* p } const celix_array_list_t* celix_properties_getStringArrayList(const celix_properties_t* properties, - const char* key, - const celix_array_list_t* defaultValue) { - return celix_properties_getTypedArrayList(properties, key, CELIX_ARRAY_LIST_ELEMENT_TYPE_STRING, defaultValue); + const char* key) { + return celix_properties_getTypedArrayList(properties, key, CELIX_ARRAY_LIST_ELEMENT_TYPE_STRING); } celix_status_t celix_properties_getAsVersionArrayList(const celix_properties_t* properties, @@ -1084,9 +1075,8 @@ celix_status_t celix_properties_getAsVersionArrayList(const celix_properties_t* } const celix_array_list_t* celix_properties_getVersionArrayList(const celix_properties_t* properties, - const char* key, - const celix_array_list_t* defaultValue) { - return celix_properties_getTypedArrayList(properties, key, CELIX_ARRAY_LIST_ELEMENT_TYPE_VERSION, defaultValue); + const char* key) { + return celix_properties_getTypedArrayList(properties, key, CELIX_ARRAY_LIST_ELEMENT_TYPE_VERSION); } size_t celix_properties_size(const celix_properties_t* properties) {