Remove dependency to std::vector and property::value from property notification API 83/39283/3
authorKimmo Hoikka <kimmo.hoikka@samsung.com>
Tue, 12 May 2015 12:48:06 +0000 (13:48 +0100)
committerKimmo Hoikka <kimmo.hoikka@samsung.com>
Tue, 12 May 2015 12:51:20 +0000 (05:51 -0700)
[Problem] inefficient API, unnecessary dependencies
[Solution] change to Dali::Vector

Change-Id: I579d1060c54444d725bcb24124f7e67a501289c2

automated-tests/src/dali/utc-Dali-PropertyNotification.cpp
dali/internal/event/common/property-conditions-impl.cpp
dali/internal/event/common/property-conditions-impl.h
dali/internal/event/common/property-notification-impl.cpp
dali/internal/event/common/property-notification-impl.h
dali/public-api/actors/actor.h
dali/public-api/object/property-conditions.cpp
dali/public-api/object/property-conditions.h
dali/public-api/object/property-notification-declarations.h

index 867880a..7e5e450 100644 (file)
@@ -708,63 +708,18 @@ int UtcDaliPropertyConditionGetArguments(void)
   tet_infoline(" UtcDaliPropertyConditionGetArguments");
 
   PropertyCondition condition = GreaterThanCondition( 50.0f );
-  PropertyCondition::ArgumentContainer arguments = condition.GetArguments();
 
-  DALI_TEST_EQUALS( arguments.size(), 1u, TEST_LOCATION );
-  Property::Value value = arguments[0];
-  DALI_TEST_EQUALS( value.Get<float>(), 50.0f, TEST_LOCATION );
+  DALI_TEST_EQUALS( condition.GetArgumentCount(), 1u, TEST_LOCATION );
+  float value = condition.GetArgument( 0 );
+  DALI_TEST_EQUALS( value, 50.0f, TEST_LOCATION );
 
   condition = InsideCondition( 125.0f, 250.0f );
-  arguments = condition.GetArguments();
 
-  DALI_TEST_EQUALS( arguments.size(), 2u, TEST_LOCATION );
-  Property::Value value1 = arguments[0];
-  Property::Value value2 = arguments[1];
-  DALI_TEST_EQUALS( value1.Get<float>(), 125.0f, TEST_LOCATION );
-  DALI_TEST_EQUALS( value2.Get<float>(), 250.0f, TEST_LOCATION );
-  END_TEST;
-}
-
-namespace
-{
-
-class PropertyConditionConstWrapper
-{
-public:
-
-  PropertyConditionConstWrapper(PropertyCondition propertyCondition)
-  :mPropertyCondition(propertyCondition)
-  {
-
-  }
-
-  /**
-   * Returns const reference to property arguments.
-   * @return const reference.
-   */
-  const PropertyCondition::ArgumentContainer& GetArguments() const
-  {
-    return mPropertyCondition.GetArguments();
-  }
-
-  PropertyCondition mPropertyCondition;
-};
-} // anon namespace
-
-int UtcDaliPropertyConditionGetArgumentsConst(void)
-{
-  TestApplication application;
-  tet_infoline(" UtcDaliPropertyConditionGetArgumentsConst");
-
-  PropertyCondition condition = GreaterThanCondition( 50.0f );
-  PropertyConditionConstWrapper conditionConst(condition);
-  const PropertyCondition::ArgumentContainer& argumentsRef1 = conditionConst.GetArguments();
-  const PropertyCondition::ArgumentContainer& argumentsRef2 = conditionConst.GetArguments();
-
-  DALI_TEST_CHECK( (&argumentsRef1) == (&argumentsRef2) );
-  DALI_TEST_EQUALS( argumentsRef1.size(), 1u, TEST_LOCATION );
-  Property::Value value = argumentsRef1[0];
-  DALI_TEST_EQUALS( value.Get<float>(), 50.0f, TEST_LOCATION );
+  DALI_TEST_EQUALS( condition.GetArgumentCount(), 2u, TEST_LOCATION );
+  float value1 = condition.GetArgument( 0 );
+  float value2 = condition.GetArgument( 1 );
+  DALI_TEST_EQUALS( value1, 125.0f, TEST_LOCATION );
+  DALI_TEST_EQUALS( value2, 250.0f, TEST_LOCATION );
   END_TEST;
 }
 
@@ -814,13 +769,13 @@ int UtcDaliPropertyNotificationVariableStep(void)
   Actor actor = Actor::New();
   Stage::GetCurrent().Add(actor);
 
-  std::vector<float> values;
+  Dali::Vector<float> values;
 
   const float averageStep = 100.0f;
 
   for( int i = 1 ; i < 10 ; i++ )
   {
-    values.push_back(i * averageStep + (i % 2 == 0 ? -(averageStep * 0.2f) : (averageStep * 0.2f)));
+    values.PushBack(i * averageStep + (i % 2 == 0 ? -(averageStep * 0.2f) : (averageStep * 0.2f)));
   }
   // float
   PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, VariableStepCondition(values) );
@@ -830,7 +785,7 @@ int UtcDaliPropertyNotificationVariableStep(void)
   actor.SetPosition(Vector3(values[0] - averageStep, 0.0f, 0.0f));
   Wait(application, DEFAULT_WAIT_PERIOD);
 
-  for( unsigned int i = 0 ; i < values.size() - 1 ; ++i )
+  for( unsigned int i = 0 ; i < values.Count() - 1 ; ++i )
   {
     gCallBackCalled = false;
     // set position half way between the current values
index 410d23b..06557ae 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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.
index f3fb03f..2a40d61 100644 (file)
@@ -2,7 +2,7 @@
 #define __DALI_INTERNAL_PROPERTY_CONDITIONS_H__
 
 /*
- * 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.
@@ -54,18 +54,18 @@ public:
     VariableStep          ///< Similar to step, except user can define a list of steps from reference value
   };
 
-  typedef Dali::PropertyCondition::ArgumentContainer ArgumentContainer;
-  typedef Dali::PropertyCondition::ArgumentIter ArgumentIter;
-  typedef Dali::PropertyCondition::ArgumentConstIter ArgumentConstIter;
-
+  /**
+   * Constructor
+   */
   PropertyCondition();
 
+  /**
+   * Virtual destructor
+   */
   virtual ~PropertyCondition();
 
 private:
 
-private:
-
   // Not implemented
   PropertyCondition(const PropertyCondition& rhs);
 
@@ -74,8 +74,8 @@ private:
 
 public:
 
-  Type type;                        ///< The condition Type.
-  ArgumentContainer arguments;      ///< The condition Arguments.
+  Type type;                     ///< The condition Type.
+  Dali::Vector<float> arguments; ///< The condition Arguments.
 
 };
 
index 7531a64..ee87eb1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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.
@@ -57,33 +57,27 @@ PropertyNotificationPtr PropertyNotification::New(Property& target,
   return propertyNotification;
 }
 
-PropertyNotification::PropertyNotification(UpdateManager& updateManager,
-                                           PropertyNotificationManager& propertyNotificationManager,
-                                           Property& target,
-                                           int componentIndex,
-                                           const Dali::PropertyCondition& condition)
-: mUpdateManager(updateManager),
-  mPropertyNotification(NULL),
-  mPropertyNotificationManager(propertyNotificationManager),
-  mObjectPropertyIndex(target.propertyIndex),
-  mPropertyType(Property::NONE),
-  mComponentIndex(componentIndex),
-  mCondition(condition),
-  mNotifyMode(Dali::PropertyNotification::NotifyOnTrue),
-  mNotifyResult(false)
-{
-  // Set condition arguments (as simple vector of floats)
-  PropertyCondition::ArgumentContainer arguments = GetImplementation(condition).arguments;
-  PropertyCondition::ArgumentConstIter iter = arguments.begin();
-
-  while( iter != arguments.end() )
+PropertyNotification::PropertyNotification( UpdateManager& updateManager,
+                                            PropertyNotificationManager& propertyNotificationManager,
+                                            Property& target,
+                                            int componentIndex,
+                                            const Dali::PropertyCondition& condition )
+: mUpdateManager( updateManager ),
+  mPropertyNotification( NULL ),
+  mPropertyNotificationManager( propertyNotificationManager ),
+  mObjectPropertyIndex( target.propertyIndex ),
+  mPropertyType( Property::NONE ),
+  mComponentIndex( componentIndex ),
+  mCondition( condition ),
+  mNotifyMode( Dali::PropertyNotification::NotifyOnTrue ),
+  mNotifyResult( false )
+{
+  const Internal::PropertyCondition& conditionImpl = GetImplementation( condition );
+
+  Dali::Vector<float>::SizeType count = conditionImpl.arguments.Count();
+  for( Dali::Vector<float>::SizeType index = 0; index < count; ++index )
   {
-    const Property::Value& value = *iter;
-    float floatValue;
-    value.Get(floatValue);
-
-    mRawConditionArgs.PushBack( floatValue );
-    ++iter;
+    mRawConditionArgs.PushBack( conditionImpl.arguments[ index ] );
   }
 
   // Observe target object and create/destroy notification scene object accordingly.
index d337365..03e2d58 100644 (file)
@@ -2,7 +2,7 @@
 #define __DALI_INTERNAL_PROPERTY_NOTIFICATION_H__
 
 /*
- * 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.
@@ -56,7 +56,6 @@ public:
 
   typedef Dali::PropertyNotification::NotifyMode NotifyMode;
   typedef PropertyCondition::Type ConditionType;
-  typedef PropertyCondition::ArgumentContainer ArgumentContainer;
 
   /**
    * RawArgumentContainer provides fast direct access to arguments for condition evaluation.
index 6ebfcdb..918fd1d 100644 (file)
@@ -433,7 +433,6 @@ public:
    * @param [in] child The child.
    * @post The child will be referenced by its parent. This means that the child will be kept alive,
    * even if the handle passed into this method is reset or destroyed.
-   * @post This may invalidate ActorContainer iterators.
    */
   void Add(Actor child);
 
@@ -452,7 +451,6 @@ public:
    * @post The child will be referenced by its parent. This means that the child will be kept alive,
    * even if the handle passed into this method is reset or destroyed.
    * @post If the index is greater than the current child count, it will be ignored and added at the end.
-   * @post This may invalidate ActorContainer iterators.
    */
   void Insert(unsigned int index, Actor child);
 
@@ -463,7 +461,6 @@ public:
    * @pre This Actor (the parent) has been initialized.
    * @pre The child actor is not the same as the parent actor.
    * @param [in] child The child.
-   * @post This may invalidate ActorContainer iterators.
    */
   void Remove(Actor child);
 
@@ -472,7 +469,6 @@ public:
    *
    * If the actor has no parent, this method does nothing.
    * @pre The (child) actor has been initialized.
-   * @post This may invalidate ActorContainer iterators.
    */
   void Unparent();
 
index 15b992f..a538a12 100644 (file)
@@ -36,86 +36,92 @@ PropertyCondition::~PropertyCondition()
 
 }
 
-PropertyCondition::PropertyCondition(const PropertyCondition& handle)
+PropertyCondition::PropertyCondition( const PropertyCondition& handle )
 : BaseHandle(handle)
 {
 }
 
-PropertyCondition& PropertyCondition::operator=(const PropertyCondition& rhs)
+PropertyCondition& PropertyCondition::operator=( const PropertyCondition& rhs )
 {
   BaseHandle::operator=(rhs);
   return *this;
 }
 
-PropertyCondition::ArgumentContainer PropertyCondition::GetArguments()
+std::size_t PropertyCondition::GetArgumentCount() const
 {
-  return GetImplementation(*this).arguments;
+  return GetImplementation(*this).arguments.Count();
 }
 
-const PropertyCondition::ArgumentContainer& PropertyCondition::GetArguments() const
+float PropertyCondition::GetArgument( std::size_t index ) const
 {
-  return GetImplementation(*this).arguments;
+  return GetImplementation(*this).arguments[ index ];
 }
 
-PropertyCondition LessThanCondition(float arg)
+PropertyCondition LessThanCondition( float arg )
 {
   PropertyCondition condition;
-  GetImplementation(condition).type = Internal::PropertyCondition::LessThan;
-  GetImplementation(condition).arguments.push_back(Property::Value(arg));
+  Internal::PropertyCondition& impl = GetImplementation( condition );
+  impl.type = Internal::PropertyCondition::LessThan;
+  impl.arguments.PushBack( arg );
 
   return condition;
 }
 
-PropertyCondition GreaterThanCondition(float arg)
+PropertyCondition GreaterThanCondition( float arg )
 {
   PropertyCondition condition;
-  GetImplementation(condition).type = Internal::PropertyCondition::GreaterThan;
-  GetImplementation(condition).arguments.push_back(Property::Value(arg));
+  Internal::PropertyCondition& impl = GetImplementation( condition );
+  impl.type = Internal::PropertyCondition::GreaterThan;
+  impl.arguments.PushBack( arg );
 
   return condition;
 }
 
-PropertyCondition InsideCondition(float arg0, float arg1)
+PropertyCondition InsideCondition( float arg0, float arg1 )
 {
   PropertyCondition condition;
-  GetImplementation(condition).type = Internal::PropertyCondition::Inside;
-  GetImplementation(condition).arguments.push_back(Property::Value(arg0));
-  GetImplementation(condition).arguments.push_back(Property::Value(arg1));
+  Internal::PropertyCondition& impl = GetImplementation( condition );
+  impl.type = Internal::PropertyCondition::Inside;
+  impl.arguments.PushBack( arg0 );
+  impl.arguments.PushBack( arg1 );
 
   return condition;
 }
 
-PropertyCondition OutsideCondition(float arg0, float arg1)
+PropertyCondition OutsideCondition( float arg0, float arg1 )
 {
   PropertyCondition condition;
-  GetImplementation(condition).type = Internal::PropertyCondition::Outside;
-  GetImplementation(condition).arguments.push_back(Property::Value(arg0));
-  GetImplementation(condition).arguments.push_back(Property::Value(arg1));
+  Internal::PropertyCondition& impl = GetImplementation( condition );
+  impl.type = Internal::PropertyCondition::Outside;
+  impl.arguments.PushBack( arg0 );
+  impl.arguments.PushBack( arg1 );
 
   return condition;
 }
 
-PropertyCondition StepCondition(float stepAmount, float referenceValue)
+PropertyCondition StepCondition( float stepAmount, float referenceValue )
 {
   PropertyCondition condition;
-  GetImplementation(condition).type = Internal::PropertyCondition::Step;
-  GetImplementation(condition).arguments.push_back(Property::Value(referenceValue));
-  GetImplementation(condition).arguments.push_back(Property::Value(1.0f / stepAmount));
-  GetImplementation(condition).arguments.push_back(Property::Value(0.0f)); // current step
+  Internal::PropertyCondition& impl = GetImplementation( condition );
+  impl.type = Internal::PropertyCondition::Step;
+  impl.arguments.PushBack( referenceValue );
+  impl.arguments.PushBack( 1.0f / stepAmount );
+  impl.arguments.PushBack( 0.0f ); // current step
 
   return condition;
 }
 
-PropertyCondition VariableStepCondition(const std::vector<float>& stepAmount)
+PropertyCondition VariableStepCondition( const Dali::Vector<float>& stepAmount )
 {
   PropertyCondition condition;
-  GetImplementation(condition).type = Internal::PropertyCondition::VariableStep;
-  GetImplementation(condition).arguments.push_back(Property::Value(0.0f)); // current step
-  int size = stepAmount.size();
-  GetImplementation(condition).arguments.push_back(Property::Value(static_cast<float>(size))); // store number of steps
-  for( std::vector<float>::const_iterator it = stepAmount.begin(), endIt = stepAmount.end(); it != endIt; ++it )
+  Internal::PropertyCondition& impl = GetImplementation( condition );
+  impl.type = Internal::PropertyCondition::VariableStep;
+  impl.arguments.PushBack( 0.0f ); // current step
+  Dali::Vector<float>::SizeType count = stepAmount.Count();
+  impl.arguments.PushBack( float( count ) ); // store number of steps
+  for( Dali::Vector<float>::SizeType index = 0; index < count; ++index )
   {
-    GetImplementation(condition).arguments.push_back(Property::Value( *it ));
+    impl.arguments.PushBack( stepAmount[index] );
   }
 
   return condition;
index 65a9970..9b64967 100644 (file)
@@ -19,7 +19,7 @@
  */
 
 // INTERNAL INCLUDES
-#include <dali/public-api/common/vector-wrapper.h>
+#include <dali/public-api/common/dali-vector.h>
 #include <dali/public-api/object/base-handle.h>
 #include <dali/public-api/object/property.h>
 
@@ -39,15 +39,6 @@ class DALI_IMPORT_API PropertyCondition : public BaseHandle
 public:
 
   /**
-   * @brief Argument container, represents the arguments to be supplied to the condition function.
-   */
-  typedef std::vector<Property::Value>      ArgumentContainer;
-  typedef ArgumentContainer::iterator       ArgumentIter;     ///< Iterator for Dali::PropertyCondition::ArgumentContainer
-  typedef ArgumentContainer::const_iterator ArgumentConstIter;///< Const Iterator for Dali::PropertyCondition::ArgumentContainer
-
-public:
-
-  /**
    * @brief Constructor for condition clause.
    */
   PropertyCondition();
@@ -62,7 +53,7 @@ public:
    *
    * @param [in] handle A reference to the copied handle
    */
-  PropertyCondition(const PropertyCondition& handle);
+  PropertyCondition( const PropertyCondition& handle );
 
   /**
    * @brief This assignment operator is required for (smart) pointer semantics.
@@ -70,7 +61,7 @@ public:
    * @param [in] rhs  A reference to the copied handle
    * @return A reference to this
    */
-  PropertyCondition& operator=(const PropertyCondition& rhs);
+  PropertyCondition& operator=( const PropertyCondition& rhs );
 
 public:
 
@@ -79,7 +70,7 @@ public:
    *
    * @return The arguments used for this condition
    */
-  ArgumentContainer GetArguments();
+  std::size_t GetArgumentCount() const;
 
   /**
    * @brief Retrieve the arguments that this condition uses.
@@ -87,7 +78,7 @@ public:
    * @return The arguments used for this condition
    * @note The container will only be valid as long PropertyCondition is valid.
    */
-  const ArgumentContainer& GetArguments() const;
+  float GetArgument( std::size_t index ) const;
 
 };
 
@@ -103,7 +94,7 @@ public:
  * @param[in] arg The argument for the condition
  * @return A property condition function object
  */
-DALI_IMPORT_API PropertyCondition LessThanCondition(float arg);
+DALI_IMPORT_API PropertyCondition LessThanCondition( float arg );
 
 /**
  * @brief GreaterThanCondition compares whether property is greater than arg.
@@ -117,7 +108,7 @@ DALI_IMPORT_API PropertyCondition LessThanCondition(float arg);
  * @param[in] arg The argument for the condition
  * @return A property condition function object
  */
-DALI_IMPORT_API PropertyCondition GreaterThanCondition(float arg);
+DALI_IMPORT_API PropertyCondition GreaterThanCondition( float arg );
 
 /**
  * @brief InsideCondition compares whether property is greater than arg0 and less than arg1.
@@ -132,7 +123,7 @@ DALI_IMPORT_API PropertyCondition GreaterThanCondition(float arg);
  * @param[in] arg1 The second argument for the condition
  * @return A property condition function object
  */
-DALI_IMPORT_API PropertyCondition InsideCondition(float arg0, float arg1);
+DALI_IMPORT_API PropertyCondition InsideCondition( float arg0, float arg1 );
 
 /**
  * @brief OutsideCondition compares whether property is less than arg0 or greater than arg1.
@@ -147,7 +138,7 @@ DALI_IMPORT_API PropertyCondition InsideCondition(float arg0, float arg1);
  * @param[in] arg1 The second argument for the condition
  * @return A property condition function object
  */
-DALI_IMPORT_API PropertyCondition OutsideCondition(float arg0, float arg1);
+DALI_IMPORT_API PropertyCondition OutsideCondition( float arg0, float arg1 );
 
 /**
  * @brief Detects when a property changes by stepAmount from initialValue, in both positive and negative directions. This will continue checking for multiples of stepAmount
@@ -161,7 +152,7 @@ DALI_IMPORT_API PropertyCondition OutsideCondition(float arg0, float arg1);
  * @param[in] initialValue The initial value to step from
  * @return A property condition function object
  */
-DALI_IMPORT_API PropertyCondition StepCondition(float stepAmount, float initialValue = 0.0f);
+DALI_IMPORT_API PropertyCondition StepCondition( float stepAmount, float initialValue = 0.0f );
 
 /**
  * @brief Receive notifications as a property goes above/below the inputted values. Values must be ordered and can be either ascending or descending
@@ -174,7 +165,7 @@ DALI_IMPORT_API PropertyCondition StepCondition(float stepAmount, float initialV
  * @param[in] steps List of values to receive notifications for as a property crosses them
  * @return A property condition function object
  */
-DALI_IMPORT_API PropertyCondition VariableStepCondition(const std::vector<float>& steps);
+DALI_IMPORT_API PropertyCondition VariableStepCondition( const Dali::Vector<float>& steps );
 
 } // namespace Dali
 
index a57cd8b..365329c 100644 (file)
@@ -20,7 +20,6 @@
 
 
 // INTERNAL INCLUDES
-#include <dali/public-api/common/vector-wrapper.h>
 #include <dali/public-api/signals/dali-signal.h>
 
 namespace Dali