Remove element of Property::Map by the specified key. 28/272428/4
authorhuayong.xu <huayong.xu@samsung.com>
Thu, 17 Mar 2022 06:05:21 +0000 (14:05 +0800)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Tue, 22 Mar 2022 11:05:10 +0000 (11:05 +0000)
Change-Id: Ife048e33a54edb6b6cebfe79b464707c0a361a45

automated-tests/src/dali/utc-Dali-PropertyMap.cpp [changed mode: 0644->0755]
dali/public-api/object/property-map.cpp
dali/public-api/object/property-map.h [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 84d58c2..61edaee
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -582,6 +582,28 @@ int UtcDaliPropertyMapAnonymousAddChainP(void)
   END_TEST;
 }
 
+int UtcDaliPropertyMapRemove(void)
+{
+  Property::Map map;
+  map["hello"] = 1;
+  map[10]      = "DALi";
+  map["world"] = 2;
+
+  DALI_TEST_CHECK(map.Count() == 3);
+  DALI_TEST_CHECK(!map.Remove(0));
+  DALI_TEST_CHECK(map.Count() == 3);
+  DALI_TEST_CHECK(!map.Remove("doesnotexist"));
+  DALI_TEST_CHECK(map.Count() == 3);
+  DALI_TEST_CHECK(map.Remove(10));
+  DALI_TEST_CHECK(map.Count() == 2);
+  DALI_TEST_CHECK(map.Remove("hello"));
+  DALI_TEST_CHECK(map.Count() == 1);
+  DALI_TEST_CHECK(map.Remove("world"));
+  DALI_TEST_CHECK(map.Count() == 0);
+
+  END_TEST;
+}
+
 int UtcDaliPropertyMapMerge(void)
 {
   Property::Map map;
index 7a500c6..579ec48 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -266,6 +266,32 @@ void Property::Map::Clear()
   mImpl->mIndexValueContainer.clear();
 }
 
+bool Property::Map::Remove(Property::Index key)
+{
+  DALI_ASSERT_DEBUG(mImpl && "Cannot use an object previously used as an r-value");
+
+  auto iter = std::find_if(mImpl->mIndexValueContainer.begin(), mImpl->mIndexValueContainer.end(), [key](const IndexValuePair& element) { return element.first == key; });
+  if(iter != mImpl->mIndexValueContainer.end())
+  {
+    mImpl->mIndexValueContainer.erase(iter);
+    return true;
+  }
+  return false;
+}
+
+bool Property::Map::Remove(std::string_view key)
+{
+  DALI_ASSERT_DEBUG(mImpl && "Cannot use an object previously used as an r-value");
+
+  auto iter = std::find_if(mImpl->mStringValueContainer.begin(), mImpl->mStringValueContainer.end(), [key](const StringValuePair& element) { return element.first == key; });
+  if(iter != mImpl->mStringValueContainer.end())
+  {
+    mImpl->mStringValueContainer.erase(iter);
+    return true;
+  }
+  return false;
+}
+
 void Property::Map::Merge(const Property::Map& from)
 {
   DALI_ASSERT_DEBUG(mImpl && "Cannot use an object previously used as an r-value");
old mode 100644 (file)
new mode 100755 (executable)
index 45431f5..181d553
@@ -2,7 +2,7 @@
 #define DALI_PROPERTY_MAP_H
 
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -273,6 +273,24 @@ public:
   void Clear();
 
   /**
+   * @brief Removes the item by the specified key.
+   *
+   * @SINCE_2_1.15
+   * @param[in] key  The key to remove
+   * @return @c true if succeeded, @c false otherwise
+   */
+  bool Remove(Property::Index key);
+
+  /**
+   * @brief Removes the item by the specified key.
+   *
+   * @SINCE_2_1.15
+   * @param[in] key  The key to remove
+   * @return @c true if succeeded, @c false otherwise
+   */
+  bool Remove(std::string_view key);
+
+  /**
    * @brief Merges values from the map 'from' to the current.
    *
    * Any values in 'from' will overwrite the values in the current map.