From baae72ecde3f942d91829d0b2a042097b0206967 Mon Sep 17 00:00:00 2001 From: Kimmo Hoikka Date: Tue, 16 Jun 2015 15:29:25 +0100 Subject: [PATCH] Change Property::Value::Get methods to return bool so developer can check if conversion is successfull Change-Id: Ic91f7180412c7bfb81f572857a534fd653e52099 --- .../src/dali/utc-Dali-PropertyValue.cpp | 228 ++++++++++++------ dali/internal/event/common/object-impl.cpp | 1 - dali/internal/render/shaders/shader.cpp | 1 - dali/public-api/math/angle-axis.h | 12 + dali/public-api/math/matrix3.cpp | 3 - dali/public-api/object/property-types.cpp | 5 +- dali/public-api/object/property-value.cpp | 255 ++++++++++----------- dali/public-api/object/property-value.h | 94 ++++---- dali/public-api/object/property.h | 3 +- 9 files changed, 340 insertions(+), 262 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-PropertyValue.cpp b/automated-tests/src/dali/utc-Dali-PropertyValue.cpp index 5163b92..e0f6905 100644 --- a/automated-tests/src/dali/utc-Dali-PropertyValue.cpp +++ b/automated-tests/src/dali/utc-Dali-PropertyValue.cpp @@ -105,11 +105,6 @@ void CheckTypeName(const Property::Type& type) DALI_TEST_CHECK( "MAP" == std::string(PropertyTypes::GetName( type ) ) ); break; } - case Property::TYPE_COUNT: - { - DALI_TEST_CHECK( "NONE" == std::string(PropertyTypes::GetName( type ) ) ); - break; - } } // switch(type) } // CheckTypeName @@ -124,43 +119,6 @@ struct CheckCopyCtorP } }; -template <> -struct CheckCopyCtorP -{ - CheckCopyCtorP(Property::Value value) - { - Property::Value copy( value ); - AngleAxis a = value.Get(); - AngleAxis b = copy.Get(); - DALI_TEST_CHECK( a.angle == b.angle ); - DALI_TEST_CHECK( a.axis == b.axis ); - } -}; - -template <> -struct CheckCopyCtorP -{ - CheckCopyCtorP(Property::Value value) - { - Property::Value copy( value ); - Property::Array a = value.Get(); - Property::Array b = copy.Get(); - DALI_TEST_CHECK( a.Size() == b.Size() ); - } -}; - -template <> -struct CheckCopyCtorP -{ - CheckCopyCtorP(Property::Value value) - { - Property::Value copy( value ); - Property::Map a = value.Get(); - Property::Map b = copy.Get(); - DALI_TEST_CHECK( a.Count() == b.Count() ); - } -}; - } // unnamed namespace void utc_dali_property_value_startup(void) @@ -189,10 +147,6 @@ int UtcDaliPropertyValueConstructorsNoneTypeP(void) DALI_TEST_CHECK( value.GetType() == Property::NONE ); - Property::Value value2( Property::TYPE_COUNT ); - - DALI_TEST_CHECK( value2.GetType() == Property::NONE ); - END_TEST; } @@ -531,8 +485,8 @@ int UtcDaliPropertyValueCopyConstructorP(void) 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 ); + DALI_TEST_EQUALS( value.GetMap(), value2.GetMap(), TEST_LOCATION ); + DALI_TEST_EQUALS( value.GetArray(), value2.GetArray(), TEST_LOCATION ); END_TEST; } @@ -647,8 +601,8 @@ int UtcDaliPropertyValueAssignmentSelfP(void) 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 ); + DALI_TEST_CHECK( value.GetMap() == NULL ); + DALI_TEST_CHECK( value.GetArray() == NULL ); END_TEST; } @@ -852,7 +806,11 @@ int UtcDaliPropertyValueGetTypeP(void) int UtcDaliPropertyValueGetBoolP(void) { Property::Value value(true); + bool boolean( false ); + DALI_TEST_CHECK( value.Get( boolean ) == true ); DALI_TEST_CHECK( value.Get() == true ); + std::string string; + DALI_TEST_CHECK( value.Get( string ) == false ); value = Property::Value(1.f); DALI_TEST_CHECK( value.Get() == 1.f ); END_TEST; @@ -862,118 +820,190 @@ int UtcDaliPropertyValueGetBoolN(void) { Property::Value value; DALI_TEST_CHECK( value.Get() == false ); + bool boolean( false ); + DALI_TEST_CHECK( value.Get( boolean ) == false ); END_TEST; } int UtcDaliPropertyValueGetFloatP(void) { Property::Value value(1.1f); + float flow( 0.0f ); DALI_TEST_EQUALS( 1.1f, value.Get(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, value.Get( flow ), TEST_LOCATION ); END_TEST; } int UtcDaliPropertyValueGetFloatN(void) { Property::Value value; - DALI_TEST_EQUALS( 0.0f, value.Get(), TEST_LOCATION ); + float result( 1.0f ); + DALI_TEST_EQUALS( false, value.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( 1.0f, result, TEST_LOCATION ); // result is not modified + Property::Value value2( "" ); + DALI_TEST_EQUALS( false, value2.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( 1.0f, result, TEST_LOCATION ); // result is not modified END_TEST; } int UtcDaliPropertyValueGetIntP(void) { Property::Value value(123); + int result( 10 ); DALI_TEST_EQUALS( 123, value.Get(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, value.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( 123, result, TEST_LOCATION ); END_TEST; } int UtcDaliPropertyValueGetIntN(void) { Property::Value value; + int result( 10 ); DALI_TEST_EQUALS( 0, value.Get(), TEST_LOCATION ); + DALI_TEST_EQUALS( false, value.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( 10, result, TEST_LOCATION ); // result is not modified + Property::Value value2(""); + DALI_TEST_EQUALS( false, value2.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( 10, result, TEST_LOCATION ); // result is not modified END_TEST; } int UtcDaliPropertyValueGetUnsignedIntP(void) { Property::Value value(123u); + unsigned int result( 10u ); DALI_TEST_EQUALS( 123u, value.Get(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, value.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( 123u, result, TEST_LOCATION ); END_TEST; } int UtcDaliPropertyValueGetUnsignedIntN(void) { Property::Value value; + unsigned int result( 10u ); DALI_TEST_EQUALS( 0u, value.Get(), TEST_LOCATION ); + DALI_TEST_EQUALS( false, value.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( 10u, result, TEST_LOCATION ); + Property::Value value2(""); + DALI_TEST_EQUALS( false, value2.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( 10u, result, TEST_LOCATION ); // result is not modified END_TEST; } int UtcDaliPropertyValueGetRectP(void) { Property::Value value( Rect(1,2,3,4) ); + Rect result(4,3,2,1); DALI_TEST_EQUALS( Rect(1,2,3,4), value.Get< Rect >(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, value.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( Rect(1,2,3,4), result, TEST_LOCATION ); END_TEST; } int UtcDaliPropertyValueGetRectN(void) { Property::Value value; + Rect result(4,3,2,1); DALI_TEST_EQUALS( Rect(0,0,0,0), value.Get< Rect >(), TEST_LOCATION ); + DALI_TEST_EQUALS( false, value.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( Rect(4,3,2,1), result, TEST_LOCATION ); + Property::Value value2(""); + DALI_TEST_EQUALS( false, value2.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( Rect(4,3,2,1), result, TEST_LOCATION ); END_TEST; } int UtcDaliPropertyValueGetVector2P(void) { Property::Value value( Vector2(1.0f,2.0f) ); + Vector2 result; DALI_TEST_EQUALS( Vector2(1.0f,2.0f), value.Get< Vector2 >(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, value.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( Vector2(1.0f,2.0f), result, TEST_LOCATION ); END_TEST; } int UtcDaliPropertyValueGetVector2N(void) { Property::Value value; + Vector2 result; DALI_TEST_EQUALS( Vector2(0.f,0.f), value.Get< Vector2 >(), TEST_LOCATION ); + DALI_TEST_EQUALS( false, value.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( Vector2(), result, TEST_LOCATION ); + Property::Value value2(""); + DALI_TEST_EQUALS( false, value2.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( Vector2(), result, TEST_LOCATION ); END_TEST; } int UtcDaliPropertyValueGetVector3P(void) { Property::Value value( Vector3(1.0f,2.0f,-1.f) ); + Vector3 result; DALI_TEST_EQUALS( Vector3(1.0f,2.0f,-1.f), value.Get< Vector3 >(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, value.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( Vector3(1.0f,2.0f,-1.f), result, TEST_LOCATION ); END_TEST; } int UtcDaliPropertyValueGetVector3N(void) { Property::Value value; + Vector3 result; DALI_TEST_EQUALS( Vector3(0.f,0.f,0.f), value.Get< Vector3 >(), TEST_LOCATION ); + DALI_TEST_EQUALS( false, value.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( Vector3(), result, TEST_LOCATION ); + Property::Value value2(""); + DALI_TEST_EQUALS( false, value2.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( Vector3(), result, TEST_LOCATION ); END_TEST; } int UtcDaliPropertyValueGetVector4P(void) { Property::Value value( Vector4(1.f,2.f,-1.f,-3.f) ); + Vector4 result; DALI_TEST_EQUALS( Vector4(1.f,2.f,-1.f,-3.f), value.Get< Vector4 >(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, value.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( Vector4(1.f,2.f,-1.f,-3.f), result, TEST_LOCATION ); END_TEST; } int UtcDaliPropertyValueGetVector4N(void) { Property::Value value; + Vector4 result; DALI_TEST_EQUALS( Vector4(0.f,0.f,0.f,0.f), value.Get< Vector4 >(), TEST_LOCATION ); + DALI_TEST_EQUALS( false, value.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( Vector4(), result, TEST_LOCATION ); + Property::Value value2(""); + DALI_TEST_EQUALS( false, value2.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( Vector4(), result, TEST_LOCATION ); END_TEST; } int UtcDaliPropertyValueGetMatrix3P(void) { Property::Value value( Matrix3(1.f,2.f,3.f,4.f,5.f,6.f,7.f,8.f,9.f) ); + Matrix3 result; 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 ); + DALI_TEST_EQUALS( true, value.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( Matrix3(1.f,2.f,3.f,4.f,5.f,6.f,7.f,8.f,9.f), result, TEST_LOCATION ); END_TEST; } int UtcDaliPropertyValueGetMatrix3N(void) { Property::Value value; - DALI_TEST_EQUALS( Matrix3::IDENTITY, value.Get< Matrix3 >(), TEST_LOCATION ); + Matrix3 result(1.f,2.f,3.f,4.f,5.f,6.f,7.f,8.f,9.f); + DALI_TEST_EQUALS( Matrix3(), value.Get< Matrix3 >(), TEST_LOCATION ); + DALI_TEST_EQUALS( false, value.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( Matrix3(1.f,2.f,3.f,4.f,5.f,6.f,7.f,8.f,9.f), result, TEST_LOCATION ); + Property::Value value2(""); + DALI_TEST_EQUALS( false, value2.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( Matrix3(1.f,2.f,3.f,4.f,5.f,6.f,7.f,8.f,9.f), result, TEST_LOCATION ); END_TEST; } @@ -982,14 +1012,24 @@ int UtcDaliPropertyValueGetMatrixP(void) 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 ); + Matrix result; DALI_TEST_EQUALS( input, value.Get< Matrix >(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, value.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( input, result, TEST_LOCATION ); END_TEST; } int UtcDaliPropertyValueGetMatrixN(void) { Property::Value value; - DALI_TEST_EQUALS( Matrix::IDENTITY, value.Get< Matrix >(), TEST_LOCATION ); + Matrix result( Matrix::IDENTITY ); + DALI_TEST_EQUALS( Matrix(), value.Get< Matrix >(), TEST_LOCATION ); + DALI_TEST_EQUALS( false, value.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( Matrix::IDENTITY, result, TEST_LOCATION ); + + Property::Value value2(""); + DALI_TEST_EQUALS( false, value2.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( Matrix::IDENTITY, result, TEST_LOCATION ); END_TEST; } @@ -1000,6 +1040,9 @@ int UtcDaliPropertyValueGetAngleAxisP(void) AngleAxis result = value.Get(); DALI_TEST_EQUALS( input.angle, result.angle, TEST_LOCATION ); DALI_TEST_EQUALS( input.axis, result.axis, TEST_LOCATION ); + + DALI_TEST_EQUALS( true, value.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( input, result, TEST_LOCATION ); END_TEST; } @@ -1007,36 +1050,72 @@ int UtcDaliPropertyValueGetAngleAxisN(void) { Property::Value value; AngleAxis b = value.Get(); + AngleAxis result; DALI_TEST_EQUALS( 0.f, b.angle, TEST_LOCATION ); DALI_TEST_EQUALS( Vector3::ZERO, b.axis, TEST_LOCATION ); + DALI_TEST_EQUALS( false, value.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( AngleAxis(), result, TEST_LOCATION ); + + Property::Value value2(""); + DALI_TEST_EQUALS( false, value2.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( AngleAxis(), result, TEST_LOCATION ); END_TEST; } int UtcDaliPropertyValueGetQuaternionP(void) { Property::Value value( Quaternion(1.f,2.f,3.f,4.f) ); + Quaternion result; DALI_TEST_EQUALS( Quaternion(1.f,2.f,3.f,4.f), value.Get< Quaternion >(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, value.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( Quaternion(1.f,2.f,3.f,4.f), result, TEST_LOCATION ); END_TEST; } int UtcDaliPropertyValueGetQuaternionN(void) { Property::Value value; - DALI_TEST_EQUALS( Quaternion::IDENTITY, value.Get< Quaternion >(), TEST_LOCATION ); + Quaternion result(1.f,2.f,3.f,4.f); + DALI_TEST_EQUALS( Quaternion(), value.Get< Quaternion >(), TEST_LOCATION ); + DALI_TEST_EQUALS( false, value.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( Quaternion(1.f,2.f,3.f,4.f), result, TEST_LOCATION ); + + Property::Value value2(""); + DALI_TEST_EQUALS( false, value2.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( Quaternion(1.f,2.f,3.f,4.f), result, TEST_LOCATION ); END_TEST; } int UtcDaliPropertyValueGetStringP(void) { Property::Value value( std::string("hello") ); + std::string result; DALI_TEST_EQUALS( std::string("hello"), value.Get< std::string >(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, value.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( std::string("hello"), result, TEST_LOCATION ); + + Property::Value value2( "C hi!" ); + DALI_TEST_EQUALS( "C hi!", value2.Get< std::string >(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, value2.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( "C hi!", result, TEST_LOCATION ); END_TEST; } int UtcDaliPropertyValueGetStringN(void) { Property::Value value; - DALI_TEST_EQUALS( std::string(""), value.Get< std::string >(), TEST_LOCATION ); + std::string result("doesn't change"); + DALI_TEST_EQUALS( std::string(), value.Get< std::string >(), TEST_LOCATION ); + DALI_TEST_EQUALS( false, value.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( "doesn't change", result, TEST_LOCATION ); + + Property::Value value2(10); + DALI_TEST_EQUALS( false, value2.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( "doesn't change", result, TEST_LOCATION ); + + Property::Value value3((char*)NULL); + DALI_TEST_EQUALS( true, value3.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( std::string(), result, TEST_LOCATION ); END_TEST; } @@ -1047,6 +1126,9 @@ int UtcDaliPropertyValueGetArrayP(void) value.GetArray()->PushBack( Property::Value(1) ); Property::Array got = value.Get(); DALI_TEST_CHECK( got[0].Get() == 1); + Property::Array result; + DALI_TEST_EQUALS( true, value.Get( result ), TEST_LOCATION ); + DALI_TEST_CHECK( result[0].Get() == 1); END_TEST; } @@ -1054,10 +1136,14 @@ int UtcDaliPropertyValueGetArrayN(void) { 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() ); + Property::Array result; + result.PushBack( Property::Value( 10 ) ); + DALI_TEST_EQUALS( false, value.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( 1, result.Count(), TEST_LOCATION ); // array is not modified + + Property::Value value2(""); + DALI_TEST_EQUALS( false, value2.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( 1, result.Count(), TEST_LOCATION ); // array is not modified END_TEST; } @@ -1067,8 +1153,10 @@ int UtcDaliPropertyValueGetMapP(void) 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); + Property::Map result = value.Get(); + DALI_TEST_CHECK(result.Find("key")->Get() == 1); + DALI_TEST_EQUALS( true, value.Get( result ), TEST_LOCATION ); + DALI_TEST_CHECK(result.Find("key")->Get() == 1); END_TEST; } @@ -1076,8 +1164,15 @@ int UtcDaliPropertyValueGetMapN(void) { Property::Value value; DALI_TEST_CHECK( NULL == value.GetMap() ); - Property::Map map = value.Get(); - DALI_TEST_CHECK( 0 == map.Count() ); + DALI_TEST_EQUALS( 0, value.Get().Count(), TEST_LOCATION ); + Property::Map result; + result.Insert("key", "value" ); + DALI_TEST_EQUALS( false, value.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( 1, result.Count(), TEST_LOCATION ); + + Property::Value value2(""); + DALI_TEST_EQUALS( false, value2.Get( result ), TEST_LOCATION ); + DALI_TEST_EQUALS( 1, result.Count(), TEST_LOCATION ); // array is not modified END_TEST; } @@ -1109,13 +1204,6 @@ int UtcDaliPropertyValueOutputStream(void) } { - Property::Value empty( Property::TYPE_COUNT ); - std::ostringstream stream; - stream << empty; - DALI_TEST_CHECK( stream.str() == "undefined type" ) - } - - { value = Property::Value(20.2f); std::ostringstream stream; stream << value; diff --git a/dali/internal/event/common/object-impl.cpp b/dali/internal/event/common/object-impl.cpp index 6b9083a..0bbab21 100644 --- a/dali/internal/event/common/object-impl.cpp +++ b/dali/internal/event/common/object-impl.cpp @@ -587,7 +587,6 @@ Property::Index Object::RegisterSceneGraphProperty(const std::string& name, Prop case Property::ARRAY: case Property::MAP: case Property::NONE: - case Property::TYPE_COUNT: { DALI_ASSERT_ALWAYS( !"PropertyType is not animatable" ); break; diff --git a/dali/internal/render/shaders/shader.cpp b/dali/internal/render/shaders/shader.cpp index fded09a..3c10a7e 100644 --- a/dali/internal/render/shaders/shader.cpp +++ b/dali/internal/render/shaders/shader.cpp @@ -466,7 +466,6 @@ void Shader::SetUniforms( Context& context, case Property::RECTANGLE: case Property::MAP: case Property::ARRAY: - case Property::TYPE_COUNT: { DALI_LOG_ERROR( "Invalid property type for a uniform" ); break; diff --git a/dali/public-api/math/angle-axis.h b/dali/public-api/math/angle-axis.h index 0d7464c..3d9f333 100644 --- a/dali/public-api/math/angle-axis.h +++ b/dali/public-api/math/angle-axis.h @@ -61,6 +61,18 @@ struct AngleAxis // compiler generated destructor, copy constructor and assignment operators are ok as this class is POD +/** + * @brief Compare two angle axis for equality + * + * @param lhs angle axis + * @param rhs angle axis + * @return true if they are equal + */ +inline bool operator==( const Dali::AngleAxis& lhs, const Dali::AngleAxis& rhs ) +{ + return (lhs.angle == rhs.angle) && (lhs.axis == rhs.axis); +} + } // namespace Dali #endif // __DALI_ANGLE_AXIS_H__ diff --git a/dali/public-api/math/matrix3.cpp b/dali/public-api/math/matrix3.cpp index 2677f99..3273a31 100644 --- a/dali/public-api/math/matrix3.cpp +++ b/dali/public-api/math/matrix3.cpp @@ -58,9 +58,6 @@ Matrix3::Matrix3() { float* m = AsFloat(); memset(m, 0, NUM_BYTES_IN_MATRIX); - mElements[S00]=1.0f; - mElements[S11]=1.0f; - mElements[S22]=1.0f; } Matrix3::Matrix3(const Matrix3& m) diff --git a/dali/public-api/object/property-types.cpp b/dali/public-api/object/property-types.cpp index 5728ed8..8ca60a9 100644 --- a/dali/public-api/object/property-types.cpp +++ b/dali/public-api/object/property-types.cpp @@ -23,7 +23,7 @@ namespace Dali namespace { -const char* const PROPERTY_TYPE_NAMES[ Property::TYPE_COUNT ] = +const char* const PROPERTY_TYPE_NAMES[] = { "NONE", "BOOLEAN", @@ -41,6 +41,7 @@ const char* const PROPERTY_TYPE_NAMES[ Property::TYPE_COUNT ] = "ARRAY", "MAP", }; +const unsigned int PROPERTY_TYPE_NAMES_COUNT = sizeof( PROPERTY_TYPE_NAMES ) / sizeof( const char* ); } namespace PropertyTypes @@ -49,7 +50,7 @@ namespace PropertyTypes DALI_EXPORT_API const char* const GetName(Property::Type type) { - if (type < Property::TYPE_COUNT) + if (type < PROPERTY_TYPE_NAMES_COUNT ) { return PROPERTY_TYPE_NAMES[type]; } diff --git a/dali/public-api/object/property-value.cpp b/dali/public-api/object/property-value.cpp index 6d1e7ef..6a46abb 100644 --- a/dali/public-api/object/property-value.cpp +++ b/dali/public-api/object/property-value.cpp @@ -148,7 +148,6 @@ struct Property::Value::Impl switch( type ) { case Property::NONE : // FALLTHROUGH - case Property::TYPE_COUNT : // FALLTHROUGH case Property::BOOLEAN : // FALLTHROUGH case Property::FLOAT : // FALLTHROUGH case Property::INTEGER : // FALLTHROUGH @@ -302,8 +301,16 @@ Property::Value::Value( const std::string& stringValue ) } Property::Value::Value( const char* stringValue ) -: mImpl( new Impl( std::string(stringValue) ) ) +: mImpl( NULL ) { + if( stringValue ) // string constructor is undefined with NULL pointer + { + mImpl = new Impl( std::string(stringValue) ); + } + else + { + mImpl = new Impl( std::string() ); + } } Property::Value::Value( Property::Array& arrayValue ) @@ -316,19 +323,6 @@ Property::Value::Value( Property::Map& mapValue ) { } - -Property::Value::~Value() -{ - delete mImpl; -} - -Property::Value::Value( const Property::Value& value ) -: mImpl( NULL ) -{ - // reuse assignment operator - operator=( value ); -} - Property::Value::Value( Type type ) { switch (type) @@ -404,13 +398,18 @@ Property::Value::Value( Type type ) break; } case Property::NONE: - case Property::TYPE_COUNT: { mImpl = new Impl(); break; } } } +Property::Value::Value( const Property::Value& value ) +: mImpl( NULL ) +{ + // reuse assignment operator + operator=( value ); +} Property::Value& Property::Value::operator=( const Property::Value& value ) { @@ -453,56 +452,55 @@ Property::Value& Property::Value::operator=( const Property::Value& value ) } case Property::VECTOR2: { - *mImpl->vector2Value = *value.mImpl->vector2Value; + *mImpl->vector2Value = *value.mImpl->vector2Value; // type cannot change in mImpl so vector is allocated break; } case Property::VECTOR3: { - *mImpl->vector3Value = *value.mImpl->vector3Value; + *mImpl->vector3Value = *value.mImpl->vector3Value; // type cannot change in mImpl so vector is allocated break; } case Property::VECTOR4: { - *mImpl->vector4Value = *value.mImpl->vector4Value; + *mImpl->vector4Value = *value.mImpl->vector4Value; // type cannot change in mImpl so vector is allocated break; } case Property::RECTANGLE: { - *mImpl->rectValue = *value.mImpl->rectValue; + *mImpl->rectValue = *value.mImpl->rectValue; // type cannot change in mImpl so rect is allocated break; } case Property::ROTATION: { - *mImpl->quaternionValue = *value.mImpl->quaternionValue; + *mImpl->quaternionValue = *value.mImpl->quaternionValue; // type cannot change in mImpl so quaternion is allocated break; } case Property::STRING: { - *mImpl->stringValue = *value.mImpl->stringValue; + *mImpl->stringValue = *value.mImpl->stringValue; // type cannot change in mImpl so string is allocated break; } case Property::MATRIX: { - *mImpl->matrixValue = *value.mImpl->matrixValue; + *mImpl->matrixValue = *value.mImpl->matrixValue; // type cannot change in mImpl so matrix is allocated break; } case Property::MATRIX3: { - *mImpl->matrix3Value = *value.mImpl->matrix3Value; + *mImpl->matrix3Value = *value.mImpl->matrix3Value; // type cannot change in mImpl so matrix is allocated break; } case Property::ARRAY: { - *mImpl->arrayValue = *value.mImpl->arrayValue; + *mImpl->arrayValue = *value.mImpl->arrayValue; // type cannot change in mImpl so array is allocated break; } case Property::MAP: { - *mImpl->mapValue = *value.mImpl->mapValue; + *mImpl->mapValue = *value.mImpl->mapValue; // type cannot change in mImpl so map is allocated break; } case Property::NONE: - case Property::TYPE_COUNT: { // mImpl will be NULL, there's no way to get to this case } } @@ -535,56 +533,55 @@ Property::Value& Property::Value::operator=( const Property::Value& value ) } case Property::VECTOR2: { - newImpl = new Impl( *value.mImpl->vector2Value ); + newImpl = new Impl( *value.mImpl->vector2Value ); // type cannot change in mImpl so vector is allocated break; } case Property::VECTOR3: { - newImpl = new Impl( *value.mImpl->vector3Value ); + newImpl = new Impl( *value.mImpl->vector3Value ); // type cannot change in mImpl so vector is allocated break; } case Property::VECTOR4: { - newImpl = new Impl( *value.mImpl->vector4Value ); + newImpl = new Impl( *value.mImpl->vector4Value ); // type cannot change in mImpl so vector is allocated break; } case Property::RECTANGLE: { - newImpl = new Impl( *value.mImpl->rectValue ); + newImpl = new Impl( *value.mImpl->rectValue ); // type cannot change in mImpl so rect is allocated break; } case Property::ROTATION: { - newImpl = new Impl( *value.mImpl->quaternionValue ); + newImpl = new Impl( *value.mImpl->quaternionValue ); // type cannot change in mImpl so quaternion is allocated break; } case Property::MATRIX3: { - newImpl = new Impl( *value.mImpl->matrix3Value ); + newImpl = new Impl( *value.mImpl->matrix3Value ); // type cannot change in mImpl so matrix is allocated break; } case Property::MATRIX: { - newImpl = new Impl( *value.mImpl->matrixValue ); + newImpl = new Impl( *value.mImpl->matrixValue ); // type cannot change in mImpl so matrix is allocated break; } case Property::STRING: { - newImpl = new Impl( *value.mImpl->stringValue ); + newImpl = new Impl( *value.mImpl->stringValue ); // type cannot change in mImpl so string is allocated break; } case Property::ARRAY: { - newImpl = new Impl( *value.mImpl->arrayValue ); + newImpl = new Impl( *value.mImpl->arrayValue ); // type cannot change in mImpl so array is allocated break; } case Property::MAP: { - newImpl = new Impl( *value.mImpl->mapValue ); + newImpl = new Impl( *value.mImpl->mapValue ); // type cannot change in mImpl so map is allocated break; } case Property::NONE: - case Property::TYPE_COUNT: { // NULL value will be used for "empty" value } } @@ -595,6 +592,11 @@ Property::Value& Property::Value::operator=( const Property::Value& value ) return *this; } +Property::Value::~Value() +{ + delete mImpl; +} + Property::Type Property::Value::GetType() const { Property::Type type( Property::NONE ); @@ -605,207 +607,191 @@ Property::Type Property::Value::GetType() const return type; } -void Property::Value::Get( bool& booleanValue ) const +bool Property::Value::Get( bool& booleanValue ) const { + bool converted = false; if( mImpl && IsIntegerType( mImpl->type ) ) { booleanValue = mImpl->integerValue; + converted = true; } - else - { - booleanValue = false; - } + return converted; } -void Property::Value::Get( float& floatValue ) const +bool Property::Value::Get( float& floatValue ) const { + bool converted = false; if( mImpl && mImpl->type == FLOAT ) { floatValue = mImpl->floatValue; + converted = true; } - else - { - floatValue = 0.f; - } + return converted; } -void Property::Value::Get( int& integerValue ) const +bool Property::Value::Get( int& integerValue ) const { + bool converted = false; if( mImpl && IsIntegerType( mImpl->type ) ) { integerValue = mImpl->integerValue; + converted = true; } - else - { - integerValue = 0; - } + return converted; } -void Property::Value::Get( unsigned int& unsignedIntegerValue ) const +bool Property::Value::Get( unsigned int& unsignedIntegerValue ) const { + bool converted = false; if( mImpl && IsIntegerType( mImpl->type ) ) { unsignedIntegerValue = mImpl->unsignedIntegerValue; + converted = true; } - else - { - unsignedIntegerValue = 0u; - } + return converted; } -void Property::Value::Get( Vector2& vectorValue ) const +bool Property::Value::Get( Vector2& vectorValue ) const { - if( mImpl && mImpl->type == VECTOR2 && mImpl->vector2Value ) + bool converted = false; + if( mImpl && (mImpl->type == VECTOR2) ) // type cannot change in mImpl so vector is allocated { vectorValue = *(mImpl->vector2Value); + converted = true; } - else - { - vectorValue.x = vectorValue.y = 0.f; - } + return converted; } -void Property::Value::Get( Vector3& vectorValue ) const +bool Property::Value::Get( Vector3& vectorValue ) const { - if( mImpl && mImpl->type == VECTOR3 && mImpl->vector3Value ) + bool converted = false; + if( mImpl && (mImpl->type == VECTOR3) ) // type cannot change in mImpl so vector is allocated { vectorValue = *(mImpl->vector3Value); + converted = true; } - else - { - vectorValue.x = vectorValue.y = vectorValue.z = 0.f; - } + return converted; } -void Property::Value::Get( Vector4& vectorValue ) const +bool Property::Value::Get( Vector4& vectorValue ) const { - if( mImpl && mImpl->type == VECTOR4 && mImpl->vector4Value ) + bool converted = false; + if( mImpl && (mImpl->type == VECTOR4) ) // type cannot change in mImpl so vector is allocated { vectorValue = *(mImpl->vector4Value); + converted = true; } - else - { - vectorValue.x = vectorValue.y = vectorValue.z = vectorValue.w = 0.f; - } + return converted; } -void Property::Value::Get( Matrix3& matrixValue ) const +bool Property::Value::Get( Matrix3& matrixValue ) const { - if( mImpl && mImpl->type == MATRIX3 && mImpl->matrix3Value ) + bool converted = false; + if( mImpl && (mImpl->type == MATRIX3) ) // type cannot change in mImpl so matrix is allocated { matrixValue = *(mImpl->matrix3Value); + converted = true; } - else - { - matrixValue.SetIdentity(); - } + return converted; } -void Property::Value::Get( Matrix& matrixValue ) const +bool Property::Value::Get( Matrix& matrixValue ) const { - if( mImpl && mImpl->type == MATRIX && mImpl->matrixValue ) + bool converted = false; + if( mImpl && (mImpl->type == MATRIX) ) // type cannot change in mImpl so matrix is allocated { matrixValue = *(mImpl->matrixValue); + converted = true; } - else - { - matrixValue.SetIdentity(); - } + return converted; } -void Property::Value::Get( Rect& rectValue ) const +bool Property::Value::Get( Rect& rectValue ) const { - if( mImpl && mImpl->type == RECTANGLE && mImpl->rectValue ) + bool converted = false; + if( mImpl && (mImpl->type == RECTANGLE) ) // type cannot change in mImpl so rect is allocated { rectValue = *(mImpl->rectValue); + converted = true; } - else - { - rectValue.x = rectValue.y = rectValue.width = rectValue.height = 0.f; - } + return converted; } -void Property::Value::Get( AngleAxis& angleAxisValue ) const +bool Property::Value::Get( AngleAxis& angleAxisValue ) const { - if( mImpl && mImpl->type == ROTATION && mImpl->quaternionValue ) + bool converted = false; + if( mImpl && (mImpl->type == ROTATION) ) // type cannot change in mImpl so quaternion is allocated { mImpl->quaternionValue->ToAxisAngle( angleAxisValue.axis, angleAxisValue.angle ); + converted = true; } - else - { - angleAxisValue.angle = 0.f; - angleAxisValue.axis = Vector3::ZERO; // identity quaternion - } + return converted; } -void Property::Value::Get( Quaternion& quaternionValue ) const +bool Property::Value::Get( Quaternion& quaternionValue ) const { - if( mImpl && mImpl->type == ROTATION && mImpl->quaternionValue ) + bool converted = false; + if( mImpl && (mImpl->type == ROTATION) ) // type cannot change in mImpl so quaternion is allocated { quaternionValue = *(mImpl->quaternionValue); + converted = true; } - else - { - quaternionValue = Quaternion::IDENTITY; - } + return converted; } -void Property::Value::Get( std::string& stringValue ) const +bool Property::Value::Get( std::string& stringValue ) const { - if( mImpl && mImpl->type == STRING && mImpl->stringValue ) + bool converted = false; + if( mImpl && (mImpl->type == STRING) ) // type cannot change in mImpl so string is allocated { stringValue.assign( *(mImpl->stringValue) ); + converted = true; } - else - { - stringValue.clear(); - } + return converted; } -void Property::Value::Get( Property::Array& arrayValue ) const +bool Property::Value::Get( Property::Array& arrayValue ) const { - if( mImpl && mImpl->type == ARRAY && mImpl->arrayValue ) + bool converted = false; + if( mImpl && (mImpl->type == ARRAY) ) // type cannot change in mImpl so array is allocated { arrayValue = *(mImpl->arrayValue); + converted = true; } - else - { - arrayValue.Clear(); - } + return converted; } -void Property::Value::Get( Property::Map& mapValue ) const +bool Property::Value::Get( Property::Map& mapValue ) const { - if( mImpl && mImpl->type == MAP && mImpl->mapValue ) + bool converted = false; + if( mImpl && (mImpl->type == MAP) ) // type cannot change in mImpl so map is allocated { mapValue = *(mImpl->mapValue); + converted = true; } - else + return converted; +} + +Property::Array* Property::Value::GetArray() const +{ + Property::Array* array = NULL; + if( mImpl && (mImpl->type == ARRAY) ) // type cannot change in mImpl so array is allocated { - mapValue.Clear(); + array = mImpl->arrayValue; } + return array; } Property::Map* Property::Value::GetMap() const { Property::Map* map = NULL; - if( mImpl && mImpl->type == MAP && mImpl->mapValue ) + if( mImpl && (mImpl->type == MAP) ) // type cannot change in mImpl so map is allocated { map = mImpl->mapValue; } return map; } -Property::Array* Property::Value::GetArray() const -{ - Property::Array* array = NULL; - if( mImpl && mImpl->type == ARRAY && mImpl->arrayValue ) - { - array = mImpl->arrayValue; - } - return array; -} - std::ostream& operator<<( std::ostream& stream, const Property::Value& value ) { if( value.mImpl ) @@ -885,7 +871,6 @@ std::ostream& operator<<( std::ostream& stream, const Property::Value& value ) break; } case Dali::Property::NONE: - case Dali::Property::TYPE_COUNT: { stream << "undefined type"; break; diff --git a/dali/public-api/object/property-value.h b/dali/public-api/object/property-value.h index f096d7b..d9a8187 100644 --- a/dali/public-api/object/property-value.h +++ b/dali/public-api/object/property-value.h @@ -149,13 +149,6 @@ public: Value( const char* stringValue ); /** - * @brief Copy a property value. - * - * @param [in] value The property value to copy. - */ - Value( const Value& value ); - - /** * @brief Create an array property value. * * @param [in] arrayValue An array @@ -177,6 +170,13 @@ public: explicit Value( Type type ); /** + * @brief Copy constructor + * + * @param [in] value The property value to copy. + */ + Value( const Value& value ); + + /** * @brief Assign a property value. * * @param [in] value The property value to assign from. @@ -186,6 +186,8 @@ public: /** * @brief Non-virtual destructor. + * + * This class is not a base class. */ ~Value(); @@ -199,14 +201,15 @@ public: /** * @brief Retrieve a specific value. * - * @pre GetType() returns the Property::Type for type T. + * Works on a best-effort approach; if value type is not convertible returns a default value of the type + * * @return A value of type T. */ template T DALI_INTERNAL Get() const { - T temp; - Get(temp); + T temp = T(); // value (zero) initialize + Get( temp ); return temp; } @@ -215,130 +218,142 @@ public: * * @pre GetType() returns Property::BOOLEAN. * @param [out] boolValue On return, a boolean value. + * @return true if the value is successfully retrieved, false if the type is not convertible */ - void Get( bool& boolValue ) const; + bool Get( bool& boolValue ) const; /** * @brief Retrieve a floating-point value. * * @pre GetType() returns Property::FLOAT. * @param [out] floatValue On return, a floating-point value. + * @return true if the value is successfully retrieved, false if the type is not convertible */ - void Get( float& floatValue ) const; + bool Get( float& floatValue ) const; /** * @brief Retrieve an integer value. * * @pre GetType() returns Property::INTEGER. * @param [out] integerValue On return, an integer value. + * @return true if the value is successfully retrieved, false if the type is not convertible */ - void Get( int& integerValue ) const; + bool Get( int& integerValue ) const; /** * @brief Retrieve an unsigned integer value. * * @pre GetType() returns Property::UNSIGNED_INTEGER. * @param [out] unsignedIntegerValue On return, an unsigned integer value. + * @return true if the value is successfully retrieved, false if the type is not convertible */ - void Get( unsigned int& unsignedIntegerValue ) const; + bool Get( unsigned int& unsignedIntegerValue ) const; /** * @brief Retrieve an integer rectangle. * * @pre GetType() returns Property::RECTANGLE. * @param [out] rect On return, an integer rectangle. + * @return true if the value is successfully retrieved, false if the type is not convertible */ - void Get( Rect& rect ) const; + bool Get( Rect& rect ) const; /** * @brief Retrieve a vector value. * * @pre GetType() returns Property::VECTOR2. * @param [out] vectorValue On return, a vector value. + * @return true if the value is successfully retrieved, false if the type is not convertible */ - void Get( Vector2& vectorValue ) const; + bool Get( Vector2& vectorValue ) const; /** * @brief Retrieve a vector value. * * @pre GetType() returns Property::VECTOR3. * @param [out] vectorValue On return, a vector value. + * @return true if the value is successfully retrieved, false if the type is not convertible */ - void Get( Vector3& vectorValue ) const; + bool Get( Vector3& vectorValue ) const; /** * @brief Retrieve a vector value. * * @pre GetType() returns Property::VECTOR4. * @param [out] vectorValue On return, a vector value. + * @return true if the value is successfully retrieved, false if the type is not convertible */ - void Get( Vector4& vectorValue ) const; + bool Get( Vector4& vectorValue ) const; /** * @brief Retrieve a matrix3 value. * * @pre GetType() returns Property::MATRIX3. * @param [out] matrixValue On return, a matrix3 value. + * @return true if the value is successfully retrieved, false if the type is not convertible */ - void Get( Matrix3& matrixValue ) const; + bool Get( Matrix3& matrixValue ) const; /** * @brief Retrieve a matrix value. * * @pre GetType() returns Property::MATRIX. * @param [out] matrixValue On return, a matrix value. + * @return true if the value is successfully retrieved, false if the type is not convertible */ - void Get( Matrix& matrixValue ) const; + bool Get( Matrix& matrixValue ) const; /** * @brief Retrieve an angle-axis value. * * @pre GetType() returns Property::ROTATION. * @param [out] angleAxisValue On return, a angle-axis value. + * @return true if the value is successfully retrieved, false if the type is not convertible */ - void Get( AngleAxis& angleAxisValue ) const; + bool Get( AngleAxis& angleAxisValue ) const; /** * @brief Retrieve a quaternion value. * * @pre GetType() returns Property::ROTATION. * @param [out] quaternionValue On return, a quaternion value. + * @return true if the value is successfully retrieved, false if the type is not convertible */ - void Get( Quaternion& quaternionValue ) const; + bool Get( Quaternion& quaternionValue ) const; /** * @brief Retrieve an string property value. * * @pre GetType() returns Property::STRING. * @param [out] stringValue A string. + * @return true if the value is successfully retrieved, false if the type is not convertible */ - void Get( std::string& stringValue ) const; + bool Get( std::string& stringValue ) const; /** * @brief Retrieve an array property value. * * @pre GetType() returns Property::ARRAY. * @param [out] arrayValue The array as a vector Property Values + * @return true if the value is successfully retrieved, false if the type is not convertible */ - void Get( Property::Array& arrayValue ) const; + bool Get( Property::Array& arrayValue ) const; /** * @brief Retrieve an map property value. * * @pre GetType() returns Property::MAP. * @param [out] mapValue The map as vector of string and Property Value pairs + * @return true if the value is successfully retrieved, false if the type is not convertible */ - void Get( Property::Map& mapValue ) const; + bool Get( Property::Map& mapValue ) const; /** - * @brief return true if this property is a Property::MAP. + * @brief Retrieve the Array API of the Property::Value without copying the contents of the map * - * @return return true if this property is a Property::MAP + * @return the Array API of the Property::Value or NULL if not a Property::Array */ - bool IsMap() const - { - return GetMap() != NULL; - } + Property::Array* GetArray() const; /** * @brief Retrieve the Map API of the Property::Value without copying the contents of the map @@ -348,23 +363,6 @@ public: Property::Map* GetMap() const; /** - * @brief return true if this property is a Property::ARRAY. - * - * @return return true if this property is a Property::ARRAY - */ - bool IsArray() const - { - return GetArray() != NULL; - } - - /** - * @brief Retrieve the Array API of the Property::Value without copying the contents of the map - * - * @return the Array API of the Property::Value or NULL if not a Property::Array - */ - Property::Array* GetArray() const; - - /** * output to stream */ friend std::ostream& operator<<( std::ostream& ouputStream, const Property::Value& value ); diff --git a/dali/public-api/object/property.h b/dali/public-api/object/property.h index 3e7d2d3..144ee07 100644 --- a/dali/public-api/object/property.h +++ b/dali/public-api/object/property.h @@ -82,8 +82,7 @@ struct DALI_IMPORT_API Property ROTATION, ///< either a quaternion or an axis angle rotation STRING, ///< A string type ARRAY, ///< an array of Property::Value - MAP, ///< a string key to Property:value mapping - TYPE_COUNT ///< The number of supported property types + MAP ///< a string key to Property:value mapping }; /** -- 2.7.4