From 82091b9d469ff98efe92ea613b9073efdb033589 Mon Sep 17 00:00:00 2001 From: Adeel Kazmi Date: Thu, 28 Jul 2016 15:18:42 +0100 Subject: [PATCH] (Property Map) Added method to find and return an index or equivalent string key Change-Id: Iaf18b8eb70523b401a13eb47db4a69b65f1fb963 --- automated-tests/src/dali/utc-Dali-PropertyMap.cpp | 46 +++++++++++++++++++++++ dali/public-api/object/property-map.cpp | 10 +++++ dali/public-api/object/property-map.h | 13 +++++++ 3 files changed, 69 insertions(+) diff --git a/automated-tests/src/dali/utc-Dali-PropertyMap.cpp b/automated-tests/src/dali/utc-Dali-PropertyMap.cpp index bb17787..2d099e0 100644 --- a/automated-tests/src/dali/utc-Dali-PropertyMap.cpp +++ b/automated-tests/src/dali/utc-Dali-PropertyMap.cpp @@ -221,6 +221,52 @@ int UtcDaliPropertyMapFind(void) END_TEST; } +int UtcDaliPropertyMapFindIndexThenString(void) +{ + // Define the valid keys and values to test with. + std::string stringKeyValid = "bar"; + std::string stringKeyInvalid = "aardvark"; + int indexKeyValid = 100; + int indexKeyInvalid = 101; + + // Define invalid key and value to test with. + std::string stringValueValid = "DALi"; + int indexValueValid = 3; + + // Set up a property map containing the valid keys and values defined above. + Property::Map map; + map[ "foo" ] = 1; + map[ 10 ] = "string"; + map[ stringKeyValid ] = stringValueValid; + map[ indexKeyValid ] = indexValueValid; + + Property::Value* value = NULL; + + // TEST: If both index and string are valid, the Property::Value of the index is returned. + value = map.Find( indexKeyValid, stringKeyValid ); + + DALI_TEST_EQUALS( value->Get(), indexValueValid, TEST_LOCATION ); + + + // TEST: If only the index is valid, the Property::Value of the index is returned. + value = map.Find( indexKeyValid, stringKeyInvalid ); + + DALI_TEST_EQUALS( value->Get(), indexValueValid, TEST_LOCATION ); + + + // TEST: If only the string is valid, the Property::Value of the string is returned. + value = map.Find( indexKeyInvalid, stringKeyValid ); + + DALI_TEST_EQUALS( value->Get(), stringValueValid, TEST_LOCATION ); + + + // TEST: If neither the index or string are valid, then a NULL pointer is returned. + value = map.Find( indexKeyInvalid, stringKeyInvalid ); + + DALI_TEST_CHECK( value == NULL ); + + END_TEST; +} int UtcDaliPropertyMapOperatorIndex(void) { diff --git a/dali/public-api/object/property-map.cpp b/dali/public-api/object/property-map.cpp index f892aae..f6d7775 100644 --- a/dali/public-api/object/property-map.cpp +++ b/dali/public-api/object/property-map.cpp @@ -131,6 +131,16 @@ Property::Value* Property::Map::Find( Property::Index key ) const return NULL; // Not found } +Property::Value* Property::Map::Find( Property::Index indexKey, const std::string& stringKey ) const +{ + Property::Value* valuePtr = Find( indexKey ); + if( !valuePtr ) + { + valuePtr = Find( stringKey ); + } + return valuePtr; +} + Property::Value* Property::Map::Find( const std::string& key, Property::Type type ) const { for ( StringValueContainer::iterator iter = mImpl->mStringValueContainer.begin(), endIter = mImpl->mStringValueContainer.end(); iter != endIter; ++iter ) diff --git a/dali/public-api/object/property-map.h b/dali/public-api/object/property-map.h index 15a3291..c530a02 100644 --- a/dali/public-api/object/property-map.h +++ b/dali/public-api/object/property-map.h @@ -178,6 +178,19 @@ public: Value* Find( Property::Index key ) const; /** + * @brief Finds the value for the specified keys if either exist. + * + * Will search for the index key first. + * + * @SINCE_1_1.45 + * @param[in] indexKey The index key to find. + * @param[in] stringKey The string key to find. + * + * @return A const pointer to the value if it exists, NULL otherwise + */ + Value* Find( Property::Index indexKey, const std::string& stringKey ) const; + + /** * @brief Finds the value for the specified key if it exists and its type is type * * @SINCE_1_0.0 -- 2.7.4