X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fevent%2Fcommon%2Ftype-registry-impl.cpp;h=73fc652b47e598bbd8dea3b375f48af129983c94;hb=33a8477946185463936981476e9772d40c37fd72;hp=de44e8eee2b3e8283a3ea689d21c9e824799ccfc;hpb=23b0c3407937f40470c8aa3ea7cd4a2bdeaaa00b;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/event/common/type-registry-impl.cpp b/dali/internal/event/common/type-registry-impl.cpp index de44e8e..73fc652 100644 --- a/dali/internal/event/common/type-registry-impl.cpp +++ b/dali/internal/event/common/type-registry-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -19,32 +19,29 @@ #include // INTERNAL INCLUDES -#include -#include #include #include #include +#include +#include #include namespace { - #if defined(DEBUG_ENABLED) Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_TYPE_REGISTRY"); #endif -} // namespace anon +} // namespace namespace Dali { - namespace Internal { - -TypeRegistry *TypeRegistry::Get() +TypeRegistry* TypeRegistry::Get() { - static TypeRegistry *_reg(new TypeRegistry()); + static TypeRegistry* _reg(new TypeRegistry()); DALI_ASSERT_DEBUG(_reg); return _reg; } @@ -56,66 +53,63 @@ TypeRegistry::~TypeRegistry() mRegistryLut.clear(); } -TypeRegistry::TypeInfoPointer TypeRegistry::GetTypeInfo( const std::string& uniqueTypeName ) +TypeRegistry::TypeInfoPointer TypeRegistry::GetTypeInfo(const std::string& uniqueTypeName) { - for( auto&& iter : mRegistryLut ) + auto iter = mRegistryLut.Get(ConstString(uniqueTypeName)); + if(iter != mRegistryLut.end()) { - // 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( iter->GetName() == uniqueTypeName ) - { - return iter; - } + return iter->second; } - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Cannot find requested type '%s'\n", uniqueTypeName.c_str() ); + + DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Cannot find requested type '%s'\n", uniqueTypeName.c_str()); return TypeRegistry::TypeInfoPointer(); } -TypeRegistry::TypeInfoPointer TypeRegistry::GetTypeInfo( const std::type_info& registerType ) +TypeRegistry::TypeInfoPointer TypeRegistry::GetTypeInfo(const std::type_info& registerType) { - std::string typeName = DemangleClassName( registerType.name() ); + std::string typeName = DemangleClassName(registerType.name()); - return GetTypeInfo( typeName ); + return GetTypeInfo(typeName); } uint32_t TypeRegistry::GetTypeNameCount() const { - return static_cast( mRegistryLut.size() ); + return static_cast(mRegistryLut.size()); } const std::string& TypeRegistry::GetTypeName(uint32_t index) const { static std::string EMPTY_STRING{}; - if( index < mRegistryLut.size() ) + if(index < mRegistryLut.size()) { - return mRegistryLut[index]->GetName(); + return mRegistryLut.GetElementByIndex(index)->GetName(); } return EMPTY_STRING; } -std::string TypeRegistry::Register( const std::type_info& theTypeInfo, - const std::type_info& baseTypeInfo, - Dali::TypeInfo::CreateFunction createInstance, - bool callCreateOnInit ) +std::string TypeRegistry::Register(const std::type_info& theTypeInfo, + const std::type_info& baseTypeInfo, + Dali::TypeInfo::CreateFunction createInstance, + bool callCreateOnInit) { - std::string uniqueTypeName = DemangleClassName( theTypeInfo.name() ); + std::string uniqueTypeName = DemangleClassName(theTypeInfo.name()); - return Register( uniqueTypeName, baseTypeInfo, createInstance, callCreateOnInit ); + return Register(uniqueTypeName, baseTypeInfo, createInstance, callCreateOnInit); } -std::string TypeRegistry::Register( const std::type_info& theTypeInfo, - const std::type_info& baseTypeInfo, - Dali::TypeInfo::CreateFunction createInstance, - bool callCreateOnInit, - const Dali::PropertyDetails* defaultProperties, - Property::Index defaultPropertyCount ) +std::string TypeRegistry::Register(const std::type_info& theTypeInfo, + const std::type_info& baseTypeInfo, + Dali::TypeInfo::CreateFunction createInstance, + bool callCreateOnInit, + const Dali::PropertyDetails* defaultProperties, + Property::Index defaultPropertyCount) { - std::string uniqueTypeName = DemangleClassName( theTypeInfo.name() ); + std::string uniqueTypeName = DemangleClassName(theTypeInfo.name()); - return Register( uniqueTypeName, baseTypeInfo, createInstance, callCreateOnInit, defaultProperties, defaultPropertyCount ); + return Register(uniqueTypeName, baseTypeInfo, createInstance, callCreateOnInit, defaultProperties, defaultPropertyCount); } std::string TypeRegistry::Register(std::string uniqueTypeName, @@ -125,24 +119,17 @@ std::string TypeRegistry::Register(std::string uniqueTypeName const Dali::PropertyDetails* defaultProperties, Property::Index defaultPropertyCount) { - std::string baseTypeName = DemangleClassName( baseTypeInfo.name() ); + std::string baseTypeName = DemangleClassName(baseTypeInfo.name()); - // check for duplicates using uniqueTypeName - for( auto&& iter : mRegistryLut ) + if(!mRegistryLut.Register(ConstString(uniqueTypeName), new Internal::TypeInfo(uniqueTypeName, baseTypeName, createInstance, defaultProperties, defaultPropertyCount))) { - 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" ); - return uniqueTypeName; // never actually happening due to the assert - } + DALI_LOG_WARNING("Duplicate name in TypeRegistry for '%s'\n", +uniqueTypeName.c_str()); + DALI_ASSERT_ALWAYS(!"Duplicate type name in Type Registration"); + return uniqueTypeName; // never actually happening due to the assert } + DALI_LOG_INFO(gLogFilter, Debug::Concise, "Type Registration %s(%s)\n", uniqueTypeName.c_str(), baseTypeName.c_str()); - 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 ) + if(callCreateOnInit) { mInitFunctions.push_back(createInstance); } @@ -152,84 +139,68 @@ std::string TypeRegistry::Register(std::string uniqueTypeName void TypeRegistry::Register(std::string uniqueTypeName, const std::type_info& baseTypeInfo, Dali::CSharpTypeInfo::CreateFunction createInstance) { - std::string baseTypeName = DemangleClassName( baseTypeInfo.name() ); + std::string baseTypeName = DemangleClassName(baseTypeInfo.name()); - // check for duplicates using uniqueTypeName - for( auto&& iter : mRegistryLut ) + if(!mRegistryLut.Register(ConstString(uniqueTypeName), TypeRegistry::TypeInfoPointer(new Internal::TypeInfo(uniqueTypeName, baseTypeName, createInstance)))) { - 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" ); - return; // never actually happening due to the assert - } + DALI_LOG_WARNING("Duplicate name in TypeRegistry for '%s'\n", +uniqueTypeName.c_str()); + DALI_ASSERT_ALWAYS(!"Duplicate type name in Type Registration"); + return; // never actually happening due to the assert } - - 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() ); + DALI_LOG_INFO(gLogFilter, Debug::Concise, "Type Registration %s(%s)\n", uniqueTypeName.c_str(), baseTypeName.c_str()); } void TypeRegistry::CallInitFunctions(void) const { - for( auto&& iter : mInitFunctions ) + for(auto&& iter : mInitFunctions) { (*iter)(); } } -std::string TypeRegistry::RegistrationName( const std::type_info& registerType ) +std::string TypeRegistry::RegistrationName(const std::type_info& registerType) { - return DemangleClassName( registerType.name() ); + return DemangleClassName(registerType.name()); } void TypeRegistry::RegisterSignal(TypeRegistration& typeRegistration, std::string name, Dali::TypeInfo::SignalConnectorFunction func) { - for( auto&& iter : mRegistryLut ) + auto iter = mRegistryLut.Get(ConstString(typeRegistration.RegisteredName())); + if(iter != mRegistryLut.end()) { - if( iter->GetName() == typeRegistration.RegisteredName() ) - { - iter->AddConnectorFunction(std::move(name), func); - break; - } + iter->second->AddConnectorFunction(std::move(name), func); } } bool TypeRegistry::RegisterAction(TypeRegistration& typeRegistration, std::string name, Dali::TypeInfo::ActionFunction f) { - for( auto&& iter : mRegistryLut ) + auto iter = mRegistryLut.Get(ConstString(typeRegistration.RegisteredName())); + if(iter != mRegistryLut.end()) { - if( iter->GetName() == typeRegistration.RegisteredName() ) - { - iter->AddActionFunction(std::move(name), f); - return true; - } + iter->second->AddActionFunction(std::move(name), f); + return true; } return false; } bool TypeRegistry::RegisterProperty(TypeRegistration& typeRegistration, std::string name, Property::Index index, Property::Type type, Dali::TypeInfo::SetPropertyFunction setFunc, Dali::TypeInfo::GetPropertyFunction getFunc) { - for( auto&& iter : mRegistryLut ) + auto iter = mRegistryLut.Get(ConstString(typeRegistration.RegisteredName())); + if(iter != mRegistryLut.end()) { - if( iter->GetName() == typeRegistration.RegisteredName() ) - { - iter->AddProperty(std::move(name), index, type, setFunc, getFunc); - return true; - } + iter->second->AddProperty(std::move(name), index, type, setFunc, getFunc); + return true; } - return false; } bool TypeRegistry::RegisterProperty(const std::string& objectName, std::string name, Property::Index index, Property::Type type, Dali::CSharpTypeInfo::SetPropertyFunction setFunc, Dali::CSharpTypeInfo::GetPropertyFunction getFunc) { - for( auto&& iter : mRegistryLut ) + auto iter = mRegistryLut.Get(ConstString(objectName)); + if(iter != mRegistryLut.end()) { - if( iter->GetName() == objectName ) - { - iter->AddProperty(std::move(name), index, type, setFunc, getFunc); - return true; - } + iter->second->AddProperty(std::move(name), index, type, setFunc, getFunc); + return true; } return false; @@ -237,13 +208,11 @@ bool TypeRegistry::RegisterProperty(const std::string& objectName, std::string n bool TypeRegistry::RegisterAnimatableProperty(TypeRegistration& typeRegistration, std::string name, Property::Index index, Property::Type type) { - for( auto&& iter : mRegistryLut ) + auto iter = mRegistryLut.Get(ConstString(typeRegistration.RegisteredName())); + if(iter != mRegistryLut.end()) { - if( iter->GetName() == typeRegistration.RegisteredName() ) - { - iter->AddAnimatableProperty(std::move(name), index, type); - return true; - } + iter->second->AddAnimatableProperty(std::move(name), index, type); + return true; } return false; @@ -251,13 +220,11 @@ bool TypeRegistry::RegisterAnimatableProperty(TypeRegistration& typeRegistration bool TypeRegistry::RegisterAnimatableProperty(TypeRegistration& typeRegistration, std::string name, Property::Index index, Property::Value value) { - for( auto&& iter : mRegistryLut ) + auto iter = mRegistryLut.Get(ConstString(typeRegistration.RegisteredName())); + if(iter != mRegistryLut.end()) { - if( iter->GetName() == typeRegistration.RegisteredName() ) - { - iter->AddAnimatableProperty(std::move(name), index, std::move(value)); - return true; - } + iter->second->AddAnimatableProperty(std::move(name), index, std::move(value)); + return true; } return false; @@ -265,13 +232,11 @@ bool TypeRegistry::RegisterAnimatableProperty(TypeRegistration& typeRegistration bool TypeRegistry::RegisterAnimatablePropertyComponent(TypeRegistration& typeRegistration, std::string name, Property::Index index, Property::Index baseIndex, unsigned int componentIndex) { - for( auto&& iter : mRegistryLut ) + auto iter = mRegistryLut.Get(ConstString(typeRegistration.RegisteredName())); + if(iter != mRegistryLut.end()) { - if( iter->GetName() == typeRegistration.RegisteredName() ) - { - iter->AddAnimatablePropertyComponent(std::move(name), index, baseIndex, componentIndex); - return true; - } + iter->second->AddAnimatablePropertyComponent(std::move(name), index, baseIndex, componentIndex); + return true; } return false; @@ -279,13 +244,11 @@ bool TypeRegistry::RegisterAnimatablePropertyComponent(TypeRegistration& typeReg bool TypeRegistry::RegisterChildProperty(const std::string& registeredType, std::string name, Property::Index index, Property::Type type) { - for( auto&& iter : mRegistryLut ) + auto iter = mRegistryLut.Get(ConstString(registeredType)); + if(iter != mRegistryLut.end()) { - if( iter->GetName() == registeredType ) - { - iter->AddChildProperty(std::move(name), index, type); - return true; - } + iter->second->AddChildProperty(std::move(name), index, type); + return true; } return false; @@ -296,16 +259,16 @@ bool TypeRegistry::RegisterChildProperty(TypeRegistration& typeRegistration, std return RegisterChildProperty(typeRegistration.RegisteredName(), std::move(name), index, type); } -bool TypeRegistry::DoActionTo( BaseObject * const object, const std::string& actionName, const Property::Map& properties ) +bool TypeRegistry::DoActionTo(BaseObject* const object, const std::string& actionName, const Property::Map& properties) { bool done = false; - auto&& type = GetTypeInfo( object ); + auto&& type = GetTypeInfo(object); // DoActionTo recurses through base classes - done = type->DoActionTo( object, actionName, properties ); + done = type->DoActionTo(object, actionName, properties); - if( !done ) + if(!done) { DALI_LOG_WARNING("Type '%s' cannot do action '%s'\n", type->GetName().c_str(), actionName.c_str()); } @@ -313,16 +276,16 @@ bool TypeRegistry::DoActionTo( BaseObject * const object, const std::string& act return done; } -bool TypeRegistry::ConnectSignal( BaseObject* object, ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor ) +bool TypeRegistry::ConnectSignal(BaseObject* object, ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor) { - bool connected( false ); + bool connected(false); - auto&& type = GetTypeInfo( object ); + auto&& type = GetTypeInfo(object); // Connect iterates through base classes - connected = type->ConnectSignal( object, connectionTracker, signalName, functor ); + connected = type->ConnectSignal(object, connectionTracker, signalName, functor); - if( !connected ) + 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 @@ -332,27 +295,27 @@ bool TypeRegistry::ConnectSignal( BaseObject* object, ConnectionTrackerInterface return connected; } -TypeRegistry::TypeInfoPointer TypeRegistry::GetTypeInfo(const Dali::BaseObject * const pBaseObject) +TypeRegistry::TypeInfoPointer TypeRegistry::GetTypeInfo(const Dali::BaseObject* const pBaseObject) { 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(pBaseObject); + const Dali::Internal::CustomActor* const pCustom = dynamic_cast(pBaseObject); - if( pCustom ) + if(pCustom) { const Dali::CustomActorImpl& custom = pCustom->GetImplementation(); - type = GetTypeInfo( typeid( custom ) ); - if( !type ) + type = GetTypeInfo(typeid(custom)); + if(!type) { // the most derived type is a descendant of custom actor but has not registered itself // so we'll just treat it as a custom actor for now so it "inherits" all of actors properties, actions and signals - type = GetTypeInfo( typeid( Dali::Internal::CustomActor ) ); + type = GetTypeInfo(typeid(Dali::Internal::CustomActor)); } } else { - type = GetTypeInfo( typeid( *pBaseObject ) ); + type = GetTypeInfo(typeid(*pBaseObject)); } return type;