/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2015 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.
// CLASS HEADER
#include <dali/public-api/object/property-value.h>
+// EXTERNAL INCLUDES
+#include <ostream>
+
// INTERNAL INCLUDES
#include <dali/public-api/object/any.h>
#include <dali/public-api/math/angle-axis.h>
#include <dali/public-api/math/matrix.h>
#include <dali/public-api/math/rect.h>
#include <dali/public-api/math/quaternion.h>
+#include <dali/public-api/object/property-map.h>
#include <dali/public-api/object/property-types.h>
#include <dali/integration-api/debug.h>
case Property::ROTATION:
{
- mImpl = new Impl( value.Get<Quaternion>() );
+ // 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<Quaternion>() );
+ }
+ else
+ {
+ mImpl = new Impl( value.Get<AngleAxis>() );
+ }
break;
}
case Property::ROTATION:
{
- mImpl = new Impl( Quaternion(0.f, Vector4::YAXIS) );
+ mImpl = new Impl( Quaternion( Radian(0.f), Vector3::YAXIS) );
break;
}
case Property::ROTATION:
{
- mImpl->mValue = value.Get<Quaternion>();
+ // 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<Quaternion>() );
+ }
+ else
+ {
+ mImpl = new Impl( value.Get<AngleAxis>() );
+ }
break;
}
{
DALI_ASSERT_ALWAYS( Property::ROTATION == GetType() && "Property type invalid" );
- // Rotations have two representations
+ // Orientations have two representations
DALI_ASSERT_DEBUG( typeid(Quaternion) == mImpl->mValue.GetType() ||
typeid(AngleAxis) == mImpl->mValue.GetType() );
{
Quaternion quaternion = AnyCast<Quaternion>(mImpl->mValue);
- Radian angleRadians(0.0f);
- quaternion.ToAxisAngle( angleAxisValue.axis, angleRadians );
- angleAxisValue.angle = angleRadians;
+ quaternion.ToAxisAngle( angleAxisValue.axis, angleAxisValue.angle );
}
else
{
{
DALI_ASSERT_DEBUG( Property::ROTATION == GetType() && "Property type invalid" );
- // Rotations have two representations
+ // Orientations have two representations
DALI_ASSERT_DEBUG( typeid(Quaternion) == mImpl->mValue.GetType() ||
typeid(AngleAxis) == mImpl->mValue.GetType() );
if(container)
{
- for(Property::Map::iterator iter = container->begin(); iter != container->end(); ++iter)
+ Property::Value* value = container->Find( key );
+ if ( value )
{
- if(iter->first == key)
- {
- return iter->second;
- }
+ return *value;
}
}
DALI_LOG_WARNING("Cannot find property map key %s", key.c_str());
DALI_ASSERT_ALWAYS(!"Cannot find property map key");
-
- // should never return this
- static Property::Value null;
- return null;
}
bool Property::Value::HasKey(const std::string& key) const
if(container)
{
- for(Property::Map::iterator iter = container->begin(); iter != container->end(); ++iter)
+ Property::Value* value = container->Find( key );
+ if ( value )
{
- if(iter->first == key)
- {
- has = true;
- }
+ has = true;
}
}
}
{
case Property::MAP:
{
- int i = 0;
Property::Map *container = AnyCast<Property::Map>(&(mImpl->mValue));
DALI_ASSERT_DEBUG(container && "Property::Map has no container?");
if(container)
{
- if(0 <= index && index < static_cast<int>(container->size()))
+ if(0 <= index && index < static_cast<int>(container->Count()))
{
- for(Property::Map::iterator iter = container->begin(); iter != container->end(); ++iter)
- {
- if(i++ == index)
- {
- return iter->first;
- }
- }
+ return container->GetKey( index );
}
}
}
if(container)
{
- for(Property::Map::iterator iter = container->begin(); iter != container->end(); ++iter)
- {
- if(iter->first == key)
- {
- iter->second = value;
- return;
- }
- }
-
- // if we get here its a new key
- container->push_back(Property::StringValuePair(key, value));
-
+ (*container)[ key ] = value;
}
}
{
case Property::MAP:
{
- int i = 0;
Property::Map *container = AnyCast<Property::Map>(&(mImpl->mValue));
DALI_ASSERT_DEBUG(container && "Property::Map has no container?");
if(container)
{
- DALI_ASSERT_ALWAYS(index < static_cast<int>(container->size()) && "Property array index invalid");
+ DALI_ASSERT_ALWAYS(index < static_cast<int>(container->Count()) && "Property array index invalid");
DALI_ASSERT_ALWAYS(index >= 0 && "Property array index invalid");
- for(Property::Map::iterator iter = container->begin(); iter != container->end(); ++iter)
- {
- if(i++ == index)
- {
- return iter->second;
- }
- }
+ return container->GetValue( index );
}
}
break;
DALI_ASSERT_ALWAYS(!"Property value index not valid");
-
- // should never return this
- static Property::Value null;
- return null;
}
Property::Value& Property::Value::GetItem(const int index, std::string& key) const
if( Property::MAP == GetType() )
{
Property::Map *container = AnyCast<Property::Map>(&(mImpl->mValue));
- if( index < static_cast<int>(container->size()) )
+ if( index < static_cast<int>(container->Count()) )
{
-
- key = (*container)[ index ].first;
+ key = container->GetKey( index );
}
}
case Property::MAP:
{
Property::Map *container = AnyCast<Property::Map>(&(mImpl->mValue));
- if( container && index < static_cast<int>(container->size()) )
+ if( container && index < static_cast<int>(container->Count()) )
{
- int i = 0;
- for(Property::Map::iterator iter = container->begin(); iter != container->end(); ++iter)
- {
- if(i++ == index)
- {
- iter->second = value;
- break;
- }
- }
+ Property::Value& indexValue = container->GetValue( index );
+ indexValue = value;
}
}
break;
Property::Map *container = AnyCast<Property::Map>(&(mImpl->mValue));
if(container)
{
- ret = container->size();
+ ret = container->Count();
}
}
break;
return ret;
}
+std::ostream& operator<< (std::ostream& stream, const Property::Value& value )
+{
+
+ const Property::Value::Impl& impl( *value.mImpl );
+
+ switch( impl.mType )
+ {
+ case Dali::Property::STRING:
+ {
+ stream << AnyCast<std::string>(impl.mValue).c_str();
+ break;
+ }
+ case Dali::Property::VECTOR2:
+ {
+ stream << AnyCast<Vector2>(impl.mValue);
+ break;
+ }
+ case Dali::Property::VECTOR3:
+ {
+ stream << AnyCast<Vector3>(impl.mValue);
+ break;
+ }
+ case Dali::Property::VECTOR4:
+ {
+ stream << AnyCast<Vector4>(impl.mValue);
+ break;
+ }
+ case Dali::Property::MATRIX:
+ {
+ stream << AnyCast<Matrix>(impl.mValue);
+ break;
+ }
+ case Dali::Property::BOOLEAN:
+ {
+ stream << AnyCast<bool>(impl.mValue);
+ break;
+ }
+ case Dali::Property::FLOAT:
+ {
+ stream << AnyCast<float>(impl.mValue);
+ break;
+ }
+ case Dali::Property::INTEGER:
+ {
+ stream << AnyCast<int>(impl.mValue);
+ break;
+ }
+ case Dali::Property::UNSIGNED_INTEGER:
+ {
+ stream << AnyCast<unsigned int>(impl.mValue);
+ break;
+ }
+ case Dali::Property::RECTANGLE:
+ {
+ Dali::Rect<int> rect; // Propery Value rectangles are currently integer based
+ value.Get( rect );
+ stream << rect;
+ break;
+ }
+ case Dali::Property::MATRIX3:
+ {
+ stream << AnyCast<Matrix3>(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;
+ }
+ }
+ return stream;
+}
+
} // namespace Dali