Making DALi core internals typesafe using guaranteed types; uint8_t, uint32_t
[platform/core/uifw/dali-core.git] / dali / internal / event / common / type-info-impl.cpp
index fec8ead..cb69d1f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
@@ -317,14 +317,34 @@ void TypeInfo::GetPropertyIndices( Property::IndexContainer& indices ) const
     baseImpl.GetPropertyIndices( indices );
   }
 
-  if ( ! mRegisteredProperties.empty() )
+  AppendProperties( indices, mRegisteredProperties );
+}
+
+void TypeInfo::GetChildPropertyIndices( Property::IndexContainer& indices ) const
+{
+  Dali::TypeInfo base = TypeRegistry::Get()->GetTypeInfo( mBaseTypeName );
+  if ( base )
+  {
+    const TypeInfo& baseImpl( GetImplementation( base ) );
+    baseImpl.GetChildPropertyIndices( indices );
+  }
+
+  AppendProperties( indices, mRegisteredChildProperties );
+}
+
+/**
+ * Append the indices in RegisteredProperties to the given index container.
+ */
+void TypeInfo::AppendProperties( Dali::Property::IndexContainer& indices,
+                                 const TypeInfo::RegisteredPropertyContainer& registeredProperties ) const
+{
+  if ( ! registeredProperties.empty() )
   {
-    indices.Reserve( indices.Size() + mRegisteredProperties.size() );
+    indices.Reserve( indices.Size() + registeredProperties.size() );
 
-    const RegisteredPropertyContainer::const_iterator endIter = mRegisteredProperties.end();
-    for ( RegisteredPropertyContainer::const_iterator iter = mRegisteredProperties.begin(); iter != endIter; ++iter )
+    for( auto&& elem : registeredProperties )
     {
-      indices.PushBack( iter->first );
+      indices.PushBack( elem.first );
     }
   }
 }
@@ -514,15 +534,15 @@ void TypeInfo::AddChildProperty( const std::string& name, Property::Index index,
   }
 }
 
-size_t TypeInfo::GetPropertyCount() const
+uint32_t TypeInfo::GetPropertyCount() const
 {
-  size_t count( mRegisteredProperties.size() );
+  uint32_t count = static_cast<uint32_t>( mRegisteredProperties.size() );
 
   Dali::TypeInfo base = TypeRegistry::Get()->GetTypeInfo( mBaseTypeName );
   while ( base )
   {
     const TypeInfo& baseImpl( GetImplementation(base) );
-    count += baseImpl.mRegisteredProperties.size();
+    count += static_cast<uint32_t>( baseImpl.mRegisteredProperties.size() );
     base = TypeRegistry::Get()->GetTypeInfo( baseImpl.mBaseTypeName );
   }
 
@@ -639,7 +659,10 @@ const std::string& TypeInfo::GetChildPropertyName( Property::Index index ) const
     return GetImplementation(base).GetChildPropertyName( index );
   }
 
-  DALI_ASSERT_ALWAYS( ! "Cannot find property index" ); // use the same assert as Object
+  DALI_LOG_WARNING("Cannot find property index");
+
+  static std::string emptyString;
+  return emptyString;
 }
 
 Property::Type TypeInfo::GetChildPropertyType( Property::Index index ) const
@@ -712,7 +735,15 @@ Property::Type TypeInfo::GetPropertyType( Property::Index index ) const
 
   if ( iter != mRegisteredProperties.end() )
   {
-    type = iter->second.type;
+    if( iter->second.componentIndex == Property::INVALID_COMPONENT_INDEX )
+    {
+      type = iter->second.type;
+    }
+    else
+    {
+      // If component index is set, then we should return FLOAT
+      type = Property::FLOAT;
+    }
   }
   else
   {