X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fevent%2Fcommon%2Ftype-info-impl.cpp;h=479f2e851c0f6998894cbe3e9c44194fbb534ecd;hb=refs%2Fchanges%2F06%2F82306%2F1;hp=91e50cf8ad3f5be3b99a782476a4381b578ad2e8;hpb=f8a75318dd2950c20fb8c6c9a6523fdb0e106030;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/event/common/type-info-impl.cpp b/dali/internal/event/common/type-info-impl.cpp index 91e50cf..479f2e8 100644 --- a/dali/internal/event/common/type-info-impl.cpp +++ b/dali/internal/event/common/type-info-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 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. @@ -74,6 +74,29 @@ private: const std::string& mFind; }; +/** + * Functor to find a matching property component index + */ +template +struct PropertyComponentFinder +{ + PropertyComponentFinder( Dali::Property::Index basePropertyIndex, const int find ) + : mBasePropertyIndex( basePropertyIndex ), + mFind( find ) + { + } + + bool operator()(const T &p) const + { + return ( p.second.basePropertyIndex == mBasePropertyIndex && p.second.componentIndex == mFind ); + } + +private: + + Dali::Property::Index mBasePropertyIndex; + const int mFind; +}; + } // namespace anon namespace Dali @@ -115,7 +138,7 @@ BaseHandle TypeInfo::CreateInstance() const return ret; } -bool TypeInfo::DoActionTo(BaseObject *object, const std::string &actionName, const std::vector &properties) + bool TypeInfo::DoActionTo(BaseObject *object, const std::string &actionName, const Property::Map &properties) { bool done = false; @@ -177,66 +200,96 @@ Dali::TypeInfo::CreateFunction TypeInfo::GetCreator() const return mCreate; } -void TypeInfo::GetActions( Dali::TypeInfo::NameContainer& ret ) const +size_t TypeInfo::GetActionCount() const { - for(ActionContainer::const_iterator iter = mActions.begin(); iter != mActions.end(); ++iter) - { - ret.push_back(iter->first); - } + size_t count = mActions.size(); Dali::TypeInfo base = Dali::TypeRegistry::Get().GetTypeInfo( mBaseTypeName ); while( base ) { - for(ActionContainer::const_iterator iter = GetImplementation(base).mActions.begin(); - iter != GetImplementation(base).mActions.end(); ++iter) - { - ret.push_back(iter->first); - } - + count += GetImplementation(base).mActions.size(); base = Dali::TypeRegistry::Get().GetTypeInfo( base.GetBaseName() ); } + + return count; } -void TypeInfo::GetSignals(Dali::TypeInfo::NameContainer& ret) const +std::string TypeInfo::GetActionName(size_t index) const { - for(ConnectorContainer::const_iterator iter = mSignalConnectors.begin(); iter != mSignalConnectors.end(); ++iter) + std::string name; + + if( index < mActions.size() ) { - ret.push_back(iter->first); + name = mActions[index].first; } - - Dali::TypeInfo base = Dali::TypeRegistry::Get().GetTypeInfo( mBaseTypeName ); - while( base ) + else { - for(ConnectorContainer::const_iterator iter = GetImplementation(base).mSignalConnectors.begin(); - iter != GetImplementation(base).mSignalConnectors.end(); ++iter) + size_t count = mActions.size(); + + Dali::TypeInfo base = Dali::TypeRegistry::Get().GetTypeInfo( mBaseTypeName ); + while( base ) { - ret.push_back(iter->first); - } + size_t baseCount = GetImplementation(base).mActions.size(); - base = Dali::TypeRegistry::Get().GetTypeInfo( base.GetBaseName() ); + if( index < count + baseCount ) + { + name = GetImplementation(base).mActions[ index - count ].first; + break; + } + + count += baseCount; + + base = Dali::TypeRegistry::Get().GetTypeInfo( base.GetBaseName() ); + } } + + return name; } -void TypeInfo::GetProperties( Dali::TypeInfo::NameContainer& ret ) const +size_t TypeInfo::GetSignalCount() const { - Property::IndexContainer indices; + size_t count = mSignalConnectors.size(); + + Dali::TypeInfo base = Dali::TypeRegistry::Get().GetTypeInfo( mBaseTypeName ); + while( base ) + { + count += GetImplementation(base).mSignalConnectors.size(); + base = Dali::TypeRegistry::Get().GetTypeInfo( base.GetBaseName() ); + } - GetPropertyIndices(indices); + return count; +} - ret.reserve(indices.size()); +std::string TypeInfo::GetSignalName(size_t index) const +{ + std::string name; - for(Property::IndexContainer::iterator iter = indices.begin(); iter != indices.end(); ++iter) + if( index < mSignalConnectors.size() ) { - const std::string& name = GetPropertyName( *iter ); - if(name.size()) - { - ret.push_back( name ); - } - else + name = mSignalConnectors[index].first; + } + else + { + size_t count = mSignalConnectors.size(); + + Dali::TypeInfo base = Dali::TypeRegistry::Get().GetTypeInfo( mBaseTypeName ); + while( base ) { - DALI_LOG_WARNING("Property had no name\n"); + size_t baseCount = GetImplementation(base).mSignalConnectors.size(); + + if( index < count + baseCount ) + { + name = GetImplementation(base).mSignalConnectors[ index - count ].first; + break; + } + + count += baseCount; + + base = Dali::TypeRegistry::Get().GetTypeInfo( base.GetBaseName() ); } } + + return name; } void TypeInfo::GetPropertyIndices( Property::IndexContainer& indices ) const @@ -250,12 +303,12 @@ void TypeInfo::GetPropertyIndices( Property::IndexContainer& indices ) const if ( ! mRegisteredProperties.empty() ) { - indices.reserve( indices.size() + mRegisteredProperties.size() ); + indices.Reserve( indices.Size() + mRegisteredProperties.size() ); const RegisteredPropertyContainer::const_iterator endIter = mRegisteredProperties.end(); for ( RegisteredPropertyContainer::const_iterator iter = mRegisteredProperties.begin(); iter != endIter; ++iter ) { - indices.push_back( iter->first ); + indices.PushBack( iter->first ); } } } @@ -296,7 +349,7 @@ void TypeInfo::AddActionFunction( const std::string &actionName, Dali::TypeInfo: } else { - DALI_LOG_WARNING("Action already exists in TypeRegistry Type", actionName.c_str()); + DALI_LOG_WARNING("Action already exists in TypeRegistry Type\n", actionName.c_str()); } } } @@ -318,7 +371,7 @@ void TypeInfo::AddConnectorFunction( const std::string& signalName, Dali::TypeIn } else { - DALI_LOG_WARNING("Signal name already exists in TypeRegistry Type for signal connector function", signalName.c_str()); + DALI_LOG_WARNING("Signal name already exists in TypeRegistry Type for signal connector function\n", signalName.c_str()); } } } @@ -338,7 +391,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 ) ) ); + mRegisteredProperties.push_back( RegisteredPropertyPair( index, RegisteredProperty( type, setFunc, getFunc, name, Property::INVALID_INDEX, Property::INVALID_COMPONENT_INDEX ) ) ); } else { @@ -347,9 +400,80 @@ void TypeInfo::AddProperty( const std::string& name, Property::Index index, Prop } } -unsigned int TypeInfo::GetPropertyCount() const +void TypeInfo::AddAnimatableProperty( const std::string& name, Property::Index index, Property::Type type ) { - unsigned int count( mRegisteredProperties.size() ); + 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, NULL, NULL, name, Property::INVALID_INDEX, Property::INVALID_COMPONENT_INDEX ) ) ); + } + else + { + DALI_ASSERT_ALWAYS( ! "Property index already added to Type" ); + } +} + +void TypeInfo::AddAnimatableProperty( const std::string& name, Property::Index index, const 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(), NULL, NULL, name, Property::INVALID_INDEX, Property::INVALID_COMPONENT_INDEX ) ) ); + mPropertyDefaultValues.push_back( PropertyDefaultValuePair( index, defaultValue ) ); + } + else + { + DALI_ASSERT_ALWAYS( ! "Property index already added to Type" ); + } +} + +void TypeInfo::AddAnimatablePropertyComponent( const std::string& name, Property::Index index, Property::Index baseIndex, unsigned int componentIndex ) +{ + Property::Type type = GetPropertyType( baseIndex ); + DALI_ASSERT_ALWAYS( ( type == Property::VECTOR2 || type == Property::VECTOR3 || type == Property::VECTOR4 ) && "Base property does not support component" ); + + bool success = false; + + RegisteredPropertyContainer::iterator iter = find_if( mRegisteredProperties.begin(), mRegisteredProperties.end(), + PairFinder< Property::Index, RegisteredPropertyPair>(index) ); + + if ( iter == mRegisteredProperties.end() ) + { + iter = find_if( mRegisteredProperties.begin(), mRegisteredProperties.end(), + PropertyComponentFinder< RegisteredPropertyPair >( baseIndex, componentIndex ) ); + + if ( iter == mRegisteredProperties.end() ) + { + mRegisteredProperties.push_back( RegisteredPropertyPair( index, RegisteredProperty( type, NULL, NULL, name, baseIndex, componentIndex ) ) ); + success = true; + } + } + + DALI_ASSERT_ALWAYS( success && "Property component already registered" ); +} + +void TypeInfo::AddChildProperty( const 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, NULL, NULL, name, Property::INVALID_INDEX, Property::INVALID_COMPONENT_INDEX ) ) ); + } + else + { + DALI_ASSERT_ALWAYS( ! "Property index already added to Type" ); + } +} + +size_t TypeInfo::GetPropertyCount() const +{ + size_t count( mRegisteredProperties.size() ); Dali::TypeInfo base = TypeRegistry::Get()->GetTypeInfo( mBaseTypeName ); while ( base ) @@ -386,6 +510,122 @@ Property::Index TypeInfo::GetPropertyIndex( const std::string& name ) const return index; } +Property::Index TypeInfo::GetBasePropertyIndex( Property::Index index ) const +{ + Property::Index basePropertyIndex = Property::INVALID_INDEX; + + RegisteredPropertyContainer::const_iterator iter = find_if( mRegisteredProperties.begin(), mRegisteredProperties.end(), + PairFinder< Property::Index, RegisteredPropertyPair >( index ) ); + + if ( iter != mRegisteredProperties.end() ) + { + basePropertyIndex = iter->second.basePropertyIndex; + } + else + { + Dali::TypeInfo base = TypeRegistry::Get()->GetTypeInfo( mBaseTypeName ); + if ( base ) + { + basePropertyIndex = GetImplementation(base).GetBasePropertyIndex( index ); + } + } + + return basePropertyIndex; +} + +int TypeInfo::GetComponentIndex( Property::Index index ) const +{ + int componentIndex = Property::INVALID_COMPONENT_INDEX; + + RegisteredPropertyContainer::const_iterator iter = find_if( mRegisteredProperties.begin(), mRegisteredProperties.end(), + PairFinder< Property::Index, RegisteredPropertyPair >( index ) ); + + if ( iter != mRegisteredProperties.end() ) + { + componentIndex = iter->second.componentIndex; + } + else + { + Dali::TypeInfo base = TypeRegistry::Get()->GetTypeInfo( mBaseTypeName ); + if ( base ) + { + componentIndex = GetImplementation(base).GetComponentIndex( index ); + } + } + + return componentIndex; +} + +Property::Index TypeInfo::GetChildPropertyIndex( const std::string& name ) const +{ + Property::Index index = Property::INVALID_INDEX; + + // Slow but should not be done that often + RegisteredPropertyContainer::const_iterator iter = find_if( mRegisteredChildProperties.begin(), mRegisteredChildProperties.end(), + PropertyNameFinder< RegisteredPropertyPair >( name ) ); + + if ( iter != mRegisteredChildProperties.end() ) + { + index = iter->first; + } + else + { + Dali::TypeInfo base = TypeRegistry::Get()->GetTypeInfo( mBaseTypeName ); + if ( base ) + { + index = GetImplementation(base).GetChildPropertyIndex( name ); + } + } + + return index; +} + +const std::string& 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; + } + + Dali::TypeInfo base = TypeRegistry::Get()->GetTypeInfo( mBaseTypeName ); + if ( base ) + { + return GetImplementation(base).GetChildPropertyName( index ); + } + + DALI_ASSERT_ALWAYS( ! "Cannot find property index" ); // use the same assert as Object +} + +Property::Type TypeInfo::GetChildPropertyType( Property::Index index ) const +{ + Property::Type type( Property::NONE ); + + RegisteredPropertyContainer::const_iterator iter = find_if( mRegisteredChildProperties.begin(), mRegisteredChildProperties.end(), + PairFinder< Property::Index, RegisteredPropertyPair >( index ) ); + + if ( iter != mRegisteredChildProperties.end() ) + { + type = iter->second.type; + } + else + { + Dali::TypeInfo base = TypeRegistry::Get()->GetTypeInfo( mBaseTypeName ); + if ( base ) + { + type = GetImplementation(base).GetChildPropertyType( index ); + } + else + { + DALI_ASSERT_ALWAYS( ! "Cannot find property index" ); // use the same assert as Object + } + } + + return type; +} + bool TypeInfo::IsPropertyWritable( Property::Index index ) const { bool writable( false ); @@ -395,7 +635,14 @@ bool TypeInfo::IsPropertyWritable( Property::Index index ) const if ( iter != mRegisteredProperties.end() ) { - writable = iter->second.setFunc ? true : false; + if( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) ) + { + writable = true; // animatable property is writable + } + else + { + writable = iter->second.setFunc ? true : false; + } } else { @@ -440,6 +687,20 @@ Property::Type TypeInfo::GetPropertyType( Property::Index index ) const return type; } +Property::Value TypeInfo::GetPropertyDefaultValue( Property::Index index ) const +{ + PropertyDefaultValueContainer::const_iterator iter = find_if( mPropertyDefaultValues.begin(), mPropertyDefaultValues.end(), + PairFinder< Property::Index, PropertyDefaultValuePair >( index ) ); + if( iter != mPropertyDefaultValues.end() ) + { + return iter->second; + } + else + { + return Property::Value( GetPropertyType( index ) ); + } +} + void TypeInfo::SetProperty( BaseObject *object, Property::Index index, const Property::Value& value ) const { RegisteredPropertyContainer::const_iterator iter = find_if( mRegisteredProperties.begin(), mRegisteredProperties.end(),