refactor dali-animation.
[platform/core/uifw/dali-core.git] / dali / internal / event / animation / key-frames-impl.cpp
index fa265cc..7ecfd6b 100644 (file)
@@ -28,14 +28,6 @@ KeyFrames* KeyFrames::New()
   return new KeyFrames();
 }
 
-KeyFrames::KeyFrames()
-  : mType(Property::NONE),
-    mKeyFrames(nullptr)
-{
-}
-
-KeyFrames::~KeyFrames() = default;
-
 void KeyFrames::CreateKeyFramesSpec(Property::Type type)
 {
   mType = type;
@@ -44,37 +36,37 @@ void KeyFrames::CreateKeyFramesSpec(Property::Type type)
   {
     case Property::BOOLEAN:
     {
-      mKeyFrames = Internal::KeyFrameBoolean::New();
+      mKeyFrames = std::make_unique<Internal::KeyFrameBoolean>();
       break;
     }
     case Property::INTEGER:
     {
-      mKeyFrames = Internal::KeyFrameInteger::New();
+      mKeyFrames = std::make_unique<Internal::KeyFrameInteger>();
       break;
     }
     case Property::FLOAT:
     {
-      mKeyFrames = Internal::KeyFrameNumber::New();
+      mKeyFrames = std::make_unique<Internal::KeyFrameNumber>();
       break;
     }
     case Property::VECTOR2:
     {
-      mKeyFrames = Internal::KeyFrameVector2::New();
+      mKeyFrames = std::make_unique<Internal::KeyFrameVector2>();
       break;
     }
     case Property::VECTOR3:
     {
-      mKeyFrames = Internal::KeyFrameVector3::New();
+      mKeyFrames = std::make_unique<Internal::KeyFrameVector3>();
       break;
     }
     case Property::VECTOR4:
     {
-      mKeyFrames = Internal::KeyFrameVector4::New();
+      mKeyFrames = std::make_unique<Internal::KeyFrameVector4>();
       break;
     }
     case Property::ROTATION:
     {
-      mKeyFrames = Internal::KeyFrameQuaternion::New();
+      mKeyFrames = std::make_unique<Internal::KeyFrameQuaternion>();
       break;
     }
     default:
@@ -90,7 +82,7 @@ Property::Type KeyFrames::GetType() const
   return mType;
 }
 
-void KeyFrames::Add(float time, Property::Value value, AlphaFunction alpha)
+void KeyFrames::Add(float time, const Property::Value& value, AlphaFunction alpha)
 {
   if(mType == Property::NONE)
   {
@@ -100,49 +92,51 @@ void KeyFrames::Add(float time, Property::Value value, AlphaFunction alpha)
   // Once we have created a type, can only add values of the same type
   DALI_ASSERT_ALWAYS( mType == value.GetType() && "Can only add values of the same type to a KeyFrame" );
 
-  DALI_ASSERT_DEBUG(mKeyFrames);
+  auto keyframes = mKeyFrames.get();
+
+  DALI_ASSERT_DEBUG(keyframes);
 
   switch(mType)
   {
     case Property::BOOLEAN:
     {
-      Internal::KeyFrameBoolean* kf = static_cast<Internal::KeyFrameBoolean*>(mKeyFrames.Get());
+      Internal::KeyFrameBoolean* kf = static_cast<Internal::KeyFrameBoolean*>(keyframes);
       kf->AddKeyFrame(time, value.Get<bool>(), alpha);
       break;
     }
     case Property::INTEGER:
     {
-      Internal::KeyFrameInteger* kf = static_cast<Internal::KeyFrameInteger*>(mKeyFrames.Get());
+      Internal::KeyFrameInteger* kf = static_cast<Internal::KeyFrameInteger*>(keyframes);
       kf->AddKeyFrame(time, value.Get<int>(), alpha);
       break;
     }
     case Property::FLOAT:
     {
-      Internal::KeyFrameNumber* kf = static_cast<Internal::KeyFrameNumber*>(mKeyFrames.Get());
+      Internal::KeyFrameNumber* kf = static_cast<Internal::KeyFrameNumber*>(keyframes);
       kf->AddKeyFrame(time, value.Get<float>(), alpha);
       break;
     }
     case Property::VECTOR2:
     {
-      Internal::KeyFrameVector2* kf = static_cast<Internal::KeyFrameVector2*>(mKeyFrames.Get());
+      Internal::KeyFrameVector2* kf = static_cast<Internal::KeyFrameVector2*>(keyframes);
       kf->AddKeyFrame(time, value.Get<Vector2>(), alpha);
       break;
     }
     case Property::VECTOR3:
     {
-      Internal::KeyFrameVector3* kf = static_cast<Internal::KeyFrameVector3*>(mKeyFrames.Get());
+      Internal::KeyFrameVector3* kf = static_cast<Internal::KeyFrameVector3*>(keyframes);
       kf->AddKeyFrame(time, value.Get<Vector3>(), alpha);
       break;
     }
     case Property::VECTOR4:
     {
-      Internal::KeyFrameVector4* kf = static_cast<Internal::KeyFrameVector4*>(mKeyFrames.Get());
+      Internal::KeyFrameVector4* kf = static_cast<Internal::KeyFrameVector4*>(keyframes);
       kf->AddKeyFrame(time, value.Get<Vector4>(), alpha);
       break;
     }
     case Property::ROTATION:
     {
-      Internal::KeyFrameQuaternion* kf = static_cast<Internal::KeyFrameQuaternion*>(mKeyFrames.Get());
+      Internal::KeyFrameQuaternion* kf = static_cast<Internal::KeyFrameQuaternion*>(keyframes);
       kf->AddKeyFrame(time, value.Get<Quaternion>(), alpha);
       break;
     }
@@ -154,7 +148,7 @@ void KeyFrames::Add(float time, Property::Value value, AlphaFunction alpha)
 
 KeyFrameSpec* KeyFrames::GetKeyFramesBase() const
 {
-  return mKeyFrames.Get();
+  return mKeyFrames.get();
 }
 
 Property::Value KeyFrames::GetLastKeyFrameValue() const