Added new API to Property::Map to enable method chaining 34/86534/3
authorDavid Steele <david.steele@partner.samsung.com>
Thu, 1 Sep 2016 16:52:50 +0000 (17:52 +0100)
committerDavid Steele <david.steele@partner.samsung.com>
Mon, 5 Sep 2016 10:24:20 +0000 (11:24 +0100)
Property::Map map;
map.Add("key1", "value").Add("key2", "value");

Or even for anonymous handles:
Property::Map().Add("key1", value).Add("key2", value);

Change-Id: I3657587ee70bd4a6ece441693f885c634544ac42
Signed-off-by: David Steele <david.steele@samsung.com>
automated-tests/src/dali/utc-Dali-PropertyMap.cpp
dali/public-api/object/property-map.h

index 2d099e0..6fb550d 100644 (file)
@@ -320,6 +320,107 @@ int UtcDaliPropertyMapInsertP(void)
   END_TEST;
 }
 
+
+int UtcDaliPropertyMapAddP(void)
+{
+  Property::Map map;
+  DALI_TEST_EQUALS( 0u, map.Count(), TEST_LOCATION );
+  map.Add( "foo", "bar");
+  DALI_TEST_EQUALS( 1u, map.Count(), TEST_LOCATION );
+  Property::Value* value = map.Find( "foo" );
+  DALI_TEST_CHECK( value );
+  DALI_TEST_EQUALS( "bar", value->Get<std::string>(), TEST_LOCATION );
+
+  map.Add( std::string("foo2"), "testing" );
+  DALI_TEST_EQUALS( 2u, map.Count(), TEST_LOCATION );
+  value = map.Find( "foo2" );
+  DALI_TEST_CHECK( value );
+  DALI_TEST_EQUALS( "testing", value->Get<std::string>(), TEST_LOCATION );
+
+  map.Add( 10, "DALi" );
+  DALI_TEST_EQUALS( 3u, map.Count(), TEST_LOCATION );
+  value = map.Find( 10 );
+  DALI_TEST_CHECK( value );
+  DALI_TEST_EQUALS( "DALi", value->Get<std::string>(), TEST_LOCATION );
+
+  map.Add( 100, 9 );
+  DALI_TEST_EQUALS( 4u, map.Count(), TEST_LOCATION );
+  value = map.Find( 100 );
+  DALI_TEST_CHECK( value );
+  DALI_TEST_CHECK( value->Get<int>() == 9 );
+
+  END_TEST;
+}
+
+int UtcDaliPropertyMapAddChainP(void)
+{
+  Property::Map map;
+  DALI_TEST_EQUALS( 0u, map.Count(), TEST_LOCATION );
+  map
+    .Add( "foo", "bar")
+    .Add( std::string("foo2"), "testing" )
+    .Add( 10, "DALi" )
+    .Add( 100, 9 );
+
+  DALI_TEST_EQUALS( 4u, map.Count(), TEST_LOCATION );
+
+  Property::Value* value = map.Find( "foo" );
+  DALI_TEST_CHECK( value );
+  DALI_TEST_EQUALS( "bar", value->Get<std::string>(), TEST_LOCATION );
+
+  value = map.Find( "foo2" );
+  DALI_TEST_CHECK( value );
+  DALI_TEST_EQUALS( "testing", value->Get<std::string>(), TEST_LOCATION );
+
+  value = map.Find( 10 );
+  DALI_TEST_CHECK( value );
+  DALI_TEST_EQUALS( "DALi", value->Get<std::string>(), TEST_LOCATION );
+
+  value = map.Find( 100 );
+  DALI_TEST_CHECK( value );
+  DALI_TEST_CHECK( value->Get<int>() == 9 );
+
+  END_TEST;
+}
+
+int UtcDaliPropertyMapAnonymousAddChainP(void)
+{
+  class TestMap
+  {
+  public:
+    TestMap(Property::Map map)
+    : mMap(map)
+    {
+    }
+    Property::Map mMap;
+  };
+
+  TestMap mapTest( Property::Map().Add( "foo", "bar")
+                                  .Add( std::string("foo2"), "testing" )
+                                  .Add( 10, "DALi" )
+                                  .Add( 100, 9 ));
+
+
+  Property::Value* value = mapTest.mMap.Find( "foo" );
+  DALI_TEST_CHECK( value );
+  DALI_TEST_EQUALS( "bar", value->Get<std::string>(), TEST_LOCATION );
+
+  value = mapTest.mMap.Find( "foo2" );
+  DALI_TEST_CHECK( value );
+  DALI_TEST_EQUALS( "testing", value->Get<std::string>(), TEST_LOCATION );
+
+  value = mapTest.mMap.Find( 10 );
+  DALI_TEST_CHECK( value );
+  DALI_TEST_EQUALS( "DALi", value->Get<std::string>(), TEST_LOCATION );
+
+  value = mapTest.mMap.Find( 100 );
+  DALI_TEST_CHECK( value );
+  DALI_TEST_CHECK( value->Get<int>() == 9 );
+
+  END_TEST;
+}
+
+
 int UtcDaliPropertyMapMerge(void)
 {
   Property::Map map;
index c530a02..2f26c1b 100644 (file)
@@ -111,6 +111,53 @@ public:
    */
   void Insert( Property::Index key, const Value& value );
 
+
+  /**
+   * @brief Inserts the key-value pair in the Map, with the key type as string.
+   *
+   * Does not check for duplicates
+   * @SINCE_1_2.5
+   * @param key to insert
+   * @param value to insert
+   * @return a reference to this object
+   */
+  inline Property::Map& Add( const char* key, const Value& value )
+  {
+    Insert(key, value);
+    return *this;
+  }
+
+  /**
+   * @brief Inserts the key-value pair in the Map, with the key type as string.
+   *
+   * Does not check for duplicates
+   * @SINCE_1_2.5
+   * @param key to insert
+   * @param value to insert
+   * @return a reference to this object
+   */
+  inline Property::Map& Add( const std::string& key, const Value& value )
+  {
+    Insert(key, value);
+    return *this;
+  }
+
+
+  /**
+   * @brief Inserts the key-value pair in the Map, with the key type as index.
+   *
+   * Does not check for duplicates
+   * @SINCE_1_2.5
+   * @param key to insert
+   * @param value to insert
+   * @return a reference to this object
+   */
+  inline Property::Map& Add( Property::Index key, const Value& value )
+  {
+    Insert(key, value);
+    return *this;
+  }
+
   /**
    * DEPRECATED_1_1.39. Retrieve the value with key instead of position, Use Find( key ) instead.
    *