/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
namespace
{
/**
- * Helper to check if the property value can be read as int/unsigned int/bool
+ * Helper to check if the property value can be read as int/bool
*/
inline bool IsIntegerType( Property::Type type )
{
- return ( Property::BOOLEAN == type )||( Property::INTEGER == type )||(Property::UNSIGNED_INTEGER == type );
+ return ( Property::BOOLEAN == type )||( Property::INTEGER == type );
}
}
integerValue( integerValue )
{ }
- Impl( unsigned int unsignedIntegerValue )
- : type( Property::UNSIGNED_INTEGER ),
- unsignedIntegerValue( unsignedIntegerValue )
- { }
-
Impl( const Vector2& vectorValue )
: type( Property::VECTOR2 ),
vector2Value( new Vector2( vectorValue ) )
Impl( const AngleAxis& angleAxisValue )
: type( Property::ROTATION ),
- quaternionValue( new Quaternion( angleAxisValue.angle, angleAxisValue.axis ) )
+ angleAxisValue( new AngleAxis(angleAxisValue) )
{
}
Impl( const Quaternion& quaternionValue )
: type( Property::ROTATION ),
- quaternionValue( new Quaternion( quaternionValue ) )
+ angleAxisValue( new AngleAxis() )
{
+ quaternionValue.ToAxisAngle( angleAxisValue->axis, angleAxisValue->angle );
}
Impl(const std::string& stringValue)
case Property::NONE : // FALLTHROUGH
case Property::BOOLEAN : // FALLTHROUGH
case Property::FLOAT : // FALLTHROUGH
- case Property::INTEGER : // FALLTHROUGH
- case Property::UNSIGNED_INTEGER :
+ case Property::INTEGER :
{
break; // nothing to do
}
}
case Property::ROTATION:
{
- delete quaternionValue;
+ delete angleAxisValue;
break;
}
case Property::STRING:
{
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;
+ AngleAxis* angleAxisValue;
std::string* stringValue;
Rect<int>* rectValue;
Property::Array* arrayValue;
{
}
-Property::Value::Value( unsigned int unsignedIntegerValue )
-: mImpl( new Impl( unsignedIntegerValue ) )
-{
-}
-
Property::Value::Value( const Vector2& vectorValue )
: mImpl( new Impl( vectorValue ) )
{
mImpl = new Impl( 0 );
break;
}
- case Property::UNSIGNED_INTEGER:
- {
- mImpl = new Impl( 0U );
- break;
- }
case Property::VECTOR2:
{
mImpl = new Impl( Vector2::ZERO );
}
case Property::ROTATION:
{
- mImpl = new Impl( Quaternion() );
+ mImpl = new Impl( AngleAxis() );
break;
}
case Property::STRING:
}
}
}
+
Property::Value::Value( const Property::Value& value )
: mImpl( NULL )
{
mImpl->integerValue = value.mImpl->integerValue;
break;
}
- case Property::UNSIGNED_INTEGER:
- {
- mImpl->unsignedIntegerValue = value.mImpl->unsignedIntegerValue;
- break;
- }
case Property::VECTOR2:
{
*mImpl->vector2Value = *value.mImpl->vector2Value; // type cannot change in mImpl so vector is allocated
}
case Property::ROTATION:
{
- *mImpl->quaternionValue = *value.mImpl->quaternionValue; // type cannot change in mImpl so quaternion is allocated
+ *mImpl->angleAxisValue = *value.mImpl->angleAxisValue; // type cannot change in mImpl so quaternion is allocated
break;
}
case Property::STRING:
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 ); // type cannot change in mImpl so vector is allocated
}
case Property::ROTATION:
{
- newImpl = new Impl( *value.mImpl->quaternionValue ); // type cannot change in mImpl so quaternion is allocated
+ newImpl = new Impl( *value.mImpl->angleAxisValue ); // type cannot change in mImpl so quaternion is allocated
break;
}
case Property::MATRIX3:
bool Property::Value::Get( float& floatValue ) const
{
bool converted = false;
- if( mImpl && mImpl->type == FLOAT )
+ if( mImpl )
{
- floatValue = mImpl->floatValue;
- converted = true;
+ if( mImpl->type == FLOAT )
+ {
+ floatValue = mImpl->floatValue;
+ converted = true;
+ }
+ else if( IsIntegerType( mImpl->type ) )
+ {
+ floatValue = static_cast< float >( mImpl->integerValue );
+ converted = true;
+ }
}
return converted;
}
bool Property::Value::Get( int& integerValue ) const
{
bool converted = false;
- if( mImpl && IsIntegerType( mImpl->type ) )
- {
- integerValue = mImpl->integerValue;
- converted = true;
- }
- return converted;
-}
-
-bool Property::Value::Get( unsigned int& unsignedIntegerValue ) const
-{
- bool converted = false;
- if( mImpl && IsIntegerType( mImpl->type ) )
+ if( mImpl )
{
- unsignedIntegerValue = mImpl->unsignedIntegerValue;
- converted = true;
+ if( IsIntegerType( mImpl->type ) )
+ {
+ integerValue = mImpl->integerValue;
+ converted = true;
+ }
+ else if( mImpl->type == FLOAT )
+ {
+ integerValue = static_cast< int >( mImpl->floatValue );
+ converted = true;
+ }
}
return converted;
}
bool Property::Value::Get( Vector2& vectorValue ) const
{
bool converted = false;
- if( mImpl && (mImpl->type == VECTOR2) ) // type cannot change in mImpl so vector is allocated
+ if( mImpl )
{
- vectorValue = *(mImpl->vector2Value);
- converted = true;
+ // type cannot change in mImpl so vector is allocated
+ if( mImpl->type == VECTOR2 || mImpl->type == VECTOR3 || mImpl->type == VECTOR4 )
+ {
+ vectorValue = *(mImpl->vector2Value); // if Vector3 or 4 only x and y are assigned
+ converted = true;
+ }
}
return converted;
}
bool Property::Value::Get( Vector3& vectorValue ) const
{
bool converted = false;
- if( mImpl && (mImpl->type == VECTOR3) ) // type cannot change in mImpl so vector is allocated
+ if( mImpl )
{
- vectorValue = *(mImpl->vector3Value);
- converted = true;
+ // type cannot change in mImpl so vector is allocated
+ if ( mImpl->type == VECTOR3 || mImpl->type == VECTOR4 )
+ {
+ vectorValue = *(mImpl->vector3Value); // if Vector4 only x,y,z are assigned
+ converted = true;
+ }
+ else if( mImpl->type == VECTOR2 )
+ {
+ vectorValue = *(mImpl->vector2Value);
+ converted = true;
+ }
}
return converted;
}
bool Property::Value::Get( Vector4& vectorValue ) const
{
bool converted = false;
- if( mImpl && (mImpl->type == VECTOR4) ) // type cannot change in mImpl so vector is allocated
+ if( mImpl )
{
- vectorValue = *(mImpl->vector4Value);
- converted = true;
+ if( mImpl->type == VECTOR4 ) // type cannot change in mImpl so vector is allocated
+ {
+ vectorValue = *(mImpl->vector4Value);
+ converted = true;
+ }
+ else if( mImpl->type == VECTOR2 )
+ {
+ vectorValue = *(mImpl->vector2Value);
+ converted = true;
+ }
+ else if( mImpl->type == VECTOR3 )
+ {
+ vectorValue = *(mImpl->vector3Value);
+ converted = true;
+ }
}
return converted;
}
bool Property::Value::Get( AngleAxis& angleAxisValue ) const
{
bool converted = false;
- if( mImpl && (mImpl->type == ROTATION) ) // type cannot change in mImpl so quaternion is allocated
+ if( mImpl && (mImpl->type == ROTATION) ) // type cannot change in mImpl so angleAxis is allocated
{
- mImpl->quaternionValue->ToAxisAngle( angleAxisValue.axis, angleAxisValue.angle );
+ angleAxisValue = *(mImpl->angleAxisValue);
converted = true;
}
return converted;
bool Property::Value::Get( Quaternion& quaternionValue ) const
{
bool converted = false;
- if( mImpl && (mImpl->type == ROTATION) ) // type cannot change in mImpl so quaternion is allocated
+ if( mImpl && (mImpl->type == ROTATION) ) // type cannot change in mImpl so angleAxis is allocated
{
- quaternionValue = *(mImpl->quaternionValue);
+ quaternionValue = Quaternion(mImpl->angleAxisValue->angle, mImpl->angleAxisValue->axis );
converted = true;
}
return converted;
stream << impl.integerValue;
break;
}
- case Dali::Property::UNSIGNED_INTEGER:
- {
- stream << impl.unsignedIntegerValue;
- break;
- }
case Dali::Property::VECTOR2:
{
stream << *impl.vector2Value;
}
case Dali::Property::ROTATION:
{
- stream << *impl.quaternionValue;
+ stream << *impl.angleAxisValue;
break;
}
case Dali::Property::STRING:
}
case Dali::Property::ARRAY:
{
- stream << "Array containing" << impl.arrayValue->Count() << " elements"; // TODO add ostream<< operator in array
+ stream << *(value.GetArray());
break;
}
case Dali::Property::MAP:
{
- stream << "Map containing " << impl.mapValue->Count() << " elements"; // TODO add ostream<< operator in map
+ stream << *(value.GetMap());
break;
}
case Dali::Property::NONE: