From: Kimmo Hoikka Date: Fri, 12 Jun 2015 19:09:23 +0000 (+0100) Subject: Remove dali-any from Property::Value - reimplement multivalue using more efficient... X-Git-Tag: accepted/tizen/mobile/20150623.070517~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;ds=sidebyside;h=965cb6a5f633173bf5afdaf9e8c7481b33e8f4e4;p=platform%2Fcore%2Fuifw%2Fdali-core.git Remove dali-any from Property::Value - reimplement multivalue using more efficient union inside value - remove unnecessary asserts when types dont match - cleanup and sanitize scripting - remove unnecessary templates from GetEnum, added error handling Change-Id: Ifb4031a8a5bdd8887f3025d8950d6526cb5fab57 --- diff --git a/automated-tests/src/dali-devel/utc-Dali-Scripting.cpp b/automated-tests/src/dali-devel/utc-Dali-Scripting.cpp index 682f5ca..60f90d3 100644 --- a/automated-tests/src/dali-devel/utc-Dali-Scripting.cpp +++ b/automated-tests/src/dali-devel/utc-Dali-Scripting.cpp @@ -28,7 +28,7 @@ using namespace Dali::Scripting; namespace { -const StringEnum< int > COLOR_MODE_VALUES[] = +const StringEnum COLOR_MODE_VALUES[] = { { "USE_OWN_COLOR", USE_OWN_COLOR }, { "USE_PARENT_COLOR", USE_PARENT_COLOR }, @@ -37,7 +37,7 @@ const StringEnum< int > COLOR_MODE_VALUES[] = }; const unsigned int COLOR_MODE_VALUES_COUNT = sizeof( COLOR_MODE_VALUES ) / sizeof( COLOR_MODE_VALUES[0] ); -const StringEnum< int > POSITION_INHERITANCE_MODE_VALUES[] = +const StringEnum POSITION_INHERITANCE_MODE_VALUES[] = { { "INHERIT_PARENT_POSITION", INHERIT_PARENT_POSITION }, { "USE_PARENT_POSITION", USE_PARENT_POSITION }, @@ -46,7 +46,7 @@ const StringEnum< int > POSITION_INHERITANCE_MODE_VALUES[] = }; const unsigned int POSITION_INHERITANCE_MODE_VALUES_COUNT = sizeof( POSITION_INHERITANCE_MODE_VALUES ) / sizeof( POSITION_INHERITANCE_MODE_VALUES[0] ); -const StringEnum< int > DRAW_MODE_VALUES[] = +const StringEnum DRAW_MODE_VALUES[] = { { "NORMAL", DrawMode::NORMAL }, { "OVERLAY", DrawMode::OVERLAY }, @@ -65,20 +65,19 @@ const unsigned int DRAW_MODE_VALUES_COUNT = sizeof( DRAW_MODE_VALUES ) / sizeof( template< typename T, typename X > void TestEnumStrings( Property::Map& map, // The map used to create instance of type X - const StringEnum< int >* values, // An array of string values + const char * const keyName, // the name of the key to iterate through + const StringEnum* values, // An array of string values unsigned int num, // Number of items in the array T ( X::*method )() const, // The member method of X to call to get the enum X ( *creator ) ( const Property::Value& ) // The method which creates an instance of type X ) { - const unsigned int lastIndex( map.Count() - 1 ); - const std::string& key = map.GetKey( lastIndex ); - Property::Value& value = map.GetValue( lastIndex ); - + // get the key reference so we can change its value + Property::Value* value = map.Find( keyName ); for ( unsigned int i = 0; i < num; ++i ) { - value = values[i].string; - tet_printf("Checking: %s: %s\n", key.c_str(), values[i].string ); + *value = values[i].string; + tet_printf("Checking: %s: %s\n", keyName, values[i].string ); X instance = creator( map ); DALI_TEST_EQUALS( values[i].value, ( instance.*method )(), TEST_LOCATION ); } @@ -109,7 +108,7 @@ template< typename T > void TestEnumStrings( const char * const keyName, // The name of the key to check TestApplication& application, // Reference to the application class - const StringEnum< int >* values, // An array of string values + const StringEnum* values, // An array of string values unsigned int num, // Number of items in the array void ( Actor::*method )( T ) // The Actor member method to set the enumeration ) @@ -128,10 +127,9 @@ void TestEnumStrings( Property::Map map; CreatePropertyMap( actor, map ); - 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 ); + DALI_TEST_CHECK( 0 < map.Count() ); + DALI_TEST_CHECK( NULL != map.Find( keyName ) ); + DALI_TEST_EQUALS( map.Find( keyName )->Get< std::string >(), values[i].string, TEST_LOCATION ); Stage::GetCurrent().Remove( actor ); } @@ -146,8 +144,6 @@ void TestEnumStrings( int UtcDaliScriptingGetColorMode(void) { - TestApplication application; - for ( unsigned int i = 0; i < COLOR_MODE_VALUES_COUNT; ++i ) { tet_printf( "Checking %s == %d\n", COLOR_MODE_VALUES[i].string, COLOR_MODE_VALUES[i].value ); @@ -155,22 +151,12 @@ int UtcDaliScriptingGetColorMode(void) DALI_TEST_EQUALS( COLOR_MODE_VALUES[i].string, GetColorMode( (ColorMode) COLOR_MODE_VALUES[i].value ), TEST_LOCATION ); } - try - { - (void)GetColorMode("INVALID_ARG"); - tet_result( TET_FAIL ); - } - catch ( DaliException& e ) - { - DALI_TEST_ASSERT( e, "!\"Unknown", TEST_LOCATION ); - } + DALI_TEST_EQUALS( USE_OWN_MULTIPLY_PARENT_ALPHA, GetColorMode("INVALID_ARG"), TEST_LOCATION ); END_TEST; } int UtcDaliScriptingGetPositionInheritanceMode(void) { - TestApplication application; - for ( unsigned int i = 0; i < POSITION_INHERITANCE_MODE_VALUES_COUNT; ++i ) { tet_printf( "Checking %s == %d\n", POSITION_INHERITANCE_MODE_VALUES[i].string, POSITION_INHERITANCE_MODE_VALUES[i].value ); @@ -178,23 +164,13 @@ int UtcDaliScriptingGetPositionInheritanceMode(void) DALI_TEST_EQUALS( POSITION_INHERITANCE_MODE_VALUES[i].string, GetPositionInheritanceMode( (PositionInheritanceMode) POSITION_INHERITANCE_MODE_VALUES[i].value ), TEST_LOCATION ); } - try - { - (void)GetPositionInheritanceMode("INVALID_ARG"); - tet_result( TET_FAIL ); - } - catch ( DaliException& e ) - { - DALI_TEST_ASSERT( e, "!\"Unknown", TEST_LOCATION ); - } + DALI_TEST_EQUALS( POSITION_INHERITANCE_MODE_VALUES[0].value, GetPositionInheritanceMode("INVALID_ARG"), TEST_LOCATION ); END_TEST; } int UtcDaliScriptingGetDrawMode(void) { - TestApplication application; - for ( unsigned int i = 0; i < DRAW_MODE_VALUES_COUNT; ++i ) { tet_printf( "Checking %s == %d\n", DRAW_MODE_VALUES[i].string, DRAW_MODE_VALUES[i].value ); @@ -202,22 +178,13 @@ int UtcDaliScriptingGetDrawMode(void) DALI_TEST_EQUALS( DRAW_MODE_VALUES[i].string, GetDrawMode( (DrawMode::Type) DRAW_MODE_VALUES[i].value ), TEST_LOCATION ); } - try - { - (void)GetDrawMode("INVALID_ARG"); - tet_result( TET_FAIL ); - } - catch ( DaliException& e ) - { - DALI_TEST_ASSERT( e, "!\"Unknown", TEST_LOCATION ); - } + DALI_TEST_EQUALS( DRAW_MODE_VALUES[0].value, GetDrawMode( "INVALID_ARG" ), TEST_LOCATION ); + END_TEST; } int UtcDaliScriptingGetAnchorConstant(void) { - TestApplication application; - DALI_TEST_EQUALS( Dali::ParentOrigin::TOP_LEFT, GetAnchorConstant( "TOP_LEFT" ), TEST_LOCATION ); DALI_TEST_EQUALS( Dali::ParentOrigin::TOP_CENTER, GetAnchorConstant( "TOP_CENTER" ), TEST_LOCATION ); DALI_TEST_EQUALS( Dali::ParentOrigin::TOP_RIGHT, GetAnchorConstant( "TOP_RIGHT" ), TEST_LOCATION ); @@ -228,344 +195,383 @@ int UtcDaliScriptingGetAnchorConstant(void) DALI_TEST_EQUALS( Dali::ParentOrigin::BOTTOM_CENTER, GetAnchorConstant( "BOTTOM_CENTER" ), TEST_LOCATION ); DALI_TEST_EQUALS( Dali::ParentOrigin::BOTTOM_RIGHT, GetAnchorConstant( "BOTTOM_RIGHT" ), TEST_LOCATION ); - try - { - (void)GetAnchorConstant("INVALID_ARG"); - tet_result( TET_FAIL ); - } - catch ( DaliException& e ) - { - DALI_TEST_ASSERT( e, "!\"Unknown", TEST_LOCATION ); - } + DALI_TEST_EQUALS( Vector3(), GetAnchorConstant("INVALID_ARG"), TEST_LOCATION ); END_TEST; } -int UtcDaliScriptingNewImageNegative(void) +int UtcDaliScriptingNewImageNegative01(void) { - TestApplication application; - // Invalid filename - try - { - Property::Map map; - map[ "filename" ] = Vector3::ZERO; - Image image = NewImage( map ); - tet_result( TET_FAIL ); - } - catch ( DaliException& e ) - { - DALI_TEST_ASSERT( e, "map.GetValue(field).GetType()", TEST_LOCATION ); - } + Property::Map map; + map[ "filename" ] = Vector3::ZERO; + // will give us an empty image handle + Image image = NewImage( map ); + DALI_TEST_CHECK( !image ); + END_TEST; +} - // Invalid load-policy - try - { - Property::Map map; - map[ "load-policy" ] = Vector3::ZERO; - Image image = NewImage( map ); - tet_result( TET_FAIL ); - } - catch ( DaliException& e ) - { - DALI_TEST_ASSERT( e, "map.GetValue(field).GetType()", TEST_LOCATION ); - - // Invalid value - try - { - Property::Map map; - map[ "load-policy" ] = "INVALID"; - Image image = NewImage( map ); - tet_result( TET_FAIL ); - } - catch ( DaliException& e ) - { - DALI_TEST_ASSERT( e, "!\"Unknown", TEST_LOCATION ); - } - } +int UtcDaliScriptingNewImageNegative02(void) +{ + TestApplication application; // Image needs application + // Invalid load-policy value type + Property::Map map; + map[ "filename" ] = "TEST_FILE"; + map[ "load-policy" ] = Vector3::ZERO; + // will give us a valid image handle with default load policy + Image image = NewImage( map ); + DALI_TEST_CHECK( image ); + ResourceImage resImage = ResourceImage::DownCast( image ); + DALI_TEST_CHECK( resImage ); + DALI_TEST_EQUALS( resImage.GetLoadPolicy(), ResourceImage::IMMEDIATE, TEST_LOCATION ); + END_TEST; +} - // Invalid release-policy - try - { - Property::Map map; - map[ "release-policy" ] = Vector3::ZERO; - Image image = NewImage( map ); - tet_result( TET_FAIL ); - } - catch ( DaliException& e ) - { - DALI_TEST_ASSERT( e, "map.GetValue(field).GetType()", TEST_LOCATION ); - - // Invalid value - try - { - Property::Map map; - map[ "release-policy" ] = "INVALID"; - Image image = NewImage( map ); - tet_result( TET_FAIL ); - } - catch ( DaliException& e ) - { - DALI_TEST_ASSERT( e, "!\"Unknown", TEST_LOCATION ); - } - } +int UtcDaliScriptingNewImageNegative03(void) +{ + TestApplication application; // Image needs application + // Invalid load-policy value + Property::Map map; + map[ "filename" ] = "TEST_FILE"; + map[ "load-policy" ] = "INVALID"; + // will give us a valid image with default load policy + Image image = NewImage( map ); + DALI_TEST_CHECK( image ); + ResourceImage resImage = ResourceImage::DownCast( image ); + DALI_TEST_CHECK( resImage ); + DALI_TEST_EQUALS( resImage.GetLoadPolicy(), ResourceImage::IMMEDIATE, TEST_LOCATION ); + END_TEST; +} - // Invalid width - try - { - Property::Map map; - map[ "width" ] = "Invalid"; - map[ "height" ] = "Invalid"; - Image image = NewImage( map ); - tet_result( TET_FAIL ); - } - catch ( DaliException& e ) - { - DALI_TEST_ASSERT( e, "value.GetType()", TEST_LOCATION ); - } +int UtcDaliScriptingNewImageNegative04(void) +{ + TestApplication application; // Image needs application + // Invalid release-policy value type + Property::Map map; + map[ "filename" ] = "TEST_FILE"; + map[ "release-policy" ] = Vector3::ZERO; + // will give us a valid image with default release policy + Image image = NewImage( map ); + DALI_TEST_CHECK( image ); + ResourceImage resImage = ResourceImage::DownCast( image ); + DALI_TEST_CHECK( resImage ); + DALI_TEST_EQUALS( resImage.GetReleasePolicy(), Image::NEVER, TEST_LOCATION ); + END_TEST; +} + +int UtcDaliScriptingNewImageNegative05(void) +{ + TestApplication application; // Image needs application + // Invalid release-policy value + Property::Map map; + map[ "filename" ] = "TEST_FILE"; + map[ "release-policy" ] = "INVALID"; + // will give us a valid image with default release policy + Image image = NewImage( map ); + DALI_TEST_CHECK( image ); + ResourceImage resImage = ResourceImage::DownCast( image ); + DALI_TEST_CHECK( resImage ); + DALI_TEST_EQUALS( resImage.GetReleasePolicy(), Image::NEVER, TEST_LOCATION ); + END_TEST; +} +int UtcDaliScriptingNewImageNegative06(void) +{ + TestApplication application; // Image needs application + // Invalid width and height + Property::Map map; + map[ "filename" ] = "TEST_FILE"; + map[ "width" ] = "Invalid"; + map[ "height" ] = 100; + // will give us a valid image + Image image = NewImage( map ); + DALI_TEST_CHECK( image ); + ResourceImage resImage = ResourceImage::DownCast( image ); + DALI_TEST_CHECK( resImage ); + DALI_TEST_EQUALS( resImage.GetWidth(), 0, TEST_LOCATION ); + DALI_TEST_EQUALS( resImage.GetHeight(), 100, TEST_LOCATION ); + END_TEST; +} + +int UtcDaliScriptingNewImageNegative07(void) +{ + TestApplication application; // Image needs application // Invalid height - try - { - Property::Map map; - map[ "width" ] = 10; - map[ "height" ] = "Invalid"; - Image image = NewImage( map ); - tet_result( TET_FAIL ); - } - catch ( DaliException& e ) - { - DALI_TEST_ASSERT( e, "value.GetType()", TEST_LOCATION ); - } + Property::Map map; + map[ "filename" ] = "TEST_FILE"; + map[ "width" ] = 10; + map[ "height" ] = "Invalid"; + // will give us a valid image + Image image = NewImage( map ); + DALI_TEST_CHECK( image ); + ResourceImage resImage = ResourceImage::DownCast( image ); + DALI_TEST_CHECK( resImage ); + DALI_TEST_EQUALS( resImage.GetWidth(), 10, TEST_LOCATION ); + DALI_TEST_EQUALS( resImage.GetHeight(), 0, TEST_LOCATION ); + END_TEST; +} +int UtcDaliScriptingNewImageNegative08(void) +{ + TestApplication application; // Image needs application // Invalid fitting-mode - try - { - Property::Map map; - map[ "fitting-mode" ] = Vector3::ZERO; - Image image = NewImage( map ); - DALI_TEST_EQUALS( "Expected exception to be thrown", "But exception was not thrown", TEST_LOCATION ); - } - catch ( DaliException& e ) - { - DALI_TEST_ASSERT( e, "value.GetType() == Property::STRING", TEST_LOCATION ); - - // Invalid value - try - { - Property::Map map; - map[ "fitting-mode" ] = "INVALID"; - Image image = NewImage( map ); - DALI_TEST_EQUALS( "Expected exception to be thrown", "But exception was not thrown", TEST_LOCATION ); - } - catch ( DaliException& e ) - { - DALI_TEST_ASSERT( e, "!\"Unknown", TEST_LOCATION ); - } - } + Property::Map map; + map[ "filename" ] = "TEST_FILE"; + map[ "fitting-mode" ] = Vector3::ZERO; + // will give us a valid image + Image image = NewImage( map ); + DALI_TEST_CHECK( image ); + ResourceImage resImage = ResourceImage::DownCast( image ); + DALI_TEST_CHECK( resImage ); + END_TEST; +} + +int UtcDaliScriptingNewImageNegative09(void) +{ + TestApplication application; // Image needs application + // Invalid value + Property::Map map; + map[ "filename" ] = "TEST_FILE"; + map[ "fitting-mode" ] = "INVALID"; + // will give us a valid image + Image image = NewImage( map ); + DALI_TEST_CHECK( image ); + ResourceImage resImage = ResourceImage::DownCast( image ); + DALI_TEST_CHECK( resImage ); + END_TEST; +} +int UtcDaliScriptingNewImageNegative10(void) +{ + TestApplication application; // Image needs application // Invalid scaling-mode - try - { - Property::Map map; - map[ "sampling-mode" ] = Vector3::ZERO; - Image image = NewImage( map ); - DALI_TEST_EQUALS( "Expected exception to be thrown", "But exception was not thrown", TEST_LOCATION ); - } - catch ( DaliException& e ) - { - DALI_TEST_ASSERT( e, "value.GetType() == Property::STRING", TEST_LOCATION ); - - // Invalid value - try - { - Property::Map map; - map[ "sampling-mode" ] = "INVALID"; - Image image = NewImage( map ); - DALI_TEST_EQUALS( "Expected exception to be thrown", "But exception was not thrown", TEST_LOCATION ); - } - catch ( DaliException& e ) - { - DALI_TEST_ASSERT( e, "!\"Unknown", TEST_LOCATION ); - } - } + Property::Map map; + map[ "filename" ] = "TEST_FILE"; + map[ "sampling-mode" ] = Vector3::ZERO; + // will give us a valid image + Image image = NewImage( map ); + DALI_TEST_CHECK( image ); + ResourceImage resImage = ResourceImage::DownCast( image ); + DALI_TEST_CHECK( resImage ); + END_TEST; +} +int UtcDaliScriptingNewImageNegative12(void) +{ + TestApplication application; // Image needs application // Invalid orientation-correction - try - { - Property::Map map; - map[ "orientation" ] = Vector3::ZERO; - Image image = NewImage( map ); - DALI_TEST_EQUALS( "Expected exception to be thrown", "But exception was not thrown", TEST_LOCATION ); - } - catch ( DaliException& e ) - { - DALI_TEST_ASSERT( e, "value.GetType() == Property::BOOLEAN", TEST_LOCATION ); - } + Property::Map map; + map[ "filename" ] = "TEST_FILE"; + map[ "orientation" ] = Vector3::ZERO; + // will give us a valid image + Image image = NewImage( map ); + DALI_TEST_CHECK( image ); + ResourceImage resImage = ResourceImage::DownCast( image ); + DALI_TEST_CHECK( resImage ); + END_TEST; +} +int UtcDaliScriptingNewImageNegative13(void) +{ + TestApplication application; // Image needs application // Invalid type - try - { - Property::Map map; - map[ "type" ] = Vector3::ZERO; - Image image = NewImage( map ); - tet_result( TET_FAIL ); - } - catch ( DaliException& e ) - { - DALI_TEST_ASSERT( e, "map.GetValue(\"type\").GetType()", TEST_LOCATION ); - - // Invalid value - try - { - Property::Map map; - map[ "type" ] = "INVALID"; - Image image = NewImage( map ); - tet_result( TET_FAIL ); - } - catch ( DaliException& e ) - { - DALI_TEST_ASSERT( e, "!\"Unknown", TEST_LOCATION ); - } - } + Property::Map map; + map[ "filename" ] = "TEST_FILE"; + map[ "type" ] = Vector3::ZERO; + // will give us a valid image + Image image = NewImage( map ); + DALI_TEST_CHECK( image ); + ResourceImage resImage = ResourceImage::DownCast( image ); + DALI_TEST_CHECK( resImage ); + END_TEST; +} - // Invalid pixel-format - try - { - Property::Map map; - map[ "pixel-format" ] = Vector3::ZERO; - Image image = NewImage( map ); - tet_result( TET_FAIL ); - } - catch ( DaliException& e ) - { - DALI_TEST_ASSERT( e, "map.GetValue(field).GetType()", TEST_LOCATION ); - - // Invalid value - try - { - Property::Map map; - map[ "pixel-format" ] = "INVALID"; - Image image = NewImage( map ); - tet_result( TET_FAIL ); - } - catch ( DaliException& e ) - { - DALI_TEST_ASSERT( e, "!\"Unknown", TEST_LOCATION ); - } - } +int UtcDaliScriptingNewImageNegative14(void) +{ + // Invalid value + Property::Map map; + map[ "type" ] = "INVALID"; + Image image = NewImage( map ); + DALI_TEST_CHECK( !image ); + END_TEST; +} +int UtcDaliScriptingNewImageNegative15(void) +{ + // Invalid pixel-format + Property::Map map; + map[ "pixel-format" ] = Vector3::ZERO; + Image image = NewImage( map ); + DALI_TEST_CHECK( !image ); END_TEST; } +int UtcDaliScriptingNewImageNegative16(void) +{ + // Invalid value + Property::Map map; + map[ "pixel-format" ] = "INVALID"; + Image image = NewImage( map ); + DALI_TEST_CHECK( !image ); + END_TEST; +} -int UtcDaliScriptingNewImage(void) +int UtcDaliScriptingNewImage01P(void) { - TestApplication application; + TestApplication application; // Image needs application Property::Map map; map[ "filename" ] = "TEST_FILE"; // Filename only - { - ResourceImage image = ResourceImage::DownCast( NewImage( map ) ); - DALI_TEST_EQUALS( "TEST_FILE", image.GetUrl(), TEST_LOCATION ); - } + ResourceImage image = ResourceImage::DownCast( NewImage( map ) ); + DALI_TEST_EQUALS( "TEST_FILE", image.GetUrl(), TEST_LOCATION ); + END_TEST; +} + +int UtcDaliScriptingNewImage02P(void) +{ + TestApplication application; + + Property::Map map; + map[ "filename" ] = "TEST_FILE"; // load-policy map[ "load-policy" ] = ""; + const StringEnum values[] = { - const StringEnum< int > values[] = - { - { "IMMEDIATE", ResourceImage::IMMEDIATE }, - { "ON_DEMAND", ResourceImage::ON_DEMAND } - }; - TestEnumStrings< ResourceImage::LoadPolicy, ResourceImage >( map, values, ( sizeof( values ) / sizeof ( values[0] ) ), &ResourceImage::GetLoadPolicy, &NewResourceImage ); - } + { "IMMEDIATE", ResourceImage::IMMEDIATE }, + { "ON_DEMAND", ResourceImage::ON_DEMAND } + }; + TestEnumStrings< ResourceImage::LoadPolicy, ResourceImage >( map, "load-policy", values, ( sizeof( values ) / sizeof ( values[0] ) ), &ResourceImage::GetLoadPolicy, &NewResourceImage ); + END_TEST; +} + +int UtcDaliScriptingNewImage03P(void) +{ + TestApplication application; + + Property::Map map; + map[ "filename" ] = "TEST_FILE"; // release-policy map[ "release-policy" ] = ""; + const StringEnum values[] = { - const StringEnum< int > values[] = - { - { "UNUSED", Image::UNUSED }, - { "NEVER", Image::NEVER } - }; - TestEnumStrings< Image::ReleasePolicy, Image >( map, values, ( sizeof( values ) / sizeof ( values[0] ) ), &Image::GetReleasePolicy, &NewImage ); - } + { "UNUSED", Image::UNUSED }, + { "NEVER", Image::NEVER } + }; + TestEnumStrings< Image::ReleasePolicy, Image >( map, "release-policy", values, ( sizeof( values ) / sizeof ( values[0] ) ), &Image::GetReleasePolicy, &NewImage ); + END_TEST; +} + +int UtcDaliScriptingNewImage04P(void) +{ + TestApplication application; + + Property::Map map; + map[ "filename" ] = "TEST_FILE"; // float width and height map[ "width" ] = (float) 10.0f; map[ "height" ] = (float) 20.0f; - { - Image image = NewImage( map ); - DALI_TEST_EQUALS( image.GetWidth(), 10.0f, TEST_LOCATION ); - DALI_TEST_EQUALS( image.GetHeight(), 20.0f, TEST_LOCATION ); - } + Image image = NewImage( map ); + DALI_TEST_EQUALS( image.GetWidth(), 10.0f, TEST_LOCATION ); + DALI_TEST_EQUALS( image.GetHeight(), 20.0f, TEST_LOCATION ); + END_TEST; +} - // int width and height - map[ "width"] = (int) 50; - map[ "height" ] = (int) 70; - { - Image image = NewImage( map ); - DALI_TEST_EQUALS( image.GetWidth(), 50u, TEST_LOCATION ); - DALI_TEST_EQUALS( image.GetHeight(), 70u, TEST_LOCATION ); - } +int UtcDaliScriptingNewImage05P(void) +{ + TestApplication application; - //map.erase( map.end() - 2, map.end() ); + Property::Map map; + map[ "filename" ] = "TEST_FILE"; + + // width and height + map[ "width"] = 50; + map[ "height" ] = 70; + Image image = NewImage( map ); + DALI_TEST_EQUALS( image.GetWidth(), 50u, TEST_LOCATION ); + DALI_TEST_EQUALS( image.GetHeight(), 70u, TEST_LOCATION ); + END_TEST; +} + +int UtcDaliScriptingNewImage06P(void) +{ + TestApplication application; + Property::Map map; // type FrameBufferImage map[ "type" ] = "FrameBufferImage"; - { - Image image = NewImage( map ); - DALI_TEST_CHECK( FrameBufferImage::DownCast( image ) ); - } + // width and height + map[ "width"] = 50; + map[ "height" ] = 70; + Image image = NewImage( map ); + DALI_TEST_CHECK( image ); + DALI_TEST_CHECK( FrameBufferImage::DownCast( image ) ); + END_TEST; +} + +int UtcDaliScriptingNewImage07P(void) +{ + TestApplication application; + + Property::Map map; // type BufferImage - map[ "type" ] = "BufferImage"; - { - Image image = NewImage( map ); - DALI_TEST_CHECK( BufferImage::DownCast( image ) ); - DALI_TEST_CHECK((BufferImage::DownCast( image )).GetPixelFormat()== Pixel::RGBA8888); - } - - // pixel-format - map[ "pixel-format" ] = ""; - { - const StringEnum< int > values[] = - { - { "A8", Pixel::A8 }, - { "L8", Pixel::L8 }, - { "LA88", Pixel::LA88 }, - { "RGB565", Pixel::RGB565 }, - { "BGR565", Pixel::BGR565 }, - { "RGBA4444", Pixel::RGBA4444 }, - { "BGRA4444", Pixel::BGRA4444 }, - { "RGBA5551", Pixel::RGBA5551 }, - { "BGRA5551", Pixel::BGRA5551 }, - { "RGB888", Pixel::RGB888 }, - { "RGB8888", Pixel::RGB8888 }, - { "BGR8888", Pixel::BGR8888 }, - { "RGBA8888", Pixel::RGBA8888 }, - { "BGRA8888", Pixel::BGRA8888 }, - /*{ "COMPRESSED_R11_EAC", Pixel::COMPRESSED_R11_EAC }, - { "COMPRESSED_SIGNED_R11_EAC", Pixel::COMPRESSED_SIGNED_R11_EAC }, - { "COMPRESSED_RG11_EAC", Pixel::COMPRESSED_RG11_EAC }, - { "COMPRESSED_SIGNED_RG11_EAC", Pixel::COMPRESSED_SIGNED_RG11_EAC }, - { "COMPRESSED_RGB8_ETC2", Pixel::COMPRESSED_RGB8_ETC2 }, - { "COMPRESSED_SRGB8_ETC2", Pixel::COMPRESSED_SRGB8_ETC2 }, - { "COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2", Pixel::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 }, - { "COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2", Pixel::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 }, - { "COMPRESSED_RGBA8_ETC2_EAC", Pixel::COMPRESSED_RGBA8_ETC2_EAC }, - { "COMPRESSED_SRGB8_ALPHA8_ETC2_EAC", Pixel::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC }, - { "COMPRESSED_RGB8_ETC1", Pixel::COMPRESSED_RGB8_ETC1 }, - { "COMPRESSED_RGB_PVRTC_4BPPV1", Pixel::COMPRESSED_RGB_PVRTC_4BPPV1 },*/ - // BufferImage does not support compressed formats - }; - - TestEnumStrings< Pixel::Format, BufferImage >( map, values, ( sizeof( values ) / sizeof ( values[0] ) ), &BufferImage::GetPixelFormat, &NewBufferImage ); - } + map[ "type" ] = "BufferImage"; + // width and height + map[ "width"] = 50; + map[ "height" ] = 70; + Image image = NewImage( map ); + DALI_TEST_CHECK( image ); + DALI_TEST_CHECK( BufferImage::DownCast( image ) ); + DALI_TEST_EQUALS( (BufferImage::DownCast( image )).GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION ); + END_TEST; +} +int UtcDaliScriptingNewImage08P(void) +{ + TestApplication application; + + Property::Map map; + map[ "type" ] = "BufferImage"; + // width and height + map[ "width"] = 66; + map[ "height" ] = 99; + // pixel-format + map[ "pixel-format" ] = ""; + const StringEnum values[] = + { + { "A8", Pixel::A8 }, + { "L8", Pixel::L8 }, + { "LA88", Pixel::LA88 }, + { "RGB565", Pixel::RGB565 }, + { "BGR565", Pixel::BGR565 }, + { "RGBA4444", Pixel::RGBA4444 }, + { "BGRA4444", Pixel::BGRA4444 }, + { "RGBA5551", Pixel::RGBA5551 }, + { "BGRA5551", Pixel::BGRA5551 }, + { "RGB888", Pixel::RGB888 }, + { "RGB8888", Pixel::RGB8888 }, + { "BGR8888", Pixel::BGR8888 }, + { "RGBA8888", Pixel::RGBA8888 }, + { "BGRA8888", Pixel::BGRA8888 }, + // BufferImage does not support compressed formats + }; + TestEnumStrings< Pixel::Format, BufferImage >( map, "pixel-format", values, ( sizeof( values ) / sizeof ( values[0] ) ), &BufferImage::GetPixelFormat, &NewBufferImage ); + + END_TEST; +} + +int UtcDaliScriptingNewImage09P(void) +{ + TestApplication application; + + Property::Map map; // type Image map[ "type" ] = "ResourceImage"; + map[ "filename" ] = "TEST_FILE"; + { Image image = NewImage( map ); DALI_TEST_CHECK( ResourceImage::DownCast( image ) ); @@ -575,6 +581,18 @@ int UtcDaliScriptingNewImage(void) END_TEST; } +int UtcDaliScriptingNewImage10P(void) +{ + TestApplication application; + + Property::Map map; + // type FrameBufferImage, empty size gives us stage size + map[ "type" ] = "FrameBufferImage"; + Image image = NewImage( map ); + DALI_TEST_CHECK( image ); + END_TEST; +} + int UtcDaliScriptingNewShaderEffect(void) { TestApplication application; @@ -764,9 +782,8 @@ int UtcDaliScriptingCreatePropertyMapActor(void) Property::Map map; CreatePropertyMap( actor, map ); 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 ); + DALI_TEST_CHECK( NULL != map.Find( "type" ) ); + DALI_TEST_EQUALS( map.Find( "type")->Get< std::string >(), "Actor", TEST_LOCATION ); Stage::GetCurrent().Remove( actor ); } @@ -778,9 +795,8 @@ int UtcDaliScriptingCreatePropertyMapActor(void) Property::Map map; CreatePropertyMap( actor, map ); 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 ); + DALI_TEST_CHECK( NULL != map.Find( "type" ) ); + DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "ImageActor", TEST_LOCATION ); Stage::GetCurrent().Remove( actor ); } @@ -810,33 +826,32 @@ int UtcDaliScriptingCreatePropertyMapActor(void) CreatePropertyMap( actor, map ); 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 ); - DALI_TEST_CHECK( value.HasKey( "position" ) ); - DALI_TEST_EQUALS( value.GetValue( "position" ).Get< Vector3 >(), Vector3::XAXIS, TEST_LOCATION ); - DALI_TEST_CHECK( value.HasKey( "scale" ) ); - DALI_TEST_EQUALS( value.GetValue( "scale" ).Get< Vector3 >(), Vector3::ZAXIS, TEST_LOCATION ); - DALI_TEST_CHECK( value.HasKey( "visible" ) ); - DALI_TEST_EQUALS( value.GetValue( "visible" ).Get< bool >(), false, TEST_LOCATION ); - DALI_TEST_CHECK( value.HasKey( "color" ) ); - DALI_TEST_EQUALS( value.GetValue( "color" ).Get< Vector4 >(), Color::MAGENTA, TEST_LOCATION ); - DALI_TEST_CHECK( value.HasKey( "name" ) ); - DALI_TEST_EQUALS( value.GetValue( "name").Get< std::string >(), "MyActor", TEST_LOCATION ); - DALI_TEST_CHECK( value.HasKey( "anchor-point" ) ); - DALI_TEST_EQUALS( value.GetValue( "anchor-point" ).Get< Vector3 >(), AnchorPoint::CENTER_LEFT, TEST_LOCATION ); - DALI_TEST_CHECK( value.HasKey( "parent-origin" ) ); - DALI_TEST_EQUALS( value.GetValue( "parent-origin" ).Get< Vector3 >(), ParentOrigin::TOP_RIGHT, TEST_LOCATION ); - DALI_TEST_CHECK( value.HasKey( "sensitive" ) ); - DALI_TEST_EQUALS( value.GetValue( "sensitive" ).Get< bool >(), false, TEST_LOCATION ); - DALI_TEST_CHECK( value.HasKey( "leave-required" ) ); - DALI_TEST_EQUALS( value.GetValue( "leave-required" ).Get< bool >(), true, TEST_LOCATION ); - DALI_TEST_CHECK( value.HasKey( "inherit-orientation" ) ); - DALI_TEST_EQUALS( value.GetValue( "inherit-orientation" ).Get< bool >(), false, TEST_LOCATION ); - DALI_TEST_CHECK( value.HasKey( "inherit-scale" ) ); - DALI_TEST_EQUALS( value.GetValue( "inherit-scale" ).Get< bool >(), false, TEST_LOCATION ); - DALI_TEST_CHECK( value.HasKey( "size-mode-factor" ) ); - DALI_TEST_EQUALS( value.GetValue( "size-mode-factor" ).Get< Vector3 >(), Vector3::ONE, TEST_LOCATION ); + DALI_TEST_CHECK( NULL != map.Find( "size" ) ); + DALI_TEST_EQUALS( map.Find( "size" )->Get< Vector3 >(), Vector3::ONE, TEST_LOCATION ); + DALI_TEST_CHECK( NULL != map.Find( "position" ) ); + DALI_TEST_EQUALS( map.Find( "position" )->Get< Vector3 >(), Vector3::XAXIS, TEST_LOCATION ); + DALI_TEST_CHECK( NULL != map.Find( "scale" ) ); + DALI_TEST_EQUALS( map.Find( "scale" )->Get< Vector3 >(), Vector3::ZAXIS, TEST_LOCATION ); + DALI_TEST_CHECK( NULL != map.Find( "visible" ) ); + DALI_TEST_EQUALS( map.Find( "visible" )->Get< bool >(), false, TEST_LOCATION ); + DALI_TEST_CHECK( NULL != map.Find( "color" ) ); + DALI_TEST_EQUALS( map.Find( "color" )->Get< Vector4 >(), Color::MAGENTA, TEST_LOCATION ); + DALI_TEST_CHECK( NULL != map.Find( "name" ) ); + DALI_TEST_EQUALS( map.Find( "name")->Get< std::string >(), "MyActor", TEST_LOCATION ); + DALI_TEST_CHECK( NULL != map.Find( "anchor-point" ) ); + DALI_TEST_EQUALS( map.Find( "anchor-point" )->Get< Vector3 >(), AnchorPoint::CENTER_LEFT, TEST_LOCATION ); + DALI_TEST_CHECK( NULL != map.Find( "parent-origin" ) ); + DALI_TEST_EQUALS( map.Find( "parent-origin" )->Get< Vector3 >(), ParentOrigin::TOP_RIGHT, TEST_LOCATION ); + DALI_TEST_CHECK( NULL != map.Find( "sensitive" ) ); + DALI_TEST_EQUALS( map.Find( "sensitive" )->Get< bool >(), false, TEST_LOCATION ); + DALI_TEST_CHECK( NULL != map.Find( "leave-required" ) ); + DALI_TEST_EQUALS( map.Find( "leave-required" )->Get< bool >(), true, TEST_LOCATION ); + DALI_TEST_CHECK( NULL != map.Find( "inherit-orientation" ) ); + DALI_TEST_EQUALS( map.Find( "inherit-orientation" )->Get< bool >(), false, TEST_LOCATION ); + DALI_TEST_CHECK( NULL != map.Find( "inherit-scale" ) ); + DALI_TEST_EQUALS( map.Find( "inherit-scale" )->Get< bool >(), false, TEST_LOCATION ); + DALI_TEST_CHECK( NULL != map.Find( "size-mode-factor" ) ); + DALI_TEST_EQUALS( map.Find( "size-mode-factor" )->Get< Vector3 >(), Vector3::ONE, TEST_LOCATION ); Stage::GetCurrent().Remove( actor ); } @@ -864,18 +879,16 @@ int UtcDaliScriptingCreatePropertyMapActor(void) CreatePropertyMap( actor, map ); 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 ); + DALI_TEST_CHECK( NULL != map.Find( "type" ) ); + DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "Actor", TEST_LOCATION ); - DALI_TEST_CHECK( value.HasKey( "actors" ) ); - Property::Array children( value.GetValue( "actors").Get< Property::Array >() ); + DALI_TEST_CHECK( NULL != map.Find( "actors" ) ); + Property::Array children( map.Find( "actors")->Get< Property::Array >() ); DALI_TEST_CHECK( !children.Empty() ); Property::Map childMap( children[0].Get< Property::Map >() ); 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 ); + DALI_TEST_CHECK( childMap.Find( "type" ) ); + DALI_TEST_EQUALS( childMap.Find( "type" )->Get< std::string >(), "ImageActor", TEST_LOCATION ); Stage::GetCurrent().Remove( actor ); } @@ -902,17 +915,16 @@ int UtcDaliScriptingCreatePropertyMapImage(void) CreatePropertyMap( image, map ); DALI_TEST_CHECK( !map.Empty() ); - Property::Value value( map ); - DALI_TEST_CHECK( value.HasKey( "type" ) ); - DALI_TEST_EQUALS( value.GetValue( "type" ).Get< std::string >(), "ResourceImage", TEST_LOCATION ); - DALI_TEST_CHECK( value.HasKey( "filename" ) ); - DALI_TEST_EQUALS( value.GetValue( "filename" ).Get< std::string >(), "MY_PATH", TEST_LOCATION ); - DALI_TEST_CHECK( value.HasKey( "load-policy") ); - DALI_TEST_EQUALS( value.GetValue( "load-policy" ).Get< std::string >(), "IMMEDIATE", TEST_LOCATION ); - DALI_TEST_CHECK( value.HasKey( "release-policy") ); - DALI_TEST_EQUALS( value.GetValue( "release-policy" ).Get< std::string >(), "NEVER", TEST_LOCATION ); - DALI_TEST_CHECK( !value.HasKey( "width" ) ); - DALI_TEST_CHECK( !value.HasKey( "height" ) ); + DALI_TEST_CHECK( NULL != map.Find( "type" ) ); + DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "ResourceImage", TEST_LOCATION ); + DALI_TEST_CHECK( NULL != map.Find( "filename" ) ); + DALI_TEST_EQUALS( map.Find( "filename" )->Get< std::string >(), "MY_PATH", TEST_LOCATION ); + DALI_TEST_CHECK( NULL != map.Find( "load-policy") ); + DALI_TEST_EQUALS( map.Find( "load-policy" )->Get< std::string >(), "IMMEDIATE", TEST_LOCATION ); + DALI_TEST_CHECK( NULL != map.Find( "release-policy") ); + DALI_TEST_EQUALS( map.Find( "release-policy" )->Get< std::string >(), "NEVER", TEST_LOCATION ); + DALI_TEST_CHECK( NULL == map.Find( "width" ) ); + DALI_TEST_CHECK( NULL == map.Find( "height" ) ); } // Change values @@ -923,19 +935,18 @@ int UtcDaliScriptingCreatePropertyMapImage(void) CreatePropertyMap( image, map ); DALI_TEST_CHECK( !map.Empty() ); - Property::Value value( map ); - DALI_TEST_CHECK( value.HasKey( "type" ) ); - DALI_TEST_EQUALS( value.GetValue( "type" ).Get< std::string >(), "ResourceImage", TEST_LOCATION ); - DALI_TEST_CHECK( value.HasKey( "filename" ) ); - DALI_TEST_EQUALS( value.GetValue( "filename" ).Get< std::string >(), "MY_PATH", TEST_LOCATION ); - DALI_TEST_CHECK( value.HasKey( "load-policy") ); - DALI_TEST_EQUALS( value.GetValue( "load-policy" ).Get< std::string >(), "ON_DEMAND", TEST_LOCATION ); - DALI_TEST_CHECK( value.HasKey( "release-policy") ); - DALI_TEST_EQUALS( value.GetValue( "release-policy" ).Get< std::string >(), "UNUSED", TEST_LOCATION ); - DALI_TEST_CHECK( value.HasKey( "width" ) ); - DALI_TEST_EQUALS( value.GetValue( "width" ).Get< int >(), 300, TEST_LOCATION ); - DALI_TEST_CHECK( value.HasKey( "height" ) ); - DALI_TEST_EQUALS( value.GetValue( "height" ).Get< int >(), 400, TEST_LOCATION ); + DALI_TEST_CHECK( NULL != map.Find( "type" ) ); + DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "ResourceImage", TEST_LOCATION ); + DALI_TEST_CHECK( NULL != map.Find( "filename" ) ); + DALI_TEST_EQUALS( map.Find( "filename" )->Get< std::string >(), "MY_PATH", TEST_LOCATION ); + DALI_TEST_CHECK( NULL != map.Find( "load-policy") ); + DALI_TEST_EQUALS( map.Find( "load-policy" )->Get< std::string >(), "ON_DEMAND", TEST_LOCATION ); + DALI_TEST_CHECK( NULL != map.Find( "release-policy") ); + DALI_TEST_EQUALS( map.Find( "release-policy" )->Get< std::string >(), "UNUSED", TEST_LOCATION ); + DALI_TEST_CHECK( NULL != map.Find( "width" ) ); + DALI_TEST_EQUALS( map.Find( "width" )->Get< int >(), 300, TEST_LOCATION ); + DALI_TEST_CHECK( NULL != map.Find( "height" ) ); + DALI_TEST_EQUALS( map.Find( "height" )->Get< int >(), 400, TEST_LOCATION ); } // BufferImage @@ -943,11 +954,10 @@ int UtcDaliScriptingCreatePropertyMapImage(void) Image image = BufferImage::New( 200, 300, Pixel::A8 ); Property::Map map; CreatePropertyMap( image, map ); - Property::Value value( map ); - DALI_TEST_CHECK( value.HasKey( "type" ) ); - DALI_TEST_EQUALS( value.GetValue( "type" ).Get< std::string >(), "BufferImage", TEST_LOCATION ); - DALI_TEST_CHECK( value.HasKey( "pixel-format") ); - DALI_TEST_EQUALS( value.GetValue( "pixel-format" ).Get< std::string >(), "A8", TEST_LOCATION ); + DALI_TEST_CHECK( NULL != map.Find( "type" ) ); + DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "BufferImage", TEST_LOCATION ); + DALI_TEST_CHECK( NULL != map.Find( "pixel-format") ); + DALI_TEST_EQUALS( map.Find( "pixel-format" )->Get< std::string >(), "A8", TEST_LOCATION ); } // FrameBufferImage @@ -955,18 +965,15 @@ int UtcDaliScriptingCreatePropertyMapImage(void) Image image = FrameBufferImage::New( 200, 300, Pixel::RGBA8888 ); Property::Map map; CreatePropertyMap( image, map ); - Property::Value value( map ); - DALI_TEST_CHECK( value.HasKey( "type" ) ); - DALI_TEST_EQUALS( value.GetValue( "type" ).Get< std::string >(), "FrameBufferImage", TEST_LOCATION ); + DALI_TEST_CHECK( NULL != map.Find( "type" ) ); + DALI_TEST_EQUALS( map.Find( "type" )->Get< std::string >(), "FrameBufferImage", TEST_LOCATION ); } END_TEST; } int UtcDaliScriptingGetEnumerationTemplates(void) { - TestApplication application; - - const Scripting::StringEnum< int > myTable[] = + const Scripting::StringEnum myTable[] = { { "ONE", 1 }, { "TWO", 2 }, @@ -979,7 +986,9 @@ int UtcDaliScriptingGetEnumerationTemplates(void) for ( unsigned int i = 0; i < myTableCount; ++i ) { tet_printf("Checking: %s\n", myTable[ i ].string ); - DALI_TEST_EQUALS( myTable[ i ].value, GetEnumeration( myTable[ i ].string, myTable, myTableCount ), TEST_LOCATION ); + int value; + DALI_TEST_CHECK( GetEnumeration( myTable[ i ].string, myTable, myTableCount, value ) ); + DALI_TEST_EQUALS( myTable[ i ].value, value, TEST_LOCATION ); } for ( unsigned int i = 0; i < myTableCount; ++i ) @@ -991,22 +1000,40 @@ int UtcDaliScriptingGetEnumerationTemplates(void) END_TEST; } -int UtcDaliScriptingCompareEnums(void) +int UtcDaliScriptingGetEnumerationNameN(void) { - // EQUAL - DALI_TEST_CHECK( CompareEnums( "", "" ) ); - DALI_TEST_CHECK( CompareEnums( "HELLO", "HELLO" ) ); - DALI_TEST_CHECK( CompareEnums( "HELLO", "hello" ) ); - DALI_TEST_CHECK( CompareEnums( "hello", "HELLO" ) ); - DALI_TEST_CHECK( CompareEnums( "hello-world", "HELLO_WORLD" ) ); - DALI_TEST_CHECK( CompareEnums( "hello_WORLD", "HELLO-world" ) ); - DALI_TEST_CHECK( CompareEnums( "hello_WORLD-", "HELLO-world_" ) ); - DALI_TEST_CHECK( CompareEnums( "_hello_WORLD-", "-HELLO-world_" ) ); - DALI_TEST_CHECK( CompareEnums( "-hello_WORLD-", "_HELLO-world_" ) ); - DALI_TEST_CHECK( CompareEnums( "hello123", "HELLO123" ) ); + const char* value = GetEnumerationName( 10, NULL, 0 ); + DALI_TEST_CHECK( NULL == value ); + + value = GetEnumerationName( 10, NULL, 1 ); + DALI_TEST_CHECK( NULL == value ); - // NOT EQUAL - DALI_TEST_CHECK( ! CompareEnums( "hello", "HELLOWORLD" ) ); + END_TEST; +} + +int UtcDaliScriptingGetLinearEnumerationNameN(void) +{ + const char* value = GetLinearEnumerationName( 10, NULL, 0 ); + DALI_TEST_CHECK( NULL == value ); + + value = GetLinearEnumerationName( 10, NULL, 1 ); + DALI_TEST_CHECK( NULL == value ); + + END_TEST; +} + +int UtcDaliScriptingFindEnumIndexN(void) +{ + const Scripting::StringEnum myTable[] = + { + { "ONE", 1 }, + { "TWO", 2 }, + { "THREE", 3 }, + { "FOUR", 4 }, + { "FIVE", 5 }, + }; + const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] ); + DALI_TEST_EQUALS( myTableCount, FindEnumIndex( "Foo", myTable, myTableCount ), TEST_LOCATION ); END_TEST; } diff --git a/automated-tests/src/dali/utc-Dali-Handle.cpp b/automated-tests/src/dali/utc-Dali-Handle.cpp index c0b4fe6..f349ac9 100644 --- a/automated-tests/src/dali/utc-Dali-Handle.cpp +++ b/automated-tests/src/dali/utc-Dali-Handle.cpp @@ -514,69 +514,34 @@ int UtcDaliHandleNonAnimtableCompositeProperties(void) Actor actor = Actor::New(); Property::Value value(Property::ARRAY); - Property::Array anArray; - DALI_TEST_CHECK( Property::Value(anArray).GetType() == Property::ARRAY ); // 2nd constructor + Property::Array* array = value.GetArray(); + DALI_TEST_CHECK( array ); - value.AppendItem( Property::Value( 0.f ) ); - value.AppendItem( "a string" ); - value.SetItem(0, Property::Value( 5.f )); // exercise SetItem + array->PushBack( Property::Value( 0.1f ) ); + array->PushBack( "a string" ); + array->PushBack( Property::Value( Vector3(1,2,3) ) ); - int index = value.AppendItem( Vector3(1,2,3) ); + DALI_TEST_EQUALS( 3, array->Count(), TEST_LOCATION ); - DALI_TEST_EQUALS( 2, index, TEST_LOCATION); - DALI_TEST_EQUALS( 3, value.GetSize(), TEST_LOCATION); - - Property::Index propertyIndex = actor.RegisterProperty( "composite", value, Property::READ_WRITE); + Property::Index propertyIndex = actor.RegisterProperty( "composite", value, Property::READ_WRITE ); Property::Value out = actor.GetProperty( propertyIndex ); + Property::Array* outArray = out.GetArray(); + DALI_TEST_CHECK( outArray != NULL ); - DALI_TEST_CHECK( Property::FLOAT == out.GetItem(0).GetType()); - DALI_TEST_CHECK( Property::STRING == out.GetItem(1).GetType()); - DALI_TEST_CHECK( Property::VECTOR3 == out.GetItem(2).GetType()); - - DALI_TEST_EQUALS( 5.f, out.GetItem(0).Get(), TEST_LOCATION); - DALI_TEST_EQUALS( "a string", out.GetItem(1).Get(), TEST_LOCATION); - DALI_TEST_EQUALS( Vector3(1,2,3), out.GetItem(2).Get(), TEST_LOCATION); - - // Property Maps - Property::Value valueMap(Property::MAP); - Property::Map aKindofMap; - DALI_TEST_CHECK( Property::Value(aKindofMap).GetType() == Property::MAP ); // 2nd constructor - - valueMap.SetValue("key", 5.f); - valueMap.SetValue("2key", "a string"); - - DALI_TEST_EQUALS( true, valueMap.HasKey("key"), TEST_LOCATION); - DALI_TEST_EQUALS( "key", valueMap.GetKey(0), TEST_LOCATION); - - DALI_TEST_EQUALS( true, valueMap.HasKey("2key"), TEST_LOCATION); - DALI_TEST_EQUALS( "2key", valueMap.GetKey(1), TEST_LOCATION); - - DALI_TEST_EQUALS( 5.f, valueMap.GetValue("key").Get(), TEST_LOCATION); - DALI_TEST_EQUALS( "a string", valueMap.GetValue("2key").Get(), TEST_LOCATION); - - valueMap.SetItem(0, Property::Value("a string")); - valueMap.SetItem(1, Property::Value(5.f)); - - DALI_TEST_EQUALS( 5.f, valueMap.GetValue("2key").Get(), TEST_LOCATION); - DALI_TEST_EQUALS( "a string", valueMap.GetValue("key").Get(), TEST_LOCATION); + DALI_TEST_CHECK( Property::FLOAT == outArray->GetElementAt(0).GetType()); + DALI_TEST_CHECK( Property::STRING == outArray->GetElementAt(1).GetType()); + DALI_TEST_CHECK( Property::VECTOR3 == outArray->GetElementAt(2).GetType()); - // ordered map - valueMap = Property::Value(Property::MAP); - - valueMap.SetValue("key", 5.f); - valueMap.SetValue("2key", "a string"); - - DALI_TEST_EQUALS( 5.f, valueMap.GetItem(0).Get(), TEST_LOCATION); - DALI_TEST_EQUALS( "a string", valueMap.GetItem(1).Get(), TEST_LOCATION); - - DALI_TEST_EQUALS( 2, valueMap.GetSize(), TEST_LOCATION); + DALI_TEST_EQUALS( 0.1f, outArray->GetElementAt(0).Get(), TEST_LOCATION); + DALI_TEST_EQUALS( "a string", outArray->GetElementAt(1).Get(), TEST_LOCATION); + DALI_TEST_EQUALS( Vector3(1,2,3), outArray->GetElementAt(2).Get(), TEST_LOCATION); // composite types not animatable bool exception = false; try { - /* Property::Index mapPropertyIndex = */ actor.RegisterProperty( "compositemap", value, Property::ANIMATABLE); + actor.RegisterProperty( "compositemap", value, Property::ANIMATABLE); } catch (Dali::DaliException& e) { @@ -588,29 +553,18 @@ int UtcDaliHandleNonAnimtableCompositeProperties(void) // Map of maps Property::Value mapOfMaps(Property::MAP); + Property::Map* map = mapOfMaps.GetMap(); - mapOfMaps.SetValue( "key", Property::Value(Property::MAP) ); - mapOfMaps.SetValue( "2key", "a string" ); - - DALI_TEST_EQUALS( "a string", mapOfMaps.GetValue("2key").Get(), TEST_LOCATION); - - mapOfMaps.GetValue("key").SetValue("subkey", 5.f); - - DALI_TEST_EQUALS( true, mapOfMaps.GetValue("key").HasKey("subkey"), TEST_LOCATION); - DALI_TEST_EQUALS( 5.f, mapOfMaps.GetValue("key").GetValue("subkey").Get(), TEST_LOCATION); - - // list of maps - Property::Value listOfMaps(Property::ARRAY); - - listOfMaps.AppendItem( Property::Value(Property::MAP) ); - listOfMaps.AppendItem( Property::Value(Property::MAP) ); + map->Insert( "key", Property::Value(Property::MAP) ); + map->Insert( "2key", "a string" ); - listOfMaps.GetItem(0).SetValue("key", 5.f); - listOfMaps.GetItem(1).SetValue("key",10.f); + DALI_TEST_EQUALS( "a string", (*map)["2key"].Get(), TEST_LOCATION); - DALI_TEST_EQUALS( 5.f, listOfMaps.GetItem(0).GetValue("key").Get(), TEST_LOCATION ); - DALI_TEST_EQUALS( 10.f, listOfMaps.GetItem(1).GetValue("key").Get(), TEST_LOCATION ); + Property::Map* innerMap = map->Find("key")->GetMap(); + innerMap->Insert( "subkey", 5.f ); + DALI_TEST_CHECK( NULL != map->Find("key")->GetMap()->Find("subkey") ); + DALI_TEST_EQUALS( 5.f, map->Find("key")->GetMap()->Find("subkey")->Get(), TEST_LOCATION); END_TEST; } diff --git a/automated-tests/src/dali/utc-Dali-ImageActor.cpp b/automated-tests/src/dali/utc-Dali-ImageActor.cpp index 4179adc..9152348 100644 --- a/automated-tests/src/dali/utc-Dali-ImageActor.cpp +++ b/automated-tests/src/dali/utc-Dali-ImageActor.cpp @@ -872,9 +872,11 @@ int UtcDaliImageActorImageProperty(void) application.SendNotification(); application.Render(); - Property::Value imageMap = imageActor.GetProperty( ImageActor::Property::IMAGE ); - DALI_TEST_CHECK( imageMap.HasKey( "filename" ) ); - DALI_TEST_EQUALS( imageMap.GetValue( "filename" ).Get< std::string >(), "MY_PATH", TEST_LOCATION ); + Property::Value imageProperty = imageActor.GetProperty( ImageActor::Property::IMAGE ); + Property::Map* imageMap = imageProperty.GetMap(); + DALI_TEST_CHECK( imageMap != NULL ); + DALI_TEST_CHECK( NULL != imageMap->Find( "filename" ) ); + DALI_TEST_EQUALS( (*imageMap)[ "filename" ].Get< std::string >(), "MY_PATH", TEST_LOCATION ); END_TEST; } diff --git a/automated-tests/src/dali/utc-Dali-PropertyMap.cpp b/automated-tests/src/dali/utc-Dali-PropertyMap.cpp index 5321d98..4867179 100644 --- a/automated-tests/src/dali/utc-Dali-PropertyMap.cpp +++ b/automated-tests/src/dali/utc-Dali-PropertyMap.cpp @@ -194,6 +194,24 @@ int UtcDaliPropertyMapFind(void) END_TEST; } +int UtcDaliPropertyMapInsertP(void) +{ + Property::Map map; + DALI_TEST_EQUALS( 0, map.Count(), TEST_LOCATION ); + map.Insert( "foo", "bar"); + DALI_TEST_EQUALS( 1, map.Count(), TEST_LOCATION ); + Property::Value* value = map.Find( "foo" ); + DALI_TEST_CHECK( value ); + DALI_TEST_EQUALS( "bar", value->Get(), TEST_LOCATION ); + map.Insert( std::string("foo2"), "testing" ); + DALI_TEST_EQUALS( 2, map.Count(), TEST_LOCATION ); + value = map.Find( "foo2" ); + DALI_TEST_CHECK( value ); + DALI_TEST_EQUALS( "testing", value->Get(), TEST_LOCATION ); + + END_TEST; +} + int UtcDaliPropertyMapMerge(void) { Property::Map map; diff --git a/automated-tests/src/dali/utc-Dali-PropertyValue.cpp b/automated-tests/src/dali/utc-Dali-PropertyValue.cpp index 300b500..5163b92 100644 --- a/automated-tests/src/dali/utc-Dali-PropertyValue.cpp +++ b/automated-tests/src/dali/utc-Dali-PropertyValue.cpp @@ -115,16 +115,6 @@ void CheckTypeName(const Property::Type& type) } // CheckTypeName template -struct GetCheckP -{ - GetCheckP(T value) - { - Property::Value v(value); - DALI_TEST_CHECK( v.Get() == value ); - } -}; - -template struct CheckCopyCtorP { CheckCopyCtorP(Property::Value value) @@ -171,81 +161,6 @@ struct CheckCopyCtorP } }; - -template -struct GetCheckN -{ - GetCheckN() - { - Property::Value v; - try - { - T got = v.Get(); - (void)got; - tet_result(TET_FAIL); - } - catch( Dali::DaliException& e ) - { - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_ASSERT( e, "Property type invalid", TEST_LOCATION ); - } - catch( ... ) - { - tet_printf("Assertion test failed - wrong Exception\n" ); - tet_result(TET_FAIL); - } - } -}; - -template<> -struct GetCheckN -{ - GetCheckN() - { - Property::Value value; - try - { - Property::Array array = value.Get(); - tet_result(TET_FAIL); - } - catch( Dali::DaliException& e ) - { - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_ASSERT( e, "Property type invalid", TEST_LOCATION ); - } - catch( ... ) - { - tet_printf("Assertion test failed - wrong Exception\n" ); - tet_result(TET_FAIL); - } - } -}; - -template<> -struct GetCheckN -{ - GetCheckN() - { - Property::Value value; - try - { - Property::Map map = value.Get(); - tet_result(TET_FAIL); - } - catch( Dali::DaliException& e ) - { - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_ASSERT( e, "Property type invalid", TEST_LOCATION ); - } - catch( ... ) - { - tet_printf("Assertion test failed - wrong Exception\n" ); - tet_result(TET_FAIL); - } - } -}; - - } // unnamed namespace void utc_dali_property_value_startup(void) @@ -259,9 +174,8 @@ void utc_dali_property_value_cleanup(void) } -int UtcDaliPropertyValueConstructors01P(void) +int UtcDaliPropertyValueConstructorsNoneP(void) { - TestApplication application; Property::Value value; DALI_TEST_CHECK( value.GetType() == Property::NONE ); @@ -269,9 +183,21 @@ int UtcDaliPropertyValueConstructors01P(void) END_TEST; } -int UtcDaliPropertyValueConstructors02P(void) +int UtcDaliPropertyValueConstructorsNoneTypeP(void) +{ + Property::Value value( Property::NONE ); + + DALI_TEST_CHECK( value.GetType() == Property::NONE ); + + Property::Value value2( Property::TYPE_COUNT ); + + DALI_TEST_CHECK( value2.GetType() == Property::NONE ); + + END_TEST; +} + +int UtcDaliPropertyValueConstructorsBoolP(void) { - TestApplication application; Property::Value value(true); DALI_TEST_CHECK( value.GetType() == Property::BOOLEAN ); @@ -280,9 +206,18 @@ int UtcDaliPropertyValueConstructors02P(void) END_TEST; } -int UtcDaliPropertyValueConstructors03P(void) +int UtcDaliPropertyValueConstructorBoolTypeP(void) +{ + Property::Value value(Property::BOOLEAN); + + DALI_TEST_CHECK( value.GetType() == Property::BOOLEAN ); + DALI_TEST_CHECK( value.Get() == false ); + + END_TEST; +} + +int UtcDaliPropertyValueConstructorsFloatP(void) { - TestApplication application; Property::Value value(2.f); DALI_TEST_CHECK( value.GetType() == Property::FLOAT ); @@ -291,9 +226,18 @@ int UtcDaliPropertyValueConstructors03P(void) END_TEST; } -int UtcDaliPropertyValueConstructors04P(void) +int UtcDaliPropertyValueConstructorsFloatTypeP(void) +{ + Property::Value value(Property::FLOAT); + + DALI_TEST_CHECK( value.GetType() == Property::FLOAT ); + DALI_TEST_CHECK( value.Get() == 0.f ); + + END_TEST; +} + +int UtcDaliPropertyValueConstructorsIntP(void) { - TestApplication application; Property::Value value(1); DALI_TEST_CHECK( value.GetType() == Property::INTEGER ); @@ -302,9 +246,18 @@ int UtcDaliPropertyValueConstructors04P(void) END_TEST; } -int UtcDaliPropertyValueConstructors05P(void) +int UtcDaliPropertyValueConstructorsIntTypeP(void) +{ + Property::Value value(Property::INTEGER); + + DALI_TEST_CHECK( value.GetType() == Property::INTEGER ); + DALI_TEST_CHECK( value.Get() == 0 ); + + END_TEST; +} + +int UtcDaliPropertyValueConstructorsUnsignedIntP(void) { - TestApplication application; Property::Value value(1u); DALI_TEST_CHECK( value.GetType() == Property::UNSIGNED_INTEGER ); @@ -313,9 +266,18 @@ int UtcDaliPropertyValueConstructors05P(void) END_TEST; } -int UtcDaliPropertyValueConstructors06P(void) +int UtcDaliPropertyValueConstructorsUnsignedIntTypeP(void) +{ + Property::Value value( Property::UNSIGNED_INTEGER ); + + DALI_TEST_CHECK( value.GetType() == Property::UNSIGNED_INTEGER ); + DALI_TEST_CHECK( value.Get() == 0u ); + + END_TEST; +} + +int UtcDaliPropertyValueConstructorsVector2P(void) { - TestApplication application; Vector2 v(1,1); Property::Value value(v); @@ -325,10 +287,19 @@ int UtcDaliPropertyValueConstructors06P(void) END_TEST; } -int UtcDaliPropertyValueConstructors07P(void) +int UtcDaliPropertyValueConstructorsVector2TypeP(void) { - TestApplication application; - Vector3 v(1.0,1.0,1.0); + Property::Value value( Property::VECTOR2 ); + + DALI_TEST_CHECK( value.GetType() == Property::VECTOR2 ); + DALI_TEST_CHECK( value.Get() == Vector2::ZERO ); + + END_TEST; +} + +int UtcDaliPropertyValueConstructorsVector3P(void) +{ + Vector3 v(1.f,2.f,3.f); Property::Value value(v); DALI_TEST_CHECK( value.GetType() == Property::VECTOR3 ); @@ -337,9 +308,39 @@ int UtcDaliPropertyValueConstructors07P(void) END_TEST; } -int UtcDaliPropertyValueConstructors08P(void) +int UtcDaliPropertyValueConstructorsVector3TypeP(void) +{ + Property::Value value( Property::VECTOR3 ); + + DALI_TEST_CHECK( value.GetType() == Property::VECTOR3 ); + DALI_TEST_CHECK( value.Get() == Vector3() ); + + END_TEST; +} + +int UtcDaliPropertyValueConstructorsVector4P(void) +{ + Vector4 v(1.f,1.f,1.f,0.9f); + Property::Value value(v); + + DALI_TEST_CHECK( value.GetType() == Property::VECTOR4 ); + DALI_TEST_CHECK( value.Get() == v ); + + END_TEST; +} + +int UtcDaliPropertyValueConstructorsVector4TypeP(void) +{ + Property::Value value( Property::VECTOR4 ); + + DALI_TEST_CHECK( value.GetType() == Property::VECTOR4 ); + DALI_TEST_CHECK( value.Get() == Vector4() ); + + END_TEST; +} + +int UtcDaliPropertyValueConstructorsMatrix3P(void) { - TestApplication application; Matrix3 v(1.0,1.0,1.0, 1.0,1.0,1.0, 1.0,1.0,1.0); Property::Value value(v); @@ -349,9 +350,18 @@ int UtcDaliPropertyValueConstructors08P(void) END_TEST; } -int UtcDaliPropertyValueConstructors09P(void) +int UtcDaliPropertyValueConstructorsMatrix3TypeP(void) +{ + Property::Value value( Property::MATRIX3 ); + + DALI_TEST_CHECK( value.GetType() == Property::MATRIX3 ); + DALI_TEST_CHECK( value.Get() == Matrix3() ); + + END_TEST; +} + +int UtcDaliPropertyValueConstructorsMatrixP(void) { - TestApplication application; float a[] = {1.0,1.0,1.0,1.0, 1.0,1.0,1.0,1.0, 1.0,1.0,1.0,1.0, 1.0,1.0,1.0,1.0}; Matrix v(a); Property::Value value(v); @@ -362,35 +372,52 @@ int UtcDaliPropertyValueConstructors09P(void) END_TEST; } -int UtcDaliPropertyValueConstructors10P(void) +int UtcDaliPropertyValueConstructorsMatrixTypeP(void) +{ + Property::Value value( Property::MATRIX ); + + DALI_TEST_CHECK( value.GetType() == Property::MATRIX ); + DALI_TEST_CHECK( value.Get() == Matrix() ); + + END_TEST; +} + +int UtcDaliPropertyValueConstructorsRectP(void) { - TestApplication application; Rect v(1.0,1.0,1.0,1.0); Property::Value value(v); - DALI_TEST_CHECK( value.GetType() == Property::RECTANGLE ); + DALI_TEST_EQUALS( value.GetType(), Property::RECTANGLE, TEST_LOCATION ); DALI_TEST_CHECK( value.Get >() == v ); END_TEST; } -int UtcDaliPropertyValueConstructors11P(void) +int UtcDaliPropertyValueConstructorsRectTypeP(void) { - TestApplication application; - AngleAxis v(Degree(1.0), Vector3(1.0,1.0,1.0)); - Property::Value value(v); + Property::Value value( Property::RECTANGLE ); + + DALI_TEST_CHECK( value.GetType() == Property::RECTANGLE ); + DALI_TEST_CHECK( value.Get >() == Rect(0,0,0,0) ); + + END_TEST; +} + +int UtcDaliPropertyValueConstructorsAngleAxisP(void) +{ + AngleAxis input( Dali::ANGLE_90, Vector3::XAXIS ); + Property::Value value( input ); DALI_TEST_CHECK( value.GetType() == Property::ROTATION ); - AngleAxis got = value.Get(); - DALI_TEST_CHECK( got.angle == v.angle ); - DALI_TEST_CHECK( got.axis == v.axis ); + AngleAxis result = value.Get(); + DALI_TEST_EQUALS( result.angle, input.angle, TEST_LOCATION ); + DALI_TEST_EQUALS( result.axis, input.axis, TEST_LOCATION ); END_TEST; } -int UtcDaliPropertyValueConstructors12P(void) +int UtcDaliPropertyValueConstructorsQuaternionP(void) { - TestApplication application; Quaternion v( Vector4(1.0,1.0,1.0,1.0) ); Property::Value value(v); @@ -400,9 +427,20 @@ int UtcDaliPropertyValueConstructors12P(void) END_TEST; } -int UtcDaliPropertyValueConstructors13P(void) +int UtcDaliPropertyValueConstructorsRotationTypeP(void) +{ + Property::Value value( Property::ROTATION ); + + DALI_TEST_CHECK( value.GetType() == Property::ROTATION ); + AngleAxis result = value.Get(); + DALI_TEST_EQUALS( result.angle, Radian(0.f), TEST_LOCATION ); + DALI_TEST_EQUALS( result.axis, Vector3::ZERO, TEST_LOCATION ); // identity quaternion returns a zero angle-axis + + END_TEST; +} + +int UtcDaliPropertyValueConstructorsStringP(void) { - TestApplication application; std::string v("1"); Property::Value value(v); @@ -412,991 +450,747 @@ int UtcDaliPropertyValueConstructors13P(void) END_TEST; } -int UtcDaliPropertyValueConstructors14P(void) +int UtcDaliPropertyValueConstructorsStringTypeP(void) { - TestApplication application; + Property::Value value( Property::STRING ); + + DALI_TEST_CHECK( value.GetType() == Property::STRING ); + DALI_TEST_CHECK( value.Get() == std::string() ); + + END_TEST; +} + +int UtcDaliPropertyValueConstructorsArrayP(void) +{ + Property::Array foo; + Property::Value value( foo ); + + DALI_TEST_CHECK( value.GetType() == Property::ARRAY ); + DALI_TEST_CHECK( value.Get().Count() == 0 ); + + END_TEST; +} + +int UtcDaliPropertyValueConstructorsArray2P(void) +{ + Property::Array foo; + foo.PushBack( Property::Value() ); + Property::Value value( foo ); + + DALI_TEST_CHECK( value.GetType() == Property::ARRAY ); + DALI_TEST_CHECK( value.Get().Count() == 1 ); + + END_TEST; +} +int UtcDaliPropertyValueConstructorsArrayTypeP(void) +{ Property::Value value(Property::ARRAY); - value.AppendItem(Property::Value(1)); DALI_TEST_CHECK( value.GetType() == Property::ARRAY ); - DALI_TEST_CHECK( value.GetSize() == 1); + DALI_TEST_CHECK( value.Get().Count() == 0 ); END_TEST; } -int UtcDaliPropertyValueConstructors15P(void) +int UtcDaliPropertyValueConstructorsMapP(void) { - TestApplication application; + Property::Map map; + Property::Value value( map ); + + DALI_TEST_CHECK( value.GetType() == Property::MAP ); + DALI_TEST_CHECK( value.Get().Count() == 0 ); + + END_TEST; +} + +int UtcDaliPropertyValueConstructorsMap2P(void) +{ + Property::Map map; + map.Insert( "", "" ); + Property::Value value( map ); + + DALI_TEST_CHECK( value.GetType() == Property::MAP ); + DALI_TEST_CHECK( value.Get().Count() == 1 ); + + END_TEST; +} +int UtcDaliPropertyValueConstructorsMapTypeP(void) +{ Property::Value value(Property::MAP); - value.SetValue("1", Property::Value(1)); DALI_TEST_CHECK( value.GetType() == Property::MAP ); - DALI_TEST_CHECK( value.GetSize() == 1); + DALI_TEST_CHECK( value.Get().Count() == 0 ); END_TEST; } -int UtcDaliPropertyValueCopyConstructor01P(void) +int UtcDaliPropertyValueCopyConstructorP(void) { - TestApplication application; - CheckCopyCtorP check(1.f); + Property::Value value; + Property::Value value2( value ); + DALI_TEST_EQUALS( value.GetType(), value2.GetType(), TEST_LOCATION ); + DALI_TEST_EQUALS( value.IsMap(), value2.IsMap(), TEST_LOCATION ); + DALI_TEST_EQUALS( value.IsArray(), value2.IsArray(), TEST_LOCATION ); END_TEST; } -int UtcDaliPropertyValueCopyConstructor02P(void) +int UtcDaliPropertyValueCopyConstructorBoolP(void) { - TestApplication application; CheckCopyCtorP check(true); END_TEST; } -int UtcDaliPropertyValueCopyConstructor03P(void) +int UtcDaliPropertyValueCopyConstructorFloatP(void) { - TestApplication application; CheckCopyCtorP check(1.f); END_TEST; } -int UtcDaliPropertyValueCopyConstructor04P(void) +int UtcDaliPropertyValueCopyConstructorIntP(void) { - TestApplication application; CheckCopyCtorP check(1); END_TEST; } -int UtcDaliPropertyValueCopyConstructor05P(void) +int UtcDaliPropertyValueCopyConstructorUnsignedIntP(void) { - TestApplication application; CheckCopyCtorP check(1u); END_TEST; } -int UtcDaliPropertyValueCopyConstructor06P(void) +int UtcDaliPropertyValueCopyConstructoVector2P(void) { - TestApplication application; - CheckCopyCtorP check( Vector2(1,1) ); + CheckCopyCtorP check( Vector2(2,1) ); END_TEST; } -int UtcDaliPropertyValueCopyConstructor07P(void) +int UtcDaliPropertyValueCopyConstructorVector3P(void) { - TestApplication application; - CheckCopyCtorP check( Vector3(1.0,1.0,1.0) ); + CheckCopyCtorP check( Vector3(3.f,2.f,1.f) ); END_TEST; } -int UtcDaliPropertyValueCopyConstructor08P(void) +int UtcDaliPropertyValueCopyConstructorVector4P(void) +{ + CheckCopyCtorP check( Vector4(4.f,3.f,2.f,1.f) ); + END_TEST; +} + +int UtcDaliPropertyValueCopyConstructorMatrix3P(void) { - TestApplication application; CheckCopyCtorP check( Matrix3::IDENTITY ); END_TEST; } -int UtcDaliPropertyValueCopyConstructor09P(void) +int UtcDaliPropertyValueCopyConstructorMatrixP(void) { - TestApplication application; CheckCopyCtorP check(Matrix::IDENTITY); END_TEST; } -int UtcDaliPropertyValueCopyConstructor10P(void) +int UtcDaliPropertyValueCopyConstructorRectP(void) { - TestApplication application; CheckCopyCtorP > check( Rect(1.0,1.0,1.0,1.0) ); END_TEST; } -int UtcDaliPropertyValueCopyConstructor11P(void) +int UtcDaliPropertyValueCopyConstructorAngleAxisP(void) { - TestApplication application; CheckCopyCtorP check( AngleAxis(Degree(1.0), Vector3(1.0,1.0,1.0)) ); END_TEST; } -int UtcDaliPropertyValueCopyConstructor12P(void) +int UtcDaliPropertyValueCopyConstructorQuaternionP(void) { - TestApplication application; CheckCopyCtorP check( Quaternion( Vector4(1.0, 1.0, 1.0, 1.0) ) ); END_TEST; } -int UtcDaliPropertyValueCopyConstructor13P(void) +int UtcDaliPropertyValueCopyConstructorStringP(void) { - TestApplication application; CheckCopyCtorP check( std::string("1") ); END_TEST; } -int UtcDaliPropertyValueCopyConstructor14P(void) +int UtcDaliPropertyValueCopyConstructorArrayP(void) { - TestApplication application; - Property::Array value; - value.PushBack(Property::Value(1)); - CheckCopyCtorP check(value); + Property::Value value1(Property::ARRAY); + Property::Array* array= value1.GetArray(); + array->PushBack(Property::Value(1)); + + Property::Value value2( value1 ); + DALI_TEST_EQUALS( value1.GetType(), value2.GetType(), TEST_LOCATION ); + DALI_TEST_EQUALS( value1.GetArray()->Count(), value2.GetArray()->Count(), TEST_LOCATION ); + END_TEST; } -int UtcDaliPropertyValueCopyConstructor15P(void) +int UtcDaliPropertyValueCopyConstructorMapP(void) { - TestApplication application; - Property::Map value; - value["1"] = Property::Value(1); - CheckCopyCtorP check(value); + Property::Value value1(Property::MAP); + Property::Map* map = value1.GetMap(); + (*map)["1"] = Property::Value(1); + + Property::Value value2( value1 ); + DALI_TEST_EQUALS( value1.GetType(), value2.GetType(), TEST_LOCATION ); + DALI_TEST_EQUALS( value1.GetMap()->Count(), value2.GetMap()->Count(), TEST_LOCATION ); + DALI_TEST_EQUALS( value1.GetMap()->GetKey( 0 ), value2.GetMap()->GetKey( 0 ), TEST_LOCATION ); + END_TEST; } - -int UtcDaliPropertyValueAssignmentOperator01P(void) +int UtcDaliPropertyValueAssignmentSelfP(void) { - TestApplication application; Property::Value value; - value = Property::Value(true); - { - Property::Value copy( false ); - copy = value; - DALI_TEST_CHECK( true == copy.Get() ); - } + Property::Value* self = &value; + value = *self; + DALI_TEST_EQUALS( value.GetType(), Property::NONE, TEST_LOCATION ); + DALI_TEST_EQUALS( value.IsMap(), false, TEST_LOCATION ); + DALI_TEST_EQUALS( value.IsArray(), false, TEST_LOCATION ); END_TEST; } - -int UtcDaliPropertyValueAssignmentOperator02P(void) +int UtcDaliPropertyValueAssignmentOperatorNoneP(void) { - TestApplication application; Property::Value value; - value = Property::Value(10.f); - { - Property::Value copy(false); - copy = value; - DALI_TEST_CHECK( Dali::Equals(10.f, copy.Get() ) ); - } + value = Property::Value(); // type match + DALI_TEST_EQUALS( value.GetType(), Property::NONE, TEST_LOCATION ); + Property::Value copy( false ); + copy = value; // type mismatch + DALI_TEST_EQUALS( value.GetType(), Property::NONE, TEST_LOCATION ); END_TEST; } -int UtcDaliPropertyValueAssignmentOperator03P(void) +int UtcDaliPropertyValueAssignmentOperatorBoolP(void) { - TestApplication application; Property::Value value; - value = Property::Value(10); - { - Property::Value copy(false); - copy = value; - DALI_TEST_CHECK( 10 == copy.Get() ); - } + value = Property::Value(true); // type mismatch + DALI_TEST_CHECK( true == value.Get() ); + Property::Value copy( false ); + copy = value; // type match + DALI_TEST_CHECK( true == copy.Get() ); END_TEST; } -int UtcDaliPropertyValueAssignmentOperator04P(void) +int UtcDaliPropertyValueAssignmentOperatorIntP(void) { - TestApplication application; Property::Value value; - value = Property::Value(10U); - { - Property::Value copy(false); - copy = value; - DALI_TEST_CHECK( 10 == copy.Get< unsigned int>() ); - } + value = Property::Value(10); // type mismatch + DALI_TEST_CHECK( 10 == value.Get() ); + Property::Value copy( 99 ); + copy = value; // type match + DALI_TEST_CHECK( 10 == copy.Get() ); END_TEST; } -int UtcDaliPropertyValueAssignmentOperator05P(void) +int UtcDaliPropertyValueAssignmentOperatorUnsignedIntP(void) { - TestApplication application; Property::Value value; - value = Property::Value( Vector2(1,1) ); - { - Property::Value copy(false); - copy = value; - DALI_TEST_CHECK( Vector2(1,1) == copy.Get() ); - } + value = Property::Value(10U); // type mismatch + DALI_TEST_CHECK( 10U == value.Get() ); + Property::Value copy( 123U); + copy = value; // type match + DALI_TEST_CHECK( 10U == copy.Get() ); END_TEST; } -int UtcDaliPropertyValueAssignmentOperator06P(void) +int UtcDaliPropertyValueAssignmentOperatorFloatP(void) { - TestApplication application; Property::Value value; - value = Property::Value( Vector3(1.f,1.f,1.f) ); - { - Property::Value copy(false); - copy = value; - DALI_TEST_CHECK( Vector3(1.f,1.f,1.f) == copy.Get() ); - } + value = Property::Value(10.f); // mismatch + DALI_TEST_CHECK( Dali::Equals(10.f, value.Get() ) ); + Property::Value copy(321.f); + copy = value; // match + DALI_TEST_CHECK( Dali::Equals(10.f, copy.Get() ) ); END_TEST; } -int UtcDaliPropertyValueAssignmentOperator07P(void) +int UtcDaliPropertyValueAssignmentOperatorVector2P(void) { - TestApplication application; Property::Value value; - value = Property::Value( Vector4(1,1,1,1) ); - { - Property::Value copy(false); - copy = value; - DALI_TEST_CHECK( Vector4(1,1,1,1) == copy.Get() ); - } + value = Property::Value( Vector2(1,2) ); // mismatch + DALI_TEST_CHECK( Vector2(1,2) == value.Get() ); + Property::Value copy( Property::VECTOR2 ); + copy = value; // match + DALI_TEST_CHECK( Vector2(1,2) == copy.Get() ); END_TEST; } -int UtcDaliPropertyValueAssignmentOperator08P(void) +int UtcDaliPropertyValueAssignmentOperatorVector3P(void) { - TestApplication application; Property::Value value; - value = Property::Value( Matrix3::IDENTITY ); - { - Property::Value copy(false); - copy = value; - DALI_TEST_CHECK( Matrix3::IDENTITY == copy.Get() ); - } + value = Property::Value( Vector3(1.f,2.f,3.f) ); // mismatch + DALI_TEST_CHECK( Vector3(1.f,2.f,3.f) == value.Get() ); + Property::Value copy( Property::VECTOR3 ); + copy = value; // match + DALI_TEST_CHECK( Vector3(1.f,2.f,3.f) == copy.Get() ); END_TEST; } -int UtcDaliPropertyValueAssignmentOperator09P(void) +int UtcDaliPropertyValueAssignmentOperatorVector4P(void) { - TestApplication application; Property::Value value; - value = Property::Value( Matrix::IDENTITY ); - { - Property::Value copy(false); - copy = value; - DALI_TEST_CHECK( Matrix::IDENTITY == copy.Get() ); - } + value = Property::Value( Vector4(1,2,3,4) ); // mismatch + DALI_TEST_CHECK( Vector4(1,2,3,4) == value.Get() ); + Property::Value copy( Vector4(0,1,2,3) ); + copy = value; // match + DALI_TEST_CHECK( Vector4(1,2,3,4) == copy.Get() ); END_TEST; } -int UtcDaliPropertyValueAssignmentOperator10P(void) +int UtcDaliPropertyValueAssignmentOperatorMatrix3P(void) { - TestApplication application; Property::Value value; - typedef Dali::Rect Rectangle; - - value = Property::Value( Rectangle(1,1,1,1) ); - { - Property::Value copy(false); - copy = value; - Rectangle copyRect; - copy.Get(copyRect); - DALI_TEST_CHECK( Rectangle(1,1,1,1) == copyRect); - } + value = Property::Value( Matrix3::IDENTITY ); // mismatch + DALI_TEST_CHECK( Matrix3::IDENTITY == value.Get() ); + Property::Value copy( Property::MATRIX3 ); + copy = value; // match + DALI_TEST_CHECK( Matrix3::IDENTITY == copy.Get() ); END_TEST; } -int UtcDaliPropertyValueAssignmentOperator11P(void) +int UtcDaliPropertyValueAssignmentOperatorMatrixP(void) { - TestApplication application; Property::Value value; - value = Property::Value( Quaternion(1,1,1,1) ); - { - Property::Value copy(false); - copy = value; - DALI_TEST_CHECK( Quaternion(1,1,1,1) == copy.Get() ); - } + value = Property::Value( Matrix::IDENTITY ); // mismatch + DALI_TEST_CHECK( Matrix::IDENTITY == value.Get() ); + Matrix foo; + Property::Value copy( foo ); + copy = value; // match + DALI_TEST_CHECK( Matrix::IDENTITY == copy.Get() ); END_TEST; } - -int UtcDaliPropertyValueAssignmentOperator12P(void) +int UtcDaliPropertyValueAssignmentOperatorRectP(void) { - TestApplication application; Property::Value value; - value = Property::Value( AngleAxis( Radian(Math::PI_2), Vector3::XAXIS )); - { - Property::Value copy(false); - copy = value; - DALI_TEST_CHECK( value.Get().axis == copy.Get().axis ); - DALI_TEST_CHECK( value.Get().angle == copy.Get().angle ); - } + typedef Dali::Rect Rectangle; + value = Property::Value( Rectangle(4,3,2,1) ); // mismatch + DALI_TEST_CHECK( Rectangle(4,3,2,1) == value.Get() ); + Property::Value copy( Property::RECTANGLE ); + copy = value; // match + Rectangle copyRect; + copy.Get(copyRect); + DALI_TEST_CHECK( Rectangle(4,3,2,1) == copyRect ); END_TEST; } -int UtcDaliPropertyValueAssignmentOperator13P(void) +int UtcDaliPropertyValueAssignmentOperatorQuaternionP(void) { - TestApplication application; Property::Value value; - value = Property::Value("yes"); - { - Property::Value copy(false); - copy = value; - DALI_TEST_CHECK( "yes" == copy.Get() ); - } + value = Property::Value( Quaternion(1,1,1,1) ); // mismatch + DALI_TEST_CHECK( Quaternion(1,1,1,1) == value.Get() ); + Property::Value copy( Property::ROTATION ); + copy = value; // match + DALI_TEST_CHECK( Quaternion(1,1,1,1) == copy.Get() ); END_TEST; } -int UtcDaliPropertyValueAssignmentOperator14P(void) + +int UtcDaliPropertyValueAssignmentOperatorAngleAxisP(void) { - TestApplication application; Property::Value value; - Property::Array array; - value = Property::Value(Property::ARRAY); - value.AppendItem(10); - { - Property::Value copy(false); - copy = value; - copy.Get( array ); - int getItem = 0; - array[0].Get( getItem ); - DALI_TEST_CHECK( getItem == 10 ); - } + value = Property::Value( AngleAxis( Radian(Math::PI_2), Vector3::XAXIS ) ); // mismatch + DALI_TEST_EQUALS( value.Get().axis, Vector3::XAXIS, TEST_LOCATION ); + DALI_TEST_EQUALS( value.Get().angle, Radian(Math::PI_2), TEST_LOCATION ); + Property::Value copy( Property::ROTATION ); + copy = value; // match + DALI_TEST_EQUALS( value.Get().axis, copy.Get().axis, TEST_LOCATION ); + DALI_TEST_EQUALS( value.Get().angle, copy.Get().angle, TEST_LOCATION ); END_TEST; } -int UtcDaliPropertyValueAssignmentOperator15P(void) +int UtcDaliPropertyValueAssignmentOperatorStringP(void) { - TestApplication application; Property::Value value; - Property::Map map; - value = Property::Value(Property::MAP); - value.SetValue("key", "value"); - { - Property::Value copy(false); - copy = value; - copy.Get( map ); - DALI_TEST_CHECK( map.GetKey(0) == "key" ); - } + value = Property::Value("yes"); // mismatch + DALI_TEST_CHECK( "yes" == value.Get() ); + Property::Value copy("no"); + copy = value; // match + DALI_TEST_CHECK( "yes" == copy.Get() ); END_TEST; } - -int UtcDaliPropertyValueGetTypeP(void) +int UtcDaliPropertyValueAssignmentOperatorArrayP(void) { - TestApplication application; - Property::Value value; - DALI_TEST_CHECK( value.GetType() == Property::NONE ); + value = Property::Value(Property::ARRAY); // mismatch + value.GetArray()->PushBack(10); + DALI_TEST_CHECK( value.GetArray() ); + Property::Value copy(Property::ARRAY); + copy = value; // match + Property::Array array; + copy.Get( array ); + int getItem = 0; + array[0].Get( getItem ); + DALI_TEST_CHECK( getItem == 10 ); END_TEST; } -int UtcDaliPropertyValueGet01P(void) +int UtcDaliPropertyValueAssignmentOperatorMapP(void) { - TestApplication application; - Property::Value value(true); - DALI_TEST_CHECK( value.Get() == true ); - value = Property::Value(1.f); - DALI_TEST_CHECK( value.Get() == 1.f ); + Property::Value value; + value = Property::Value(Property::MAP); // mismatch + value.GetMap()->Insert("key", "value"); + Property::Value copy( Property::MAP ); // match + copy = value; + Property::Map map; + copy.Get( map ); + DALI_TEST_CHECK( map.GetKey(0) == "key" ); END_TEST; } -int UtcDaliPropertyValueGet01N(void) +int UtcDaliPropertyValueGetTypeP(void) { - TestApplication application; - Property::Value value; - try - { - value.Get() == true; - tet_result(TET_FAIL); - } - catch( Dali::DaliException& e ) - { - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_ASSERT( e, "Property type invalid", TEST_LOCATION ); - } - catch( ... ) - { - tet_printf("Assertion test failed - wrong Exception\n" ); - tet_result(TET_FAIL); - } - + DALI_TEST_CHECK( value.GetType() == Property::NONE ); END_TEST; } -int UtcDaliPropertyValueGet02P(void) +int UtcDaliPropertyValueGetBoolP(void) { - TestApplication application; Property::Value value(true); DALI_TEST_CHECK( value.Get() == true ); + value = Property::Value(1.f); + DALI_TEST_CHECK( value.Get() == 1.f ); END_TEST; } -int UtcDaliPropertyValueGet02N(void) -{ - TestApplication application; - GetCheckN check; - END_TEST; -} - - -int UtcDaliPropertyValueGet03P(void) -{ - TestApplication application; - GetCheckP check(1.f); - END_TEST; -} - -int UtcDaliPropertyValueGet03N(void) -{ - TestApplication application; - GetCheckN check; - END_TEST; -} - -int UtcDaliPropertyValueGet04P(void) -{ - TestApplication application; - GetCheckP check(1); - END_TEST; -} - -int UtcDaliPropertyValueGet04N(void) +int UtcDaliPropertyValueGetBoolN(void) { - TestApplication application; - GetCheckN check; + Property::Value value; + DALI_TEST_CHECK( value.Get() == false ); END_TEST; } -int UtcDaliPropertyValueGet05P(void) +int UtcDaliPropertyValueGetFloatP(void) { - TestApplication application; - GetCheckP check(1u); + Property::Value value(1.1f); + DALI_TEST_EQUALS( 1.1f, value.Get(), TEST_LOCATION ); END_TEST; } -int UtcDaliPropertyValueGet05N(void) +int UtcDaliPropertyValueGetFloatN(void) { - TestApplication application; - GetCheckN check; + Property::Value value; + DALI_TEST_EQUALS( 0.0f, value.Get(), TEST_LOCATION ); END_TEST; } -int UtcDaliPropertyValueGet06P(void) +int UtcDaliPropertyValueGetIntP(void) { - TestApplication application; - GetCheckP > check(Rect(1,1,1,1)); + Property::Value value(123); + DALI_TEST_EQUALS( 123, value.Get(), TEST_LOCATION ); END_TEST; } -int UtcDaliPropertyValueGet06N(void) +int UtcDaliPropertyValueGetIntN(void) { - TestApplication application; - GetCheckN > check; + Property::Value value; + DALI_TEST_EQUALS( 0, value.Get(), TEST_LOCATION ); END_TEST; } -int UtcDaliPropertyValueGet07P(void) +int UtcDaliPropertyValueGetUnsignedIntP(void) { - TestApplication application; - GetCheckP check(Vector2(1.0,1.0)); + Property::Value value(123u); + DALI_TEST_EQUALS( 123u, value.Get(), TEST_LOCATION ); END_TEST; } -int UtcDaliPropertyValueGet07N(void) +int UtcDaliPropertyValueGetUnsignedIntN(void) { - TestApplication application; - GetCheckN check; + Property::Value value; + DALI_TEST_EQUALS( 0u, value.Get(), TEST_LOCATION ); END_TEST; } -int UtcDaliPropertyValueGet8P(void) +int UtcDaliPropertyValueGetRectP(void) { - TestApplication application; - GetCheckP check(Vector3(1.0,1.0,1.0)); + Property::Value value( Rect(1,2,3,4) ); + DALI_TEST_EQUALS( Rect(1,2,3,4), value.Get< Rect >(), TEST_LOCATION ); END_TEST; } -int UtcDaliPropertyValueGet08N(void) +int UtcDaliPropertyValueGetRectN(void) { - TestApplication application; - GetCheckN check; + Property::Value value; + DALI_TEST_EQUALS( Rect(0,0,0,0), value.Get< Rect >(), TEST_LOCATION ); END_TEST; } -int UtcDaliPropertyValueGet09P(void) +int UtcDaliPropertyValueGetVector2P(void) { - TestApplication application; - GetCheckP check(Vector4(1.0,1.0,1.0,1.0)); + Property::Value value( Vector2(1.0f,2.0f) ); + DALI_TEST_EQUALS( Vector2(1.0f,2.0f), value.Get< Vector2 >(), TEST_LOCATION ); END_TEST; } -int UtcDaliPropertyValueGet09N(void) +int UtcDaliPropertyValueGetVector2N(void) { - TestApplication application; - GetCheckN check; + Property::Value value; + DALI_TEST_EQUALS( Vector2(0.f,0.f), value.Get< Vector2 >(), TEST_LOCATION ); END_TEST; } -int UtcDaliPropertyValueGet10P(void) +int UtcDaliPropertyValueGetVector3P(void) { - TestApplication application; - GetCheckP check(Matrix3(Matrix3::IDENTITY)); + Property::Value value( Vector3(1.0f,2.0f,-1.f) ); + DALI_TEST_EQUALS( Vector3(1.0f,2.0f,-1.f), value.Get< Vector3 >(), TEST_LOCATION ); END_TEST; } -int UtcDaliPropertyValueGet10N(void) +int UtcDaliPropertyValueGetVector3N(void) { - TestApplication application; - GetCheckN check; + Property::Value value; + DALI_TEST_EQUALS( Vector3(0.f,0.f,0.f), value.Get< Vector3 >(), TEST_LOCATION ); END_TEST; } -int UtcDaliPropertyValueGet11P(void) +int UtcDaliPropertyValueGetVector4P(void) { - TestApplication application; - GetCheckP check(Matrix(Matrix::IDENTITY)); + Property::Value value( Vector4(1.f,2.f,-1.f,-3.f) ); + DALI_TEST_EQUALS( Vector4(1.f,2.f,-1.f,-3.f), value.Get< Vector4 >(), TEST_LOCATION ); END_TEST; } -int UtcDaliPropertyValueGet11N(void) +int UtcDaliPropertyValueGetVector4N(void) { - TestApplication application; - GetCheckN check; + Property::Value value; + DALI_TEST_EQUALS( Vector4(0.f,0.f,0.f,0.f), value.Get< Vector4 >(), TEST_LOCATION ); END_TEST; } -int UtcDaliPropertyValueGet12P(void) +int UtcDaliPropertyValueGetMatrix3P(void) { - TestApplication application; - AngleAxis a(Degree(1.0), Vector3(1.0,1.0,1.0)); - Property::Value v(a); - AngleAxis b = v.Get(); - DALI_TEST_CHECK(a.angle == b.angle); - DALI_TEST_CHECK(a.axis == b.axis); + Property::Value value( Matrix3(1.f,2.f,3.f,4.f,5.f,6.f,7.f,8.f,9.f) ); + DALI_TEST_EQUALS( Matrix3(1.f,2.f,3.f,4.f,5.f,6.f,7.f,8.f,9.f), value.Get< Matrix3 >(), TEST_LOCATION ); END_TEST; } -int UtcDaliPropertyValueGet12N(void) +int UtcDaliPropertyValueGetMatrix3N(void) { - TestApplication application; - GetCheckN check; + Property::Value value; + DALI_TEST_EQUALS( Matrix3::IDENTITY, value.Get< Matrix3 >(), TEST_LOCATION ); END_TEST; } -int UtcDaliPropertyValueGet13P(void) +int UtcDaliPropertyValueGetMatrixP(void) { - TestApplication application; - GetCheckP check(Quaternion(1.0,1.0,1.0,1.0)); + float matrixValues[16] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 }; + Matrix input( matrixValues ); + Property::Value value( input ); + DALI_TEST_EQUALS( input, value.Get< Matrix >(), TEST_LOCATION ); END_TEST; } -int UtcDaliPropertyValueGet13N(void) +int UtcDaliPropertyValueGetMatrixN(void) { - TestApplication application; - GetCheckN check; + Property::Value value; + DALI_TEST_EQUALS( Matrix::IDENTITY, value.Get< Matrix >(), TEST_LOCATION ); END_TEST; } -int UtcDaliPropertyValueGet14P(void) +int UtcDaliPropertyValueGetAngleAxisP(void) { - TestApplication application; - GetCheckP check(std::string("astring")); + AngleAxis input( Dali::ANGLE_90, Vector3::XAXIS ); + Property::Value value( input ); + AngleAxis result = value.Get(); + DALI_TEST_EQUALS( input.angle, result.angle, TEST_LOCATION ); + DALI_TEST_EQUALS( input.axis, result.axis, TEST_LOCATION ); END_TEST; } -int UtcDaliPropertyValueGet14N(void) +int UtcDaliPropertyValueGetAngleAxisN(void) { - TestApplication application; - GetCheckN check; + Property::Value value; + AngleAxis b = value.Get(); + DALI_TEST_EQUALS( 0.f, b.angle, TEST_LOCATION ); + DALI_TEST_EQUALS( Vector3::ZERO, b.axis, TEST_LOCATION ); END_TEST; } -int UtcDaliPropertyValueGet15P(void) +int UtcDaliPropertyValueGetQuaternionP(void) { - TestApplication application; - Property::Value a(Property::ARRAY); - a.AppendItem(Property::Value(1)); - Property::Array got = a.Get(); - DALI_TEST_CHECK(got[0].Get() == 1); + Property::Value value( Quaternion(1.f,2.f,3.f,4.f) ); + DALI_TEST_EQUALS( Quaternion(1.f,2.f,3.f,4.f), value.Get< Quaternion >(), TEST_LOCATION ); END_TEST; } -int UtcDaliPropertyValueGet15N(void) +int UtcDaliPropertyValueGetQuaternionN(void) { - TestApplication application; - GetCheckN check; + Property::Value value; + DALI_TEST_EQUALS( Quaternion::IDENTITY, value.Get< Quaternion >(), TEST_LOCATION ); END_TEST; } -int UtcDaliPropertyValueGet16P(void) +int UtcDaliPropertyValueGetStringP(void) { - TestApplication application; - Property::Value a(Property::MAP); - a.SetValue("key", Property::Value(1)); - Property::Map got = a.Get(); - DALI_TEST_CHECK(got.GetValue(0).Get() == 1); + Property::Value value( std::string("hello") ); + DALI_TEST_EQUALS( std::string("hello"), value.Get< std::string >(), TEST_LOCATION ); END_TEST; } -int UtcDaliPropertyValueGet16N(void) +int UtcDaliPropertyValueGetStringN(void) { - TestApplication application; - GetCheckN check; + Property::Value value; + DALI_TEST_EQUALS( std::string(""), value.Get< std::string >(), TEST_LOCATION ); END_TEST; } -int UtcDaliPropertyValueGetValueP(void) +int UtcDaliPropertyValueGetArrayP(void) { - TestApplication application; - Property::Value map(Property::MAP); - Property::Value a(1); - map.SetValue("key", a); - DALI_TEST_CHECK( map.GetValue("key").Get() == 1 ); + Property::Value value( Property::ARRAY ); + DALI_TEST_CHECK( NULL != value.GetArray() ); + value.GetArray()->PushBack( Property::Value(1) ); + Property::Array got = value.Get(); + DALI_TEST_CHECK( got[0].Get() == 1); END_TEST; } -int UtcDaliPropertyValueGetValue01N(void) +int UtcDaliPropertyValueGetArrayN(void) { - TestApplication application; - Property::Value value(1); - - try - { - Property::Value got = value.GetValue("key"); - tet_result(TET_FAIL); - } - catch( Dali::DaliException& e ) - { - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_ASSERT( e, "Property type invalid", TEST_LOCATION ); - } - catch( ... ) - { - tet_printf("Assertion test failed - wrong Exception\n" ); - tet_result(TET_FAIL); - } - + Property::Value value; + DALI_TEST_CHECK( NULL == value.GetArray() ); + Property::Array array; + array.PushBack( Property::Value( 10 ) ); + value.Get( array ); + DALI_TEST_CHECK( 0 == array.Count() ); END_TEST; } -int UtcDaliPropertyValueGetValue02N(void) +int UtcDaliPropertyValueGetMapP(void) { - TestApplication application; Property::Value value(Property::MAP); - value.SetValue("key", Property::Value(1)); - - try - { - Property::Value got = value.GetValue("nokey"); - tet_result(TET_FAIL); - } - catch( Dali::DaliException& e ) - { - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_ASSERT( e, "Cannot find property map key", TEST_LOCATION ); - } - catch( ... ) - { - tet_printf("Assertion test failed - wrong Exception\n" ); - tet_result(TET_FAIL); - } - - END_TEST; -} - -int UtcDaliPropertyValueHasKeyP(void) -{ - TestApplication application; - Property::Value map(Property::MAP); - Property::Value a(1); - map.SetValue("key", a); - DALI_TEST_CHECK( map.HasKey("key") == true ); - DALI_TEST_CHECK( map.HasKey("key2") == false ); - END_TEST; -} - -int UtcDaliPropertyValueHasKeyN(void) -{ - TestApplication application; - Property::Value a(1); - DALI_TEST_CHECK( a.HasKey("key") == false ); - END_TEST; -} - -int UtcDaliPropertyValueGetKeyP(void) -{ - TestApplication application; - Property::Value map(Property::MAP); - Property::Value a(1); - map.SetValue("key", a); - std::string empty; - DALI_TEST_CHECK( map.GetKey(-1) == empty ); - DALI_TEST_CHECK( map.GetKey(1) == empty ); + DALI_TEST_CHECK( NULL == value.GetArray() ); + DALI_TEST_CHECK( NULL != value.GetMap() ); + value.GetMap()->Insert("key", Property::Value(1)); + Property::Map got = value.Get(); + DALI_TEST_CHECK(got.Find("key")->Get() == 1); END_TEST; } -int UtcDaliPropertyValueGetKeyN(void) +int UtcDaliPropertyValueGetMapN(void) { - TestApplication application; - Property::Value a(1); - std::string empty; - DALI_TEST_CHECK( a.GetKey(0) == empty ); - END_TEST; -} - -int UtcDaliPropertyValueSetValueP(void) -{ - TestApplication application; - Property::Value map(Property::MAP); - Property::Value a(1); - map.SetValue("key", a); - DALI_TEST_CHECK( map.GetValue("key").Get() == 1 ); - END_TEST; -} - -int UtcDaliPropertyValueSetValueN(void) -{ - TestApplication application; - Property::Value value(1); - - try - { - value.SetValue("key", Property::Value(1)); - tet_result(TET_FAIL); - } - catch( Dali::DaliException& e ) - { - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_ASSERT( e, "Property type invalid", TEST_LOCATION ); - } - catch( ... ) - { - tet_printf("Assertion test failed - wrong Exception\n" ); - tet_result(TET_FAIL); - } - - END_TEST; -} - -int UtcDaliPropertyValueGetItem01P(void) -{ - TestApplication application; - Property::Value value(Property::ARRAY); - value.AppendItem(Property::Value(0)); - value.SetItem(0, Property::Value(1)); - DALI_TEST_CHECK( value.GetItem(0).Get() == 1 ); - - value = Property::Value(Property::MAP); - value.SetValue("key", Property::Value(0)); - value.SetItem(0, Property::Value(1)); - DALI_TEST_CHECK( value.GetItem(0).Get() == 1 ); - + Property::Value value; + DALI_TEST_CHECK( NULL == value.GetMap() ); + Property::Map map = value.Get(); + DALI_TEST_CHECK( 0 == map.Count() ); END_TEST; } -int UtcDaliPropertyValueGetItem01N(void) +int UtcDaliPropertyValueOutputStream(void) { TestApplication application; + tet_infoline("Testing Property::Value output stream"); + typedef Dali::Rect Rectangle; - Property::Value value(1); - - try - { - Property::Value item = value.GetItem(0); - tet_result(TET_FAIL); - } - catch( Dali::DaliException& e ) - { - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_ASSERT( e, "Cannot GetItem on property Type; not a container", TEST_LOCATION ); - } - catch( ... ) + Property::Value value(true); { - tet_printf("Assertion test failed - wrong Exception\n" ); - tet_result(TET_FAIL); + std::ostringstream stream; + stream << value; + DALI_TEST_CHECK( stream.str() == "1" ) } - END_TEST; -} - -int UtcDaliPropertyValueGetItem02P(void) -{ - TestApplication application; - Property::Value value(Property::ARRAY); - value.AppendItem(Property::Value(0)); - value.SetItem(0, Property::Value(1)); - std::string key; - DALI_TEST_CHECK( value.GetItem(0, key).Get() == 1 ); - DALI_TEST_CHECK( key.size() == 0u ); - - value = Property::Value(Property::MAP); - value.SetValue("key", Property::Value(0)); - value.SetItem(0, Property::Value(1)); - DALI_TEST_CHECK( value.GetItem(0, key).Get() == 1 ); - DALI_TEST_CHECK( key.size() == 3 ); - DALI_TEST_CHECK( key == std::string("key") ); - - END_TEST; -} - -int UtcDaliPropertyValueGetItem02N(void) -{ - TestApplication application; - - Property::Value value(1); - std::string key; - try - { - Property::Value item = value.GetItem(0, key); - tet_result(TET_FAIL); - } - catch( Dali::DaliException& e ) - { - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_ASSERT( e, "Cannot GetItem on property Type; not a container", TEST_LOCATION ); - } - catch( ... ) { - tet_printf("Assertion test failed - wrong Exception\n" ); - tet_result(TET_FAIL); - } - - END_TEST; -} - -int UtcDaliPropertyValueSetItemP(void) -{ - TestApplication application; - - Property::Value value(Property::ARRAY); - value.AppendItem(Property::Value(0)); - value.SetItem(0, Property::Value(1)); - DALI_TEST_CHECK( value.GetItem(0).Get() == 1 ); - - value = Property::Value(Property::MAP); - value.SetValue("key", Property::Value(0)); - value.SetItem(0, Property::Value(1)); - DALI_TEST_CHECK( value.GetItem(0).Get() == 1 ); - - END_TEST; -} - -int UtcDaliPropertyValueSetItemN(void) -{ - TestApplication application; - - Property::Value value(1); - - try - { - value.SetItem(0, Property::Value(2)); - tet_result(TET_FAIL); - } - catch( Dali::DaliException& e ) - { - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_ASSERT( e, "Cannot SetItem on property Type; not a container", TEST_LOCATION ); - } - catch( ... ) - { - tet_printf("Assertion test failed - wrong Exception\n" ); - tet_result(TET_FAIL); + Property::Value empty; + std::ostringstream stream; + stream << empty; + DALI_TEST_EQUALS( stream.str(), "empty type", TEST_LOCATION ); } - END_TEST; -} - -int UtcDaliPropertyValueAppendItemP(void) -{ - TestApplication application; - - Property::Value value(Property::ARRAY); - value.AppendItem(Property::Value(1)); - DALI_TEST_CHECK( value.GetItem(0).Get() == 1 ); - - END_TEST; -} - -int UtcDaliPropertyValueAppendItemN(void) -{ - TestApplication application; - - Property::Value value(1); - - try - { - Property::Value item = value.AppendItem(Property::Value(1)); - tet_result(TET_FAIL); - } - catch( Dali::DaliException& e ) - { - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_ASSERT( e, "Property type invalid", TEST_LOCATION ); - } - catch( ... ) { - tet_printf("Assertion test failed - wrong Exception\n" ); - tet_result(TET_FAIL); + Property::Value empty( Property::NONE ); + std::ostringstream stream; + stream << empty; + DALI_TEST_CHECK( stream.str() == "undefined type" ) } - END_TEST; -} - - -int UtcDaliPropertyValueOutputStream(void) -{ - TestApplication application; - tet_infoline("Testing Property::Value output stream"); - typedef Dali::Rect Rectangle; - - Property::Value value(true); { + Property::Value empty( Property::TYPE_COUNT ); std::ostringstream stream; - stream << value; - DALI_TEST_CHECK( stream.str() == "1") + stream << empty; + DALI_TEST_CHECK( stream.str() == "undefined type" ) } { value = Property::Value(20.2f); std::ostringstream stream; stream << value; - DALI_TEST_CHECK( stream.str() == "20.2") + DALI_TEST_CHECK( stream.str() == "20.2" ) } { value = Property::Value(-25); std::ostringstream stream; stream << value; - DALI_TEST_CHECK( stream.str() == "-25") + DALI_TEST_CHECK( stream.str() == "-25" ) } { value = Property::Value(25U); std::ostringstream stream; stream << value; - DALI_TEST_CHECK( stream.str() == "25") + DALI_TEST_CHECK( stream.str() == "25" ) } { value = Property::Value( Vector2(1.f,1.f) ); std::ostringstream stream; stream << value; - DALI_TEST_CHECK( stream.str() == "[1, 1]"); + DALI_TEST_CHECK( stream.str() == "[1, 1]" ); } { value = Property::Value( Vector3(1.f,1.f,1.f) ); std::ostringstream stream; stream << value; - DALI_TEST_CHECK( stream.str() == "[1, 1, 1]"); + DALI_TEST_CHECK( stream.str() == "[1, 1, 1]" ); + } + + { + value = Property::Value( Vector4(-4.f,-3.f,-2.f,-1.f) ); + std::ostringstream stream; + stream << value; + DALI_TEST_EQUALS( stream.str(), "[-4, -3, -2, -1]", TEST_LOCATION ); } { value = Property::Value( Matrix3::IDENTITY ); std::ostringstream stream; stream << value; - DALI_TEST_CHECK( stream.str() == "[ [1, 0, 0], [0, 1, 0], [0, 0, 1] ]"); + DALI_TEST_CHECK( stream.str() == "[ [1, 0, 0], [0, 1, 0], [0, 0, 1] ]" ); } { value = Property::Value( Matrix::IDENTITY ); std::ostringstream stream; stream << value; - DALI_TEST_CHECK( stream.str() == "[ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ]"); + DALI_TEST_CHECK( stream.str() == "[ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ]" ); } { value = Property::Value( Rectangle(1,2,3,4) ); std::ostringstream stream; stream << value; - DALI_TEST_CHECK( stream.str() == "[1, 2, 3, 4]"); + DALI_TEST_CHECK( stream.str() == "[1, 2, 3, 4]" ); } { - value = Property::Value( AngleAxis( Radian(1.2f), Vector3::XAXIS )); + value = Property::Value( AngleAxis( Dali::ANGLE_120, Vector3::XAXIS ) ); std::ostringstream stream; stream << value; tet_printf("angle axis = %s \n", stream.str().c_str() ); - DALI_TEST_CHECK( stream.str() == "[1.2, -0, 0, 0]"); + DALI_TEST_EQUALS( stream.str(), "[ Axis: [1, 0, 0], Angle: 120 degrees ]", TEST_LOCATION ); + } + + { + value = Property::Value( std::string( "Foo" ) ); + std::ostringstream stream; + stream << value; + DALI_TEST_CHECK( stream.str() == "Foo" ); } // Maps and arrays currently not supported, we just check a message is output @@ -1415,7 +1209,5 @@ int UtcDaliPropertyValueOutputStream(void) DALI_TEST_CHECK( !stream.str().empty() ); } - END_TEST; - } diff --git a/automated-tests/src/dali/utc-Dali-ShaderEffect.cpp b/automated-tests/src/dali/utc-Dali-ShaderEffect.cpp index ddbf86d..dd3c774 100644 --- a/automated-tests/src/dali/utc-Dali-ShaderEffect.cpp +++ b/automated-tests/src/dali/utc-Dali-ShaderEffect.cpp @@ -946,7 +946,7 @@ int UtcDaliShaderBinaries(void) END_TEST; } -int UtcDaliShaderEffectFromProperties01(void) +int UtcDaliShaderEffectFromPropertiesP(void) { TestApplication application; tet_infoline("UtcDaliShaderEffectFromProperties01()"); @@ -969,21 +969,25 @@ int UtcDaliShaderEffectFromProperties01(void) ShaderEffect effect = ShaderEffect::DownCast( typeInfo.CreateInstance() ); DALI_TEST_CHECK( effect ); - Property::Value programMap = Property::Value(Property::MAP); + Property::Value programValue = Property::Value(Property::MAP); + Property::Map* programMap = programValue.GetMap(); + DALI_TEST_CHECK( programMap ); - programMap.SetValue("vertex", vertexShader); - programMap.SetValue("fragment", fragmentShader); + programMap->Insert("vertex", vertexShader); + programMap->Insert("fragment", fragmentShader); - programMap.SetValue("vertex-prefix", vertexShaderPrefix); - programMap.SetValue("fragment-prefix", fragmentShaderPrefix); + programMap->Insert("vertex-prefix", vertexShaderPrefix); + programMap->Insert("fragment-prefix", fragmentShaderPrefix); - programMap.SetValue("geometry-type", "GEOMETRY_TYPE_IMAGE"); + programMap->Insert("geometry-type", "GEOMETRY_TYPE_IMAGE"); - effect.SetProperty(effect.GetPropertyIndex("program"), programMap); + effect.SetProperty(effect.GetPropertyIndex("program"), programValue); - Property::Value imageMap = Property::Value(Property::MAP); - imageMap.SetValue("filename", Property::Value(TestImageFilename)); - effect.SetProperty(effect.GetPropertyIndex("image"), imageMap); + Property::Value imageValue = Property::Value(Property::MAP); + Property::Map* imageMap = imageValue.GetMap(); + DALI_TEST_CHECK( imageMap ); + imageMap->Insert("filename", Property::Value(TestImageFilename)); + effect.SetProperty(effect.GetPropertyIndex("image"), imageValue); // do a update & render to get the image request application.SendNotification(); @@ -1021,7 +1025,7 @@ int UtcDaliShaderEffectFromProperties01(void) END_TEST; } -int UtcDaliShaderEffectFromProperties02(void) +int UtcDaliShaderEffectFromPropertiesN(void) { try { @@ -1031,8 +1035,6 @@ int UtcDaliShaderEffectFromProperties02(void) // Call render to compile default shaders. application.SendNotification(); application.Render(); - application.Render(); - application.Render(); // create from type registry (currently only way to get ShaderEffect with no shader setup in constructor TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( "ShaderEffect" ); @@ -1040,16 +1042,15 @@ int UtcDaliShaderEffectFromProperties02(void) ShaderEffect effect = ShaderEffect::DownCast( typeInfo.CreateInstance() ); DALI_TEST_CHECK( effect ); - Property::Value programMap = Property::Value(Property::MAP); - - programMap.SetValue("vertex", std::string(VertexSource)); - programMap.SetValue("fragment", std::string(FragmentSource)); + Property::Value programValue = Property::Value(Property::MAP); + Property::Map* programMap = programValue.GetMap(); + DALI_TEST_CHECK( programMap ); - // programMap.SetValue("geometry-type", "GEOMETRY_TYPE_IMAGE"); - // dont set by value - programMap.SetValue("geometry-type", GeometryType( GEOMETRY_TYPE_IMAGE )); + programMap->Insert("vertex", std::string(VertexSource)); + programMap->Insert("fragment", std::string(FragmentSource)); - effect.SetProperty(effect.GetPropertyIndex("program"), programMap); + // use wrong index on purpose + effect.SetProperty(effect.GetPropertyIndex("program") + 1, programValue ); tet_result( TET_FAIL ); } @@ -1060,7 +1061,7 @@ int UtcDaliShaderEffectFromProperties02(void) END_TEST; } -int UtcDaliShaderEffectFromProperties03(void) +int UtcDaliShaderEffectFromProperties2N(void) { try { @@ -1070,8 +1071,6 @@ int UtcDaliShaderEffectFromProperties03(void) // Call render to compile default shaders. application.SendNotification(); application.Render(); - application.Render(); - application.Render(); // create from type registry (currently only way to get ShaderEffect with no shader setup in constructor TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( "ShaderEffect" ); diff --git a/dali/devel-api/scripting/scripting.cpp b/dali/devel-api/scripting/scripting.cpp index 636874a..be86108 100644 --- a/dali/devel-api/scripting/scripting.cpp +++ b/dali/devel-api/scripting/scripting.cpp @@ -39,8 +39,26 @@ namespace { // Tables used here for converting strings to the enumerations and vice versa +struct AnchorValue +{ + const char* name; + const Vector3 value; +}; +const AnchorValue ANCHOR_CONSTANT_TABLE[] = +{ + { "TOP_LEFT", ParentOrigin::TOP_LEFT }, + { "TOP_CENTER", ParentOrigin::TOP_CENTER }, + { "TOP_RIGHT", ParentOrigin::TOP_RIGHT }, + { "CENTER_LEFT", ParentOrigin::CENTER_LEFT }, + { "CENTER", ParentOrigin::CENTER }, + { "CENTER_RIGHT", ParentOrigin::CENTER_RIGHT }, + { "BOTTOM_LEFT", ParentOrigin::BOTTOM_LEFT }, + { "BOTTOM_CENTER", ParentOrigin::BOTTOM_CENTER }, + { "BOTTOM_RIGHT", ParentOrigin::BOTTOM_RIGHT }, +}; +const unsigned int ANCHOR_CONSTANT_TABLE_COUNT = sizeof( ANCHOR_CONSTANT_TABLE ) / sizeof( ANCHOR_CONSTANT_TABLE[0] ); -const StringEnum< ColorMode > COLOR_MODE_TABLE[] = +const StringEnum COLOR_MODE_TABLE[] = { { "USE_OWN_COLOR", USE_OWN_COLOR }, { "USE_PARENT_COLOR", USE_PARENT_COLOR }, @@ -49,7 +67,7 @@ const StringEnum< ColorMode > COLOR_MODE_TABLE[] = }; const unsigned int COLOR_MODE_TABLE_COUNT = sizeof( COLOR_MODE_TABLE ) / sizeof( COLOR_MODE_TABLE[0] ); -const StringEnum< PositionInheritanceMode > POSITION_INHERITANCE_MODE_TABLE[] = +const StringEnum POSITION_INHERITANCE_MODE_TABLE[] = { { "INHERIT_PARENT_POSITION", INHERIT_PARENT_POSITION }, { "USE_PARENT_POSITION", USE_PARENT_POSITION }, @@ -58,7 +76,7 @@ const StringEnum< PositionInheritanceMode > POSITION_INHERITANCE_MODE_TABLE[] = }; const unsigned int POSITION_INHERITANCE_MODE_TABLE_COUNT = sizeof( POSITION_INHERITANCE_MODE_TABLE ) / sizeof( POSITION_INHERITANCE_MODE_TABLE[0] ); -const StringEnum< DrawMode::Type > DRAW_MODE_TABLE[] = +const StringEnum DRAW_MODE_TABLE[] = { { "NORMAL", DrawMode::NORMAL }, { "OVERLAY", DrawMode::OVERLAY }, @@ -66,35 +84,21 @@ const StringEnum< DrawMode::Type > DRAW_MODE_TABLE[] = }; const unsigned int DRAW_MODE_TABLE_COUNT = sizeof( DRAW_MODE_TABLE ) / sizeof( DRAW_MODE_TABLE[0] ); -const StringEnum< Vector3 > ANCHOR_CONSTANT_TABLE[] = -{ - { "TOP_LEFT", ParentOrigin::TOP_LEFT }, - { "TOP_CENTER", ParentOrigin::TOP_CENTER }, - { "TOP_RIGHT", ParentOrigin::TOP_RIGHT }, - { "CENTER_LEFT", ParentOrigin::CENTER_LEFT }, - { "CENTER", ParentOrigin::CENTER }, - { "CENTER_RIGHT", ParentOrigin::CENTER_RIGHT }, - { "BOTTOM_LEFT", ParentOrigin::BOTTOM_LEFT }, - { "BOTTOM_CENTER", ParentOrigin::BOTTOM_CENTER }, - { "BOTTOM_RIGHT", ParentOrigin::BOTTOM_RIGHT }, -}; -const unsigned int ANCHOR_CONSTANT_TABLE_COUNT = sizeof( ANCHOR_CONSTANT_TABLE ) / sizeof( ANCHOR_CONSTANT_TABLE[0] ); - -const StringEnum< ResourceImage::LoadPolicy > IMAGE_LOAD_POLICY_TABLE[] = +const StringEnum IMAGE_LOAD_POLICY_TABLE[] = { { "IMMEDIATE", ResourceImage::IMMEDIATE }, { "ON_DEMAND", ResourceImage::ON_DEMAND }, }; const unsigned int IMAGE_LOAD_POLICY_TABLE_COUNT = sizeof( IMAGE_LOAD_POLICY_TABLE ) / sizeof( IMAGE_LOAD_POLICY_TABLE[0] ); -const StringEnum< Image::ReleasePolicy > IMAGE_RELEASE_POLICY_TABLE[] = +const StringEnum IMAGE_RELEASE_POLICY_TABLE[] = { { "UNUSED", Image::UNUSED }, { "NEVER", Image::NEVER }, }; const unsigned int IMAGE_RELEASE_POLICY_TABLE_COUNT = sizeof( IMAGE_RELEASE_POLICY_TABLE ) / sizeof( IMAGE_RELEASE_POLICY_TABLE[0] ); -const StringEnum< Pixel::Format > PIXEL_FORMAT_TABLE[] = +const StringEnum PIXEL_FORMAT_TABLE[] = { { "A8", Pixel::A8 }, { "L8", Pixel::L8 }, @@ -125,7 +129,7 @@ const StringEnum< Pixel::Format > PIXEL_FORMAT_TABLE[] = }; const unsigned int PIXEL_FORMAT_TABLE_COUNT = sizeof( PIXEL_FORMAT_TABLE ) / sizeof( PIXEL_FORMAT_TABLE[0] ); -const StringEnum< FittingMode::Type > IMAGE_FITTING_MODE_TABLE[] = +const StringEnum IMAGE_FITTING_MODE_TABLE[] = { { "SHRINK_TO_FIT", FittingMode::SHRINK_TO_FIT }, { "SCALE_TO_FILL", FittingMode::SCALE_TO_FILL }, @@ -134,7 +138,7 @@ const StringEnum< FittingMode::Type > IMAGE_FITTING_MODE_TABLE[] = }; const unsigned int IMAGE_FITTING_MODE_TABLE_COUNT = sizeof( IMAGE_FITTING_MODE_TABLE ) / sizeof( IMAGE_FITTING_MODE_TABLE[0] ); -const StringEnum< SamplingMode::Type > IMAGE_SAMPLING_MODE_TABLE[] = +const StringEnum IMAGE_SAMPLING_MODE_TABLE[] = { { "BOX", SamplingMode::BOX }, { "NEAREST", SamplingMode::NEAREST }, @@ -146,7 +150,9 @@ const StringEnum< SamplingMode::Type > IMAGE_SAMPLING_MODE_TABLE[] = }; const unsigned int IMAGE_SAMPLING_MODE_TABLE_COUNT = sizeof( IMAGE_SAMPLING_MODE_TABLE ) / sizeof( IMAGE_SAMPLING_MODE_TABLE[0] ); -} // unnamed namespace +const char* ImageTypeName[] = { "ResourceImage", "FrameBufferImage", "BufferImage" }; +enum ImageType { RESOURCE_IMAGE, FRAME_BUFFER_IMAGE, BUFFER_IMAGE }; +const unsigned int imageTypeCount = sizeof( ImageTypeName ) / sizeof( const char* ); bool CompareEnums( const char * a, const char * b ) { @@ -190,187 +196,260 @@ bool CompareEnums( const char * a, const char * b ) return false; } +} // unnamed namespace + +unsigned int FindEnumIndex( const char* value, const StringEnum* table, unsigned int tableCount ) +{ + unsigned int index = 0; + bool found = false; + for ( unsigned int i = 0; i < tableCount; ++i, ++index ) + { + if( CompareEnums( value, table->string ) ) + { + found = true; + break; + } + ++table; + } + if ( !found ) + { + DALI_LOG_ERROR( "Unknown enumeration string %s\n", value ); + } + return index; +} ColorMode GetColorMode( const std::string& value ) { - return GetEnumeration< ColorMode >( value.c_str(), COLOR_MODE_TABLE, COLOR_MODE_TABLE_COUNT ); + // return default on error + ColorMode mode( USE_OWN_MULTIPLY_PARENT_ALPHA ); + GetEnumeration< ColorMode >( value.c_str(), COLOR_MODE_TABLE, COLOR_MODE_TABLE_COUNT, mode ); + return mode; } std::string GetColorMode( ColorMode value ) { - return GetEnumerationName< ColorMode >( value, COLOR_MODE_TABLE, COLOR_MODE_TABLE_COUNT ); + const char* name = GetEnumerationName< ColorMode >( value, COLOR_MODE_TABLE, COLOR_MODE_TABLE_COUNT ); + if( name ) + { + return std::string( name ); + } + return std::string(); } PositionInheritanceMode GetPositionInheritanceMode( const std::string& value ) { - return GetEnumeration< PositionInheritanceMode >( value.c_str(), POSITION_INHERITANCE_MODE_TABLE, POSITION_INHERITANCE_MODE_TABLE_COUNT ); + // return default on error + PositionInheritanceMode mode( INHERIT_PARENT_POSITION ); + GetEnumeration< PositionInheritanceMode >( value.c_str(), POSITION_INHERITANCE_MODE_TABLE, POSITION_INHERITANCE_MODE_TABLE_COUNT, mode ); + return mode; } std::string GetPositionInheritanceMode( PositionInheritanceMode value ) { - return GetEnumerationName< PositionInheritanceMode >( value, POSITION_INHERITANCE_MODE_TABLE, POSITION_INHERITANCE_MODE_TABLE_COUNT ); + const char* name = GetEnumerationName< PositionInheritanceMode >( value, POSITION_INHERITANCE_MODE_TABLE, POSITION_INHERITANCE_MODE_TABLE_COUNT ); + if( name ) + { + return std::string( name ); + } + return std::string(); } DrawMode::Type GetDrawMode( const std::string& value ) { - return GetEnumeration< DrawMode::Type >( value.c_str(), DRAW_MODE_TABLE, DRAW_MODE_TABLE_COUNT ); + // return default on error + DrawMode::Type mode( DrawMode::NORMAL ); + GetEnumeration< DrawMode::Type >( value.c_str(), DRAW_MODE_TABLE, DRAW_MODE_TABLE_COUNT, mode ); + return mode; } std::string GetDrawMode( DrawMode::Type value ) { - return GetEnumerationName< DrawMode::Type >( value, DRAW_MODE_TABLE, DRAW_MODE_TABLE_COUNT ); + const char* name = GetEnumerationName< DrawMode::Type >( value, DRAW_MODE_TABLE, DRAW_MODE_TABLE_COUNT ); + if( name ) + { + return std::string( name ); + } + return std::string(); } Vector3 GetAnchorConstant( const std::string& value ) { - return GetEnumeration< Vector3 >( value.c_str(), ANCHOR_CONSTANT_TABLE, ANCHOR_CONSTANT_TABLE_COUNT ); + for( unsigned int i = 0; i < ANCHOR_CONSTANT_TABLE_COUNT; ++i ) + { + if( CompareEnums( value.c_str(), ANCHOR_CONSTANT_TABLE[ i ].name ) ) + { + return ANCHOR_CONSTANT_TABLE[ i ].value; + } + } + return Vector3(); } -Image NewImage( const Property::Value& map ) +Image NewImage( const Property::Value& property ) { Image ret; std::string filename; - ResourceImage::LoadPolicy loadPolicy = Dali::Internal::IMAGE_LOAD_POLICY_DEFAULT; - Image::ReleasePolicy releasePolicy = Dali::Internal::IMAGE_RELEASE_POLICY_DEFAULT; + ResourceImage::LoadPolicy loadPolicy = Dali::Internal::IMAGE_LOAD_POLICY_DEFAULT; + Image::ReleasePolicy releasePolicy = Dali::Internal::IMAGE_RELEASE_POLICY_DEFAULT; Internal::ImageAttributes attributes = Internal::ImageAttributes::New(); - if( Property::MAP == map.GetType() ) + const Property::Map* map = property.GetMap(); + ImageType imageType = RESOURCE_IMAGE; // default to resource image + if( map ) { - std::string field = "filename"; - if( map.HasKey(field) ) + // first check the type as it determines, which other parameters are needed + const Property::Value* value = map->Find( "type" ); + if( value ) + { + std::string type; + value->Get( type ); + for( unsigned int i = 0; i < imageTypeCount; ++i ) + { + if( 0 == type.compare( ImageTypeName[ i ] ) ) + { + imageType = static_cast( i ); + break; + } + } + } + + // filename is only needed for resource images + if( RESOURCE_IMAGE == imageType ) { - DALI_ASSERT_ALWAYS(map.GetValue(field).GetType() == Property::STRING && "Image filename property is not a string" ); - filename = map.GetValue(field).Get(); + const Property::Value* value = map->Find( "filename" ); + if( value ) + { + value->Get( filename ); + } + // if empty file, no need to go further + if( filename.size() == 0 ) + { + DALI_LOG_ERROR( "No filename\n" ); + return Image(); + } } - field = "load-policy"; - if( map.HasKey(field) ) + value = map->Find( "load-policy" ); + if( value ) { - DALI_ASSERT_ALWAYS(map.GetValue(field).GetType() == Property::STRING && "Image load-policy property is not a string" ); - std::string v(map.GetValue(field).Get()); - loadPolicy = GetEnumeration< ResourceImage::LoadPolicy >( v.c_str(), IMAGE_LOAD_POLICY_TABLE, IMAGE_LOAD_POLICY_TABLE_COUNT ); + std::string policy; + value->Get( policy ); + // keep default value on error + GetEnumeration< ResourceImage::LoadPolicy >( policy.c_str(), IMAGE_LOAD_POLICY_TABLE, IMAGE_LOAD_POLICY_TABLE_COUNT, loadPolicy ); } - field = "release-policy"; - if( map.HasKey(field) ) + value = map->Find( "release-policy" ); + if( value ) { - DALI_ASSERT_ALWAYS(map.GetValue(field).GetType() == Property::STRING && "Image release-policy property is not a string" ); - std::string v(map.GetValue(field).Get()); - releasePolicy = GetEnumeration< Image::ReleasePolicy >( v.c_str(), IMAGE_RELEASE_POLICY_TABLE, IMAGE_RELEASE_POLICY_TABLE_COUNT ); + std::string policy; + value->Get( policy ); + // keep default value on error + GetEnumeration< Image::ReleasePolicy >( policy.c_str(), IMAGE_RELEASE_POLICY_TABLE, IMAGE_RELEASE_POLICY_TABLE_COUNT, releasePolicy ); } // Width and height can be set individually. Dali derives the unspecified // dimension from the aspect ratio of the raw image. unsigned int width = 0, height = 0; - field = "width"; - if( map.HasKey( field ) ) + value = map->Find( "width" ); + if( value ) { - Property::Value &value = map.GetValue( field ); - // handle floats and integer the same for json script - if( value.GetType() == Property::FLOAT ) + if( value->GetType() == Property::FLOAT ) { - width = static_cast( value.Get() ); + width = static_cast( value->Get() ); } else { - DALI_ASSERT_ALWAYS( value.GetType() == Property::INTEGER && "Image width property is not a number" ); - width = value.Get(); + value->Get( width ); } } - - field = "height"; - if( map.HasKey( field ) ) + value = map->Find( "height" ); + if( value ) { - Property::Value &value = map.GetValue( field ); - if( value.GetType() == Property::FLOAT ) + if( value->GetType() == Property::FLOAT ) { - height = static_cast( value.Get() ); + height = static_cast( value->Get() ); } else { - DALI_ASSERT_ALWAYS( value.GetType() == Property::INTEGER && "Image width property is not a number" ); - height = value.Get(); + value->Get( height ); } } - attributes.SetSize( width, height ); - field = "pixel-format"; Pixel::Format pixelFormat = Pixel::RGBA8888; - if( map.HasKey(field) ) + value = map->Find( "pixel-format" ); + if( value ) { - DALI_ASSERT_ALWAYS( map.GetValue(field).GetType() == Property::STRING && "Image release-policy property is not a string" ); - std::string s( map.GetValue(field).Get() ); - pixelFormat = GetEnumeration< Pixel::Format >( s.c_str(), PIXEL_FORMAT_TABLE, PIXEL_FORMAT_TABLE_COUNT ); + std::string format; + value->Get( format ); + GetEnumeration< Pixel::Format >( format.c_str(), PIXEL_FORMAT_TABLE, PIXEL_FORMAT_TABLE_COUNT, pixelFormat ); } - field = "fitting-mode"; - if( map.HasKey( field ) ) + value = map->Find( "fitting-mode" ); + if( value ) { - Property::Value& value = map.GetValue( field ); - DALI_ASSERT_ALWAYS( value.GetType() == Property::STRING && "Image fitting-mode property is not a string" ); - std::string s( value.Get() ); - attributes.SetScalingMode( GetEnumeration< FittingMode::Type >( s.c_str(), IMAGE_FITTING_MODE_TABLE, IMAGE_FITTING_MODE_TABLE_COUNT ) ); + std::string fitting; + value->Get( fitting ); + FittingMode::Type mode; + if( GetEnumeration< FittingMode::Type >( fitting.c_str(), IMAGE_FITTING_MODE_TABLE, IMAGE_FITTING_MODE_TABLE_COUNT, mode ) ) + { + attributes.SetScalingMode( mode ); + } } - field = "sampling-mode"; - if( map.HasKey( field ) ) + value = map->Find( "sampling-mode" ); + if( value ) { - Property::Value& value = map.GetValue( field ); - DALI_ASSERT_ALWAYS( value.GetType() == Property::STRING && "Image sampling-mode property is not a string" ); - std::string s( value.Get() ); - attributes.SetFilterMode( GetEnumeration< SamplingMode::Type >( s.c_str(), IMAGE_SAMPLING_MODE_TABLE, IMAGE_SAMPLING_MODE_TABLE_COUNT ) ); + std::string sampling; + value->Get( sampling ); + SamplingMode::Type mode; + if( GetEnumeration< SamplingMode::Type >( sampling.c_str(), IMAGE_SAMPLING_MODE_TABLE, IMAGE_SAMPLING_MODE_TABLE_COUNT, mode ) ) + { + attributes.SetFilterMode( mode ); + } } - field = "orientation"; - if( map.HasKey( field ) ) + value = map->Find( "orientation" ); + if( value ) { - Property::Value& value = map.GetValue( field ); - DALI_ASSERT_ALWAYS( value.GetType() == Property::BOOLEAN && "Image orientation property is not a boolean" ); - bool b = value.Get(); + bool b = value->Get(); attributes.SetOrientationCorrection( b ); } - if( map.HasKey("type") ) + switch( imageType ) { - DALI_ASSERT_ALWAYS( map.GetValue("type").GetType() == Property::STRING ); - std::string s(map.GetValue("type").Get()); - if("FrameBufferImage" == s) - { - ret = FrameBufferImage::New(attributes.GetWidth(), - attributes.GetHeight(), - pixelFormat, - releasePolicy); - } - else if("BufferImage" == s) + case RESOURCE_IMAGE : { - ret = BufferImage::New(attributes.GetWidth(), - attributes.GetHeight(), - pixelFormat, - releasePolicy); + ret = ResourceImage::New( filename, loadPolicy, releasePolicy, + ImageDimensions( attributes.GetSize().x, attributes.GetSize().y ), + attributes.GetScalingMode(), attributes.GetFilterMode(), attributes.GetOrientationCorrection() ); + break; } - else if("ResourceImage" == s) + case BUFFER_IMAGE : { - ret = ResourceImage::New( filename, loadPolicy, releasePolicy, ImageDimensions( attributes.GetSize().x, attributes.GetSize().y ), attributes.GetScalingMode(), attributes.GetFilterMode(), attributes.GetOrientationCorrection() ); + ret = BufferImage::New( attributes.GetWidth(), + attributes.GetHeight(), + pixelFormat, + releasePolicy ); + break; } - else + case FRAME_BUFFER_IMAGE : { - DALI_ASSERT_ALWAYS( !"Unknown image type" ); + ret = FrameBufferImage::New( attributes.GetWidth(), + attributes.GetHeight(), + pixelFormat, + releasePolicy ); + break; } } - else - { - ret = ResourceImage::New( filename, loadPolicy, releasePolicy, ImageDimensions( attributes.GetSize().x, attributes.GetSize().y ), attributes.GetScalingMode(), attributes.GetFilterMode(), attributes.GetOrientationCorrection() ); - } } return ret; @@ -378,46 +457,47 @@ Image NewImage( const Property::Value& map ) } // Image NewImage( Property::Value map ) -ShaderEffect NewShaderEffect( const Property::Value& map ) +ShaderEffect NewShaderEffect( const Property::Value& property ) { Internal::ShaderEffectPtr ret; - if( map.GetType() == Property::MAP ) + const Property::Map* map = property.GetMap(); + if( map ) { - ret = Internal::ShaderEffect::New(Dali::ShaderEffect::HINT_NONE); // hint can be reset if in map + ret = Internal::ShaderEffect::New( Dali::ShaderEffect::HINT_NONE ); // hint can be reset if in map - if( map.HasKey("program") ) + const Property::Value* value = map->Find( "program" ); + if( value ) { - Property::Index index = ret->GetPropertyIndex("program"); - DALI_ASSERT_DEBUG( map.GetValue("program").GetType() == Property::MAP ); - ret->SetProperty(index, map.GetValue("program")); + Property::Index index = ret->GetPropertyIndex( "program" ); + ret->SetProperty( index, *value ); } - for(int i = 0; i < map.GetSize(); ++i) + for( unsigned int i = 0; i < map->Count(); ++i ) { - const std::string& key = map.GetKey(i); - if(key != "program") + const std::string& key = map->GetKey( i ); + if( key != "program" ) { Property::Index index = ret->GetPropertyIndex( key ); + const Property::Value& value = map->GetValue( i ); if( Property::INVALID_INDEX != index ) { - ret->SetProperty(index, map.GetItem(i)); + ret->SetProperty( index, value ); } else { // if its not a property then register it as a uniform (making a custom property) - - if(map.GetItem(i).GetType() == Property::INTEGER) + if( value.GetType() == Property::INTEGER ) { // valid uniforms are floats, vec3's etc so we recast if the user accidentally // set as integer. Note the map could have come from json script. - Property::Value asFloat( static_cast( map.GetItem(i).Get() ) ); + Property::Value asFloat( static_cast( value.Get() ) ); ret->SetUniform( key, asFloat, Dali::ShaderEffect::COORDINATE_TYPE_DEFAULT ); } else { - ret->SetUniform( key, map.GetItem(i), Dali::ShaderEffect::COORDINATE_TYPE_DEFAULT ); + ret->SetUniform( key, value, Dali::ShaderEffect::COORDINATE_TYPE_DEFAULT ); } } } @@ -445,7 +525,7 @@ Actor NewActor( const Property::Map& map ) if ( !handle ) { - DALI_LOG_ERROR( "Actor type not provided, returning empty handle" ); + DALI_LOG_ERROR( "Actor type not provided\n" ); return Actor(); } @@ -468,17 +548,12 @@ Actor NewActor( const Property::Map& map ) if ( key == "actors" ) { // Create children - Property::Array actorArray = value.Get< Property::Array >(); - for ( size_t i = 0; i < actorArray.Size(); ++i) + for ( Property::Array::SizeType i = 0; i < actorArray.Size(); ++i) { actor.Add( NewActor( actorArray[i].Get< Property::Map >() ) ); } } - else if ( key == "signals" ) - { - DALI_LOG_ERROR( "signals not supported" ); - } else if( key == "parent-origin" ) { // Parent Origin can be a string constant as well as a Vector3 @@ -597,34 +672,6 @@ void CreatePropertyMap( Image image, Property::Map& map ) } } - -DALI_IMPORT_API bool SetRotation( const Property::Value& value, Quaternion& quaternion ) -{ - bool done = false; - Property::Type type = value.GetType(); - if( Property::VECTOR3 == type ) - { - Vector3 v3; - value.Get(v3); - quaternion.SetEuler( Radian(Degree(v3.x)), Radian(Degree(v3.y)), Radian(Degree(v3.z)) ); - done = true; - } - else if( Property::VECTOR4 == type ) - { - Vector4 v4; - value.Get(v4); - quaternion = Quaternion(v4); - done = true; - } - else if( Property::ROTATION == type ) - { - value.Get(quaternion); - done = true; - } - - return done; -} - } // namespace scripting } // namespace Dali diff --git a/dali/devel-api/scripting/scripting.h b/dali/devel-api/scripting/scripting.h index b0cd9ad..40787de 100644 --- a/dali/devel-api/scripting/scripting.h +++ b/dali/devel-api/scripting/scripting.h @@ -40,46 +40,21 @@ namespace Scripting /** * @brief Template structure which stores an enumeration and its string equivalent. */ -template< typename T > struct StringEnum { const char* string; ///< The string representation - const T value; ///< The actual enumeration + const int value; ///< The enumeration value wrapped in int }; /** - * @brief Permissive comparison for string enums. - * - * Case insensitive and ignores '_', '-' in either string when comparing. - * - * @note If both strings are empty return true; - * - * @param[in] a The first string - * @param[in] b The string to compare - * @return true if the strings are equal as defined above. If both empty, then return true. - */ -DALI_IMPORT_API bool CompareEnums( const char * a, const char * b ); - -/** - * @brief Set the value if strings pass a permissive compare. + * @brief Find the given enum index from the table * - * @param[in] a The input string - * @param[in] b The string to compare - * @param[in] set The variable to set - * @param[in] value The value to set - * @return true if the strings pass the permissive compare + * @param[in] value The string equivalent (case-insensitive). + * @param[in] table A pointer to an array with the enumeration to string equivalents. + * @param[in] tableCount Number of items in the array. + * @return The index of the enumeration. If enumeration is not found, logs an error and returns tableCount. */ -template -bool SetIfEqual(const char * a, const char * b, T& set, const T& value) -{ - if( CompareEnums( a, b ) ) - { - set = value; - return true; - } - - return false; -} +DALI_IMPORT_API unsigned int FindEnumIndex( const char* value, const StringEnum* table, unsigned int tableCount ); /** * @brief Chooses the appropriate enumeration for the provided string from the given table. @@ -87,26 +62,24 @@ bool SetIfEqual(const char * a, const char * b, T& set, const T& value) * @param[in] value The string equivalent (case-insensitive). * @param[in] table A pointer to an array with the enumeration to string equivalents. * @param[in] tableCount Number of items in the array. + * @param[out] result The enum value * - * @return The equivalent enumeration for the given string. + * @return True if the value was found from the table */ template< typename T > -T GetEnumeration( const char * value, const StringEnum< T >* table, unsigned int tableCount ) +bool GetEnumeration( const char* value, const StringEnum* table, unsigned int tableCount, T& result ) { - T retVal( table->value ); - bool set( false ); - - for ( unsigned int i = 0; ( i < tableCount ) && ( !set ); ++i ) - { - set = SetIfEqual( value, table->string, retVal, table->value ); - ++table; - } - - if ( !set ) + bool retVal( false ); + if( table ) { - DALI_ASSERT_ALWAYS( !"Unknown enumeration string" ); + unsigned int index = FindEnumIndex( value, table, tableCount ); + // check to avoid crash, not asserting on purpose, error is logged instead + if( index < tableCount ) + { + result = static_cast( table[ index ].value ); + retVal = true; + } } - return retVal; } @@ -122,16 +95,18 @@ T GetEnumeration( const char * value, const StringEnum< T >* table, unsigned int * @note The caller is NOT responsible for cleaning up the returned pointer as it is statically allocated. */ template< typename T > -const char * GetEnumerationName( T value, const StringEnum< T >* table, unsigned int tableCount ) +const char* GetEnumerationName( T value, const StringEnum* table, unsigned int tableCount ) { - for ( unsigned int i = 0; i < tableCount; ++i ) + if( table ) { - if ( value == table[ i ].value ) + for ( unsigned int i = 0; i < tableCount; ++i ) { - return table[ i ].string; + if ( value == T(table[ i ].value) ) + { + return table[ i ].string; + } } } - return NULL; } @@ -148,14 +123,13 @@ const char * GetEnumerationName( T value, const StringEnum< T >* table, unsigned * @note The caller is NOT responsible for cleaning up the returned pointer as it is statically allocated. */ template< typename T > -const char * GetLinearEnumerationName( T value, const StringEnum< T >* table, unsigned int tableCount ) +const char * GetLinearEnumerationName( T value, const StringEnum* table, unsigned int tableCount ) { - if ( value < 0 || value >= (int)tableCount ) + if ( table && ( value > 0 || value <= (int)tableCount ) ) { - return NULL; + return table[value].string; } - - return table[value].string; + return NULL; } /** @@ -217,7 +191,7 @@ DALI_IMPORT_API Vector3 GetAnchorConstant( const std::string& value ); /** * @brief Creates object with data from the property value map. * - * @param[in] map The property value map with the following valid fields: + * @param[in] property The property value map with the following valid fields: * @code * "filename": type std::string * "load-policy" type std::string (enum) @@ -234,12 +208,12 @@ DALI_IMPORT_API Vector3 GetAnchorConstant( const std::string& value ); * * @return a pointer to a newly created object. */ -DALI_IMPORT_API Image NewImage( const Property::Value& map ); +DALI_IMPORT_API Image NewImage( const Property::Value& property ); /** * @brief Creates object with data from the property value map. * - * @param[in] map The property value map with the following valid fields: + * @param[in] property The property value map with the following valid fields: * @code * // a program can be specified as string or a filename. * // some fields may be ignored depending on the geometry-type @@ -267,7 +241,7 @@ DALI_IMPORT_API Image NewImage( const Property::Value& map ); * * @return a pointer to a newly created object. */ -DALI_IMPORT_API ShaderEffect NewShaderEffect( const Property::Value& map ); +DALI_IMPORT_API ShaderEffect NewShaderEffect( const Property::Value& property ); /** * @brief Creates an actor with the date from the property value map. @@ -311,15 +285,6 @@ DALI_IMPORT_API void CreatePropertyMap( Actor actor, Property::Map& map ); */ DALI_IMPORT_API void CreatePropertyMap( Image image, Property::Map& map ); -/** - * @brief Sets a quaterion rotation from a script provided value (quaternion,euler vector3,quaternion vector4) - * - * @param[in] value Propery value - * @param[out] quaternion Output Rotation - * @return true if quaternion was set - */ -DALI_IMPORT_API bool SetRotation( const Property::Value& value, Quaternion& quaternion ); - } } // namespace Dali diff --git a/dali/internal/event/actors/actor-impl.cpp b/dali/internal/event/actors/actor-impl.cpp index a6bee0a..2f48fed 100644 --- a/dali/internal/event/actors/actor-impl.cpp +++ b/dali/internal/event/actors/actor-impl.cpp @@ -279,18 +279,15 @@ float GetDimensionValue( const Vector2& values, Dimension::Type dimension ) { return values.width; } - case Dimension::HEIGHT: { return values.height; } - default: { break; } } - return 0.0f; } @@ -306,6 +303,7 @@ float GetDimensionValue( const Vector3& values, Dimension::Type dimension ) return GetDimensionValue( values.GetVectorXY(), dimension ); } + } // unnamed namespace ActorPtr Actor::New() @@ -2882,19 +2880,31 @@ void Actor::SetDefaultProperty( Property::Index index, const Property::Value& pr case Dali::Actor::Property::WIDTH_RESIZE_POLICY: { - SetResizePolicy( Scripting::GetEnumeration< ResizePolicy::Type >( property.Get< std::string >().c_str(), ResizePolicy::TypeTable, ResizePolicy::TypeTableCount ), Dimension::WIDTH ); + ResizePolicy::Type type; + if( Scripting::GetEnumeration< ResizePolicy::Type >( property.Get< std::string >().c_str(), ResizePolicy::TypeTable, ResizePolicy::TypeTableCount, type ) ) + { + SetResizePolicy( type, Dimension::WIDTH ); + } break; } case Dali::Actor::Property::HEIGHT_RESIZE_POLICY: { - SetResizePolicy( Scripting::GetEnumeration< ResizePolicy::Type >( property.Get< std::string >().c_str(), ResizePolicy::TypeTable, ResizePolicy::TypeTableCount ), Dimension::HEIGHT ); + ResizePolicy::Type type; + if( Scripting::GetEnumeration< ResizePolicy::Type >( property.Get< std::string >().c_str(), ResizePolicy::TypeTable, ResizePolicy::TypeTableCount, type ) ) + { + SetResizePolicy( type, Dimension::HEIGHT ); + } break; } case Dali::Actor::Property::SIZE_SCALE_POLICY: { - SetSizeScalePolicy( Scripting::GetEnumeration< SizeScalePolicy::Type >( property.Get< std::string >().c_str(), SizeScalePolicy::TypeTable, SizeScalePolicy::TypeTableCount ) ); + SizeScalePolicy::Type type; + if( Scripting::GetEnumeration< SizeScalePolicy::Type >( property.Get< std::string >().c_str(), SizeScalePolicy::TypeTable, SizeScalePolicy::TypeTableCount, type ) ) + { + SetSizeScalePolicy( type ); + } break; } diff --git a/dali/internal/event/animation/linear-constrainer-impl.cpp b/dali/internal/event/animation/linear-constrainer-impl.cpp index 22c9dfe..593e62b 100644 --- a/dali/internal/event/animation/linear-constrainer-impl.cpp +++ b/dali/internal/event/animation/linear-constrainer-impl.cpp @@ -24,6 +24,8 @@ // INTERNAL INCLUDES #include #include +#include + namespace Dali { @@ -113,47 +115,59 @@ Property::Type LinearConstrainer::GetDefaultPropertyType(Property::Index index) Property::Value LinearConstrainer::GetDefaultProperty( Property::Index index ) const { - Property::Value value; if( index == Dali::LinearConstrainer::Property::VALUE ) { - value = Property::Value(Property::ARRAY); + Property::Value value( Property::ARRAY ); + Property::Array* array = value.GetArray(); + DALI_ASSERT_DEBUG( array ); // should always exist in this case size_t count( mValue.Size() ); + array->Reserve( count ); for( size_t i( 0 ); i != count; ++i ) { - value.AppendItem( mValue[i] ); + array->PushBack( mValue[i] ); } + return value; } else if( index == Dali::LinearConstrainer::Property::PROGRESS ) { - value = Property::Value(Property::ARRAY); + Property::Value value( Property::ARRAY ); + Property::Array* array = value.GetArray(); + DALI_ASSERT_DEBUG( array ); // should always exist in this case size_t count( mValue.Size() ); + array->Reserve( count ); for( size_t i( 0 ); i != count; ++i ) { - value.AppendItem( mProgress[i] ); + array->PushBack( mProgress[i] ); } + return value; } - return value; + return Property::Value(); } -void LinearConstrainer::SetDefaultProperty(Property::Index index, const Property::Value& propertyValue) +void LinearConstrainer::SetDefaultProperty( Property::Index index, const Property::Value& propertyValue ) { - if( index == Dali::LinearConstrainer::Property::VALUE ) + const Property::Array* array = propertyValue.GetArray(); + if( array ) { - size_t propertyArrayCount = propertyValue.GetSize(); - mValue.Resize( propertyArrayCount ); - for( size_t i(0); i != propertyArrayCount; ++i ) + size_t propertyArrayCount = array->Count(); + if( index == Dali::LinearConstrainer::Property::VALUE ) { - propertyValue.GetItem(i).Get( mValue[i] ); + mValue.Clear(); // remove old values + mValue.Resize( propertyArrayCount ); + for( size_t i(0); i != propertyArrayCount; ++i ) + { + array->GetElementAt( i ).Get( mValue[ i ] ); + } } - } - else if( index == Dali::LinearConstrainer::Property::PROGRESS ) - { - size_t propertyArrayCount = propertyValue.GetSize(); - mProgress.Resize( propertyArrayCount ); - for( size_t i(0); i != propertyArrayCount; ++i ) + else if( index == Dali::LinearConstrainer::Property::PROGRESS ) { - propertyValue.GetItem(i).Get( mProgress[i] ); + mProgress.Clear(); // remove old values + mProgress.Resize( propertyArrayCount ); + for( size_t i(0); i != propertyArrayCount; ++i ) + { + array->GetElementAt( i ).Get( mProgress[ i ] ); + } } } } diff --git a/dali/internal/event/animation/path-constrainer-impl.cpp b/dali/internal/event/animation/path-constrainer-impl.cpp index 7e5111c..4c45fe5 100644 --- a/dali/internal/event/animation/path-constrainer-impl.cpp +++ b/dali/internal/event/animation/path-constrainer-impl.cpp @@ -116,36 +116,44 @@ Property::Type PathConstrainer::GetDefaultPropertyType(Property::Index index) co Property::Value PathConstrainer::GetDefaultProperty( Property::Index index ) const { - Property::Value value; if( index == Dali::PathConstrainer::Property::FORWARD ) { - value = Property::Value( mForward ); + return Property::Value( mForward ); } - else if( index == Dali::PathConstrainer::Property::POINTS ) + else { - value = Property::Value(Property::ARRAY); - const Dali::Vector& point = mPath->GetPoints(); - size_t pointCount( point.Size() ); - for( size_t i( 0 ); i != pointCount; ++i ) + if( index == Dali::PathConstrainer::Property::POINTS ) { - value.AppendItem( point[i] ); + Property::Value value( Property::ARRAY ); + Property::Array* array = value.GetArray(); + const Dali::Vector& point = mPath->GetPoints(); + Property::Array::SizeType pointCount = point.Size(); + array->Reserve( pointCount ); + for( Property::Array::SizeType i = 0; i < pointCount; ++i ) + { + array->PushBack( point[i] ); + } + return value; } - } - else if( index == Dali::PathConstrainer::Property::CONTROL_POINTS ) - { - value = Property::Value(Property::ARRAY); - const Dali::Vector& point = mPath->GetControlPoints(); - size_t pointCount( point.Size() ); - for( size_t i( 0 ); i != pointCount; ++i ) + else if( index == Dali::PathConstrainer::Property::CONTROL_POINTS ) { - value.AppendItem( point[i] ); + Property::Value value( Property::ARRAY ); + Property::Array* array = value.GetArray(); + const Dali::Vector& point = mPath->GetControlPoints(); + Property::Array::SizeType pointCount = point.Size(); + array->Reserve( pointCount ); + for( Property::Array::SizeType i = 0; i < pointCount; ++i ) + { + array->PushBack( point[i] ); + } + return value; } } - return value; + return Property::Value(); } -void PathConstrainer::SetDefaultProperty(Property::Index index, const Property::Value& propertyValue) +void PathConstrainer::SetDefaultProperty( Property::Index index, const Property::Value& propertyValue ) { if( index == Dali::PathConstrainer::Property::FORWARD ) { @@ -153,25 +161,31 @@ void PathConstrainer::SetDefaultProperty(Property::Index index, const Property:: } else if( index == Dali::PathConstrainer::Property::POINTS ) { - size_t propertyArrayCount = propertyValue.GetSize(); - Dali::Vector point; - point.Resize( propertyArrayCount ); - for( size_t i(0); i != propertyArrayCount; ++i ) + const Property::Array* array = propertyValue.GetArray(); + mPath->ClearPoints(); + if( array ) { - propertyValue.GetItem(i).Get( point[i] ); + for( Property::Array::SizeType i = 0, count = array->Count(); i < count; ++i ) + { + Vector3 point; + array->GetElementAt( i ).Get( point ); + mPath->AddPoint( point ); + } } - mPath->SetPoints( point ); } else if( index == Dali::PathConstrainer::Property::CONTROL_POINTS ) { - size_t propertyArrayCount = propertyValue.GetSize(); - Dali::Vector point; - point.Resize( propertyArrayCount ); - for( size_t i(0); i != propertyArrayCount; ++i ) + const Property::Array* array = propertyValue.GetArray(); + mPath->ClearControlPoints(); + if( array ) { - propertyValue.GetItem(i).Get( point[i] ); + for( Property::Array::SizeType i = 0, count = array->Count(); i < count; ++i ) + { + Vector3 point; + array->GetElementAt( i ).Get( point ); + mPath->AddControlPoint( point ); + } } - mPath->SetControlPoints( point ); } } diff --git a/dali/internal/event/animation/path-impl.cpp b/dali/internal/event/animation/path-impl.cpp index 1572cae..540bc29 100644 --- a/dali/internal/event/animation/path-impl.cpp +++ b/dali/internal/event/animation/path-impl.cpp @@ -142,55 +142,59 @@ Property::Type Path::GetDefaultPropertyType(Property::Index index) const Property::Value Path::GetDefaultProperty( Property::Index index ) const { - Property::Value value; if( index == Dali::Path::Property::POINTS ) { - Property::Array propertyArray; - value = Property::Value(propertyArray); - size_t pointCount( mPoint.Size() ); - for( size_t i( 0 ); i != pointCount; ++i ) + Property::Value value( Property::ARRAY ); + Property::Array* array = value.GetArray(); + Property::Array::SizeType pointCount = mPoint.Count(); + array->Reserve( pointCount ); + for( Property::Array::SizeType i = 0; i < pointCount; ++i ) { - value.AppendItem( mPoint[i] ); + array->PushBack( mPoint[i] ); } + return value; } else if( index == Dali::Path::Property::CONTROL_POINTS ) { - Property::Array propertyArray; - value = Property::Value(propertyArray); - size_t controlpointCount( mControlPoint.Size() ); - for( size_t i( 0 ); i != controlpointCount; ++i ) + Property::Value value( Property::ARRAY ); + Property::Array* array = value.GetArray(); + Property::Array::SizeType controlpointCount = mControlPoint.Count(); + array->Reserve( controlpointCount ); + for( Property::Array::SizeType i = 0; i < controlpointCount; ++i ) { - value.AppendItem( mControlPoint[i] ); + array->PushBack( mControlPoint[i] ); } + return value; } - return value; + return Property::Value(); } void Path::SetDefaultProperty(Property::Index index, const Property::Value& propertyValue) { - if( index == Dali::Path::Property::POINTS ) + const Property::Array* array = propertyValue.GetArray(); + if( array ) { - Property::Array propertyArray; - propertyValue.Get(propertyArray); - - size_t propertyArrayCount = propertyArray.Size(); - mPoint.Resize( propertyArrayCount ); - for( size_t i(0); i!=propertyArrayCount; ++i ) + Property::Array::SizeType propertyArrayCount = array->Count(); + if( index == Dali::Path::Property::POINTS ) { - propertyArray[i].Get( mPoint[i]); + mPoint.Reserve( propertyArrayCount ); + for( Property::Array::SizeType i = 0; i < propertyArrayCount; ++i ) + { + Vector3 point; + array->GetElementAt( i ).Get( point ); + mPoint.PushBack( point ); + } } - } - else if( index == Dali::Path::Property::CONTROL_POINTS ) - { - Property::Array propertyArray; - propertyValue.Get(propertyArray); - - size_t propertyArrayCount = propertyArray.Size(); - mControlPoint.Resize( propertyArrayCount ); - for( size_t i(0); i!=propertyArrayCount; ++i ) + else if( index == Dali::Path::Property::CONTROL_POINTS ) { - propertyArray[i].Get( mControlPoint[i]); + mControlPoint.Reserve( propertyArrayCount ); + for( Property::Array::SizeType i = 0; i < propertyArrayCount; ++i ) + { + Vector3 point; + array->GetElementAt( i ).Get( point ); + mControlPoint.PushBack( point ); + } } } } @@ -501,5 +505,15 @@ size_t Path::GetPointCount() const return mPoint.Size(); } +void Path::ClearPoints() +{ + mPoint.Clear(); +} + +void Path::ClearControlPoints() +{ + mControlPoint.Clear(); +} + } // Internal } // Dali diff --git a/dali/internal/event/animation/path-impl.h b/dali/internal/event/animation/path-impl.h index 671cbd5..26a1a01 100644 --- a/dali/internal/event/animation/path-impl.h +++ b/dali/internal/event/animation/path-impl.h @@ -196,6 +196,16 @@ public: size_t GetPointCount() const; /** + * Clears the points of the path + */ + void ClearPoints(); + + /** + * Clears the control points of the path + */ + void ClearControlPoints(); + + /** * @brief Get mPoint property * * @return A const reference to mPoint vector diff --git a/dali/internal/event/common/object-impl.cpp b/dali/internal/event/common/object-impl.cpp index 4db4ebd..6b9083a 100644 --- a/dali/internal/event/common/object-impl.cpp +++ b/dali/internal/event/common/object-impl.cpp @@ -586,18 +586,12 @@ Property::Index Object::RegisterSceneGraphProperty(const std::string& name, Prop case Property::STRING: case Property::ARRAY: case Property::MAP: + case Property::NONE: + case Property::TYPE_COUNT: { - DALI_LOG_WARNING( "Property Type %d\n", propertyValue.GetType() ); DALI_ASSERT_ALWAYS( !"PropertyType is not animatable" ); break; } - - default: - { - DALI_LOG_WARNING( "Property Type %d\n", propertyValue.GetType() ); - DALI_ASSERT_ALWAYS( !"PropertyType enumeration is out of bounds" ); - break; - } } // get the scene property owner from derived class diff --git a/dali/internal/event/common/property-helper.h b/dali/internal/event/common/property-helper.h index 8ebf477..4807990 100644 --- a/dali/internal/event/common/property-helper.h +++ b/dali/internal/event/common/property-helper.h @@ -90,7 +90,7 @@ struct PropertyDetails * { "SIZE_EQUAL_TO_PARENT", SIZE_EQUAL_TO_PARENT }, * }; const unsigned int SizeModeTableCount = sizeof( SizeModeTable ) / sizeof( SizeModeTable[0] ); */ -#define DALI_ENUM_TO_STRING_TABLE_BEGIN( t ) const Scripting::StringEnum< t > t##Table[] = { +#define DALI_ENUM_TO_STRING_TABLE_BEGIN( t ) const Scripting::StringEnum t##Table[] = { #define DALI_ENUM_TO_STRING_TABLE_END( t ) }; const unsigned int t##TableCount = sizeof( t##Table ) / sizeof( t##Table[0] ); #define DALI_ENUM_TO_STRING( s ) { #s, s }, diff --git a/dali/internal/event/effects/shader-effect-impl.cpp b/dali/internal/event/effects/shader-effect-impl.cpp index 58ff0eb..d808e39 100644 --- a/dali/internal/event/effects/shader-effect-impl.cpp +++ b/dali/internal/event/effects/shader-effect-impl.cpp @@ -179,16 +179,18 @@ void WrapAndSetProgram( Internal::ShaderEffect& effect, std::string GetShader(const std::string& field, const Property::Value& property) { - std::string value; - if( property.HasKey(field) ) + std::string retval; + const Property::Map* map = property.GetMap(); + if( map ) { - DALI_ASSERT_ALWAYS(property.GetValue(field).GetType() == Property::STRING && "Shader property is not a string" ); - - // we could also check here for an array of strings as convenience for json not having multi line strings - value = property.GetValue(field).Get(); + const Property::Value* value = map->Find( field ); + if( value ) + { + value->Get( retval ); + } } - return value; + return retval; } } // unnamed namespace @@ -476,31 +478,7 @@ void ShaderEffect::SetDefaultProperty( Property::Index index, const Property::Va std::string vertex = GetShader("vertex", propertyValue); std::string fragment = GetShader("fragment", propertyValue); - GeometryType geometryType = GEOMETRY_TYPE_IMAGE; - - if( propertyValue.HasKey("geometry-type") ) - { - Property::Value geometryValue = propertyValue.GetValue("geometry-type"); - DALI_ASSERT_ALWAYS(geometryValue.GetType() == Property::STRING && "Geometry type is not a string" ); - - std::string s = geometryValue.Get(); - if(s == "GEOMETRY_TYPE_IMAGE") - { - geometryType = GEOMETRY_TYPE_IMAGE; - } - else if( s == "GEOMETRY_TYPE_UNTEXTURED_MESH") - { - geometryType = GEOMETRY_TYPE_UNTEXTURED_MESH; - } - else if( s == "GEOMETRY_TYPE_TEXTURED_MESH") - { - geometryType = GEOMETRY_TYPE_TEXTURED_MESH; - } - else - { - DALI_ASSERT_ALWAYS(!"Geometry type unknown" ); - } - } + GeometryType geometryType = GEOMETRY_TYPE_IMAGE; // only images are supported SetPrograms( geometryType, vertexPrefix, fragmentPrefix, vertex, fragment ); break; } diff --git a/dali/internal/event/images/resource-image-impl.cpp b/dali/internal/event/images/resource-image-impl.cpp index 675fbcc..7463eac 100644 --- a/dali/internal/event/images/resource-image-impl.cpp +++ b/dali/internal/event/images/resource-image-impl.cpp @@ -166,8 +166,6 @@ unsigned int ResourceImage::GetWidth() const Size size; mImageFactory.GetImageSize( mRequest, mTicket, size ); mWidth = size.width; - // The app will probably ask for the height immediately, so don't waste the synchronous file IO that ImageFactory may have just done: - DALI_ASSERT_DEBUG( 0 == mHeight || unsigned(size.height) == mHeight ); if( 0 == mHeight ) { mHeight = size.height; @@ -183,7 +181,6 @@ unsigned int ResourceImage::GetHeight() const Size size; mImageFactory.GetImageSize( mRequest, mTicket, size ); mHeight = size.height; - DALI_ASSERT_DEBUG( 0 == mWidth || unsigned(size.width) == mWidth ); if( 0 == mWidth ) { mWidth = size.width; diff --git a/dali/public-api/object/property-array.cpp b/dali/public-api/object/property-array.cpp index 2522113..e401f32 100644 --- a/dali/public-api/object/property-array.cpp +++ b/dali/public-api/object/property-array.cpp @@ -51,53 +51,42 @@ Property::Array::~Array() delete mImpl; } - -unsigned int Property::Array::Size() const +Property::Array::SizeType Property::Array::Count() const { return mImpl->mArray.size(); } -unsigned int Property::Array::Count() const -{ - return Size(); -} - -void Property::Array::PushBack(const Value& value) +void Property::Array::PushBack( const Value& value ) { mImpl->mArray.push_back( value ); } -bool Property::Array::Empty() const -{ - return mImpl->mArray.empty(); -} - void Property::Array::Clear() { mImpl->mArray.clear(); } -void Property::Array::Reserve(size_t size) +void Property::Array::Reserve( SizeType size ) { mImpl->mArray.reserve(size); } -void Property::Array::Resize(size_t size) +void Property::Array::Resize( SizeType size ) { mImpl->mArray.resize(size); } -size_t Property::Array::Capacity() +Property::Array::SizeType Property::Array::Capacity() { return mImpl->mArray.capacity(); } -const Property::Value& Property::Array::operator[]( const std::size_t index ) const +const Property::Value& Property::Array::operator[]( SizeType index ) const { return mImpl->mArray[ index ]; } -Property::Value& Property::Array::operator[]( const std::size_t index ) +Property::Value& Property::Array::operator[]( SizeType index ) { return mImpl->mArray[ index ]; } diff --git a/dali/public-api/object/property-array.h b/dali/public-api/object/property-array.h index 9bfbfdf..7a6e173 100644 --- a/dali/public-api/object/property-array.h +++ b/dali/public-api/object/property-array.h @@ -36,6 +36,8 @@ class DALI_IMPORT_API Property::Array { public: + typedef std::size_t SizeType; + /** * @brief Default constructor. */ @@ -58,21 +60,27 @@ public: * * @return The number of elements in the array. */ - unsigned int Size() const; + SizeType Size() const + { + return Count(); + } /** * @brief Retrieve the number of elements in the array. * * @return The number of elements in the array. */ - unsigned int Count() const; + SizeType Count() const; /** * @brief Returns whether the array is empty. * * @return true if empty, false otherwise */ - bool Empty() const; + bool Empty() const + { + return Count() == 0; + } /** * @brief Clears the array. @@ -82,29 +90,50 @@ public: /** * @brief Increase the capcity of the array. */ - void Reserve(size_t size); + void Reserve( SizeType size ); /** * @brief Resize to size. */ - void Resize(size_t size); + void Resize( SizeType size ); /** * @brief Retrieve the capacity of the array. * * @return The allocated capacity of the array */ - size_t Capacity(); + SizeType Capacity(); /** * @brief Add an element to the array. * * @param[in] value The value to add to the end of the array + */ + void PushBack( const Value& value ); + + /** + * @brief Const access an element. + * + * @param[in] index The element index to access. No bounds checking is performed. * * @return The a reference to the element. + */ + const Value& GetElementAt( SizeType index ) const + { + return operator[]( index ); + } + + /** + * @brief Access an element. * + * @param[in] index The element index to access. No bounds checking is performed. + * + * @return The a reference to the element. */ - void PushBack(const Value& value); + Value& GetElementAt( SizeType index ) + { + return operator[]( index ); + } /** * @brief Const operator to access an element. @@ -114,7 +143,7 @@ public: * @return The a reference to the element. * */ - const Value& operator[]( const size_t index ) const; + const Value& operator[]( SizeType index ) const; /** * @brief Operator to access an element. @@ -124,7 +153,7 @@ public: * @return The a reference to the element. * */ - Value& operator[]( const size_t index ); + Value& operator[]( SizeType index ); /** * @brief Assignment Operator diff --git a/dali/public-api/object/property-map.cpp b/dali/public-api/object/property-map.cpp index 882aad7..fdf1cef 100644 --- a/dali/public-api/object/property-map.cpp +++ b/dali/public-api/object/property-map.cpp @@ -50,7 +50,7 @@ Property::Map::~Map() delete mImpl; } -unsigned int Property::Map::Count() const +Property::Map::SizeType Property::Map::Count() const { return mImpl->mContainer.size(); } @@ -60,28 +60,38 @@ bool Property::Map::Empty() const return mImpl->mContainer.empty(); } -Property::Value& Property::Map::GetValue( unsigned int position ) const +void Property::Map::Insert( const char* key, const Value& value ) +{ + mImpl->mContainer.push_back( std::make_pair( key, value ) ); +} + +void Property::Map::Insert( const std::string& key, const Value& value ) +{ + mImpl->mContainer.push_back( std::make_pair( key, value ) ); +} + +Property::Value& Property::Map::GetValue( SizeType 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 +const std::string& Property::Map::GetKey( SizeType position ) const { DALI_ASSERT_ALWAYS( position < Count() && "position out-of-bounds" ); return mImpl->mContainer[ position ].first; } -StringValuePair& Property::Map::GetPair( unsigned int position ) const +StringValuePair& Property::Map::GetPair( SizeType 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 +Property::Value* Property::Map::Find( const char* key ) const { for ( Container::iterator iter = mImpl->mContainer.begin(), endIter = mImpl->mContainer.end(); iter != endIter; ++iter ) { @@ -93,6 +103,12 @@ Property::Value* Property::Map::Find( const std::string& key ) const return NULL; // Not found } +Property::Value* Property::Map::Find( const std::string& key ) const +{ + return Find( key.c_str() ); + +} + Property::Value* Property::Map::Find( const std::string& key, Property::Type type ) const { for ( Container::iterator iter = mImpl->mContainer.begin(), endIter = mImpl->mContainer.end(); iter != endIter; ++iter ) @@ -156,7 +172,7 @@ Property::Value& Property::Map::operator[]( const std::string& key ) } // Create and return reference to new value - mImpl->mContainer.push_back( StringValuePair( key, Value() ) ); + mImpl->mContainer.push_back( std::make_pair( key, Property::Value() ) ); return (mImpl->mContainer.end() - 1)->second; } diff --git a/dali/public-api/object/property-map.h b/dali/public-api/object/property-map.h index 2a41a78..8c1be41 100644 --- a/dali/public-api/object/property-map.h +++ b/dali/public-api/object/property-map.h @@ -37,6 +37,8 @@ class DALI_IMPORT_API Property::Map { public: + typedef std::size_t SizeType; + /** * @brief Default constructor. */ @@ -59,7 +61,7 @@ public: * * @return The number of elements in the map. */ - unsigned int Count() const; + SizeType Count() const; /** * @brief Returns whether the map is empty. @@ -69,13 +71,31 @@ public: bool Empty() const; /** + * @brief Inserts the key-value pair in the Map. + * + * Does not check for duplicates + * @param key to insert + * @param value to insert + */ + void Insert( const char* key, const Value& value ); + + /** + * @brief Inserts the key-value pair in the Map. + * + * Does not check for duplicates + * @param key to insert + * @param value to insert + */ + void Insert( const std::string& key, const Value& value ); + + /** * @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; + Value& GetValue( SizeType position ) const; /** * @brief Retrieve the key at the specified position. @@ -84,7 +104,7 @@ public: * * @note Will assert if position >= Count() */ - const std::string& GetKey( unsigned int position ) const; + const std::string& GetKey( SizeType position ) const; /** * @brief Retrieve the key & the value at the specified position. @@ -93,7 +113,16 @@ public: * * @note Will assert if position >= Count() */ - StringValuePair& GetPair( unsigned int position ) const; + StringValuePair& GetPair( SizeType 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 char* key ) const; /** * @brief Finds the value for the specified key if it exists. diff --git a/dali/public-api/object/property-value.cpp b/dali/public-api/object/property-value.cpp index bb347ab..6d1e7ef 100644 --- a/dali/public-api/object/property-value.cpp +++ b/dali/public-api/object/property-value.cpp @@ -22,7 +22,6 @@ #include // INTERNAL INCLUDES -#include #include #include #include @@ -40,204 +39,281 @@ namespace Dali { +namespace +{ +/** + * Helper to check if the property value can be read as int/unsigned int/bool + */ +inline bool IsIntegerType( Property::Type type ) +{ + return ( Property::BOOLEAN == type )||( Property::INTEGER == type )||(Property::UNSIGNED_INTEGER == type ); +} +} + struct Property::Value::Impl { Impl() - : mType( Property::NONE ) - { - } + : type( Property::NONE ), + integerValue( 0 ) + { } - Impl(bool boolValue) - : mType( PropertyTypes::Get() ), - mValue( boolValue ) - { - } + Impl( bool booleanValue ) + : type( Property::BOOLEAN ), + integerValue( booleanValue ) + { } - Impl(float floatValue) - : mType( PropertyTypes::Get() ), - mValue( floatValue ) - { - } + Impl( float floatValue ) + : type( Property::FLOAT ), + floatValue( floatValue ) + { } - Impl(int integerValue) - : mType( PropertyTypes::Get() ), - mValue( integerValue ) - { - } + Impl( int integerValue ) + : type( Property::INTEGER ), + integerValue( integerValue ) + { } - Impl(unsigned int unsignedIntegerValue) - : mType( PropertyTypes::Get() ), - mValue( unsignedIntegerValue ) - { - } + Impl( unsigned int unsignedIntegerValue ) + : type( Property::UNSIGNED_INTEGER ), + unsignedIntegerValue( unsignedIntegerValue ) + { } - Impl(const Vector2& vectorValue) - : mType( PropertyTypes::Get() ), - mValue( vectorValue ) - { - } + Impl( const Vector2& vectorValue ) + : type( Property::VECTOR2 ), + vector2Value( new Vector2( vectorValue ) ) + { } - Impl(const Vector3& vectorValue) - : mType( PropertyTypes::Get() ), - mValue( vectorValue ) - { - } + Impl( const Vector3& vectorValue ) + : type( Property::VECTOR3 ), + vector3Value( new Vector3( vectorValue ) ) + { } - Impl(const Vector4& vectorValue) - : mType( PropertyTypes::Get() ), - mValue( vectorValue ) + Impl( const Vector4& vectorValue ) + : type( Property::VECTOR4 ), + vector4Value( new Vector4( vectorValue ) ) + { } + + Impl( const Matrix3& matrixValue ) + : type( Property::MATRIX3 ), + matrix3Value( new Matrix3( matrixValue ) ) { } - Impl(const Matrix3& matrixValue) - : mType(PropertyTypes::Get()), - mValue(matrixValue) + Impl( const Matrix& matrixValue ) + : type( Property::MATRIX ), + matrixValue( new Matrix( matrixValue ) ) { } - Impl(const Matrix& matrixValue) - : mType(PropertyTypes::Get()), - mValue(matrixValue) + Impl( const AngleAxis& angleAxisValue ) + : type( Property::ROTATION ), + quaternionValue( new Quaternion( angleAxisValue.angle, angleAxisValue.axis ) ) { } - Impl(const AngleAxis& angleAxisValue) - : mType( PropertyTypes::Get() ), - mValue( angleAxisValue ) + Impl( const Quaternion& quaternionValue ) + : type( Property::ROTATION ), + quaternionValue( new Quaternion( quaternionValue ) ) { } - Impl(const Quaternion& quaternionValue) - : mType( PropertyTypes::Get() ), - mValue( quaternionValue ) + Impl(const std::string& stringValue) + : type( Property::STRING ), + stringValue( new std::string( stringValue ) ) { } - Impl(const std::string& stringValue) - : mType( PropertyTypes::Get() ), - mValue( stringValue ) + Impl( const Rect& rectValue ) + : type( Property::RECTANGLE ), + rectValue( new Rect( rectValue ) ) { } - Impl(const Rect& rect) - : mType( PropertyTypes::Get >() ), - mValue( rect ) + Impl( const Property::Array& arrayValue ) + : type( Property::ARRAY ), + arrayValue( new Property::Array( arrayValue ) ) { } - Impl(Property::Map container) - : mType( PropertyTypes::Get() ), - mValue( container ) + Impl( const Property::Map& mapValue ) + : type( Property::MAP ), + mapValue( new Property::Map( mapValue ) ) { } - Impl(Property::Array container) - : mType( PropertyTypes::Get() ), - mValue( container ) + /** + * Destructor, takes care of releasing the dynamically allocated types + */ + ~Impl() { + switch( type ) + { + case Property::NONE : // FALLTHROUGH + case Property::TYPE_COUNT : // FALLTHROUGH + case Property::BOOLEAN : // FALLTHROUGH + case Property::FLOAT : // FALLTHROUGH + case Property::INTEGER : // FALLTHROUGH + case Property::UNSIGNED_INTEGER : + { + break; // nothing to do + } + case Property::VECTOR2 : + { + delete vector2Value; + break; + } + case Property::VECTOR3: + { + delete vector3Value; + break; + } + case Property::VECTOR4: + { + delete vector4Value; + break; + } + case Property::MATRIX3: + { + delete matrix3Value; + break; + } + case Property::MATRIX: + { + delete matrixValue; + break; + } + case Property::RECTANGLE: + { + delete rectValue; + break; + } + case Property::ROTATION: + { + delete quaternionValue; + break; + } + case Property::STRING: + { + delete stringValue; + break; + } + case Property::ARRAY: + { + delete arrayValue; + break; + } + case Property::MAP: + { + delete mapValue; + break; + } + } } - Type mType; +public: // Data - typedef Any AnyValue; - AnyValue mValue; + Type type; + union + { + int integerValue; + float floatValue; + unsigned int unsignedIntegerValue; + // must use pointers for any class value pre c++ 11 + Vector2* vector2Value; + Vector3* vector3Value; + Vector4* vector4Value; + Matrix3* matrix3Value; + Matrix* matrixValue; + Quaternion* quaternionValue; + std::string* stringValue; + Rect* rectValue; + Property::Array* arrayValue; + Property::Map* mapValue; + }; }; Property::Value::Value() : mImpl( NULL ) { - mImpl = new Impl(); } -Property::Value::Value(bool boolValue) -: mImpl( NULL ) +Property::Value::Value( bool booleanValue ) +: mImpl( new Impl( booleanValue ) ) { - mImpl = new Impl( boolValue ); } -Property::Value::Value(float floatValue) -: mImpl( NULL ) +Property::Value::Value( float floatValue ) +: mImpl( new Impl( floatValue ) ) { - mImpl = new Impl( floatValue ); } -Property::Value::Value(int integerValue) -: mImpl( NULL ) +Property::Value::Value( int integerValue ) +: mImpl( new Impl( integerValue ) ) { - mImpl = new Impl( integerValue ); } -Property::Value::Value(unsigned int unsignedIntegerValue) -: mImpl( NULL ) +Property::Value::Value( unsigned int unsignedIntegerValue ) +: mImpl( new Impl( unsignedIntegerValue ) ) { - mImpl = new Impl( unsignedIntegerValue ); } -Property::Value::Value(const Vector2& vectorValue) -: mImpl( NULL ) +Property::Value::Value( const Vector2& vectorValue ) +: mImpl( new Impl( vectorValue ) ) { - mImpl = new Impl( vectorValue ); } -Property::Value::Value(const Vector3& vectorValue) -: mImpl( NULL ) +Property::Value::Value( const Vector3& vectorValue ) +: mImpl( new Impl( vectorValue ) ) { - mImpl = new Impl( vectorValue ); } -Property::Value::Value(const Vector4& vectorValue) -: mImpl( NULL ) +Property::Value::Value( const Vector4& vectorValue ) +: mImpl( new Impl( vectorValue ) ) { - mImpl = new Impl( vectorValue ); } -Property::Value::Value(const Matrix3& matrixValue) -: mImpl( NULL ) +Property::Value::Value( const Matrix3& matrixValue ) +: mImpl( new Impl( matrixValue ) ) { - mImpl = new Impl( matrixValue ); } -Property::Value::Value(const Matrix& matrixValue) -: mImpl( NULL ) +Property::Value::Value( const Matrix& matrixValue ) +: mImpl( new Impl( matrixValue ) ) { - mImpl = new Impl( matrixValue ); } -Property::Value::Value(const Rect& rect) -: mImpl( NULL ) +Property::Value::Value( const Rect& rectValue ) +: mImpl( new Impl( rectValue ) ) { - mImpl = new Impl( rect ); } -Property::Value::Value(const AngleAxis& angleAxisValue) -: mImpl( NULL ) +Property::Value::Value( const AngleAxis& angleAxisValue ) +: mImpl( new Impl( angleAxisValue ) ) { - mImpl = new Impl( angleAxisValue ); } -Property::Value::Value(const Quaternion& quaternionValue) +Property::Value::Value( const Quaternion& quaternionValue ) +: mImpl( new Impl( quaternionValue ) ) { - mImpl = new Impl( quaternionValue ); } -Property::Value::Value(const std::string& stringValue) +Property::Value::Value( const std::string& stringValue ) +: mImpl( new Impl( stringValue ) ) { - mImpl = new Impl( stringValue ); } -Property::Value::Value(const char *stringValue) +Property::Value::Value( const char* stringValue ) +: mImpl( new Impl( std::string(stringValue) ) ) { - mImpl = new Impl( std::string(stringValue) ); } -Property::Value::Value(Property::Array &arrayValue) +Property::Value::Value( Property::Array& arrayValue ) +: mImpl( new Impl( arrayValue ) ) { - mImpl = new Impl( arrayValue ); } -Property::Value::Value(Property::Map &mapValue) +Property::Value::Value( Property::Map& mapValue ) +: mImpl( new Impl( mapValue ) ) { - mImpl = new Impl( mapValue ); } @@ -246,115 +322,14 @@ Property::Value::~Value() delete mImpl; } -Property::Value::Value(const Value& value) +Property::Value::Value( const Property::Value& value ) +: mImpl( NULL ) { - switch (value.GetType()) - { - case Property::BOOLEAN: - { - mImpl = new Impl( value.Get() ); - break; - } - - case Property::FLOAT: - { - mImpl = new Impl( value.Get() ); - break; - } - - case Property::INTEGER: - { - mImpl = new Impl( value.Get() ); - break; - } - - case Property::UNSIGNED_INTEGER: - { - mImpl = new Impl( value.Get() ); - break; - } - - case Property::VECTOR2: - { - mImpl = new Impl( value.Get() ); - break; - } - - case Property::VECTOR3: - { - mImpl = new Impl( value.Get() ); - break; - } - - case Property::VECTOR4: - { - mImpl = new Impl( value.Get() ); - break; - } - - case Property::RECTANGLE: - { - mImpl = new Impl( value.Get >() ); - break; - } - - case Property::ROTATION: - { - // Orientations have two representations - DALI_ASSERT_DEBUG( typeid(Quaternion) == value.mImpl->mValue.GetType() || - typeid(AngleAxis) == value.mImpl->mValue.GetType() ); - - if ( typeid(Quaternion) == value.mImpl->mValue.GetType() ) - { - mImpl = new Impl( value.Get() ); - } - else - { - mImpl = new Impl( value.Get() ); - } - break; - } - - case Property::MATRIX3: - { - mImpl = new Impl( value.Get()); - break; - } - - case Property::MATRIX: - { - mImpl = new Impl( value.Get()); - break; - } - - case Property::STRING: - { - mImpl = new Impl( value.Get() ); - break; - } - - case Property::MAP: - { - mImpl = new Impl( value.Get() ); - break; - } - - case Property::ARRAY: - { - mImpl = new Impl( value.Get() ); - break; - } - - case Property::NONE: // fall - default: - { - mImpl = new Impl(); - break; - } - } + // reuse assignment operator + operator=( value ); } -Property::Value::Value(Type type) +Property::Value::Value( Type type ) { switch (type) { @@ -363,87 +338,73 @@ Property::Value::Value(Type type) mImpl = new Impl( false ); break; } - case Property::FLOAT: { mImpl = new Impl( 0.f ); break; } - case Property::INTEGER: { mImpl = new Impl( 0 ); break; } - case Property::UNSIGNED_INTEGER: { mImpl = new Impl( 0U ); break; } - case Property::VECTOR2: { mImpl = new Impl( Vector2::ZERO ); break; } - case Property::VECTOR3: { mImpl = new Impl( Vector3::ZERO ); break; } - case Property::VECTOR4: { mImpl = new Impl( Vector4::ZERO ); break; } - case Property::RECTANGLE: { mImpl = new Impl( Rect(0,0,0,0) ); break; } - case Property::ROTATION: { - mImpl = new Impl( Quaternion( Radian(0.f), Vector3::YAXIS) ); + mImpl = new Impl( Quaternion() ); break; } - case Property::STRING: { mImpl = new Impl( std::string() ); break; } - - case Property::MAP: - { - mImpl = new Impl( Property::Map() ); - break; - } - case Property::MATRIX: { mImpl = new Impl( Matrix() ); break; } - case Property::MATRIX3: { mImpl = new Impl( Matrix3() ); break; } - case Property::ARRAY: { mImpl = new Impl( Property::Array() ); break; } - - case Property::NONE: // fall - default: + case Property::MAP: + { + mImpl = new Impl( Property::Map() ); + break; + } + case Property::NONE: + case Property::TYPE_COUNT: { mImpl = new Impl(); break; @@ -451,119 +412,184 @@ Property::Value::Value(Type type) } } -Property::Value& Property::Value::operator=(const Property::Value& value) +Property::Value& Property::Value::operator=( const Property::Value& value ) { - if (this == &value) + if ( this == &value ) { // skip self assignment return *this; } - - mImpl->mType = value.GetType(); - - switch (mImpl->mType) + // if we are assigned an empty value, just drop impl + if( !value.mImpl ) { - case Property::BOOLEAN: - { - mImpl->mValue = value.Get(); - break; - } - - case Property::FLOAT: - { - mImpl->mValue = value.Get(); - break; - } - - case Property::INTEGER: - { - mImpl->mValue = value.Get(); - break; - } - - case Property::UNSIGNED_INTEGER: - { - mImpl->mValue = value.Get(); - break; - } - - case Property::VECTOR2: - { - mImpl->mValue = value.Get(); - break; - } - - case Property::VECTOR3: - { - mImpl->mValue = value.Get(); - break; - } - - case Property::VECTOR4: - { - mImpl->mValue = value.Get(); - break; - } - - case Property::RECTANGLE: - { - mImpl->mValue = value.Get >(); - break; - } - - case Property::ROTATION: + delete mImpl; + mImpl = NULL; + return *this; + } + // first check if the type is the same, no need to change impl, just assign + if( mImpl && ( mImpl->type == value.mImpl->type ) ) + { + switch( mImpl->type ) { - // Orientations have two representations - DALI_ASSERT_DEBUG( typeid(Quaternion) == value.mImpl->mValue.GetType() || - typeid(AngleAxis) == value.mImpl->mValue.GetType() ); - - if ( typeid(Quaternion) == value.mImpl->mValue.GetType() ) + case Property::BOOLEAN: { - mImpl = new Impl( value.Get() ); + mImpl->integerValue = value.mImpl->integerValue; + break; } - else + case Property::FLOAT: { - mImpl = new Impl( value.Get() ); + mImpl->floatValue = value.mImpl->floatValue; + break; + } + case Property::INTEGER: + { + mImpl->integerValue = value.mImpl->integerValue; + break; + } + case Property::UNSIGNED_INTEGER: + { + mImpl->unsignedIntegerValue = value.mImpl->unsignedIntegerValue; + break; + } + case Property::VECTOR2: + { + *mImpl->vector2Value = *value.mImpl->vector2Value; + break; + } + case Property::VECTOR3: + { + *mImpl->vector3Value = *value.mImpl->vector3Value; + break; + } + case Property::VECTOR4: + { + *mImpl->vector4Value = *value.mImpl->vector4Value; + break; + } + case Property::RECTANGLE: + { + *mImpl->rectValue = *value.mImpl->rectValue; + break; + } + case Property::ROTATION: + { + *mImpl->quaternionValue = *value.mImpl->quaternionValue; + break; + } + case Property::STRING: + { + *mImpl->stringValue = *value.mImpl->stringValue; + break; + } + case Property::MATRIX: + { + *mImpl->matrixValue = *value.mImpl->matrixValue; + break; + } + case Property::MATRIX3: + { + *mImpl->matrix3Value = *value.mImpl->matrix3Value; + break; + } + case Property::ARRAY: + { + *mImpl->arrayValue = *value.mImpl->arrayValue; + break; + } + case Property::MAP: + { + *mImpl->mapValue = *value.mImpl->mapValue; + break; + } + case Property::NONE: + case Property::TYPE_COUNT: + { // mImpl will be NULL, there's no way to get to this case } - break; - } - - case Property::STRING: - { - mImpl->mValue = value.Get(); - break; - } - - case Property::MATRIX: - { - mImpl->mValue = value.Get(); - break; } - - case Property::MATRIX3: + } + else + { + // different type, release old impl and create new + Impl* newImpl( NULL ); + switch ( value.mImpl->type ) { - mImpl->mValue = value.Get(); - break; - } - - case Property::MAP: - { - mImpl->mValue = value.Get(); - break; - } - - case Property::ARRAY: - { - mImpl->mValue = value.Get(); - break; - } - - case Property::NONE: // fall - default: - { - mImpl->mValue = Impl::AnyValue(0); - break; + case Property::BOOLEAN: + { + newImpl = new Impl( bool( value.mImpl->integerValue ) ); + break; + } + case Property::FLOAT: + { + newImpl = new Impl( value.mImpl->floatValue ); + break; + } + case Property::INTEGER: + { + newImpl = new Impl( value.mImpl->integerValue ); + break; + } + case Property::UNSIGNED_INTEGER: + { + newImpl = new Impl( value.mImpl->unsignedIntegerValue ); + break; + } + case Property::VECTOR2: + { + newImpl = new Impl( *value.mImpl->vector2Value ); + break; + } + case Property::VECTOR3: + { + newImpl = new Impl( *value.mImpl->vector3Value ); + break; + } + case Property::VECTOR4: + { + newImpl = new Impl( *value.mImpl->vector4Value ); + break; + } + case Property::RECTANGLE: + { + newImpl = new Impl( *value.mImpl->rectValue ); + break; + } + case Property::ROTATION: + { + newImpl = new Impl( *value.mImpl->quaternionValue ); + break; + } + case Property::MATRIX3: + { + newImpl = new Impl( *value.mImpl->matrix3Value ); + break; + } + case Property::MATRIX: + { + newImpl = new Impl( *value.mImpl->matrixValue ); + break; + } + case Property::STRING: + { + newImpl = new Impl( *value.mImpl->stringValue ); + break; + } + case Property::ARRAY: + { + newImpl = new Impl( *value.mImpl->arrayValue ); + break; + } + case Property::MAP: + { + newImpl = new Impl( *value.mImpl->mapValue ); + break; + } + case Property::NONE: + case Property::TYPE_COUNT: + { // NULL value will be used for "empty" value + } } + delete mImpl; + mImpl = newImpl; } return *this; @@ -571,526 +597,304 @@ Property::Value& Property::Value::operator=(const Property::Value& value) Property::Type Property::Value::GetType() const { - return mImpl->mType; -} - -void Property::Value::Get(bool& boolValue) const -{ - DALI_ASSERT_DEBUG( Property::BOOLEAN == GetType() && "Property type invalid" ); // AnyCast does asserted type checking - - boolValue = AnyCast(mImpl->mValue); -} - -void Property::Value::Get(float& floatValue) const -{ - DALI_ASSERT_DEBUG( Property::FLOAT == GetType() && "Property type invalid" ); - - floatValue = AnyCast(mImpl->mValue); + Property::Type type( Property::NONE ); + if( mImpl ) + { + type = mImpl->type; + } + return type; } -void Property::Value::Get(int& integerValue) const +void Property::Value::Get( bool& booleanValue ) const { - DALI_ASSERT_DEBUG( Property::INTEGER == GetType() && "Property type invalid" ); - - integerValue = AnyCast(mImpl->mValue); + if( mImpl && IsIntegerType( mImpl->type ) ) + { + booleanValue = mImpl->integerValue; + } + else + { + booleanValue = false; + } } -void Property::Value::Get(unsigned int& unsignedIntegerValue) const +void Property::Value::Get( float& floatValue ) const { - DALI_ASSERT_DEBUG( Property::UNSIGNED_INTEGER == GetType() && "Property type invalid" ); - - unsignedIntegerValue = AnyCast(mImpl->mValue); + if( mImpl && mImpl->type == FLOAT ) + { + floatValue = mImpl->floatValue; + } + else + { + floatValue = 0.f; + } } -void Property::Value::Get(Vector2& vectorValue) const +void Property::Value::Get( int& integerValue ) const { - DALI_ASSERT_DEBUG( Property::VECTOR2 == GetType() && "Property type invalid" ); - - vectorValue = AnyCast(mImpl->mValue); + if( mImpl && IsIntegerType( mImpl->type ) ) + { + integerValue = mImpl->integerValue; + } + else + { + integerValue = 0; + } } -void Property::Value::Get(Vector3& vectorValue) const +void Property::Value::Get( unsigned int& unsignedIntegerValue ) const { - DALI_ASSERT_DEBUG( Property::VECTOR3 == GetType() && "Property type invalid" ); - - vectorValue = AnyCast(mImpl->mValue); + if( mImpl && IsIntegerType( mImpl->type ) ) + { + unsignedIntegerValue = mImpl->unsignedIntegerValue; + } + else + { + unsignedIntegerValue = 0u; + } } -void Property::Value::Get(Vector4& vectorValue) const +void Property::Value::Get( Vector2& vectorValue ) const { - DALI_ASSERT_DEBUG( Property::VECTOR4 == GetType() && "Property type invalid" ); - - vectorValue = AnyCast(mImpl->mValue); + if( mImpl && mImpl->type == VECTOR2 && mImpl->vector2Value ) + { + vectorValue = *(mImpl->vector2Value); + } + else + { + vectorValue.x = vectorValue.y = 0.f; + } } -void Property::Value::Get(Matrix3& matrixValue) const +void Property::Value::Get( Vector3& vectorValue ) const { - DALI_ASSERT_DEBUG( Property::MATRIX3 == GetType() && "Property type invalid" ); - matrixValue = AnyCast(mImpl->mValue); + if( mImpl && mImpl->type == VECTOR3 && mImpl->vector3Value ) + { + vectorValue = *(mImpl->vector3Value); + } + else + { + vectorValue.x = vectorValue.y = vectorValue.z = 0.f; + } } -void Property::Value::Get(Matrix& matrixValue) const +void Property::Value::Get( Vector4& vectorValue ) const { - DALI_ASSERT_DEBUG( Property::MATRIX == GetType() && "Property type invalid" ); - matrixValue = AnyCast(mImpl->mValue); + if( mImpl && mImpl->type == VECTOR4 && mImpl->vector4Value ) + { + vectorValue = *(mImpl->vector4Value); + } + else + { + vectorValue.x = vectorValue.y = vectorValue.z = vectorValue.w = 0.f; + } } -void Property::Value::Get(Rect& rect) const +void Property::Value::Get( Matrix3& matrixValue ) const { - DALI_ASSERT_DEBUG( Property::RECTANGLE == GetType() && "Property type invalid" ); - - rect = AnyCast >(mImpl->mValue); + if( mImpl && mImpl->type == MATRIX3 && mImpl->matrix3Value ) + { + matrixValue = *(mImpl->matrix3Value); + } + else + { + matrixValue.SetIdentity(); + } } -void Property::Value::Get(AngleAxis& angleAxisValue) const +void Property::Value::Get( Matrix& matrixValue ) const { - DALI_ASSERT_ALWAYS( Property::ROTATION == GetType() && "Property type invalid" ); - - // Orientations have two representations - DALI_ASSERT_DEBUG( typeid(Quaternion) == mImpl->mValue.GetType() || - typeid(AngleAxis) == mImpl->mValue.GetType() ); - - if ( typeid(Quaternion) == mImpl->mValue.GetType() ) + if( mImpl && mImpl->type == MATRIX && mImpl->matrixValue ) { - Quaternion quaternion = AnyCast(mImpl->mValue); - - quaternion.ToAxisAngle( angleAxisValue.axis, angleAxisValue.angle ); + matrixValue = *(mImpl->matrixValue); } else { - angleAxisValue = AnyCast(mImpl->mValue); + matrixValue.SetIdentity(); } } -void Property::Value::Get(Quaternion& quaternionValue) const +void Property::Value::Get( Rect& rectValue ) const { - DALI_ASSERT_DEBUG( Property::ROTATION == GetType() && "Property type invalid" ); - - // Orientations have two representations - DALI_ASSERT_DEBUG( typeid(Quaternion) == mImpl->mValue.GetType() || - typeid(AngleAxis) == mImpl->mValue.GetType() ); - - if ( typeid(Quaternion) == mImpl->mValue.GetType() ) + if( mImpl && mImpl->type == RECTANGLE && mImpl->rectValue ) { - quaternionValue = AnyCast(mImpl->mValue); + rectValue = *(mImpl->rectValue); } else { - AngleAxis angleAxis = AnyCast(mImpl->mValue); - - quaternionValue = Quaternion( Radian(angleAxis.angle), angleAxis.axis ); + rectValue.x = rectValue.y = rectValue.width = rectValue.height = 0.f; } } -void Property::Value::Get(std::string &out) const +void Property::Value::Get( AngleAxis& angleAxisValue ) const { - DALI_ASSERT_DEBUG(Property::STRING == GetType() && "Property type invalid"); - - out = AnyCast(mImpl->mValue); + if( mImpl && mImpl->type == ROTATION && mImpl->quaternionValue ) + { + mImpl->quaternionValue->ToAxisAngle( angleAxisValue.axis, angleAxisValue.angle ); + } + else + { + angleAxisValue.angle = 0.f; + angleAxisValue.axis = Vector3::ZERO; // identity quaternion + } } -void Property::Value::Get(Property::Array &out) const +void Property::Value::Get( Quaternion& quaternionValue ) const { - DALI_ASSERT_DEBUG(Property::ARRAY == GetType() && "Property type invalid"); - - out = AnyCast(mImpl->mValue); + if( mImpl && mImpl->type == ROTATION && mImpl->quaternionValue ) + { + quaternionValue = *(mImpl->quaternionValue); + } + else + { + quaternionValue = Quaternion::IDENTITY; + } } -void Property::Value::Get(Property::Map &out) const +void Property::Value::Get( std::string& stringValue ) const { - DALI_ASSERT_DEBUG(Property::MAP == GetType() && "Property type invalid"); - - out = AnyCast(mImpl->mValue); + if( mImpl && mImpl->type == STRING && mImpl->stringValue ) + { + stringValue.assign( *(mImpl->stringValue) ); + } + else + { + stringValue.clear(); + } } -Property::Value& Property::Value::GetValue(const std::string& key) const +void Property::Value::Get( Property::Array& arrayValue ) const { - DALI_ASSERT_DEBUG(Property::MAP == GetType() && "Property type invalid"); - - Property::Map *container = AnyCast(&(mImpl->mValue)); - - DALI_ASSERT_DEBUG(container); - - if(container) + if( mImpl && mImpl->type == ARRAY && mImpl->arrayValue ) { - Property::Value* value = container->Find( key ); - if ( value ) - { - return *value; - } + arrayValue = *(mImpl->arrayValue); + } + else + { + arrayValue.Clear(); } - - DALI_LOG_WARNING("Cannot find property map key %s", key.c_str()); - DALI_ASSERT_ALWAYS(!"Cannot find property map key"); } -bool Property::Value::HasKey(const std::string& key) const +void Property::Value::Get( Property::Map& mapValue ) const { - bool has = false; - - if( Property::MAP == GetType() ) + if( mImpl && mImpl->type == MAP && mImpl->mapValue ) { - Property::Map *container = AnyCast(&(mImpl->mValue)); - - DALI_ASSERT_DEBUG(container && "Property::Map has no container?"); - - if(container) - { - Property::Value* value = container->Find( key ); - if ( value ) - { - has = true; - } - } + mapValue = *(mImpl->mapValue); + } + else + { + mapValue.Clear(); } - - return has; } - -const std::string& Property::Value::GetKey(const int index) const +Property::Map* Property::Value::GetMap() const { - switch( GetType() ) + Property::Map* map = NULL; + if( mImpl && mImpl->type == MAP && mImpl->mapValue ) { - case Property::MAP: - { - Property::Map *container = AnyCast(&(mImpl->mValue)); - DALI_ASSERT_DEBUG(container && "Property::Map has no container?"); - if(container) - { - if(0 <= index && index < static_cast(container->Count())) - { - return container->GetKey( index ); - } - } - } - break; - case Property::NONE: - case Property::ARRAY: - case Property::BOOLEAN: - case Property::FLOAT: - case Property::UNSIGNED_INTEGER: - case Property::INTEGER: - case Property::VECTOR2: - case Property::VECTOR3: - case Property::VECTOR4: - case Property::MATRIX: - case Property::MATRIX3: - case Property::RECTANGLE: - case Property::ROTATION: - case Property::STRING: - case Property::TYPE_COUNT: - { - break; - } + map = mImpl->mapValue; } - - - // should never return this - static std::string null; - return null; + return map; } - -void Property::Value::SetValue(const std::string& key, const Property::Value &value) +Property::Array* Property::Value::GetArray() const { - DALI_ASSERT_DEBUG(Property::MAP == GetType() && "Property type invalid"); - - Property::Map *container = AnyCast(&(mImpl->mValue)); - - if(container) + Property::Array* array = NULL; + if( mImpl && mImpl->type == ARRAY && mImpl->arrayValue ) { - (*container)[ key ] = value; + array = mImpl->arrayValue; } + return array; } -Property::Value& Property::Value::GetItem(const int index) const +std::ostream& operator<<( std::ostream& stream, const Property::Value& value ) { - switch( GetType() ) + if( value.mImpl ) { - case Property::MAP: - { - Property::Map *container = AnyCast(&(mImpl->mValue)); + const Property::Value::Impl& impl( *value.mImpl ); - DALI_ASSERT_DEBUG(container && "Property::Map has no container?"); - if(container) + switch( impl.type ) + { + case Dali::Property::BOOLEAN: { - DALI_ASSERT_ALWAYS(index < static_cast(container->Count()) && "Property array index invalid"); - DALI_ASSERT_ALWAYS(index >= 0 && "Property array index invalid"); - - return container->GetValue( index ); + stream << impl.integerValue; + break; } - } - break; - - case Property::ARRAY: - { - Property::Array *container = AnyCast(&(mImpl->mValue)); - - DALI_ASSERT_DEBUG(container && "Property::Map has no container?"); - if(container) + case Dali::Property::FLOAT: { - DALI_ASSERT_ALWAYS(index < static_cast(container->Size()) && "Property array index invalid"); - DALI_ASSERT_ALWAYS(index >= 0 && "Property array index invalid"); - - return (*container)[index]; + stream << impl.floatValue; + break; } - } - break; - - case Property::NONE: - case Property::BOOLEAN: - case Property::FLOAT: - case Property::INTEGER: - case Property::UNSIGNED_INTEGER: - case Property::VECTOR2: - case Property::VECTOR3: - case Property::VECTOR4: - case Property::MATRIX3: - case Property::MATRIX: - case Property::RECTANGLE: - case Property::ROTATION: - case Property::STRING: - case Property::TYPE_COUNT: - { - DALI_ASSERT_ALWAYS(!"Cannot GetItem on property Type; not a container"); - break; - } - - } // switch GetType() - - - DALI_ASSERT_ALWAYS(!"Property value index not valid"); -} - -Property::Value& Property::Value::GetItem(const int index, std::string& key) const -{ - Property::Value& ret( GetItem(index) ); - - if( Property::MAP == GetType() ) - { - Property::Map *container = AnyCast(&(mImpl->mValue)); - if( container && index < static_cast(container->Count()) ) - { - key = container->GetKey( index ); - } - } - - return ret; -} - -void Property::Value::SetItem(const int index, const Property::Value &value) -{ - switch( GetType() ) - { - case Property::MAP: - { - Property::Map *container = AnyCast(&(mImpl->mValue)); - if( container && index < static_cast(container->Count()) ) + case Dali::Property::INTEGER: { - Property::Value& indexValue = container->GetValue( index ); - indexValue = value; + stream << impl.integerValue; + break; } - } - break; - - case Property::ARRAY: - { - Property::Array *container = AnyCast(&(mImpl->mValue)); - if( container && index < static_cast(container->Size()) ) + case Dali::Property::UNSIGNED_INTEGER: { - (*container)[index] = value; + stream << impl.unsignedIntegerValue; + break; } - } - break; - - case Property::NONE: - case Property::BOOLEAN: - case Property::FLOAT: - case Property::INTEGER: - case Property::UNSIGNED_INTEGER: - case Property::VECTOR2: - case Property::VECTOR3: - case Property::VECTOR4: - case Property::MATRIX3: - case Property::MATRIX: - case Property::RECTANGLE: - case Property::ROTATION: - case Property::STRING: - case Property::TYPE_COUNT: - { - DALI_ASSERT_ALWAYS(!"Cannot SetItem on property Type; not a container"); - break; - } - } -} - -int Property::Value::AppendItem(const Property::Value &value) -{ - DALI_ASSERT_DEBUG(Property::ARRAY == GetType() && "Property type invalid"); - - Property::Array *container = AnyCast(&(mImpl->mValue)); - - if(container) - { - container->PushBack(value); - return container->Size() - 1; - } - else - { - return -1; - } - -} - -int Property::Value::GetSize() const -{ - int ret = 0; - - switch(GetType()) - { - case Property::MAP: - { - Property::Map *container = AnyCast(&(mImpl->mValue)); - if(container) + case Dali::Property::VECTOR2: { - ret = container->Count(); + stream << *impl.vector2Value; + break; } - } - break; - - case Property::ARRAY: - { - Property::Array *container = AnyCast(&(mImpl->mValue)); - if(container) + case Dali::Property::VECTOR3: { - ret = container->Size(); + stream << *impl.vector3Value; + break; + } + case Dali::Property::VECTOR4: + { + stream << *impl.vector4Value; + break; + } + case Dali::Property::MATRIX3: + { + stream << *impl.matrix3Value; + break; + } + case Dali::Property::MATRIX: + { + stream << *impl.matrixValue; + break; + } + case Dali::Property::RECTANGLE: + { + stream << *impl.rectValue; + break; + } + case Dali::Property::ROTATION: + { + stream << *impl.quaternionValue; + break; + } + case Dali::Property::STRING: + { + stream << *impl.stringValue; + break; + } + case Dali::Property::ARRAY: + { + stream << "Array containing" << impl.arrayValue->Count() << " elements"; // TODO add ostream<< operator in array + break; + } + case Dali::Property::MAP: + { + stream << "Map containing " << impl.mapValue->Count() << " elements"; // TODO add ostream<< operator in map + break; + } + case Dali::Property::NONE: + case Dali::Property::TYPE_COUNT: + { + stream << "undefined type"; + break; } } - break; - - case Property::NONE: - case Property::BOOLEAN: - case Property::FLOAT: - case Property::INTEGER: - case Property::UNSIGNED_INTEGER: - case Property::VECTOR2: - case Property::VECTOR3: - case Property::VECTOR4: - case Property::MATRIX3: - case Property::MATRIX: - case Property::RECTANGLE: - case Property::ROTATION: - case Property::STRING: - case Property::TYPE_COUNT: - { - break; - } - } - - return ret; -} - -std::ostream& operator<< (std::ostream& stream, const Property::Value& value ) -{ - - const Property::Value::Impl& impl( *value.mImpl ); - - switch( impl.mType ) + else { - case Dali::Property::STRING: - { - stream << AnyCast(impl.mValue).c_str(); - break; - } - case Dali::Property::VECTOR2: - { - stream << AnyCast(impl.mValue); - break; - } - case Dali::Property::VECTOR3: - { - stream << AnyCast(impl.mValue); - break; - } - case Dali::Property::VECTOR4: - { - stream << AnyCast(impl.mValue); - break; - } - case Dali::Property::MATRIX: - { - stream << AnyCast(impl.mValue); - break; - } - case Dali::Property::BOOLEAN: - { - stream << AnyCast(impl.mValue); - break; - } - case Dali::Property::FLOAT: - { - stream << AnyCast(impl.mValue); - break; - } - case Dali::Property::INTEGER: - { - stream << AnyCast(impl.mValue); - break; - } - case Dali::Property::UNSIGNED_INTEGER: - { - stream << AnyCast(impl.mValue); - break; - } - case Dali::Property::RECTANGLE: - { - Dali::Rect rect; // Propery Value rectangles are currently integer based - value.Get( rect ); - stream << rect; - break; - } - case Dali::Property::MATRIX3: - { - stream << AnyCast(impl.mValue); - break; - } - case Dali::Property::ROTATION: - { - // @todo this may change to Quaternion - Dali::Quaternion q; - value.Get( q ); - Dali::Vector4 v4 = q.EulerAngles(); - stream << v4; - break; - } - - case Dali::Property::ARRAY: - { - // @todo Need to think about the best way to support array - // E.g Do we want to create a JSON style array like: - // [ {"property-name-0":"property-value-0", "property-name-1":"property-value-1"} ] - stream << "ARRAY unsupported"; - break; - } - case Dali::Property::MAP: - { - Dali::Property::Map map; - value.Get( map ); - stream << "Map containing " << map.Count() << " elements"; - break; - } - case Dali::Property::TYPE_COUNT: - { - stream << "unsupported TYPE_COUNT"; - break; - } - default: - { - stream << "unsupported type = " << value.GetType(); - break; - } + stream << "empty type"; } return stream; } diff --git a/dali/public-api/object/property-value.h b/dali/public-api/object/property-value.h index 378fba2..f096d7b 100644 --- a/dali/public-api/object/property-value.h +++ b/dali/public-api/object/property-value.h @@ -43,8 +43,6 @@ class DALI_IMPORT_API Property::Value { public: - friend std::ostream& operator<< (std::ostream& ouputStream, const Property::Value& value); - /** * @brief Default constructor. * @@ -57,126 +55,126 @@ public: * * @param [in] boolValue A boolean value. */ - Value(bool boolValue); + Value( bool boolValue ); /** * @brief Create an integer property value. * * @param [in] integerValue An integer value. */ - Value(int integerValue); + Value( int integerValue ); /** * @brief Create an unsigned integer property value. * * @param [in] unsignedIntegerValue An unsigned integer value. */ - Value(unsigned int unsignedIntegerValue); + Value( unsigned int unsignedIntegerValue ); /** * @brief Create a float property value. * * @param [in] floatValue A floating-point value. */ - Value(float floatValue); + Value( float floatValue ); /** * @brief Create a Vector2 property value. * * @param [in] vectorValue A vector of 2 floating-point values. */ - Value(const Vector2& vectorValue); + Value( const Vector2& vectorValue ); /** * @brief Create a Vector3 property value. * * @param [in] vectorValue A vector of 3 floating-point values. */ - Value(const Vector3& vectorValue); + Value( const Vector3& vectorValue ); /** * @brief Create a Vector4 property value. * * @param [in] vectorValue A vector of 4 floating-point values. */ - Value(const Vector4& vectorValue); + Value( const Vector4& vectorValue ); /** * @brief Create a Matrix3 property value. * * @param [in] matrixValue A matrix of 3x3 floating-point values. */ - Value(const Matrix3& matrixValue); + Value( const Matrix3& matrixValue ); /** * @brief Create a Matrix property value. * * @param [in] matrixValue A matrix of 4x4 floating-point values. */ - Value(const Matrix& matrixValue); + Value( const Matrix& matrixValue ); /** * @brief Create a Vector4 property value. * * @param [in] vectorValue A vector of 4 integer values. */ - Value(const Rect& vectorValue); + Value( const Rect& vectorValue ); /** * @brief Create an orientation property value. * * @param [in] angleAxis An angle-axis representing the rotation. */ - Value(const AngleAxis& angleAxis); + Value( const AngleAxis& angleAxis ); /** * @brief Create an orientation property value. * * @param [in] quaternion A quaternion representing the rotation. */ - Value(const Quaternion& quaternion); + Value( const Quaternion& quaternion ); /** * @brief Create an string property value. * * @param [in] stringValue A string. */ - Value(const std::string& stringValue); + Value( const std::string& stringValue ); /** * @brief Create an string property value. * * @param [in] stringValue A string. */ - Value(const char* stringValue); + Value( const char* stringValue ); /** * @brief Copy a property value. * * @param [in] value The property value to copy. */ - Value(const Value& value); + Value( const Value& value ); /** * @brief Create an array property value. * * @param [in] arrayValue An array */ - Value(Property::Array& arrayValue); + Value( Property::Array& arrayValue ); /** * @brief Create a map property value. * * @param [in] mapValue An array */ - Value(Property::Map& mapValue); + Value( Property::Map& mapValue ); /** * @brief Explicitly set a type and initialize it. * * @param [in] type The property value type. */ - explicit Value(Type type); + explicit Value( Type type ); /** * @brief Assign a property value. @@ -184,7 +182,7 @@ public: * @param [in] value The property value to assign from. * @return a reference to this */ - Value& operator=(const Value& value); + Value& operator=( const Value& value ); /** * @brief Non-virtual destructor. @@ -218,7 +216,7 @@ public: * @pre GetType() returns Property::BOOLEAN. * @param [out] boolValue On return, a boolean value. */ - void Get(bool& boolValue) const; + void Get( bool& boolValue ) const; /** * @brief Retrieve a floating-point value. @@ -226,7 +224,7 @@ public: * @pre GetType() returns Property::FLOAT. * @param [out] floatValue On return, a floating-point value. */ - void Get(float& floatValue) const; + void Get( float& floatValue ) const; /** * @brief Retrieve an integer value. @@ -234,7 +232,7 @@ public: * @pre GetType() returns Property::INTEGER. * @param [out] integerValue On return, an integer value. */ - void Get(int& integerValue) const; + void Get( int& integerValue ) const; /** * @brief Retrieve an unsigned integer value. @@ -242,7 +240,7 @@ public: * @pre GetType() returns Property::UNSIGNED_INTEGER. * @param [out] unsignedIntegerValue On return, an unsigned integer value. */ - void Get(unsigned int& unsignedIntegerValue) const; + void Get( unsigned int& unsignedIntegerValue ) const; /** * @brief Retrieve an integer rectangle. @@ -250,7 +248,7 @@ public: * @pre GetType() returns Property::RECTANGLE. * @param [out] rect On return, an integer rectangle. */ - void Get(Rect& rect) const; + void Get( Rect& rect ) const; /** * @brief Retrieve a vector value. @@ -258,7 +256,7 @@ public: * @pre GetType() returns Property::VECTOR2. * @param [out] vectorValue On return, a vector value. */ - void Get(Vector2& vectorValue) const; + void Get( Vector2& vectorValue ) const; /** * @brief Retrieve a vector value. @@ -266,7 +264,7 @@ public: * @pre GetType() returns Property::VECTOR3. * @param [out] vectorValue On return, a vector value. */ - void Get(Vector3& vectorValue) const; + void Get( Vector3& vectorValue ) const; /** * @brief Retrieve a vector value. @@ -274,7 +272,7 @@ public: * @pre GetType() returns Property::VECTOR4. * @param [out] vectorValue On return, a vector value. */ - void Get(Vector4& vectorValue) const; + void Get( Vector4& vectorValue ) const; /** * @brief Retrieve a matrix3 value. @@ -282,7 +280,7 @@ public: * @pre GetType() returns Property::MATRIX3. * @param [out] matrixValue On return, a matrix3 value. */ - void Get(Matrix3& matrixValue) const; + void Get( Matrix3& matrixValue ) const; /** * @brief Retrieve a matrix value. @@ -290,7 +288,7 @@ public: * @pre GetType() returns Property::MATRIX. * @param [out] matrixValue On return, a matrix value. */ - void Get(Matrix& matrixValue) const; + void Get( Matrix& matrixValue ) const; /** * @brief Retrieve an angle-axis value. @@ -298,7 +296,7 @@ public: * @pre GetType() returns Property::ROTATION. * @param [out] angleAxisValue On return, a angle-axis value. */ - void Get(AngleAxis& angleAxisValue) const; + void Get( AngleAxis& angleAxisValue ) const; /** * @brief Retrieve a quaternion value. @@ -306,7 +304,7 @@ public: * @pre GetType() returns Property::ROTATION. * @param [out] quaternionValue On return, a quaternion value. */ - void Get(Quaternion& quaternionValue) const; + void Get( Quaternion& quaternionValue ) const; /** * @brief Retrieve an string property value. @@ -314,7 +312,7 @@ public: * @pre GetType() returns Property::STRING. * @param [out] stringValue A string. */ - void Get(std::string& stringValue) const; + void Get( std::string& stringValue ) const; /** * @brief Retrieve an array property value. @@ -322,7 +320,7 @@ public: * @pre GetType() returns Property::ARRAY. * @param [out] arrayValue The array as a vector Property Values */ - void Get(Property::Array& arrayValue) const; + void Get( Property::Array& arrayValue ) const; /** * @brief Retrieve an map property value. @@ -330,96 +328,52 @@ public: * @pre GetType() returns Property::MAP. * @param [out] mapValue The map as vector of string and Property Value pairs */ - void Get(Property::Map& mapValue) const; - - /** - * @brief Retrieve a property value from the internal map. - * - * @pre GetType() returns Property::MAP. - * @param [in] key A string. - * @return Property value if available at key or Invalid - */ - Property::Value& GetValue(const std::string& key) const; - - /** - * @brief Retrieve a property value from the internal map. - * - * @param [in] key A string. - * @return true if the key exists, false if not a map or key does not exist - */ - bool HasKey(const std::string& key) const; + void Get( Property::Map& mapValue ) const; /** - * @brief Retrieve a property value from the internal array or map. + * @brief return true if this property is a Property::MAP. * - * @pre GetType() returns Property::ARRAY or Property::MAP. - * @param [in] index The item index. - * @return Key at the index or empty if index is out of range + * @return return true if this property is a Property::MAP */ - const std::string& GetKey(const int index) const; - - /** - * @brief Set a property value in the map. - * - * @pre GetType() returns Property::MAP. - * @param [in] key A string key. - * @param [in] value The value to set. - * @return Property value if available at key - */ - void SetValue(const std::string& key, const Property::Value &value); - - /** - * @brief Retrieve a property value from the internal array or map. - * - * @pre GetType() returns Property::ARRAY or Property::MAP. - * @param [in] index The item index. - * @return Property value if available at index or Invalid - */ - Property::Value& GetItem(const int index) const; + bool IsMap() const + { + return GetMap() != NULL; + } /** - * @brief Retrieve a property value from the internal array or map. + * @brief Retrieve the Map API of the Property::Value without copying the contents of the map * - * @pre GetType() returns Property::ARRAY or Property::MAP. - * @param [in] index The item index. - * @param [out] key The key of the index (Applicable only for Property::MAP). - * @return Property value if available at index or Invalid + * @return the Map API of the Property::Value or NULL if not a Property::Map */ - Property::Value& GetItem(const int index, std::string& key) const; + Property::Map* GetMap() const; /** - * @brief Set a property value in the array or map. + * @brief return true if this property is a Property::ARRAY. * - * @pre GetType() returns Property::ARRAY or Property::MAP. - * @pre index < GetSize() - * @param [in] index The property value index - * @param [in] value The value to set. - * @return Property value if index < GetSize() + * @return return true if this property is a Property::ARRAY */ - void SetItem(const int index, const Property::Value &value); + bool IsArray() const + { + return GetArray() != NULL; + } /** - * @brief Set a property value in the array. + * @brief Retrieve the Array API of the Property::Value without copying the contents of the map * - * @pre GetType() returns Property::ARRAY. - * @param [in] value The value to set. - * @return THe index of the item just added + * @return the Array API of the Property::Value or NULL if not a Property::Array */ - int AppendItem(const Property::Value &value); + Property::Array* GetArray() const; /** - * @brief Retrieve the length of the array or map. - * - * Zero if neither. - * @pre GetType() returns Property::ARRAY or Property::MAP - * @return The length of the array + * output to stream */ - int GetSize() const; + friend std::ostream& operator<<( std::ostream& ouputStream, const Property::Value& value ); private: struct DALI_INTERNAL Impl; Impl* mImpl; ///< Pointer to the implementation + }; /** @@ -429,8 +383,7 @@ private: * @param [in] value The value to insert * @return The output stream operator. */ -DALI_IMPORT_API std::ostream& operator<< (std::ostream& ouputStream, const Property::Value& value); - +DALI_IMPORT_API std::ostream& operator<<( std::ostream& ouputStream, const Property::Value& value ); } // namespace Dali