Skip to content

Commit

Permalink
gh-674: Remove defaultValue arg from props get array functions
Browse files Browse the repository at this point in the history
  • Loading branch information
pnoltes committed Apr 1, 2024
1 parent be6ca79 commit 3989ce1
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 76 deletions.
24 changes: 12 additions & 12 deletions libs/utils/gtest/src/PropertiesTestSuite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -892,11 +892,11 @@ TEST_F(PropertiesTestSuite, GetTypedArrayListTest) {


///When the celix_properties_get<Type>ArrayList 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);
Expand All @@ -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));
Expand Down
10 changes: 5 additions & 5 deletions libs/utils/include/celix/Properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ namespace celix {
* set or its value is not a array of longs.
*/
std::vector<long> getLongVector(const std::string& key, const std::vector<long>& 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<long>(list, defaultValue, celix_arrayList_getLong);
}

Expand Down Expand Up @@ -511,7 +511,7 @@ namespace celix {
* set or its value is not a array of booleans.
*/
std::vector<bool> getBoolVector(const std::string& key, const std::vector<bool>& 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<bool>(list, defaultValue, celix_arrayList_getBool);
}

Expand Down Expand Up @@ -548,7 +548,7 @@ namespace celix {
*/
std::vector<double> getDoubleVector(const std::string& key,
const std::vector<double>& 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<double>(list, defaultValue, celix_arrayList_getDouble);
}

Expand Down Expand Up @@ -597,7 +597,7 @@ namespace celix {
*/
std::vector<celix::Version> getVersionVector(const std::string& key,
const std::vector<celix::Version>& 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<celix::Version> result{};
for (int i = 0; i < celix_arrayList_size(list); ++i) {
Expand Down Expand Up @@ -653,7 +653,7 @@ namespace celix {
*/
std::vector<std::string> getStringVector(const std::string& key,
const std::vector<std::string>& 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<std::string> result{};
for (int i = 0; i < celix_arrayList_size(list); ++i) {
Expand Down
60 changes: 24 additions & 36 deletions libs/utils/include/celix_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
Loading

0 comments on commit 3989ce1

Please sign in to comment.