From 5f3b519ef08ac015127614ee9e3322f57c8aa0ab Mon Sep 17 00:00:00 2001 From: Adeel Kazmi Date: Fri, 17 Oct 2014 14:14:48 +0100 Subject: [PATCH] (Properties) Property::Map class added Before, this was just a Vector and then a map was redefined in Toolkit. Change-Id: I862676ce8c05ee4e5b0e47ddb5b2186708dee4a6 --- .../src/dali-unmanaged/utc-Dali-Scripting.cpp | 167 ++++++------- automated-tests/src/dali/CMakeLists.txt | 1 + automated-tests/src/dali/utc-Dali-Handle.cpp | 2 +- automated-tests/src/dali/utc-Dali-PropertyMap.cpp | 258 +++++++++++++++++++++ dali/public-api/dali-core.h | 1 + dali/public-api/file.list | 2 + dali/public-api/object/property-map.cpp | 169 ++++++++++++++ dali/public-api/object/property-map.h | 158 +++++++++++++ dali/public-api/object/property-value.cpp | 72 ++---- dali/public-api/object/property-value.h | 10 +- dali/public-api/object/property.h | 2 +- dali/public-api/scripting/scripting.cpp | 76 +++--- dali/public-api/scripting/scripting.h | 1 + 13 files changed, 736 insertions(+), 183 deletions(-) create mode 100644 automated-tests/src/dali/utc-Dali-PropertyMap.cpp create mode 100644 dali/public-api/object/property-map.cpp create mode 100644 dali/public-api/object/property-map.h diff --git a/automated-tests/src/dali-unmanaged/utc-Dali-Scripting.cpp b/automated-tests/src/dali-unmanaged/utc-Dali-Scripting.cpp index f73cb64..1d3aa68 100644 --- a/automated-tests/src/dali-unmanaged/utc-Dali-Scripting.cpp +++ b/automated-tests/src/dali-unmanaged/utc-Dali-Scripting.cpp @@ -71,11 +71,14 @@ void TestEnumStrings( X ( *creator ) ( const Property::Value& ) // The method which creates an instance of type X ) { - Property::Map::iterator iter = map.end() - 1; + const unsigned int lastIndex( map.Count() - 1 ); + const std::string& key = map.GetKey( lastIndex ); + Property::Value& value = map.GetValue( lastIndex ); + for ( unsigned int i = 0; i < num; ++i ) { - iter->second = values[i].string; - tet_printf("Checking: %s: %s\n", iter->first.c_str(), values[i].string ); + value = values[i].string; + tet_printf("Checking: %s: %s\n", key.c_str(), values[i].string ); X instance = creator( map ); DALI_TEST_EQUALS( values[i].value, ( instance.*method )(), TEST_LOCATION ); } @@ -118,7 +121,7 @@ void TestEnumStrings( Property::Map map; CreatePropertyMap( actor, map ); - DALI_TEST_CHECK( !map.empty() ); + DALI_TEST_CHECK( map.Count() ); Property::Value value( map ); DALI_TEST_CHECK( value.HasKey( keyName ) ); DALI_TEST_EQUALS( value.GetValue( keyName ).Get< std::string >(), values[i].string, TEST_LOCATION ); @@ -256,7 +259,7 @@ int UtcDaliScriptingNewImageNegative(void) try { Property::Map map; - map.push_back( Property::StringValuePair( "filename", Vector3::ZERO ) ); + map[ "filename" ] = Vector3::ZERO; Image image = NewImage( map ); tet_result( TET_FAIL ); } @@ -269,7 +272,7 @@ int UtcDaliScriptingNewImageNegative(void) try { Property::Map map; - map.push_back( Property::StringValuePair( "load-policy", Vector3::ZERO ) ); + map[ "load-policy" ] = Vector3::ZERO; Image image = NewImage( map ); tet_result( TET_FAIL ); } @@ -281,7 +284,7 @@ int UtcDaliScriptingNewImageNegative(void) try { Property::Map map; - map.push_back( Property::StringValuePair( "load-policy", "INVALID" ) ); + map[ "load-policy" ] = "INVALID"; Image image = NewImage( map ); tet_result( TET_FAIL ); } @@ -295,7 +298,7 @@ int UtcDaliScriptingNewImageNegative(void) try { Property::Map map; - map.push_back( Property::StringValuePair( "release-policy", Vector3::ZERO ) ); + map[ "release-policy" ] = Vector3::ZERO; Image image = NewImage( map ); tet_result( TET_FAIL ); } @@ -307,7 +310,7 @@ int UtcDaliScriptingNewImageNegative(void) try { Property::Map map; - map.push_back( Property::StringValuePair( "release-policy", "INVALID" ) ); + map[ "release-policy" ] = "INVALID"; Image image = NewImage( map ); tet_result( TET_FAIL ); } @@ -321,8 +324,8 @@ int UtcDaliScriptingNewImageNegative(void) try { Property::Map map; - map.push_back( Property::StringValuePair( "width", "Invalid" ) ); - map.push_back( Property::StringValuePair( "height", "Invalid" ) ); + map[ "width" ] = "Invalid"; + map[ "height" ] = "Invalid"; Image image = NewImage( map ); tet_result( TET_FAIL ); } @@ -335,8 +338,8 @@ int UtcDaliScriptingNewImageNegative(void) try { Property::Map map; - map.push_back( Property::StringValuePair( "width", 10 ) ); - map.push_back( Property::StringValuePair( "height", "Invalid" ) ); + map[ "width" ] = 10; + map[ "height" ] = "Invalid"; Image image = NewImage( map ); tet_result( TET_FAIL ); } @@ -349,7 +352,7 @@ int UtcDaliScriptingNewImageNegative(void) try { Property::Map map; - map.push_back( Property::StringValuePair( "pixel-format", Vector3::ZERO ) ); + map[ "pixel-format" ] = Vector3::ZERO; Image image = NewImage( map ); tet_result( TET_FAIL ); } @@ -361,7 +364,7 @@ int UtcDaliScriptingNewImageNegative(void) try { Property::Map map; - map.push_back( Property::StringValuePair( "pixel-format", "INVALID" ) ); + map[ "pixel-format" ] = "INVALID"; Image image = NewImage( map ); tet_result( TET_FAIL ); } @@ -375,7 +378,7 @@ int UtcDaliScriptingNewImageNegative(void) try { Property::Map map; - map.push_back( Property::StringValuePair( "scaling-mode", Vector3::ZERO ) ); + map[ "scaling-mode" ] = Vector3::ZERO; Image image = NewImage( map ); tet_result( TET_FAIL ); } @@ -387,7 +390,7 @@ int UtcDaliScriptingNewImageNegative(void) try { Property::Map map; - map.push_back( Property::StringValuePair( "scaling-mode", "INVALID" ) ); + map[ "scaling-mode" ] = "INVALID"; Image image = NewImage( map ); tet_result( TET_FAIL ); } @@ -401,7 +404,7 @@ int UtcDaliScriptingNewImageNegative(void) try { Property::Map map; - map.push_back( Property::StringValuePair( "type", Vector3::ZERO ) ); + map[ "type" ] = Vector3::ZERO; Image image = NewImage( map ); tet_result( TET_FAIL ); } @@ -413,7 +416,7 @@ int UtcDaliScriptingNewImageNegative(void) try { Property::Map map; - map.push_back( Property::StringValuePair( "type", "INVALID" ) ); + map[ "type" ] = "INVALID"; Image image = NewImage( map ); tet_result( TET_FAIL ); } @@ -433,7 +436,7 @@ int UtcDaliScriptingNewImage(void) TestApplication application; Property::Map map; - map.push_back( Property::StringValuePair( "filename", "TEST_FILE" ) ); + map[ "filename" ] = "TEST_FILE"; // Filename only { @@ -442,7 +445,7 @@ int UtcDaliScriptingNewImage(void) } // load-policy - map.push_back( Property::StringValuePair( "load-policy", "" ) ); + map[ "load-policy" ] = ""; { const StringEnum< int > values[] = { @@ -453,7 +456,7 @@ int UtcDaliScriptingNewImage(void) } // release-policy - map.push_back( Property::StringValuePair( "release-policy", "" ) ); + map[ "release-policy" ] = ""; { const StringEnum< int > values[] = { @@ -464,8 +467,8 @@ int UtcDaliScriptingNewImage(void) } // float width and height - map.push_back( Property::StringValuePair( "width", (float) 10.0f ) ); - map.push_back( Property::StringValuePair( "height", (float) 20.0f ) ); + map[ "width" ] = (float) 10.0f; + map[ "height" ] = (float) 20.0f; { Image image = NewImage( map ); DALI_TEST_EQUALS( image.GetWidth(), 10.0f, TEST_LOCATION ); @@ -473,9 +476,8 @@ int UtcDaliScriptingNewImage(void) } // int width and height - map.erase( map.end() - 2, map.end() ); - map.push_back( Property::StringValuePair( "width", 50 ) ); - map.push_back( Property::StringValuePair( "height", 70 ) ); + map[ "width"] = (int) 50; + map[ "height" ] = (int) 70; { Image image = NewImage( map ); DALI_TEST_EQUALS( image.GetWidth(), 50u, TEST_LOCATION ); @@ -485,7 +487,7 @@ int UtcDaliScriptingNewImage(void) //map.erase( map.end() - 2, map.end() ); // pixel-format - map.push_back( Property::StringValuePair( "pixel-format", "" ) ); + map[ "pixel-format" ] = ""; { const StringEnum< int > values[] = { @@ -521,7 +523,7 @@ int UtcDaliScriptingNewImage(void) } // scaling-mode - map.push_back( Property::StringValuePair( "scaling-mode", "" ) ); + map[ "scaling-mode" ] = ""; { const StringEnum< int > values[] = { @@ -534,19 +536,19 @@ int UtcDaliScriptingNewImage(void) } // type FrameBufferImage - map.push_back( Property::StringValuePair( "type", "FrameBufferImage" ) ); + map[ "type" ] = "FrameBufferImage"; { Image image = NewImage( map ); DALI_TEST_CHECK( FrameBufferImage::DownCast( image ) ); } // type BitMapImage - (map.end() - 1)->second = "BitmapImage"; + map[ "type" ] = "BitmapImage"; { Image image = NewImage( map ); DALI_TEST_CHECK( BitmapImage::DownCast( image ) ); } // type Image - (map.end() - 1)->second = "Image"; + map[ "type" ] = "Image"; { Image image = NewImage( map ); DALI_TEST_CHECK( Image::DownCast( image ) ); @@ -561,17 +563,17 @@ int UtcDaliScriptingNewShaderEffect(void) TestApplication application; Property::Map programMap; - programMap.push_back( Property::StringValuePair( "vertex-filename", "bump.vert" ) ); - programMap.push_back( Property::StringValuePair( "fragment-filename", "bump.frag" ) ); + programMap[ "vertex-filename" ] = "bump.vert"; + programMap[ "fragment-filename" ] = "bump.frag"; Property::Map imageMap; - imageMap.push_back( Property::StringValuePair( "filename", "image.png" ) ); + imageMap[ "filename" ] = "image.png"; Property::Map map; - map.push_back( Property::StringValuePair( "image", imageMap ) ); - map.push_back( Property::StringValuePair( "program", programMap ) ); - map.push_back( Property::StringValuePair( "uLightPosition", Vector3( 0.0, 0.0, -1.5) ) ); - map.push_back( Property::StringValuePair( "uAmbientLight", (int)10 ) ); + map[ "image" ] = imageMap; + map[ "program" ] = programMap; + map[ "uLightPosition" ] = Vector3( 0.0, 0.0, -1.5); + map[ "uAmbientLight" ] = (int)10; ShaderEffect shader = NewShaderEffect( map ); @@ -592,8 +594,8 @@ int UtcDaliScriptingNewActorNegative(void) // Map with only properties { Property::Map map; - map.push_back( Property::StringValuePair( "parent-origin", ParentOrigin::TOP_CENTER ) ); - map.push_back( Property::StringValuePair( "anchor-point", AnchorPoint::TOP_CENTER ) ); + map[ "parent-origin" ] = ParentOrigin::TOP_CENTER; + map[ "anchor-point" ] = AnchorPoint::TOP_CENTER; Actor handle = NewActor( map ); DALI_TEST_CHECK( !handle ); } @@ -601,8 +603,8 @@ int UtcDaliScriptingNewActorNegative(void) // Add some signals to the map, we should have no signal connections as its not yet supported { Property::Map map; - map.push_back( Property::StringValuePair( "type", "Actor" ) ); - map.push_back( Property::StringValuePair( "signals", Property::MAP ) ); + map[ "type" ] = "Actor"; + map[ "signals" ] = Property::MAP; Actor handle = NewActor( map ); DALI_TEST_CHECK( handle ); DALI_TEST_CHECK( !handle.MouseWheelEventSignal().GetConnectionCount() ); @@ -619,21 +621,21 @@ int UtcDaliScriptingNewActorProperties(void) TestApplication application; Property::Map map; - map.push_back( Property::StringValuePair( "type", "Actor" ) ); - map.push_back( Property::StringValuePair( "size", Vector3::ONE ) ); - map.push_back( Property::StringValuePair( "position", Vector3::XAXIS ) ); - map.push_back( Property::StringValuePair( "scale", Vector3::ONE ) ); - map.push_back( Property::StringValuePair( "visible", false ) ); - map.push_back( Property::StringValuePair( "color", Color::MAGENTA ) ); - map.push_back( Property::StringValuePair( "name", "MyActor" ) ); - map.push_back( Property::StringValuePair( "color-mode", "USE_PARENT_COLOR" ) ); - map.push_back( Property::StringValuePair( "inherit-shader-effect", false ) ); - map.push_back( Property::StringValuePair( "sensitive", false ) ); - map.push_back( Property::StringValuePair( "leave-required", true ) ); - map.push_back( Property::StringValuePair( "position-inheritance", "DONT_INHERIT_POSITION" ) ); - map.push_back( Property::StringValuePair( "draw-mode", "STENCIL" ) ); - map.push_back( Property::StringValuePair( "inherit-rotation", false ) ); - map.push_back( Property::StringValuePair( "inherit-scale", false ) ); + map[ "type" ] = "Actor"; + map[ "size" ] = Vector3::ONE; + map[ "position" ] = Vector3::XAXIS; + map[ "scale" ] = Vector3::ONE; + map[ "visible" ] = false; + map[ "color" ] = Color::MAGENTA; + map[ "name" ] = "MyActor"; + map[ "color-mode" ] = "USE_PARENT_COLOR"; + map[ "inherit-shader-effect" ] = false; + map[ "sensitive" ] = false; + map[ "leave-required" ] = true; + map[ "position-inheritance" ] = "DONT_INHERIT_POSITION"; + map[ "draw-mode" ] = "STENCIL"; + map[ "inherit-rotation" ] = false; + map[ "inherit-scale" ] = false; // Default properties { @@ -662,8 +664,8 @@ int UtcDaliScriptingNewActorProperties(void) } // Check Anchor point and parent origin vector3s - map.push_back( Property::StringValuePair( "parent-origin", ParentOrigin::TOP_CENTER ) ); - map.push_back( Property::StringValuePair( "anchor-point", AnchorPoint::TOP_LEFT ) ); + map[ "parent-origin" ] = ParentOrigin::TOP_CENTER; + map[ "anchor-point" ] = AnchorPoint::TOP_LEFT; { Actor handle = NewActor( map ); DALI_TEST_CHECK( handle ); @@ -679,9 +681,8 @@ int UtcDaliScriptingNewActorProperties(void) } // Check Anchor point and parent origin STRINGS - map.erase( map.end() - 2, map.end() ); // delete previously added parent origin and anchor point - map.push_back( Property::StringValuePair( "parent-origin", "BACK_TOP_LEFT" ) ); - map.push_back( Property::StringValuePair( "anchor-point", "FRONT_CENTER_LEFT" ) ); + map[ "parent-origin" ] = "BACK_TOP_LEFT"; + map[ "anchor-point" ] = "FRONT_CENTER_LEFT"; { Actor handle = NewActor( map ); DALI_TEST_CHECK( handle ); @@ -703,29 +704,29 @@ int UtcDaliScriptingNewActorChildren(void) TestApplication application; Property::Map map; - map.push_back( Property::StringValuePair( "type", "Actor" ) ); - map.push_back( Property::StringValuePair( "position", Vector3::XAXIS ) ); + map[ "type" ] = "Actor"; + map[ "position" ] = Vector3::XAXIS; Property::Map child1Map; - child1Map.push_back( Property::StringValuePair( "type", "ImageActor" ) ); - child1Map.push_back( Property::StringValuePair( "position", Vector3::YAXIS ) ); + child1Map[ "type" ] = "ImageActor"; + child1Map[ "position" ] = Vector3::YAXIS; Property::Map child2Map; - child2Map.push_back( Property::StringValuePair( "type", "TextActor" ) ); - child2Map.push_back( Property::StringValuePair( "position", Vector3::ZAXIS ) ); + child2Map[ "type" ] = "TextActor"; + child2Map[ "position" ] = Vector3::ZAXIS; Property::Map grandChildMap; - grandChildMap.push_back( Property::StringValuePair( "type", "LightActor" ) ); - grandChildMap.push_back( Property::StringValuePair( "position", Vector3::ONE ) ); + grandChildMap[ "type" ] = "LightActor"; + grandChildMap[ "position" ] = Vector3::ONE; // Add arrays to appropriate maps Property::Array grandChildArray; grandChildArray.push_back( grandChildMap ); Property::Array childArray; - child1Map.push_back( Property::StringValuePair( "actors", grandChildArray ) ); + child1Map[ "actors" ] = grandChildArray; childArray.push_back( child1Map ); childArray.push_back( child2Map ); - map.push_back( Property::StringValuePair( "actors", childArray ) ); + map[ "actors" ] = childArray; // Create Actor handle = NewActor( map ); @@ -771,7 +772,7 @@ int UtcDaliScriptingCreatePropertyMapActor(void) Property::Map map; CreatePropertyMap( actor, map ); - DALI_TEST_CHECK( !map.empty() ); + DALI_TEST_CHECK( !map.Empty() ); Property::Value value( map ); DALI_TEST_CHECK( value.HasKey( "type" ) ); DALI_TEST_EQUALS( value.GetValue( "type").Get< std::string >(), "Actor", TEST_LOCATION ); @@ -785,7 +786,7 @@ int UtcDaliScriptingCreatePropertyMapActor(void) Property::Map map; CreatePropertyMap( actor, map ); - DALI_TEST_CHECK( !map.empty() ); + DALI_TEST_CHECK( !map.Empty() ); Property::Value value( map ); DALI_TEST_CHECK( value.HasKey( "type" ) ); DALI_TEST_EQUALS( value.GetValue( "type").Get< std::string >(), "ImageActor", TEST_LOCATION ); @@ -816,7 +817,7 @@ int UtcDaliScriptingCreatePropertyMapActor(void) Property::Map map; CreatePropertyMap( actor, map ); - DALI_TEST_CHECK( !map.empty() ); + DALI_TEST_CHECK( !map.Empty() ); Property::Value value( map ); DALI_TEST_CHECK( value.HasKey( "size" ) ); DALI_TEST_EQUALS( value.GetValue( "size" ).Get< Vector3 >(), Vector3::ONE, TEST_LOCATION ); @@ -871,7 +872,7 @@ int UtcDaliScriptingCreatePropertyMapActor(void) Property::Map map; CreatePropertyMap( actor, map ); - DALI_TEST_CHECK( !map.empty() ); + DALI_TEST_CHECK( !map.Empty() ); Property::Value value( map ); DALI_TEST_CHECK( value.HasKey( "type" ) ); @@ -881,7 +882,7 @@ int UtcDaliScriptingCreatePropertyMapActor(void) Property::Array children( value.GetValue( "actors").Get< Property::Array >() ); DALI_TEST_CHECK( !children.empty() ); Property::Map childMap( children[0].Get< Property::Map >() ); - DALI_TEST_CHECK( !childMap.empty() ); + DALI_TEST_CHECK( !childMap.Empty() ); Property::Value childValue( childMap ); DALI_TEST_CHECK( childValue.HasKey( "type" ) ); DALI_TEST_EQUALS( childValue.GetValue( "type" ).Get< std::string >(), "ImageActor", TEST_LOCATION ); @@ -891,13 +892,13 @@ int UtcDaliScriptingCreatePropertyMapActor(void) DALI_TEST_CHECK( grandChildren.size() == 2u ); Property::Map grandChildMap( grandChildren[0].Get< Property::Map >() ); - DALI_TEST_CHECK( !grandChildMap.empty() ); + DALI_TEST_CHECK( !grandChildMap.Empty() ); Property::Value grandChildValue( grandChildMap ); DALI_TEST_CHECK( grandChildValue.HasKey( "type" ) ); DALI_TEST_EQUALS( grandChildValue.GetValue( "type" ).Get< std::string >(), "TextActor", TEST_LOCATION ); Property::Map grandChild2Map( grandChildren[1].Get< Property::Map >() ); - DALI_TEST_CHECK( !grandChild2Map.empty() ); + DALI_TEST_CHECK( !grandChild2Map.Empty() ); Property::Value grandChild2Value( grandChild2Map ); DALI_TEST_CHECK( grandChild2Value.HasKey( "type" ) ); DALI_TEST_EQUALS( grandChild2Value.GetValue( "type" ).Get< std::string >(), "LightActor", TEST_LOCATION ); @@ -916,7 +917,7 @@ int UtcDaliScriptingCreatePropertyMapImage(void) Image image; Property::Map map; CreatePropertyMap( image, map ); - DALI_TEST_CHECK( map.empty() ); + DALI_TEST_CHECK( map.Empty() ); } // Default @@ -925,7 +926,7 @@ int UtcDaliScriptingCreatePropertyMapImage(void) Property::Map map; CreatePropertyMap( image, map ); - DALI_TEST_CHECK( !map.empty() ); + DALI_TEST_CHECK( !map.Empty() ); Property::Value value( map ); DALI_TEST_CHECK( value.HasKey( "type" ) ); @@ -954,7 +955,7 @@ int UtcDaliScriptingCreatePropertyMapImage(void) Property::Map map; CreatePropertyMap( image, map ); - DALI_TEST_CHECK( !map.empty() ); + DALI_TEST_CHECK( !map.Empty() ); Property::Value value( map ); DALI_TEST_CHECK( value.HasKey( "type" ) ); diff --git a/automated-tests/src/dali/CMakeLists.txt b/automated-tests/src/dali/CMakeLists.txt index 7c5f402..85a0bcf 100644 --- a/automated-tests/src/dali/CMakeLists.txt +++ b/automated-tests/src/dali/CMakeLists.txt @@ -44,6 +44,7 @@ SET(TC_SOURCES utc-Dali-PinchGesture.cpp utc-Dali-PinchGestureDetector.cpp utc-Dali-Pixel.cpp + utc-Dali-PropertyMap.cpp utc-Dali-PropertyNotification.cpp utc-Dali-Quaternion.cpp utc-Dali-Radian.cpp diff --git a/automated-tests/src/dali/utc-Dali-Handle.cpp b/automated-tests/src/dali/utc-Dali-Handle.cpp index 04f7259..0eb04f3 100644 --- a/automated-tests/src/dali/utc-Dali-Handle.cpp +++ b/automated-tests/src/dali/utc-Dali-Handle.cpp @@ -954,7 +954,7 @@ int UtcDaliHandleGetPropertyGet(void) value = Property::Value(Property::MAP); value.SetValue("key", "value"); value.Get(map); - DALI_TEST_CHECK( map[0].first == "key" ); + DALI_TEST_CHECK( map.GetKey(0) == "key" ); END_TEST; } diff --git a/automated-tests/src/dali/utc-Dali-PropertyMap.cpp b/automated-tests/src/dali/utc-Dali-PropertyMap.cpp new file mode 100644 index 0000000..179e3f6 --- /dev/null +++ b/automated-tests/src/dali/utc-Dali-PropertyMap.cpp @@ -0,0 +1,258 @@ +/* + * Copyright (c) 2014 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include +#include +#include +#include + +using namespace Dali; + +void utc_dali_property_map_startup(void) +{ + test_return_value = TET_UNDEF; +} + +void utc_dali_property_map_cleanup(void) +{ + test_return_value = TET_PASS; +} + +int UtcDaliPropertyMapPopulate(void) +{ + Property::Map map; + DALI_TEST_CHECK( map.Empty() ); + + map[ "hello" ] = 1; + map[ "world" ] = "world"; + map[ "world" ] = 3; // same item as line above + DALI_TEST_CHECK( !map.Empty() ); // Should no longer be empty + DALI_TEST_CHECK( map.Count() == 2 ); // Should only have two items, not three!! + DALI_TEST_CHECK( map["hello"].Get() == 1 ); + DALI_TEST_CHECK( map["world"].Get() == 3 ); + + map.Clear(); + DALI_TEST_CHECK( map.Empty() ); + END_TEST; +} + +int UtcDaliPropertyMapCopyAndAssignment(void) +{ + Property::Map map; + map[ "hello" ] = 1; + map[ "world" ] = 2; + + Property::Map assignedMap; + assignedMap[ "foo" ] = 3; + DALI_TEST_CHECK( assignedMap.Count() == 1 ); + assignedMap = map; + DALI_TEST_CHECK( assignedMap.Count() == 2 ); + + Property::Map copiedMap( map ); + DALI_TEST_CHECK( copiedMap.Count() == 2 ); + + // Self assignment + DALI_TEST_CHECK( map.Count() == 2 ); + map = map; + DALI_TEST_CHECK( map.Count() == 2 ); + + END_TEST; +} + +int UtcDaliPropertyMapConstOperator(void) +{ + Property::Map map; + map[ "hello" ] = 1; + map[ "world" ] = 2; + DALI_TEST_CHECK( map.Count() == 2 ); + + const Property::Map& constMap( map ); + DALI_TEST_CHECK( constMap[ "world" ].Get() == 2 ); + DALI_TEST_CHECK( constMap.Count() == 2 ); // Ensure count hasn't gone up + + // Invalid Key + try + { + constMap[ "invalid-key" ]; + tet_result( TET_FAIL ); + } + catch ( DaliException& e ) + { + DALI_TEST_ASSERT( e, "! \"Invalid Key\"", TEST_LOCATION ); + } + + END_TEST; +} + +int UtcDaliPropertyMapGetValue(void) +{ + Property::Map map; + map[ "hello" ] = 1; + map[ "world" ] = 2; + + Property::Value& value = map.GetValue( 0 ); + DALI_TEST_CHECK( value.Get() == 1 ); + value = 10; // Allows the actual changing of the value as we have a ref + DALI_TEST_CHECK( map[ "hello" ].Get() == 10 ); + + // Out of bounds + try + { + map.GetValue( 2 ); + tet_result( TET_FAIL ); + } + catch ( DaliException& e ) + { + DALI_TEST_ASSERT( e, "position", TEST_LOCATION ); + } + + END_TEST; +} + +int UtcDaliPropertyMapGetKey(void) +{ + Property::Map map; + map[ "hello" ] = 1; + map[ "world" ] = 2; + + DALI_TEST_CHECK( map.GetKey( 0 ) == "hello" ); + DALI_TEST_CHECK( map.GetKey( 1 ) == "world" ); + + // Out of bounds + try + { + map.GetKey( 2 ); + tet_result( TET_FAIL ); + } + catch ( DaliException& e ) + { + DALI_TEST_ASSERT( e, "position", TEST_LOCATION ); + } + + END_TEST; +} + +int UtcDaliPropertyMapGetPair(void) +{ + Property::Map map; + map[ "hello" ] = 1; + map[ "world" ] = 2; + + DALI_TEST_CHECK( map.GetPair( 0 ).first == "hello" ); + DALI_TEST_CHECK( map.GetPair( 0 ).second.Get< int >() == 1 ); + DALI_TEST_CHECK( map.GetPair( 1 ).first == "world" ); + DALI_TEST_CHECK( map.GetPair( 1 ).second.Get< int >() == 2 ); + + // Out of bounds + try + { + map.GetPair( 2 ); + tet_result( TET_FAIL ); + } + catch ( DaliException& e ) + { + DALI_TEST_ASSERT( e, "position", TEST_LOCATION ); + } + + END_TEST; +} + +int UtcDaliPropertyMapFind(void) +{ + Property::Map map; + map[ "hello" ] = 1; + map[ "world" ] = 2; + + Property::Value* value = NULL; + + value = map.Find( "hello" ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == 1 ); + + value = map.Find( "world" ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == 2 ); + + value = map.Find( "invalid-key" ); + DALI_TEST_CHECK( !value ); + + END_TEST; +} + +int UtcDaliPropertyMapMerge(void) +{ + Property::Map map; + map[ "hello" ] = 1; + map[ "world" ] = 2; + + DALI_TEST_CHECK( map.Count() == 2 ); + + // Create another map with the same keys but different values + Property::Map map2; + map[ "hello" ] = 3; + map[ "world" ] = 4; + + // Merge map2 into map1, count should still be 2, map values should be from map2 + map.Merge( map2 ); + DALI_TEST_CHECK( map.Count() == 2 ); + DALI_TEST_CHECK( map[ "hello" ].Get< int >() == 3 ); + DALI_TEST_CHECK( map[ "world"].Get< int >() == 4 ); + + // Create another map with different keys + Property::Map map3; + map3[ "foo" ] = 5; + map3[ "bar" ] = 6; + + // Merge map3 into map1, count should increase, existing values should match previous and new values should match map3 + map.Merge( map3 ); + DALI_TEST_CHECK( map.Count() == 4 ); + DALI_TEST_CHECK( map[ "hello" ].Get< int >() == 3 ); + DALI_TEST_CHECK( map[ "world"].Get< int >() == 4 ); + DALI_TEST_CHECK( map[ "foo"].Get< int >() == 5 ); + DALI_TEST_CHECK( map[ "bar"].Get< int >() == 6 ); + + // Create an empty map and attempt to merge, should be successful, nothing should change + Property::Map map4; + DALI_TEST_CHECK( map4.Empty() ); + map.Merge( map4 ); + DALI_TEST_CHECK( map4.Empty() ); + DALI_TEST_CHECK( map.Count() == 4 ); + DALI_TEST_CHECK( map[ "hello" ].Get< int >() == 3 ); + DALI_TEST_CHECK( map[ "world"].Get< int >() == 4 ); + DALI_TEST_CHECK( map[ "foo"].Get< int >() == 5 ); + DALI_TEST_CHECK( map[ "bar"].Get< int >() == 6 ); + + // Merge map into map4, map4 should be the same as map now. + map4.Merge( map ); + DALI_TEST_CHECK( map4.Count() == 4 ); + DALI_TEST_CHECK( map4[ "hello" ].Get< int >() == 3 ); + DALI_TEST_CHECK( map4[ "world"].Get< int >() == 4 ); + DALI_TEST_CHECK( map4[ "foo"].Get< int >() == 5 ); + DALI_TEST_CHECK( map4[ "bar"].Get< int >() == 6 ); + + // Attempt to merge into itself, should be successful, nothing should change + map.Merge( map ); + DALI_TEST_CHECK( map.Count() == 4 ); + DALI_TEST_CHECK( map[ "hello" ].Get< int >() == 3 ); + DALI_TEST_CHECK( map[ "world"].Get< int >() == 4 ); + DALI_TEST_CHECK( map[ "foo"].Get< int >() == 5 ); + DALI_TEST_CHECK( map[ "bar"].Get< int >() == 6 ); + + END_TEST; +} diff --git a/dali/public-api/dali-core.h b/dali/public-api/dali-core.h index 3fdd352..23b1912 100644 --- a/dali/public-api/dali-core.h +++ b/dali/public-api/dali-core.h @@ -130,6 +130,7 @@ #include #include #include +#include #include #include #include diff --git a/dali/public-api/file.list b/dali/public-api/file.list index 45d0040..aecf4b7 100644 --- a/dali/public-api/file.list +++ b/dali/public-api/file.list @@ -93,6 +93,7 @@ public_api_src_files = \ $(public_api_src_dir)/object/property.cpp \ $(public_api_src_dir)/object/property-conditions.cpp \ $(public_api_src_dir)/object/property-input.cpp \ + $(public_api_src_dir)/object/property-map.cpp \ $(public_api_src_dir)/object/property-notification.cpp \ $(public_api_src_dir)/object/property-types.cpp \ $(public_api_src_dir)/object/property-value.cpp \ @@ -254,6 +255,7 @@ public_api_core_object_header_files = \ $(public_api_src_dir)/object/property-conditions.h \ $(public_api_src_dir)/object/property-index.h \ $(public_api_src_dir)/object/property-input.h \ + $(public_api_src_dir)/object/property-map.h \ $(public_api_src_dir)/object/property-notification-declarations.h \ $(public_api_src_dir)/object/property-notification.h \ $(public_api_src_dir)/object/property-types.h \ diff --git a/dali/public-api/object/property-map.cpp b/dali/public-api/object/property-map.cpp new file mode 100644 index 0000000..5c70cbf --- /dev/null +++ b/dali/public-api/object/property-map.cpp @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2014 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// CLASS HEADER +#include + +// EXTERNAL INCLUDES +#include + +// INTERNAL INCLUDES +#include +#include + +namespace Dali +{ + +namespace +{ +typedef std::vector< Property::StringValuePair > Container; +}; // unnamed namespace + +struct Property::Map::Impl +{ + Container mContainer; +}; + +Property::Map::Map() +: mImpl( new Impl ) +{ +} + +Property::Map::Map( const Property::Map& other ) +: mImpl( new Impl ) +{ + mImpl->mContainer = other.mImpl->mContainer; +} + +Property::Map::~Map() +{ + delete mImpl; +} + +unsigned int Property::Map::Count() const +{ + return mImpl->mContainer.size(); +} + +bool Property::Map::Empty() const +{ + return mImpl->mContainer.empty(); +} + +Property::Value& Property::Map::GetValue( unsigned int position ) const +{ + DALI_ASSERT_ALWAYS( position < Count() && "position out-of-bounds" ); + + return mImpl->mContainer[ position ].second; +} + +const std::string& Property::Map::GetKey( unsigned int position ) const +{ + DALI_ASSERT_ALWAYS( position < Count() && "position out-of-bounds" ); + + return mImpl->mContainer[ position ].first; +} + +Property::StringValuePair& Property::Map::GetPair( unsigned int position ) const +{ + DALI_ASSERT_ALWAYS( position < Count() && "position out-of-bounds" ); + + return mImpl->mContainer[ position ]; +} + +Property::Value* Property::Map::Find( const std::string& key ) const +{ + for ( Container::iterator iter = mImpl->mContainer.begin(), endIter = mImpl->mContainer.end(); iter != endIter; ++iter ) + { + if ( iter->first == key ) + { + return &iter->second; + } + } + return NULL; // Not found +} + +void Property::Map::Clear() +{ + mImpl->mContainer.clear(); +} + +void Property::Map::Merge( const Property::Map& from ) +{ + // Ensure we're not attempting to merge with ourself + if ( this != &from ) + { + if ( Count() ) + { + for ( unsigned int i = 0, count = from.Count(); i < count; ++i ) + { + StringValuePair& pair( from.GetPair( i ) ); + (*this)[ pair.first ] = pair.second; + } + } + else + { + // If we're empty, then just copy + *this = from; + } + } +} + +const Property::Value& Property::Map::operator[]( const std::string& key ) const +{ + for ( Container::const_iterator iter = mImpl->mContainer.begin(), endIter = mImpl->mContainer.end(); iter != endIter; ++iter ) + { + if ( iter->first == key ) + { + return iter->second; + } + } + + DALI_ASSERT_ALWAYS( ! "Invalid Key" ); + + // Should not reach here + static Value value; + return value; +} + +Property::Value& Property::Map::operator[]( const std::string& key ) +{ + for ( Container::iterator iter = mImpl->mContainer.begin(), endIter = mImpl->mContainer.end(); iter != endIter; ++iter ) + { + if ( iter->first == key ) + { + return iter->second; + } + } + + // Create and return reference to new value + mImpl->mContainer.push_back( StringValuePair( key, Value() ) ); + return (mImpl->mContainer.end() - 1)->second; +} + +Property::Map& Property::Map::operator=( const Property::Map& other ) +{ + if( this != &other ) + { + delete mImpl; + mImpl = new Impl; + mImpl->mContainer = other.mImpl->mContainer; + } + return *this; +} + +} // namespace Dali diff --git a/dali/public-api/object/property-map.h b/dali/public-api/object/property-map.h new file mode 100644 index 0000000..95592f3 --- /dev/null +++ b/dali/public-api/object/property-map.h @@ -0,0 +1,158 @@ +#ifndef __DALI_PROPERTY_MAP_H__ +#define __DALI_PROPERTY_MAP_H__ + +/* + * Copyright (c) 2014 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// EXTERNAL INCLUDES +#include + +// INTERNAL INCLUDES +#include +#include +#include + +namespace Dali +{ + +/** + * @brief A Map of property values. + */ +class DALI_IMPORT_API Property::Map +{ +public: + + /** + * @brief Default constructor. + */ + Map(); + + /** + * @brief Copy Constructor. + * + * @param[in] other The Map to copy from. + */ + Map( const Map& other ); + + /** + * @brief Non-virtual destructor. + */ + ~Map(); + + /** + * @brief Retrieve the number of elements in the map. + * + * @return The number of elements in the map. + */ + unsigned int Count() const; + + /** + * @brief Returns whether the map is empty. + * + * @return true if empty, false otherwise + */ + bool Empty() const; + + /** + * @brief Retrieve the value at the specified position. + * + * @return A reference to the value at the specified position. + * + * @note Will assert if position >= Count() + */ + Value& GetValue( unsigned int position ) const; + + /** + * @brief Retrieve the key at the specified position. + * + * @return A const reference to the key at the specified position. + * + * @note Will assert if position >= Count() + */ + const std::string& GetKey( unsigned int position ) const; + + /** + * @brief Retrieve the key & the value at the specified position. + * + * @return A reference to the pair of key and value at the specified position. + * + * @note Will assert if position >= Count() + */ + StringValuePair& GetPair( unsigned int position ) const; + + /** + * @brief Finds the value for the specified key if it exists. + * + * @param[in] key The key to find. + * + * @return A const pointer to the value if it exists, NULL otherwise + */ + Value* Find( const std::string& key ) const; + + /** + * @brief Clears the map. + */ + void Clear(); + + /** + * @brief Merges values from the map 'from' to the current. + * + * Any values in 'from' will overwrite the values in the current map. + * + * @param[in] from The map to merge from. + */ + void Merge( const Map& from ); + + /** + * @brief Const operator to access element with the specified key. + * + * @param[in] key The key whose value to access. + * + * @return The value for the element with the specified key, if key doesn't exist, then Property::NONE is returned. + * + * @note Will assert if invalid-key is given. + */ + const Value& operator[]( const std::string& key ) const; + + /** + * @brief Operator to access the element with the specified key. + * + * @param[in] key The key whose value to access. + * + * @return A reference to the value for the element with the specified key. + * + * @note If an element with the key does not exist, then it is created. + */ + Value& operator[]( const std::string& key ); + + /** + * @brief Assignment Operator + * + * @param[in] other The map to copy from. + * + * @return The copied map. + */ + Map& operator=( const Map& other ); + +private: + struct DALI_INTERNAL Impl; ///< Private data + Impl* mImpl; ///< Pointer to private data +}; + +} // namespace Dali + +#endif // __DALI_PROPERTY_MAP_H__ diff --git a/dali/public-api/object/property-value.cpp b/dali/public-api/object/property-value.cpp index d03b012..1141062 100644 --- a/dali/public-api/object/property-value.cpp +++ b/dali/public-api/object/property-value.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -688,12 +689,10 @@ Property::Value& Property::Value::GetValue(const std::string& key) const if(container) { - for(Property::Map::iterator iter = container->begin(); iter != container->end(); ++iter) + Property::Value* value = container->Find( key ); + if ( value ) { - if(iter->first == key) - { - return iter->second; - } + return *value; } } @@ -717,12 +716,10 @@ bool Property::Value::HasKey(const std::string& key) const if(container) { - for(Property::Map::iterator iter = container->begin(); iter != container->end(); ++iter) + Property::Value* value = container->Find( key ); + if ( value ) { - if(iter->first == key) - { - has = true; - } + has = true; } } } @@ -737,20 +734,13 @@ const std::string& Property::Value::GetKey(const int index) const { case Property::MAP: { - int i = 0; Property::Map *container = AnyCast(&(mImpl->mValue)); DALI_ASSERT_DEBUG(container && "Property::Map has no container?"); if(container) { - if(0 <= index && index < static_cast(container->size())) + if(0 <= index && index < static_cast(container->Count())) { - for(Property::Map::iterator iter = container->begin(); iter != container->end(); ++iter) - { - if(i++ == index) - { - return iter->first; - } - } + return container->GetKey( index ); } } } @@ -790,18 +780,7 @@ void Property::Value::SetValue(const std::string& key, const Property::Value &va if(container) { - for(Property::Map::iterator iter = container->begin(); iter != container->end(); ++iter) - { - if(iter->first == key) - { - iter->second = value; - return; - } - } - - // if we get here its a new key - container->push_back(Property::StringValuePair(key, value)); - + (*container)[ key ] = value; } } @@ -811,22 +790,15 @@ Property::Value& Property::Value::GetItem(const int index) const { case Property::MAP: { - int i = 0; Property::Map *container = AnyCast(&(mImpl->mValue)); DALI_ASSERT_DEBUG(container && "Property::Map has no container?"); if(container) { - DALI_ASSERT_ALWAYS(index < static_cast(container->size()) && "Property array index invalid"); + DALI_ASSERT_ALWAYS(index < static_cast(container->Count()) && "Property array index invalid"); DALI_ASSERT_ALWAYS(index >= 0 && "Property array index invalid"); - for(Property::Map::iterator iter = container->begin(); iter != container->end(); ++iter) - { - if(i++ == index) - { - return iter->second; - } - } + return container->GetValue( index ); } } break; @@ -889,10 +861,9 @@ Property::Value& Property::Value::GetItem(const int index, std::string& key) con if( Property::MAP == GetType() ) { Property::Map *container = AnyCast(&(mImpl->mValue)); - if( index < static_cast(container->size()) ) + if( index < static_cast(container->Count()) ) { - - key = (*container)[ index ].first; + key = container->GetKey( index ); } } @@ -906,17 +877,10 @@ void Property::Value::SetItem(const int index, const Property::Value &value) case Property::MAP: { Property::Map *container = AnyCast(&(mImpl->mValue)); - if( container && index < static_cast(container->size()) ) + if( container && index < static_cast(container->Count()) ) { - int i = 0; - for(Property::Map::iterator iter = container->begin(); iter != container->end(); ++iter) - { - if(i++ == index) - { - iter->second = value; - break; - } - } + Property::Value& indexValue = container->GetValue( index ); + indexValue = value; } } break; @@ -981,7 +945,7 @@ int Property::Value::GetSize() const Property::Map *container = AnyCast(&(mImpl->mValue)); if(container) { - ret = container->size(); + ret = container->Count(); } } break; diff --git a/dali/public-api/object/property-value.h b/dali/public-api/object/property-value.h index 368b5af..ed6b0c5 100644 --- a/dali/public-api/object/property-value.h +++ b/dali/public-api/object/property-value.h @@ -22,7 +22,7 @@ #include #include -namespace Dali DALI_IMPORT_API +namespace Dali { struct AngleAxis; @@ -43,14 +43,14 @@ typedef PropertyValueContainer::const_iterator PropertyValueConstIter; ///< Cons /** * @brief A value-type representing a property value. */ -class Property::Value +class DALI_IMPORT_API Property::Value { public: /** * @brief Default constructor. * - * This creates a property with type Property::INVALID. + * This creates a property with type Property::NONE. */ Value(); @@ -207,7 +207,7 @@ public: * @return A value of type T. */ template - T Get() const + T DALI_INTERNAL Get() const { T temp; Get(temp); @@ -420,7 +420,7 @@ public: private: - struct Impl; + struct DALI_INTERNAL Impl; Impl* mImpl; ///< Pointer to the implementation }; diff --git a/dali/public-api/object/property.h b/dali/public-api/object/property.h index 7480409..f7d562c 100644 --- a/dali/public-api/object/property.h +++ b/dali/public-api/object/property.h @@ -59,7 +59,7 @@ struct Property /** * @brief A Map of property values. */ - typedef std::vector Map; + class Map; /** * @brief An Array of property values. diff --git a/dali/public-api/scripting/scripting.cpp b/dali/public-api/scripting/scripting.cpp index 59628a5..b9a2a07 100644 --- a/dali/public-api/scripting/scripting.cpp +++ b/dali/public-api/scripting/scripting.cpp @@ -419,20 +419,14 @@ Actor NewActor( const Property::Map& map ) { BaseHandle handle; - const Property::Map::const_iterator endIter = map.end(); - // First find type and create Actor - Property::Map::const_iterator typeIter = map.begin(); - for (; typeIter != endIter; ++typeIter ) + Property::Value* typeValue = map.Find( "type" ); + if ( typeValue ) { - if ( typeIter->first == "type" ) + TypeInfo type = TypeRegistry::Get().GetTypeInfo( typeValue->Get< std::string >() ); + if ( type ) { - TypeInfo type = TypeRegistry::Get().GetTypeInfo( typeIter->second.Get< std::string >() ); - if ( type ) - { - handle = type.CreateInstance(); - } - break; + handle = type.CreateInstance(); } } @@ -447,62 +441,66 @@ Actor NewActor( const Property::Map& map ) if ( actor ) { // Now set the properties, or create children - for ( Property::Map::const_iterator iter = map.begin(); iter != endIter; ++iter ) + for ( unsigned int i = 0, mapCount = map.Count(); i < mapCount; ++i ) { - if ( iter == typeIter ) + const Property::StringValuePair& pair( map.GetPair( i ) ); + const std::string& key( pair.first ); + if ( key == "type" ) { continue; } - if ( iter->first == "actors" ) + const Property::Value& value( pair.second ); + + if ( key == "actors" ) { // Create children - Property::Array actorArray = iter->second.Get< Property::Array >(); + Property::Array actorArray = value.Get< Property::Array >(); for ( Property::Array::iterator arrayIter = actorArray.begin(), arrayEndIter = actorArray.end(); arrayIter != arrayEndIter; ++arrayIter ) { actor.Add( NewActor( arrayIter->Get< Property::Map >() ) ); } } - else if ( iter->first == "signals" ) + else if ( key == "signals" ) { DALI_LOG_ERROR( "signals not supported" ); } - else if( iter->first == "parent-origin" ) + else if( key == "parent-origin" ) { // Parent Origin can be a string constant as well as a Vector3 - const Property::Type type( iter->second.GetType() ); + const Property::Type type( value.GetType() ); if ( type == Property::VECTOR3 ) { - actor.SetParentOrigin( iter->second.Get< Vector3 >() ); + actor.SetParentOrigin( value.Get< Vector3 >() ); } else if( type == Property::STRING ) { - actor.SetParentOrigin( GetAnchorConstant( iter->second.Get< std::string >() ) ); + actor.SetParentOrigin( GetAnchorConstant( value.Get< std::string >() ) ); } } - else if( iter->first == "anchor-point" ) + else if( key == "anchor-point" ) { // Anchor Point can be a string constant as well as a Vector3 - const Property::Type type( iter->second.GetType() ); + const Property::Type type( value.GetType() ); if ( type == Property::VECTOR3 ) { - actor.SetAnchorPoint( iter->second.Get< Vector3 >() ); + actor.SetAnchorPoint( value.Get< Vector3 >() ); } else if( type == Property::STRING ) { - actor.SetAnchorPoint( GetAnchorConstant( iter->second.Get< std::string >() ) ); + actor.SetAnchorPoint( GetAnchorConstant( value.Get< std::string >() ) ); } } else { - Property::Index index( actor.GetPropertyIndex( iter->first ) ); + Property::Index index( actor.GetPropertyIndex( key ) ); if ( index != Property::INVALID_INDEX ) { - actor.SetProperty( index, iter->second ); + actor.SetProperty( index, value ); } } } @@ -513,11 +511,11 @@ Actor NewActor( const Property::Map& map ) void CreatePropertyMap( Actor actor, Property::Map& map ) { - map.clear(); + map.Clear(); if ( actor ) { - map.push_back( Property::StringValuePair( "type", actor.GetTypeName() ) ); + map[ "type" ] = actor.GetTypeName(); // Default properties Property::IndexContainer indices; @@ -525,7 +523,7 @@ void CreatePropertyMap( Actor actor, Property::Map& map ) const Property::IndexContainer::const_iterator endIter = indices.end(); for ( Property::IndexContainer::iterator iter = indices.begin(); iter != endIter; ++iter ) { - map.push_back( Property::StringValuePair( actor.GetPropertyName( *iter ), actor.GetProperty( *iter ) ) ); + map[ actor.GetPropertyName( *iter ) ] = actor.GetProperty( *iter ); } // Children @@ -539,14 +537,14 @@ void CreatePropertyMap( Actor actor, Property::Map& map ) CreatePropertyMap( actor.GetChildAt( child ), childMap ); childArray.push_back( childMap ); } - map.push_back( Property::StringValuePair( "actors", childArray ) ); + map[ "actors" ] = childArray; } } } void CreatePropertyMap( Image image, Property::Map& map ) { - map.clear(); + map.Clear(); if ( image ) { @@ -562,22 +560,22 @@ void CreatePropertyMap( Image image, Property::Map& map ) imageType = "FrameBufferImage"; } - map.push_back( Property::StringValuePair( "type", imageType ) ); - map.push_back( Property::StringValuePair( "filename", image.GetFilename() ) ); - map.push_back( Property::StringValuePair( "load-policy", GetEnumerationName< Image::LoadPolicy >( image.GetLoadPolicy(), IMAGE_LOAD_POLICY_TABLE, IMAGE_LOAD_POLICY_TABLE_COUNT ) ) ); - map.push_back( Property::StringValuePair( "release-policy", GetEnumerationName< Image::ReleasePolicy >( image.GetReleasePolicy(), IMAGE_RELEASE_POLICY_TABLE, IMAGE_RELEASE_POLICY_TABLE_COUNT ) ) ); + map[ "type" ] = imageType; + map[ "filename" ] = image.GetFilename(); + map[ "load-policy" ] = GetEnumerationName< Image::LoadPolicy >( image.GetLoadPolicy(), IMAGE_LOAD_POLICY_TABLE, IMAGE_LOAD_POLICY_TABLE_COUNT ); + map[ "release-policy" ] = GetEnumerationName< Image::ReleasePolicy >( image.GetReleasePolicy(), IMAGE_RELEASE_POLICY_TABLE, IMAGE_RELEASE_POLICY_TABLE_COUNT ); ImageAttributes attributes( image.GetAttributes() ); - map.push_back( Property::StringValuePair( "pixel-format", GetEnumerationName< Pixel::Format >( attributes.GetPixelFormat(), PIXEL_FORMAT_TABLE, PIXEL_FORMAT_TABLE_COUNT ) ) ); - map.push_back( Property::StringValuePair( "scaling-mode", GetEnumerationName< ImageAttributes::ScalingMode >( attributes.GetScalingMode(), IMAGE_SCALING_MODE_TABLE, IMAGE_SCALING_MODE_TABLE_COUNT ) ) ); + map[ "pixel-format" ] = GetEnumerationName< Pixel::Format >( attributes.GetPixelFormat(), PIXEL_FORMAT_TABLE, PIXEL_FORMAT_TABLE_COUNT ); + map[ "scaling-mode" ] = GetEnumerationName< ImageAttributes::ScalingMode >( attributes.GetScalingMode(), IMAGE_SCALING_MODE_TABLE, IMAGE_SCALING_MODE_TABLE_COUNT ); int width( image.GetWidth() ); int height( image.GetHeight() ); if ( width && height ) { - map.push_back( Property::StringValuePair( "width", width ) ); - map.push_back( Property::StringValuePair( "height", height ) ); + map[ "width" ] = width; + map[ "height" ] = height; } } } diff --git a/dali/public-api/scripting/scripting.h b/dali/public-api/scripting/scripting.h index df9910c..ed11bf1 100644 --- a/dali/public-api/scripting/scripting.h +++ b/dali/public-api/scripting/scripting.h @@ -23,6 +23,7 @@ #include #include #include +#include #include namespace Dali DALI_IMPORT_API -- 2.7.4