Making DALi core internals typesafe using guaranteed types; uint8_t, uint32_t
[platform/core/uifw/dali-core.git] / dali / internal / event / animation / linear-constrainer-impl.cpp
index 3a793b7..8d17414 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 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.
@@ -24,6 +24,8 @@
 // INTERNAL INCLUDES
 #include <dali/internal/event/common/property-helper.h>
 #include <dali/public-api/animation/constraint.h>
+#include <dali/public-api/object/property-array.h>
+
 
 namespace Dali
 {
@@ -64,11 +66,11 @@ unsigned int LinearConstrainer::GetDefaultPropertyCount() const
 
 void LinearConstrainer::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
 {
-  indices.reserve( DEFAULT_PROPERTY_COUNT );
+  indices.Reserve( DEFAULT_PROPERTY_COUNT );
 
-  for ( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i )
+  for ( Property::Index i = 0; i < DEFAULT_PROPERTY_COUNT; ++i )
   {
-    indices.push_back( i );
+    indices.PushBack( i );
   }
 }
 
@@ -88,7 +90,7 @@ Property::Index LinearConstrainer::GetDefaultPropertyIndex(const std::string& na
   Property::Index index = Property::INVALID_INDEX;
 
   // Look for name in default properties
-  for( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i )
+  for( Property::Index i = 0; i < DEFAULT_PROPERTY_COUNT; ++i )
   {
     const Internal::PropertyDetails* property = &DEFAULT_PROPERTY_DETAILS[ i ];
     if( 0 == strcmp( name.c_str(), property->name ) )
@@ -113,55 +115,70 @@ Property::Type LinearConstrainer::GetDefaultPropertyType(Property::Index index)
 
 Property::Value LinearConstrainer::GetDefaultProperty( Property::Index index ) const
 {
-  Property::Value value;
   if( index == Dali::LinearConstrainer::Property::VALUE )
   {
-    Property::Array propertyArray;
-    value = Property::Value(propertyArray);
+    Property::Value value( Property::ARRAY );
+    Property::Array* array = value.GetArray();
     size_t count( mValue.Size() );
-    for( size_t i( 0 ); i != count; ++i )
+
+    if( array )
     {
-      value.AppendItem( mValue[i] );
+      array->Reserve( count );
+      for( size_t i( 0 ); i != count; ++i )
+      {
+        array->PushBack( mValue[i] );
+      }
     }
+    return value;
   }
   else if( index == Dali::LinearConstrainer::Property::PROGRESS )
   {
-    Property::Array propertyArray;
-    value = Property::Value(propertyArray);
-    size_t count( mValue.Size() );
-    for( size_t i( 0 ); i != count; ++i )
+    Property::Value value( Property::ARRAY );
+    Property::Array* array = value.GetArray();
+    size_t count( mProgress.Size() );
+
+    if( array )
     {
-      value.AppendItem( mProgress[i] );
+      array->Reserve( count );
+      for( size_t i( 0 ); i != count; ++i )
+      {
+        array->PushBack( mProgress[i] );
+      }
     }
+    return value;
   }
 
-  return value;
+  return Property::Value();
 }
 
-void LinearConstrainer::SetDefaultProperty(Property::Index index, const Property::Value& propertyValue)
+Property::Value LinearConstrainer::GetDefaultPropertyCurrentValue( Property::Index index ) const
 {
-  if( index == Dali::LinearConstrainer::Property::VALUE  )
-  {
-    Property::Array propertyArray;
-    propertyValue.Get(propertyArray);
+  return GetDefaultProperty( index ); // Event-side only properties
+}
 
-    size_t propertyArrayCount = propertyArray.size();
-    mValue.Resize( propertyArrayCount );
-    for( size_t i(0); i!=propertyArrayCount; ++i )
+void LinearConstrainer::SetDefaultProperty( Property::Index index, const Property::Value& propertyValue )
+{
+  const Property::Array* array = propertyValue.GetArray();
+  if( array )
+  {
+    size_t propertyArrayCount = array->Count();
+    if( index == Dali::LinearConstrainer::Property::VALUE  )
     {
-      propertyArray[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  )
-  {
-    Property::Array propertyArray;
-    propertyValue.Get(propertyArray);
-
-    size_t propertyArrayCount = propertyArray.size();
-    mProgress.Resize( propertyArrayCount );
-    for( size_t i(0); i!=propertyArrayCount; ++i )
+    else if( index == Dali::LinearConstrainer::Property::PROGRESS  )
     {
-      propertyArray[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 ] );
+      }
     }
   }
 }
@@ -201,11 +218,10 @@ void LinearConstrainer::Apply( Property target, Property source, const Vector2&
   Dali::Constraint constraint = Dali::Constraint::New<float>( target.object, target.propertyIndex, LinearConstraintFunctor( mValue, mProgress, range, wrap ) );
   constraint.AddSource( Dali::Source(source.object, source.propertyIndex ) );
 
-  constraint.SetTag( reinterpret_cast<size_t>( this ) );
+  constraint.SetTag( static_cast<uint32_t>( reinterpret_cast<uintptr_t>( this ) ) ); // taking 32bits of this as tag
   constraint.SetRemoveAction( Dali::Constraint::Discard );
   constraint.Apply();
 
-
   //Start observing the object
   Observe( target.object );
 }