namespace Dali
{
+namespace Internal
+{
+
namespace
{
return found;
}
-} // unnamed namespace
+// static pointer value to mark that a base class address has not been resolved
+// 0x01 is not a valid pointer but used here to differentiate from nullptr
+// unfortunately it cannot be constexpr as C++ does not allow them to be initialised with reinterpret_cast
+Internal::TypeInfo* const UNRESOLVED = reinterpret_cast<Internal::TypeInfo*>( 0x1 );
-namespace Internal
+/**
+ * Helper function to resolve and return the pointer to the base type info
+ * Not a member function to avoid having to #include additional headers and to make sure this gets inlined inside this cpp
+ * @param[in/out] baseType pointer to resolve and set
+ * @param[in] typeRegistry reference to the type registry
+ * @param[in] baseTypeName string name of the base type
+ * @return true is base type exists
+ */
+inline bool GetBaseType( Internal::TypeInfo*& baseType, TypeRegistry& typeRegistry, const std::string& baseTypeName )
{
+ // if greater than unresolved means we have a base type, null means no base
+ bool baseExists = ( baseType > UNRESOLVED );
+ // base only needs to be resolved once
+ if( UNRESOLVED == baseType )
+ {
+ TypeRegistry::TypeInfoPointer base = typeRegistry.GetTypeInfo( baseTypeName );
+ if( base )
+ {
+ baseType = base.Get(); // dont pass ownership, just return raw pointer
+ baseExists = true;
+ }
+ else
+ {
+ // no type info found so assuming no base as all type registration is done in startup for now
+ baseType = nullptr;
+ }
+ }
+ return baseExists;
+}
+
+} // unnamed namespace
TypeInfo::TypeInfo( const std::string &name, const std::string &baseTypeName, Dali::TypeInfo::CreateFunction creator,
const Dali::PropertyDetails* defaultProperties, Property::Index defaultPropertyCount )
-: mTypeRegistry( *TypeRegistry::Get() ),
- mTypeName(name), mBaseTypeName(baseTypeName), mCreate(creator), mDefaultProperties( defaultProperties ),
- mDefaultPropertyCount( defaultPropertyCount ), mCSharpType(false)
+: mTypeRegistry( *TypeRegistry::Get() ), mBaseType( UNRESOLVED ),
+ mTypeName( name ), mBaseTypeName( baseTypeName ), mCreate( creator ), mDefaultProperties( defaultProperties ),
+ mDefaultPropertyCount( defaultPropertyCount ), mCSharpType( false )
{
DALI_ASSERT_ALWAYS(!name.empty() && "Type info construction must have a name");
DALI_ASSERT_ALWAYS(!baseTypeName.empty() && "Type info construction must have a base type name");
}
TypeInfo::TypeInfo(const std::string &name, const std::string &baseTypeName, Dali::CSharpTypeInfo::CreateFunction creator)
-: mTypeRegistry( *TypeRegistry::Get() ),
- mTypeName(name), mBaseTypeName(baseTypeName), mCSharpCreate(creator), mCSharpType(true)
+: mTypeRegistry( *TypeRegistry::Get() ), mBaseType( UNRESOLVED ),
+ mTypeName( name ), mBaseTypeName( baseTypeName ), mCSharpCreate( creator ), mCSharpType( true )
{
DALI_ASSERT_ALWAYS(!name.empty() && "Type info construction must have a name");
DALI_ASSERT_ALWAYS(!baseTypeName.empty() && "Type info construction must have a base type name");
if( !done )
{
- Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName );
- while( base )
+ if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
{
- done = GetImplementation(base).DoActionTo(object, actionName, properties);
- if( done )
- {
- break;
- }
- base = mTypeRegistry.GetTypeInfo( base.GetBaseName() );
+ // call base type recursively
+ done = mBaseType->DoActionTo( object, actionName, properties );
}
}
connected = (iter->second)( object, connectionTracker, signalName, functor );
}
+ if( !connected )
+ {
+ if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
+ {
+ // call base type recursively
+ connected = mBaseType->ConnectSignal( object, connectionTracker, signalName, functor );
+ }
+ }
+
return connected;
}
{
size_t count = mActions.size();
- Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName );
- while( base )
+ if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
{
- count += GetImplementation(base).mActions.size();
- base = mTypeRegistry.GetTypeInfo( base.GetBaseName() );
+ // call base type recursively
+ count += mBaseType->GetActionCount();
}
return count;
std::string TypeInfo::GetActionName(size_t index) const
{
std::string name;
+ const size_t count = mActions.size();
- if( index < mActions.size() )
+ if( index < count )
{
name = mActions[index].first;
}
else
{
- size_t count = mActions.size();
-
- Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName );
- while( base )
+ if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
{
- size_t baseCount = GetImplementation(base).mActions.size();
-
- if( index < count + baseCount )
- {
- name = GetImplementation(base).mActions[ index - count ].first;
- break;
- }
-
- count += baseCount;
-
- base = mTypeRegistry.GetTypeInfo( base.GetBaseName() );
+ // call base type recursively
+ return mBaseType->GetActionName( index - count );
}
}
{
size_t count = mSignalConnectors.size();
- Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName );
- while( base )
+ if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
{
- count += GetImplementation(base).mSignalConnectors.size();
- base = mTypeRegistry.GetTypeInfo( base.GetBaseName() );
+ // call base type recursively
+ count += mBaseType->GetSignalCount();
}
return count;
std::string TypeInfo::GetSignalName(size_t index) const
{
std::string name;
+ const size_t count = mSignalConnectors.size();
- if( index < mSignalConnectors.size() )
+ if( index < count )
{
name = mSignalConnectors[index].first;
}
else
{
- size_t count = mSignalConnectors.size();
-
- Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName );
- while( base )
+ if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
{
- size_t baseCount = GetImplementation(base).mSignalConnectors.size();
-
- if( index < count + baseCount )
- {
- name = GetImplementation(base).mSignalConnectors[ index - count ].first;
- break;
- }
-
- count += baseCount;
-
- base = mTypeRegistry.GetTypeInfo( base.GetBaseName() );
+ // call base type recursively
+ return mBaseType->GetSignalName( index - count );
}
}
}
}
- Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName );
- if ( base )
+ if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
{
- const TypeInfo& baseImpl( GetImplementation( base ) );
- baseImpl.GetPropertyIndices( indices );
+ // call base type recursively
+ mBaseType->GetPropertyIndices( indices );
}
AppendProperties( indices, mRegisteredProperties );
void TypeInfo::GetChildPropertyIndices( Property::IndexContainer& indices ) const
{
- Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName );
- if ( base )
+ if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
{
- const TypeInfo& baseImpl( GetImplementation( base ) );
- baseImpl.GetChildPropertyIndices( indices );
+ // call base type recursively
+ mBaseType->GetChildPropertyIndices( indices );
}
AppendProperties( indices, mRegisteredChildProperties );
{
return iter->second.name;
}
- Dali::TypeInfo base = TypeRegistry::Get()->GetTypeInfo( mBaseTypeName );
- if ( base )
+ if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
{
- return GetImplementation(base).GetRegisteredPropertyName( index );
+ // call base type recursively
+ return mBaseType->GetRegisteredPropertyName( index );
}
static std::string empty;
return empty;
// if not our property, go to parent
if( propertyName.empty() )
{
- Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName );
- if ( base )
+ if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
{
- return GetImplementation(base).GetPropertyName( index );
+ // call base type recursively
+ return mBaseType->GetPropertyName( index );
}
}
{
uint32_t count = mDefaultPropertyCount + static_cast<uint32_t>( mRegisteredProperties.size() );
- Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName );
- while ( base )
+ if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
{
- const TypeInfo& baseImpl( GetImplementation(base) );
- count += baseImpl.mDefaultPropertyCount + static_cast<uint32_t>( baseImpl.mRegisteredProperties.size() );
- base = mTypeRegistry.GetTypeInfo( baseImpl.mBaseTypeName );
+ // call base type recursively
+ count += mBaseType->GetPropertyCount();
}
return count;
{
index = iter->first;
}
- else
+ else if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
{
- Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName );
- if ( base )
- {
- index = GetImplementation(base).GetPropertyIndex( name );
- }
+ // call base type recursively
+ index = mBaseType->GetPropertyIndex( name );
}
}
{
basePropertyIndex = iter->second.basePropertyIndex;
}
- else
+ else if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
{
- Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName );
- if ( base )
- {
- basePropertyIndex = GetImplementation(base).GetBasePropertyIndex( index );
- }
+ // call base type recursively
+ basePropertyIndex = mBaseType->GetBasePropertyIndex( index );
}
return basePropertyIndex;
{
componentIndex = iter->second.componentIndex;
}
- else
+ else if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
{
- Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName );
- if ( base )
- {
- componentIndex = GetImplementation(base).GetComponentIndex( index );
- }
+ // call base type recursively
+ componentIndex = mBaseType->GetComponentIndex( index );
}
return componentIndex;
{
index = iter->first;
}
- else
+ else if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
{
- Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName );
- if ( base )
- {
- index = GetImplementation(base).GetChildPropertyIndex( name );
- }
+ // call base type recursively
+ index = mBaseType->GetChildPropertyIndex( name );
}
return index;
return iter->second.name;
}
- Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName );
- if ( base )
+ if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
{
- return GetImplementation(base).GetChildPropertyName( index );
+ // call base type recursively
+ return mBaseType->GetChildPropertyName( index );
}
DALI_LOG_ERROR( "Property index %d not found\n", index );
{
type = iter->second.type;
}
+ else if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
+ {
+ // call base type recursively
+ type = mBaseType->GetChildPropertyType( index );
+ }
else
{
- Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName );
- if ( base )
- {
- type = GetImplementation(base).GetChildPropertyType( index );
- }
- else
- {
- DALI_LOG_ERROR( "Property index %d not found\n", index );
- }
+ DALI_LOG_ERROR( "Property index %d not found\n", index );
}
return type;
// if not found, continue to base
if( !found )
{
- Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName );
- if ( base )
+ if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
{
- writable = GetImplementation(base).IsPropertyWritable( index );
+ // call base type recursively
+ writable = mBaseType->IsPropertyWritable( index );
}
else
{
// if not found, continue to base
if( !found )
{
- Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName );
- if ( base )
+ if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
{
- animatable = GetImplementation(base).IsPropertyAnimatable( index );
+ // call base type recursively
+ animatable = mBaseType->IsPropertyAnimatable( index );
}
else
{
// if not found, continue to base
if( !found )
{
- Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName );
- if ( base )
+ if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
{
- constraintInput = GetImplementation(base).IsPropertyAConstraintInput( index );
+ // call base type recursively
+ constraintInput = mBaseType->IsPropertyAConstraintInput( index );
}
else
{
if( !found )
{
- Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName );
- if ( base )
+ if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
{
- type = GetImplementation(base).GetPropertyType( index );
+ // call base type recursively
+ type = mBaseType->GetPropertyType( index );
}
else
{
{
PropertyDefaultValueContainer::const_iterator iter = find_if( mPropertyDefaultValues.begin(), mPropertyDefaultValues.end(),
PairFinder< Property::Index, PropertyDefaultValuePair >( index ) );
- if( iter != mPropertyDefaultValues.end() )
+ if( iter != mPropertyDefaultValues.end() )
{
return iter->second;
}
}
}
}
+ else if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
+ {
+ // call base type recursively
+ mBaseType->SetProperty( object, index, value );
+ }
else
{
- Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName );
- if ( base )
- {
- GetImplementation(base).SetProperty( object, index, value );
- }
- else
- {
- DALI_LOG_ERROR( "Property index %d not found\n", index );
- }
+ DALI_LOG_ERROR( "Property index %d not found\n", index );
}
}
iter->second.setFunc( object, iter->first, value );
}
}
+ else if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
+ {
+ // call base type recursively
+ mBaseType->SetProperty( object, name, value );
+ }
else
{
- Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName );
- if ( base )
- {
- GetImplementation(base).SetProperty( object, name, value );
- }
- else
- {
- DALI_LOG_ERROR( "Property %s not found", name.c_str() );
- }
+ DALI_LOG_ERROR( "Property %s not found", name.c_str() );
}
}
}
}
- Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName );
- if ( base )
+ if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
{
- return GetImplementation( base ).GetProperty( object, index );
+ // call base type recursively
+ return mBaseType->GetProperty( object, index );
}
DALI_LOG_ERROR( "Property index %d not found\n", index );
}
}
- Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName );
- if ( base )
+ if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
{
- return GetImplementation( base ).GetProperty( object, name );
+ // call base type recursively
+ return mBaseType->GetProperty( object, name );
}
DALI_LOG_ERROR( "Property %s not found", name.c_str() );
mRegistryLut.clear();
}
-Dali::TypeInfo TypeRegistry::GetTypeInfo( const std::string& uniqueTypeName )
+TypeRegistry::TypeInfoPointer TypeRegistry::GetTypeInfo( const std::string& uniqueTypeName )
{
for( auto&& iter : mRegistryLut )
{
// Note! mRegistryLut contains Dali::TypeInfo handles, so cannot call GetTypeName()
// as it calls us back resulting in infinite loop (GetTypeName is in BaseHandle part)
- if( GetImplementation( iter ).GetName() == uniqueTypeName )
+ if( iter->GetName() == uniqueTypeName )
{
return iter;
}
}
DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Cannot find requested type '%s'\n", uniqueTypeName.c_str() );
- return Dali::TypeInfo();
+ return TypeRegistry::TypeInfoPointer();
}
-Dali::TypeInfo TypeRegistry::GetTypeInfo( const std::type_info& registerType )
+TypeRegistry::TypeInfoPointer TypeRegistry::GetTypeInfo( const std::type_info& registerType )
{
std::string typeName = DemangleClassName( registerType.name() );
if( index < mRegistryLut.size() )
{
- name = GetImplementation( mRegistryLut[ index ] ).GetName();
+ name = mRegistryLut[ index ]->GetName();
}
return name;
// check for duplicates using uniqueTypeName
for( auto&& iter : mRegistryLut )
{
- if( GetImplementation( iter ).GetName() == uniqueTypeName )
+ if( iter->GetName() == uniqueTypeName )
{
DALI_LOG_WARNING( "Duplicate name in TypeRegistry for '%s'\n", + uniqueTypeName.c_str() );
DALI_ASSERT_ALWAYS( !"Duplicate type name in Type Registration" );
}
}
- mRegistryLut.push_back( Dali::TypeInfo( new Internal::TypeInfo( uniqueTypeName, baseTypeName, createInstance, defaultProperties, defaultPropertyCount ) ) );
+ mRegistryLut.push_back( TypeRegistry::TypeInfoPointer( new Internal::TypeInfo( uniqueTypeName, baseTypeName, createInstance, defaultProperties, defaultPropertyCount ) ) );
DALI_LOG_INFO( gLogFilter, Debug::Concise, "Type Registration %s(%s)\n", uniqueTypeName.c_str(), baseTypeName.c_str() );
if( callCreateOnInit )
// check for duplicates using uniqueTypeName
for( auto&& iter : mRegistryLut )
{
- if( GetImplementation( iter ).GetName() == uniqueTypeName )
+ if( iter->GetName() == uniqueTypeName )
{
DALI_LOG_WARNING( "Duplicate name in TypeRegistry for '%s'\n", + uniqueTypeName.c_str() );
DALI_ASSERT_ALWAYS( !"Duplicate type name in Type Registration" );
}
}
- mRegistryLut.push_back( Dali::TypeInfo( new Internal::TypeInfo( uniqueTypeName, baseTypeName, createInstance ) ) );
+ mRegistryLut.push_back( TypeRegistry::TypeInfoPointer( new Internal::TypeInfo( uniqueTypeName, baseTypeName, createInstance ) ) );
DALI_LOG_INFO( gLogFilter, Debug::Concise, "Type Registration %s(%s)\n", uniqueTypeName.c_str(), baseTypeName.c_str() );
}
{
for( auto&& iter : mRegistryLut )
{
- auto&& impl = GetImplementation( iter );
- if( impl.GetName() == typeRegistration.RegisteredName() )
+ if( iter->GetName() == typeRegistration.RegisteredName() )
{
- impl.AddConnectorFunction( name, func );
+ iter->AddConnectorFunction( name, func );
break;
}
}
{
for( auto&& iter : mRegistryLut )
{
- auto&& impl = GetImplementation( iter );
- if( impl.GetName() == typeRegistration.RegisteredName() )
+ if( iter->GetName() == typeRegistration.RegisteredName() )
{
- impl.AddActionFunction( name, f );
+ iter->AddActionFunction( name, f );
return true;
}
}
{
for( auto&& iter : mRegistryLut )
{
- auto&& impl = GetImplementation( iter );
- if( impl.GetName() == typeRegistration.RegisteredName() )
+ if( iter->GetName() == typeRegistration.RegisteredName() )
{
- impl.AddProperty( name, index, type, setFunc, getFunc );
+ iter->AddProperty( name, index, type, setFunc, getFunc );
return true;
}
}
{
for( auto&& iter : mRegistryLut )
{
- auto&& impl = GetImplementation( iter );
- if( impl.GetName() == objectName )
+ if( iter->GetName() == objectName )
{
- impl.AddProperty( name, index, type, setFunc, getFunc );
+ iter->AddProperty( name, index, type, setFunc, getFunc );
return true;
}
}
{
for( auto&& iter : mRegistryLut )
{
- auto&& impl = GetImplementation( iter );
- if( impl.GetName() == typeRegistration.RegisteredName() )
+ if( iter->GetName() == typeRegistration.RegisteredName() )
{
- impl.AddAnimatableProperty( name, index, type );
+ iter->AddAnimatableProperty( name, index, type );
return true;
}
}
{
for( auto&& iter : mRegistryLut )
{
- auto&& impl = GetImplementation( iter );
- if( impl.GetName() == typeRegistration.RegisteredName() )
+ if( iter->GetName() == typeRegistration.RegisteredName() )
{
- impl.AddAnimatableProperty( name, index, value );
+ iter->AddAnimatableProperty( name, index, value );
return true;
}
}
{
for( auto&& iter : mRegistryLut )
{
- auto&& impl = GetImplementation( iter );
- if( impl.GetName() == typeRegistration.RegisteredName() )
+ if( iter->GetName() == typeRegistration.RegisteredName() )
{
- impl.AddAnimatablePropertyComponent( name, index, baseIndex, componentIndex );
+ iter->AddAnimatablePropertyComponent( name, index, baseIndex, componentIndex );
return true;
}
}
{
for( auto&& iter : mRegistryLut )
{
- auto&& impl = GetImplementation( iter );
- if( impl.GetName() == registeredType )
+ if( iter->GetName() == registeredType )
{
- impl.AddChildProperty( name, index, type );
+ iter->AddChildProperty( name, index, type );
return true;
}
}
{
bool done = false;
- Dali::TypeInfo type = GetTypeInfo( object );
+ auto&& type = GetTypeInfo( object );
- auto&& impl = GetImplementation( type );
// DoActionTo recurses through base classes
- done = impl.DoActionTo( object, actionName, properties );
+ done = type->DoActionTo( object, actionName, properties );
if( !done )
{
- DALI_LOG_WARNING("Type '%s' cannot do action '%s'\n", type.GetName().c_str(), actionName.c_str());
+ DALI_LOG_WARNING("Type '%s' cannot do action '%s'\n", type->GetName().c_str(), actionName.c_str());
}
return done;
{
bool connected( false );
- Dali::TypeInfo type = GetTypeInfo( object );
+ auto&& type = GetTypeInfo( object );
- while( type )
- {
- auto&& impl = GetImplementation( type );
- connected = impl.ConnectSignal( object, connectionTracker, signalName, functor );
- if( connected )
- {
- break;
- }
- type = GetTypeInfo( impl.GetBaseName() );
- }
+ // Connect iterates through base classes
+ connected = type->ConnectSignal( object, connectionTracker, signalName, functor );
if( !connected )
{
+ DALI_LOG_WARNING("Type '%s' signal '%s' connection failed \n", type->GetName().c_str(), signalName.c_str());
// Ownership of functor was not passed to Dali::CallbackBase, so clean-up now
delete functor;
}
return connected;
}
-Dali::TypeInfo TypeRegistry::GetTypeInfo(const Dali::BaseObject * const pBaseObject)
+TypeRegistry::TypeInfoPointer TypeRegistry::GetTypeInfo(const Dali::BaseObject * const pBaseObject)
{
- Dali::TypeInfo type;
+ TypeInfoPointer type;
// test for custom actor which has another indirection to get to the type hiearchy we're after
const Dali::Internal::CustomActor * const pCustom = dynamic_cast<const Dali::Internal::CustomActor*>(pBaseObject);
- if(pCustom)
+ if( pCustom )
{
const Dali::CustomActorImpl& custom = pCustom->GetImplementation();
type = GetTypeInfo( typeid( custom ) );