refactor Object,TypeInfo and PropertyMetaData to use ConstString
[platform/core/uifw/dali-core.git] / dali / internal / event / common / type-info-impl.cpp
index fe1fd20..7f52423 100644 (file)
@@ -65,8 +65,8 @@ private:
 template <typename T>
 struct PropertyNameFinder
 {
-  PropertyNameFinder( const std::string& find )
-  : mFind( find )
+  PropertyNameFinder(ConstString find)
+  : mFind(find)
   {
   }
 
@@ -76,8 +76,7 @@ struct PropertyNameFinder
   }
 
 private:
-
-  const std::string& mFind;
+  ConstString mFind;
 };
 
 /**
@@ -176,9 +175,7 @@ TypeInfo::TypeInfo(const std::string &name, const std::string &baseTypeName, Dal
   DALI_ASSERT_ALWAYS(!baseTypeName.empty() && "Type info construction must have a base type name");
 }
 
-TypeInfo::~TypeInfo()
-{
-}
+TypeInfo::~TypeInfo() = default;
 
 BaseHandle TypeInfo::CreateInstance() const
 {
@@ -273,9 +270,9 @@ Dali::TypeInfo::CreateFunction TypeInfo::GetCreator() const
   return mCreate;
 }
 
-size_t TypeInfo::GetActionCount() const
+uint32_t TypeInfo::GetActionCount() const
 {
-  size_t count = mActions.size();
+  uint32_t count = static_cast<uint32_t>( mActions.size() );
 
   if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
   {
@@ -286,10 +283,10 @@ size_t TypeInfo::GetActionCount() const
   return count;
 }
 
-std::string TypeInfo::GetActionName(size_t index) const
+std::string TypeInfo::GetActionName( uint32_t index ) const
 {
   std::string name;
-  const size_t count = mActions.size();
+  const uint32_t count = static_cast<uint32_t>( mActions.size() );
 
   if( index < count )
   {
@@ -307,9 +304,9 @@ std::string TypeInfo::GetActionName(size_t index) const
   return name;
 }
 
-size_t TypeInfo::GetSignalCount() const
+uint32_t TypeInfo::GetSignalCount() const
 {
-  size_t count = mSignalConnectors.size();
+  uint32_t count = static_cast<uint32_t>( mSignalConnectors.size() );
 
   if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
   {
@@ -320,10 +317,10 @@ size_t TypeInfo::GetSignalCount() const
   return count;
 }
 
-std::string TypeInfo::GetSignalName(size_t index) const
+std::string TypeInfo::GetSignalName( uint32_t index ) const
 {
   std::string name;
-  const size_t count = mSignalConnectors.size();
+  const uint32_t count = static_cast<uint32_t>( mSignalConnectors.size() );
 
   if( index < count )
   {
@@ -390,13 +387,13 @@ void TypeInfo::AppendProperties( Dali::Property::IndexContainer& indices,
   }
 }
 
-const std::string& TypeInfo::GetRegisteredPropertyName( Property::Index index ) const
+std::string_view TypeInfo::GetRegisteredPropertyName(Property::Index index) const
 {
   RegisteredPropertyContainer::const_iterator iter = find_if( mRegisteredProperties.begin(), mRegisteredProperties.end(),
                                                           PairFinder< Property::Index, RegisteredPropertyPair >( index ) );
   if ( iter != mRegisteredProperties.end() )
   {
-    return iter->second.name;
+    return iter->second.name.GetStringView();
   }
   if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
   {
@@ -407,13 +404,13 @@ const std::string& TypeInfo::GetRegisteredPropertyName( Property::Index index )
   return empty;
 }
 
-std::string TypeInfo::GetPropertyName( Property::Index index ) const
+std::string_view TypeInfo::GetPropertyName(Property::Index index) const
 {
-  std::string propertyName;
+  std::string_view propertyName;
   // default or custom
   if ( mDefaultProperties && ( index < DEFAULT_PROPERTY_MAX_COUNT ) )
   {
-    const char* name = nullptr;
+    std::string_view name;
     if( GetDefaultPropertyField( mDefaultProperties, mDefaultPropertyCount,index, &Dali::PropertyDetails::name, name ) )
     {
       propertyName = name;
@@ -425,7 +422,7 @@ std::string TypeInfo::GetPropertyName( Property::Index index ) const
                                                             PairFinder< Property::Index, RegisteredPropertyPair >( index ) );
     if ( iter != mRegisteredProperties.end() )
     {
-      return iter->second.name;
+      return iter->second.name.GetStringView();
     }
   }
   // if not our property, go to parent
@@ -441,9 +438,9 @@ std::string TypeInfo::GetPropertyName( Property::Index index ) const
   return propertyName;
 }
 
-void TypeInfo::AddActionFunction( const std::string &actionName, Dali::TypeInfo::ActionFunction function )
+void TypeInfo::AddActionFunction(std::string actionName, Dali::TypeInfo::ActionFunction function)
 {
-  if( NULL == function)
+  if( nullptr == function)
   {
     DALI_LOG_WARNING("Action function is empty\n");
   }
@@ -454,7 +451,7 @@ void TypeInfo::AddActionFunction( const std::string &actionName, Dali::TypeInfo:
 
     if( iter == mActions.end() )
     {
-      mActions.push_back( ActionPair( actionName, function ) );
+      mActions.push_back(ActionPair(std::move(actionName), function));
     }
     else
     {
@@ -463,9 +460,9 @@ void TypeInfo::AddActionFunction( const std::string &actionName, Dali::TypeInfo:
   }
 }
 
-void TypeInfo::AddConnectorFunction( const std::string& signalName, Dali::TypeInfo::SignalConnectorFunction function )
+void TypeInfo::AddConnectorFunction(std::string signalName, Dali::TypeInfo::SignalConnectorFunction function)
 {
-  if( NULL == function)
+  if( nullptr == function)
   {
     DALI_LOG_WARNING("Connector function is empty\n");
   }
@@ -476,7 +473,7 @@ void TypeInfo::AddConnectorFunction( const std::string& signalName, Dali::TypeIn
 
     if( iter == mSignalConnectors.end() )
     {
-      mSignalConnectors.push_back( ConnectionPair( signalName, function ) );
+      mSignalConnectors.push_back(ConnectionPair(std::move(signalName), function));
     }
     else
     {
@@ -485,11 +482,11 @@ void TypeInfo::AddConnectorFunction( const std::string& signalName, Dali::TypeIn
   }
 }
 
-void TypeInfo::AddProperty( const std::string& name, Property::Index index, Property::Type type, Dali::TypeInfo::SetPropertyFunction setFunc, Dali::TypeInfo::GetPropertyFunction getFunc )
+void TypeInfo::AddProperty(std::string name, Property::Index index, Property::Type type, Dali::TypeInfo::SetPropertyFunction setFunc, Dali::TypeInfo::GetPropertyFunction getFunc)
 {
   // The setter can be empty as a property can be read-only.
 
-  if ( NULL == getFunc )
+  if ( nullptr == getFunc )
   {
     DALI_ASSERT_ALWAYS( ! "GetProperty Function is empty" );
   }
@@ -500,7 +497,7 @@ void TypeInfo::AddProperty( const std::string& name, Property::Index index, Prop
 
     if ( iter == mRegisteredProperties.end() )
     {
-      mRegisteredProperties.push_back( RegisteredPropertyPair( index, RegisteredProperty( type, setFunc, getFunc, name, Property::INVALID_INDEX, Property::INVALID_COMPONENT_INDEX ) ) );
+      mRegisteredProperties.push_back(RegisteredPropertyPair(index, RegisteredProperty(type, setFunc, getFunc, ConstString(name), Property::INVALID_INDEX, Property::INVALID_COMPONENT_INDEX)));
     }
     else
     {
@@ -509,12 +506,12 @@ void TypeInfo::AddProperty( const std::string& name, Property::Index index, Prop
   }
 }
 
-void TypeInfo::AddProperty( const std::string& name, Property::Index index, Property::Type type, Dali::CSharpTypeInfo::SetPropertyFunction setFunc, Dali::CSharpTypeInfo::GetPropertyFunction getFunc)
+void TypeInfo::AddProperty(std::string name, Property::Index index, Property::Type type, Dali::CSharpTypeInfo::SetPropertyFunction setFunc, Dali::CSharpTypeInfo::GetPropertyFunction getFunc)
 {
 
   // The setter can be empty as a property can be read-only.
 
-  if ( NULL == getFunc )
+  if ( nullptr == getFunc )
   {
     DALI_ASSERT_ALWAYS( ! "GetProperty Function is empty" );
   }
@@ -525,7 +522,7 @@ void TypeInfo::AddProperty( const std::string& name, Property::Index index, Prop
 
     if ( iter == mRegisteredProperties.end() )
     {
-      mRegisteredProperties.push_back( RegisteredPropertyPair( index, RegisteredProperty( type, setFunc, getFunc, name, Property::INVALID_INDEX, Property::INVALID_COMPONENT_INDEX ) ) );
+      mRegisteredProperties.push_back(RegisteredPropertyPair(index, RegisteredProperty(type, setFunc, getFunc, ConstString(name), Property::INVALID_INDEX, Property::INVALID_COMPONENT_INDEX)));
     }
     else
     {
@@ -535,15 +532,14 @@ void TypeInfo::AddProperty( const std::string& name, Property::Index index, Prop
 
 }
 
-
-void TypeInfo::AddAnimatableProperty( const std::string& name, Property::Index index, Property::Type type )
+void TypeInfo::AddAnimatableProperty(std::string name, Property::Index index, Property::Type type)
 {
   RegisteredPropertyContainer::iterator iter = find_if( mRegisteredProperties.begin(), mRegisteredProperties.end(),
                                                         PairFinder< Property::Index, RegisteredPropertyPair>(index) );
 
   if ( iter == mRegisteredProperties.end() )
   {
-    mRegisteredProperties.push_back( RegisteredPropertyPair( index, RegisteredProperty( type, name, Property::INVALID_INDEX, Property::INVALID_COMPONENT_INDEX ) ) );
+    mRegisteredProperties.push_back(RegisteredPropertyPair(index, RegisteredProperty(type, ConstString(name), Property::INVALID_INDEX, Property::INVALID_COMPONENT_INDEX)));
   }
   else
   {
@@ -551,15 +547,15 @@ void TypeInfo::AddAnimatableProperty( const std::string& name, Property::Index i
   }
 }
 
-void TypeInfo::AddAnimatableProperty( const std::string& name, Property::Index index, const Property::Value& defaultValue )
+void TypeInfo::AddAnimatableProperty(std::string name, Property::Index index, Property::Value defaultValue)
 {
   RegisteredPropertyContainer::iterator iter = find_if( mRegisteredProperties.begin(), mRegisteredProperties.end(),
                                                         PairFinder< Property::Index, RegisteredPropertyPair>(index) );
 
   if ( iter == mRegisteredProperties.end() )
   {
-    mRegisteredProperties.push_back( RegisteredPropertyPair( index, RegisteredProperty( defaultValue.GetType(), name, Property::INVALID_INDEX, Property::INVALID_COMPONENT_INDEX ) ) );
-    mPropertyDefaultValues.push_back( PropertyDefaultValuePair( index, defaultValue ) );
+    mRegisteredProperties.push_back(RegisteredPropertyPair(index, RegisteredProperty(defaultValue.GetType(), ConstString(name), Property::INVALID_INDEX, Property::INVALID_COMPONENT_INDEX)));
+    mPropertyDefaultValues.push_back(PropertyDefaultValuePair(index, std::move(defaultValue)));
   }
   else
   {
@@ -567,7 +563,7 @@ void TypeInfo::AddAnimatableProperty( const std::string& name, Property::Index i
   }
 }
 
-void TypeInfo::AddAnimatablePropertyComponent( const std::string& name, Property::Index index, Property::Index baseIndex, uint32_t componentIndex )
+void TypeInfo::AddAnimatablePropertyComponent(std::string name, Property::Index index, Property::Index baseIndex, uint32_t componentIndex)
 {
   Property::Type type = GetPropertyType( baseIndex );
   DALI_ASSERT_ALWAYS( ( type == Property::VECTOR2 || type == Property::VECTOR3 || type == Property::VECTOR4 ) && "Base property does not support component" );
@@ -584,7 +580,7 @@ void TypeInfo::AddAnimatablePropertyComponent( const std::string& name, Property
 
     if ( iter == mRegisteredProperties.end() )
     {
-      mRegisteredProperties.push_back( RegisteredPropertyPair( index, RegisteredProperty( type, name, baseIndex, componentIndex ) ) );
+      mRegisteredProperties.push_back(RegisteredPropertyPair(index, RegisteredProperty(type, ConstString(name), baseIndex, componentIndex)));
       success = true;
     }
   }
@@ -592,14 +588,14 @@ void TypeInfo::AddAnimatablePropertyComponent( const std::string& name, Property
   DALI_ASSERT_ALWAYS( success && "Property component already registered" );
 }
 
-void TypeInfo::AddChildProperty( const std::string& name, Property::Index index, Property::Type type )
+void TypeInfo::AddChildProperty(std::string name, Property::Index index, Property::Type type)
 {
   RegisteredPropertyContainer::iterator iter = find_if( mRegisteredChildProperties.begin(), mRegisteredChildProperties.end(),
                                                         PairFinder< Property::Index, RegisteredPropertyPair>(index) );
 
   if ( iter == mRegisteredChildProperties.end() )
   {
-    mRegisteredChildProperties.push_back( RegisteredPropertyPair( index, RegisteredProperty( type, name, Property::INVALID_INDEX, Property::INVALID_COMPONENT_INDEX ) ) );
+    mRegisteredChildProperties.push_back(RegisteredPropertyPair(index, RegisteredProperty(type, ConstString(name), Property::INVALID_INDEX, Property::INVALID_COMPONENT_INDEX)));
   }
   else
   {
@@ -620,7 +616,7 @@ uint32_t TypeInfo::GetPropertyCount() const
   return count;
 }
 
-Property::Index TypeInfo::GetPropertyIndex( const std::string& name ) const
+Property::Index TypeInfo::GetPropertyIndex(ConstString name) const
 {
   Property::Index index = Property::INVALID_INDEX;
   bool found = false;
@@ -628,9 +624,10 @@ Property::Index TypeInfo::GetPropertyIndex( const std::string& name ) const
   // check default properties
   if( mDefaultProperties )
   {
+    auto stringView = name.GetStringView();
     for( Property::Index tableIndex = 0; tableIndex < mDefaultPropertyCount; ++tableIndex )
     {
-      if( 0 == name.compare( mDefaultProperties[ tableIndex ].name ) )
+      if(mDefaultProperties[tableIndex].name == stringView)
       {
         index = mDefaultProperties[ tableIndex ].enumIndex;
         found = true;
@@ -677,7 +674,7 @@ Property::Index TypeInfo::GetBasePropertyIndex( Property::Index index ) const
   return basePropertyIndex;
 }
 
-int TypeInfo::GetComponentIndex( Property::Index index ) const
+int32_t TypeInfo::GetComponentIndex( Property::Index index ) const
 {
   int componentIndex = Property::INVALID_COMPONENT_INDEX;
 
@@ -697,7 +694,7 @@ int TypeInfo::GetComponentIndex( Property::Index index ) const
   return componentIndex;
 }
 
-Property::Index TypeInfo::GetChildPropertyIndex( const std::string& name ) const
+Property::Index TypeInfo::GetChildPropertyIndex(ConstString name) const
 {
   Property::Index index = Property::INVALID_INDEX;
 
@@ -718,14 +715,14 @@ Property::Index TypeInfo::GetChildPropertyIndex( const std::string& name ) const
   return index;
 }
 
-const std::string& TypeInfo::GetChildPropertyName( Property::Index index ) const
+std::string_view TypeInfo::GetChildPropertyName(Property::Index index) const
 {
   RegisteredPropertyContainer::const_iterator iter = find_if( mRegisteredChildProperties.begin(), mRegisteredChildProperties.end(),
                                                           PairFinder< Property::Index, RegisteredPropertyPair >( index ) );
 
   if ( iter != mRegisteredChildProperties.end() )
   {
-    return iter->second.name;
+    return iter->second.name.GetStringView();
   }
 
   if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
@@ -736,8 +733,7 @@ const std::string& TypeInfo::GetChildPropertyName( Property::Index index ) const
 
   DALI_LOG_ERROR( "Property index %d not found\n", index );
 
-  static std::string empty;
-  return empty;
+  return {};
 }
 
 Property::Type TypeInfo::GetChildPropertyType( Property::Index index ) const
@@ -950,7 +946,7 @@ Property::Value TypeInfo::GetPropertyDefaultValue( Property::Index index ) const
   return Property::Value(); // return none
 }
 
-void TypeInfo::SetProperty( BaseObject *object, Property::Index index, const Property::Value& value ) const
+void TypeInfo::SetProperty(BaseObject* object, Property::Index index, Property::Value value) const
 {
   RegisteredPropertyContainer::const_iterator iter = find_if( mRegisteredProperties.begin(), mRegisteredProperties.end(),
                                                               PairFinder< Property::Index, RegisteredPropertyPair >( index ) );
@@ -961,20 +957,20 @@ void TypeInfo::SetProperty( BaseObject *object, Property::Index index, const Pro
       if( mCSharpType )
       {
         // CSharp wants a property name not an index
-        const std::string& name = (iter->second).name;
+        auto name = (iter->second).name;
 
-        iter->second.cSharpSetFunc( object,name.c_str(), const_cast< Property::Value* >(&value) );
+        iter->second.cSharpSetFunc(object, name.GetCString(), const_cast<Property::Value*>(&value));
       }
       else
       {
-        iter->second.setFunc( object, index, value );
+        iter->second.setFunc(object, index, std::move(value));
       }
     }
   }
   else if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
   {
     // call base type recursively
-    mBaseType->SetProperty( object, index, value );
+    mBaseType->SetProperty(object, index, std::move(value));
   }
   else
   {
@@ -982,10 +978,9 @@ void TypeInfo::SetProperty( BaseObject *object, Property::Index index, const Pro
   }
 }
 
-void TypeInfo::SetProperty( BaseObject *object, const std::string& name, const Property::Value& value ) const
+void TypeInfo::SetProperty(BaseObject* object, const std::string& name, Property::Value value) const
 {
-  RegisteredPropertyContainer::const_iterator iter = find_if( mRegisteredProperties.begin(), mRegisteredProperties.end(),
-                                                              PropertyNameFinder< RegisteredPropertyPair >( name ) );
+  RegisteredPropertyContainer::const_iterator iter = find_if(mRegisteredProperties.begin(), mRegisteredProperties.end(), PropertyNameFinder<RegisteredPropertyPair>(ConstString(name)));
   if ( iter != mRegisteredProperties.end() )
   {
     DALI_ASSERT_ALWAYS( iter->second.setFunc && "Trying to write to a read-only property" );
@@ -997,13 +992,13 @@ void TypeInfo::SetProperty( BaseObject *object, const std::string& name, const P
     }
     else
     {
-      iter->second.setFunc( object, iter->first, value );
+      iter->second.setFunc(object, iter->first, std::move(value));
     }
   }
   else if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
   {
     // call base type recursively
-    mBaseType->SetProperty( object, name, value );
+    mBaseType->SetProperty(object, name, std::move(value));
   }
   else
   {
@@ -1022,10 +1017,9 @@ Property::Value TypeInfo::GetProperty( const BaseObject *object, Property::Index
       // CSharp wants a property name not an index
       // CSharp callback can't return an object by value, it can only return a pointer
       // CSharp has ownership of the pointer contents, which is fine because we are returning by from this function by value
-      const std::string& name = (iter->second).name;
-
-      return *( iter->second.cSharpGetFunc( const_cast< BaseObject* >( object ), name.c_str()) );
+      auto name = (iter->second).name;
 
+      return *(iter->second.cSharpGetFunc(const_cast<BaseObject*>(object), name.GetCString()));
     }
     else
     {
@@ -1046,10 +1040,7 @@ Property::Value TypeInfo::GetProperty( const BaseObject *object, Property::Index
 
 Property::Value TypeInfo::GetProperty( const BaseObject *object, const std::string& name ) const
 {
-  RegisteredPropertyContainer::const_iterator iter = find_if( mRegisteredProperties.begin(), mRegisteredProperties.end(),
-                                                            PropertyNameFinder< RegisteredPropertyPair >( name ) );
-
-
+  RegisteredPropertyContainer::const_iterator iter = find_if(mRegisteredProperties.begin(), mRegisteredProperties.end(), PropertyNameFinder<RegisteredPropertyPair>(ConstString(name)));
 
   if( iter != mRegisteredProperties.end() )
   {