Assert when proprety notification is used in a thread other than the main thread
[platform/core/uifw/dali-core.git] / dali / internal / event / animation / property-constraint.h
index 196c229..e007486 100644 (file)
@@ -1,8 +1,8 @@
-#ifndef __DALI_PROPERTY_CONSTRAINT_H__
-#define __DALI_PROPERTY_CONSTRAINT_H__
+#ifndef DALI_PROPERTY_CONSTRAINT_H
+#define DALI_PROPERTY_CONSTRAINT_H
 
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
  */
 
 // INTERNAL INCLUDES
-#include <dali/public-api/animation/constraint.h>
-#include <dali/public-api/common/dali-vector.h>
-#include <dali/public-api/common/vector-wrapper.h>
 #include <dali/internal/event/animation/property-input-accessor.h>
 #include <dali/internal/event/animation/property-input-indexer.h>
 #include <dali/internal/event/common/property-input-impl.h>
+#include <dali/public-api/animation/constraint.h>
+#include <dali/public-api/common/dali-vector.h>
+#include <dali/public-api/common/vector-wrapper.h>
 
 namespace Dali
 {
-
 namespace Internal
 {
-
 /**
  * A class for connecting properties to a constraint function.
  */
-template < typename PropertyType >
+template<typename PropertyType>
 class PropertyConstraint
 {
 public:
-
-  typedef std::vector < PropertyInputAccessor > InputContainer;
-  typedef typename InputContainer::iterator InputContainerIter;
-  typedef typename InputContainer::const_iterator InputContainerConstIter;
-
-  typedef std::vector< PropertyInputIndexer< PropertyInputAccessor > > InputIndexerContainer;
-
-  typedef Dali::Constraint::Function< PropertyType > ConstraintFunction;
+  using ConstraintFunction    = Dali::Constraint::Function<PropertyType>;
+  using InputContainer        = std::vector<PropertyInputAccessor>;
+  using InputIndexerContainer = std::vector<PropertyInputIndexer<PropertyInputAccessor> >;
 
   /**
    * Create a property constraint.
    *
    * @param[in]  func  A constraint function. Ownership of this callback-function is passed to this object.
    */
-  PropertyConstraint( Dali::Constraint::Function< PropertyType >* func )
-  : mInputsInitialized( false ),
-    mFunction( func ),
-    mInputs()
+  PropertyConstraint(ConstraintFunction* func)
+  : mFunction(func),
+    mInputs(),
+    mInputsInitialized(false)
   {
   }
 
@@ -65,11 +58,11 @@ public:
    * @param [in]  func    A constraint function. Ownership of this callback-function is passed to this object.
    * @param [in]  inputs  Property inputs.
    */
-  PropertyConstraint( Dali::Constraint::Function< PropertyType >* func,
-                      const InputContainer& inputs )
-  : mInputsInitialized( false ),
-    mFunction( func ),
-    mInputs( inputs )
+  PropertyConstraint(ConstraintFunction*   func,
+                     const InputContainer& inputs)
+  : mFunction(func),
+    mInputs(inputs),
+    mInputsInitialized(false)
   {
   }
 
@@ -88,39 +81,34 @@ public:
    *
    * @note This function will create a copy of the stored constraint function for the clone.
    */
-  PropertyConstraint< PropertyType >* Clone()
+  PropertyConstraint<PropertyType>* Clone()
   {
-    return new PropertyConstraint< PropertyType >( reinterpret_cast< ConstraintFunction* >( mFunction->Clone() ), mInputs );
+    return new PropertyConstraint<PropertyType>(reinterpret_cast<ConstraintFunction*>(mFunction->Clone()), mInputs);
   }
 
   /**
    * Set the input for one of the property constraint parameters.
-   * @param [in] index The parameter index.
    * @param [in] input The interface for receiving a property value.
+   * @param [in] componentIndex Component index.
    */
-  void SetInput( unsigned int index, int componentIndex, const PropertyInputImpl& input )
+  void AddInput(const PropertyInputImpl* input, int32_t componentIndex)
   {
-    if ( index >= mInputs.size() )
-    {
-      mInputs.push_back( PropertyInputAccessor() );
-    }
-
-    mInputs[ index ].SetInput( input, componentIndex );
+    mInputs.push_back(PropertyInputAccessor{input, componentIndex});
   }
 
   /**
    * Retrieve the input for one of the property constraint parameters.
    * @param [in] index The parameter index.
-   * @return The property input, or NULL if no input exists with this index.
+   * @return The property input, or nullptr if no input exists with this index.
    */
-  const PropertyInputImpl* GetInput( unsigned int index ) const
+  const PropertyInputImpl* GetInput(uint32_t index) const
   {
-    if ( index < mInputs.size() )
+    if(index < mInputs.size())
     {
-      return mInputs[ index ].GetInput();
+      return mInputs[index].GetInput();
     }
 
-    return NULL;
+    return nullptr;
   }
 
   /**
@@ -129,15 +117,15 @@ public:
    */
   bool InputsInitialized()
   {
-    if ( !mInputsInitialized )
+    if(!mInputsInitialized)
     {
       // Check whether the inputs are initialized yet
-      unsigned int index( 0u );
-      for ( const PropertyInputImpl* input = GetInput( index );
-            NULL != input;
-            input = GetInput( ++index ) )
+      uint32_t index(0u);
+      for(const PropertyInputImpl* input = GetInput(index);
+          nullptr != input;
+          input = GetInput(++index))
       {
-        if ( !input->InputInitialized() )
+        if(!input->InputInitialized())
         {
           return false;
         }
@@ -156,12 +144,12 @@ public:
    */
   bool InputsChanged()
   {
-    unsigned int index( 0u );
-    for ( const PropertyInputImpl* input = GetInput( index );
-          NULL != input;
-          input = GetInput( ++index ) )
+    uint32_t index(0u);
+    for(const PropertyInputImpl* input = GetInput(index);
+        nullptr != input;
+        input = GetInput(++index))
     {
-      if ( input->InputChanged() )
+      if(input->InputChanged())
       {
         // At least one of the inputs has changed
         return true;
@@ -176,46 +164,41 @@ public:
    * @param [in] bufferIndex The current update buffer index.
    * @param [in,out] current The current property value, will be set to the constrained value upon return.
    */
-  void Apply( BufferIndex bufferIndex, PropertyType& current )
+  void Apply(BufferIndex bufferIndex, PropertyType& current)
   {
-    InputIndexerContainer mInputIndices;
-    PropertyInputContainer mIndices;
-    const unsigned int noOfInputs = mInputs.size();
+    InputIndexerContainer  inputIndices;
+    PropertyInputContainer indices;
+    const uint32_t         noOfInputs = static_cast<uint32_t>(mInputs.size());
 
-    mInputIndices.reserve( noOfInputs );
-    mIndices.Reserve( noOfInputs );
+    inputIndices.reserve(noOfInputs);
+    indices.Reserve(noOfInputs);
 
-    const InputContainerConstIter endIter = mInputs.end();
-    unsigned int index = 0;
-    for ( InputContainerConstIter iter = mInputs.begin(); iter != endIter; ++iter, ++index )
+    const auto&& endIter = mInputs.end();
+    uint32_t     index   = 0;
+    for(auto&& iter = mInputs.begin(); iter != endIter; ++iter, ++index)
     {
-      DALI_ASSERT_DEBUG( NULL != iter->GetInput() );
-      mInputIndices.push_back( PropertyInputIndexer< PropertyInputAccessor >( bufferIndex, &*iter ) );
-      mIndices.PushBack( &mInputIndices[ index ] );
+      DALI_ASSERT_DEBUG(nullptr != iter->GetInput());
+      inputIndices.push_back(PropertyInputIndexer<PropertyInputAccessor>(bufferIndex, &*iter));
+      indices.PushBack(&inputIndices[index]);
     }
 
-    CallbackBase::Execute< PropertyType&, const PropertyInputContainer& >( *mFunction, current, mIndices );
+    CallbackBase::Execute<PropertyType&, const PropertyInputContainer&>(*mFunction, current, indices);
   }
 
 private:
-
   // Undefined
-  PropertyConstraint( const PropertyConstraint& );
-
-  // Undefined
-  PropertyConstraint& operator=( const PropertyConstraint& rhs );
+  PropertyConstraint()                          = delete;
+  PropertyConstraint(const PropertyConstraint&) = delete;
+  PropertyConstraint& operator=(const PropertyConstraint& rhs) = delete;
 
 private:
-
-  bool mInputsInitialized;
-
   ConstraintFunction* mFunction;
-
-  InputContainer mInputs;
+  InputContainer      mInputs;
+  bool                mInputsInitialized;
 };
 
 } // namespace Internal
 
 } // namespace Dali
 
-#endif // __DALI_PROPERTY_CONSTRAINT_H__
+#endif // DALI_PROPERTY_CONSTRAINT_H