From 75cd170d0e46bbb1294f19bd8a247f5c73b18c61 Mon Sep 17 00:00:00 2001 From: Subhransu Mohanty Date: Thu, 3 Dec 2020 10:55:33 +0900 Subject: [PATCH] refactor Object,TypeInfo and PropertyMetaData to use ConstString Change-Id: I03e7021895d3089cb1427683accdff426b40286f --- .../dali-test-suite-utils/dali-test-suite-utils.h | 32 +++++++++++ automated-tests/src/dali/utc-Dali-TypeRegistry.cpp | 3 +- dali/internal/event/common/object-impl.cpp | 61 ++++++++++----------- dali/internal/event/common/object-impl.h | 63 ++++++++++++++++------ dali/internal/event/common/property-metadata.h | 36 ++++++------- dali/internal/event/common/type-info-impl.cpp | 60 ++++++++++----------- dali/internal/event/common/type-info-impl.h | 31 +++++------ dali/public-api/object/handle.cpp | 14 ++--- dali/public-api/object/handle.h | 10 ++-- dali/public-api/object/type-info.cpp | 6 +-- dali/public-api/object/type-info.h | 4 +- 11 files changed, 190 insertions(+), 130 deletions(-) diff --git a/automated-tests/src/dali/dali-test-suite-utils/dali-test-suite-utils.h b/automated-tests/src/dali/dali-test-suite-utils/dali-test-suite-utils.h index b8de978..a4b45c9 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/dali-test-suite-utils.h +++ b/automated-tests/src/dali/dali-test-suite-utils/dali-test-suite-utils.h @@ -306,6 +306,38 @@ void DALI_TEST_EQUALS(const std::string& str1, const char* str2, const char* loc void DALI_TEST_EQUALS(const char* str1, const std::string& str2, const char* location); /** + * Test whether two strings are equal. + * @param[in] str1 The first string + * @param[in] str2 The second string + * @param[in] location The TEST_LOCATION macro should be used here + */ +template<> +inline void DALI_TEST_EQUALS(std::string_view str1, std::string_view str2, const char* location) +{ + DALI_TEST_EQUALS(str1.data(), str2.data(), location); +} + +inline void DALI_TEST_EQUALS(std::string_view str1, const char* str2, const char* location) +{ + DALI_TEST_EQUALS(str1.data(), str2, location); +} + +inline void DALI_TEST_EQUALS(std::string_view str1, const std::string& str2, const char* location) +{ + DALI_TEST_EQUALS(str1.data(), str2.c_str(), location); +} + +inline void DALI_TEST_EQUALS(const std::string& str2, std::string_view str1, const char* location) +{ + DALI_TEST_EQUALS(str2.c_str(), str1.data(), location); +} + +inline void DALI_TEST_EQUALS(const char* str1, std::string_view str2, const char* location) +{ + DALI_TEST_EQUALS(str1, str2.data(), location); +} + +/** * Test if a property value type is equal to a trivial type. */ template diff --git a/automated-tests/src/dali/utc-Dali-TypeRegistry.cpp b/automated-tests/src/dali/utc-Dali-TypeRegistry.cpp index fd7f134..db133de 100644 --- a/automated-tests/src/dali/utc-Dali-TypeRegistry.cpp +++ b/automated-tests/src/dali/utc-Dali-TypeRegistry.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -1691,7 +1692,7 @@ int UtcDaliTypeRegistryChildPropertyRegistrationP(void) // check the child property type Internal::TypeInfo& typeInfoImpl = GetImplementation(typeInfo); - Property::Type type = typeInfoImpl.GetChildPropertyType(typeInfoImpl.GetChildPropertyIndex("childProp4")); + Property::Type type = typeInfoImpl.GetChildPropertyType(typeInfoImpl.GetChildPropertyIndex(Dali::Internal::ConstString("childProp4"))); DALI_TEST_EQUALS(type, Property::INTEGER, TEST_LOCATION); std::string unRegisteredChildName(typeInfoImpl.GetChildPropertyName(CHILD_PROPERTY_REGISTRATION_START_INDEX + 4)); diff --git a/dali/internal/event/common/object-impl.cpp b/dali/internal/event/common/object-impl.cpp index 5e16c11..6e71fec 100644 --- a/dali/internal/event/common/object-impl.cpp +++ b/dali/internal/event/common/object-impl.cpp @@ -111,7 +111,7 @@ uint32_t Object::GetPropertyCount() const return count; } -std::string Object::GetPropertyName( Property::Index index ) const +std::string_view Object::GetPropertyName(Property::Index index) const { DALI_ASSERT_ALWAYS( index > Property::INVALID_INDEX && "Property index out of bounds" ); @@ -129,24 +129,24 @@ std::string Object::GetPropertyName( Property::Index index ) const CustomPropertyMetadata* custom = FindCustomProperty( index ); if( custom ) { - return custom->name; + return custom->name.GetStringView(); } } DALI_LOG_ERROR( "Property index %d not found\n", index ); - return std::string(); + return {}; } -Property::Index Object::GetPropertyIndex( Property::Key key ) const +Property::Index Object::GetPropertyIndex(KeyRef key) const { Property::Index index = Property::INVALID_INDEX; - if( key.type == Property::Key::STRING ) + if(key.mType == Property::Key::STRING) { const TypeInfo* typeInfo( GetTypeInfo() ); if ( typeInfo ) { - index = typeInfo->GetPropertyIndex( key.stringKey ); + index = typeInfo->GetPropertyIndex(key.mString); } } @@ -158,8 +158,8 @@ Property::Index Object::GetPropertyIndex( Property::Key key ) const { CustomPropertyMetadata* custom = static_cast(*iter); - if( ( key.type == Property::Key::STRING && custom->name == key.stringKey) || - ( key.type == Property::Key::INDEX && custom->key == key.indexKey ) ) + if((key.mType == Property::Key::STRING && custom->name == key.mString) || + (key.mType == Property::Key::INDEX && custom->key == key.mIndex)) { if ( custom->childPropertyIndex != Property::INVALID_INDEX ) { @@ -335,7 +335,7 @@ void Object::SetProperty(Property::Index index, Property::Value propertyValue) if( !custom ) { // If the child property is not registered yet, register it. - custom = new CustomPropertyMetadata( "", propertyValue, Property::READ_WRITE ); + custom = new CustomPropertyMetadata({}, propertyValue, Property::READ_WRITE); mCustomProperties.PushBack( custom ); } @@ -348,7 +348,7 @@ void Object::SetProperty(Property::Index index, Property::Value propertyValue) const TypeInfo* parentTypeInfo( parent->GetTypeInfo() ); if( parentTypeInfo ) { - custom->name = parentTypeInfo->GetChildPropertyName( index ); + custom->name = ConstString(parentTypeInfo->GetChildPropertyName(index)); } } } @@ -537,14 +537,14 @@ void Object::GetPropertyIndices( Property::IndexContainer& indices ) const } } -Property::Index Object::RegisterProperty(std::string name, Property::Value propertyValue) +Property::Index Object::RegisterProperty(std::string_view name, Property::Value propertyValue) { - return RegisterProperty(std::move(name), Property::INVALID_KEY, std::move(propertyValue), Property::ANIMATABLE); + return RegisterProperty(name, Property::INVALID_KEY, std::move(propertyValue), Property::ANIMATABLE); } -Property::Index Object::RegisterProperty(std::string name, Property::Index key, Property::Value propertyValue) +Property::Index Object::RegisterProperty(std::string_view name, Property::Index key, Property::Value propertyValue) { - return RegisterProperty(std::move(name), key, std::move(propertyValue), Property::ANIMATABLE); + return RegisterProperty(name, key, std::move(propertyValue), Property::ANIMATABLE); } void Object::SetProperties( const Property::Map& properties ) @@ -579,18 +579,19 @@ void Object::GetProperties( Property::Map& properties ) } } -Property::Index Object::RegisterProperty(std::string name, +Property::Index Object::RegisterProperty(std::string_view name, Property::Value propertyValue, Property::AccessMode accessMode) { - return RegisterProperty(std::move(name), Property::INVALID_KEY, std::move(propertyValue), accessMode); + return RegisterProperty(name, Property::INVALID_KEY, std::move(propertyValue), accessMode); } -Property::Index Object::RegisterProperty(std::string name, +Property::Index Object::RegisterProperty(std::string_view name, Property::Index key, Property::Value propertyValue, Property::AccessMode accessMode) { + auto constString = ConstString(name); // If property with the required key already exists, then just set it. Property::Index index = Property::INVALID_INDEX; if( key != Property::INVALID_KEY ) // Try integer key first if it's valid @@ -599,7 +600,7 @@ Property::Index Object::RegisterProperty(std::string name, } if( index == Property::INVALID_INDEX ) // If it wasn't valid, or doesn't exist, try name { - index = GetPropertyIndex( name ); + index = GetPropertyIndex(constString); } if( index != Property::INVALID_INDEX ) // If there was a valid index found by either key, set it. @@ -612,11 +613,11 @@ Property::Index Object::RegisterProperty(std::string name, if( Property::ANIMATABLE == accessMode ) { index = RegisterSceneGraphProperty( - name, + constString, key, PROPERTY_CUSTOM_START_INDEX + static_cast(mCustomProperties.Count()), std::move(propertyValue)); - AddUniformMapping(index, std::move(name)); + AddUniformMapping(index, constString); } else { @@ -624,7 +625,7 @@ Property::Index Object::RegisterProperty(std::string name, index = PROPERTY_CUSTOM_START_INDEX + static_cast( mCustomProperties.Count() ); CustomPropertyMetadata* customProperty = - new CustomPropertyMetadata(std::move(name), std::move(propertyValue), accessMode); + new CustomPropertyMetadata(constString, std::move(propertyValue), accessMode); // Resolve index for the child property Object* parent = GetParentObject(); @@ -633,7 +634,7 @@ Property::Index Object::RegisterProperty(std::string name, const TypeInfo* parentTypeInfo( parent->GetTypeInfo() ); if( parentTypeInfo ) { - Property::Index childPropertyIndex = parentTypeInfo->GetChildPropertyIndex( customProperty->name ); + Property::Index childPropertyIndex = parentTypeInfo->GetChildPropertyIndex(customProperty->name); if( childPropertyIndex != Property::INVALID_INDEX ) { customProperty->childPropertyIndex = childPropertyIndex; @@ -775,7 +776,7 @@ void Object::NotifyPropertyAnimation( Animation& animation, Property::Index inde } } -void Object::AddUniformMapping(Property::Index propertyIndex, std::string uniformName) const +void Object::AddUniformMapping(Property::Index propertyIndex, ConstString uniformName) const { // Get the address of the property if it's a scene property const PropertyInputImpl* propertyPtr = GetSceneObjectInputProperty( propertyIndex ); @@ -803,7 +804,7 @@ void Object::AddUniformMapping(Property::Index propertyIndex, std::string unifor { const SceneGraph::PropertyOwner& sceneObject = GetSceneObject(); - SceneGraph::UniformPropertyMapping map(ConstString(uniformName), propertyPtr); + SceneGraph::UniformPropertyMapping map(uniformName, propertyPtr); // Message takes ownership of Uniform map (and will delete it after copy) AddUniformMapMessage( const_cast(GetEventThreadServices()), sceneObject, map ); } @@ -1066,7 +1067,7 @@ AnimatablePropertyMetadata* Object::FindAnimatableProperty( Property::Index inde return nullptr; } -Property::Index Object::RegisterSceneGraphProperty( std::string name, Property::Index key, Property::Index index, Property::Value propertyValue ) const +Property::Index Object::RegisterSceneGraphProperty(ConstString name, Property::Index key, Property::Index index, Property::Value propertyValue) const { // Create a new property Dali::Internal::OwnerPointer newProperty; @@ -1147,7 +1148,7 @@ Property::Index Object::RegisterSceneGraphProperty( std::string name, Property:: { DALI_ASSERT_ALWAYS( index <= PROPERTY_CUSTOM_MAX_INDEX && "Too many custom properties have been registered" ); - mCustomProperties.PushBack( new CustomPropertyMetadata( std::move(name), key, std::move(propertyValue), property ) ); + mCustomProperties.PushBack(new CustomPropertyMetadata(name, key, std::move(propertyValue), property)); } else { @@ -1165,7 +1166,7 @@ void Object::RegisterAnimatableProperty( const TypeInfo& typeInfo, const Property::Value* value ) const { // If the property is not a component of a base property, register the whole property itself. - const std::string& propertyName = typeInfo.GetPropertyName( index ); + auto propertyName = ConstString(typeInfo.GetPropertyName(index)); Property::Value initialValue; if( value ) { @@ -1236,17 +1237,17 @@ void Object::ResolveChildProperties() { CustomPropertyMetadata* customProperty = static_cast( entry ); - if( customProperty->name.empty() ) + if(customProperty->name.IsEmpty()) { if( customProperty->childPropertyIndex != Property::INVALID_INDEX ) { // Resolve name for any child property with no name - customProperty->name = parentTypeInfo->GetChildPropertyName( customProperty->childPropertyIndex ); + customProperty->name = ConstString(parentTypeInfo->GetChildPropertyName(customProperty->childPropertyIndex)); } } else { - Property::Index childPropertyIndex = parentTypeInfo->GetChildPropertyIndex( customProperty->name ); + Property::Index childPropertyIndex = parentTypeInfo->GetChildPropertyIndex(customProperty->name); if( childPropertyIndex != Property::INVALID_INDEX ) { // Resolve index for any property with a name that matches the parent's child property name diff --git a/dali/internal/event/common/object-impl.h b/dali/internal/event/common/object-impl.h index fffe3ee..3a65844 100644 --- a/dali/internal/event/common/object-impl.h +++ b/dali/internal/event/common/object-impl.h @@ -22,23 +22,24 @@ #include // uint32_t // INTERNAL INCLUDES +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include #include #include -#include #include #include #include #include -#include -#include -#include -#include -#include -#include -#include +#include namespace Dali { @@ -64,6 +65,36 @@ using ConstraintContainer = std::vector< Dali::Constraint >; using ConstraintIter = ConstraintContainer::iterator; using ConstraintConstIter = ConstraintContainer::const_iterator; +class KeyRef +{ +public: + KeyRef(const Property::Key& key) + : mType(key.type) + { + if(mType == Property::Key::STRING) + { + mString = ConstString(key.stringKey); + } + else + { + mIndex = key.indexKey; + } + } + KeyRef(ConstString str) + : mType(Property::Key::STRING) + { + mString = str; + } + KeyRef(Property::Index index) + : mType(Property::Key::INDEX) + { + mIndex = index; + } + Property::Key::Type mType; + Property::Index mIndex{Property::INVALID_INDEX}; + ConstString mString; +}; + /** * A base class for objects which optionally provide properties. * The concrete derived class is responsible for implementing the property system methods. @@ -145,12 +176,12 @@ public: /** * @copydoc Dali::Handle::GetPropertyName() */ - std::string GetPropertyName( Property::Index index ) const; + std::string_view GetPropertyName(Property::Index index) const; /** * @copydoc Dali::Handle::GetPropertyIndex() */ - Property::Index GetPropertyIndex( Property::Key key ) const; + Property::Index GetPropertyIndex(KeyRef key) const; /** * @copydoc Dali::Handle::IsPropertyWritable() @@ -197,12 +228,12 @@ public: /** * @copydoc Dali::Handle::RegisterProperty() */ - Property::Index RegisterProperty(std::string name, Property::Value propertyValue); + Property::Index RegisterProperty(std::string_view name, Property::Value propertyValue); /** * @copydoc Dali::Handle::RegisterProperty() */ - Property::Index RegisterProperty(std::string name, Property::Index key, Property::Value propertyValue); + Property::Index RegisterProperty(std::string_view name, Property::Index key, Property::Value propertyValue); /** * @copydoc Dali::DevelHandle::SetProperties() @@ -217,12 +248,12 @@ public: /** * @copydoc Dali::Handle::RegisterProperty(std::string name, Property::Value propertyValue, Property::AccessMode accessMode) */ - Property::Index RegisterProperty(std::string name, Property::Value propertyValue, Property::AccessMode accessMode); + Property::Index RegisterProperty(std::string_view name, Property::Value propertyValue, Property::AccessMode accessMode); /** * @brief Implementing method for this override */ - Property::Index RegisterProperty(std::string name, + Property::Index RegisterProperty(std::string_view name, Property::Index key, Property::Value propertyValue, Property::AccessMode accessMode); @@ -273,7 +304,7 @@ public: * @param propertyIndex index of the property * @param uniformName name of the uniform (same as property name) */ - void AddUniformMapping(Property::Index propertyIndex, std::string uniformName) const; + void AddUniformMapping(Property::Index propertyIndex, ConstString uniformName) const; /** * Removes uniform mapping for given property @@ -435,7 +466,7 @@ protected: * @param [in] value The value of the property. * @return The index of the registered property or Property::INVALID_INDEX if registration failed. */ - Property::Index RegisterSceneGraphProperty( std::string name, Property::Index key, Property::Index index, Property::Value propertyValue ) const; + Property::Index RegisterSceneGraphProperty(ConstString name, Property::Index key, Property::Index index, Property::Value propertyValue) const; /** * Registers animatable scene property diff --git a/dali/internal/event/common/property-metadata.h b/dali/internal/event/common/property-metadata.h index 3dbf675..b6a7ed1 100644 --- a/dali/internal/event/common/property-metadata.h +++ b/dali/internal/event/common/property-metadata.h @@ -23,9 +23,10 @@ #include // INTERNAL INCLUDES +#include #include -#include #include +#include namespace Dali { @@ -258,14 +259,14 @@ public: * * @note A valid sceneGraphProperty is mandatory otherwise this will debug assert. */ - CustomPropertyMetadata( std::string propertyName, - Property::Index propertyKey, - Property::Value propertyValue, - const SceneGraph::PropertyBase* sceneGraphProperty ) - : PropertyMetadata( std::move(propertyValue), sceneGraphProperty, true ), - name( std::move(propertyName) ), - key( propertyKey ), - childPropertyIndex( Property::INVALID_INDEX ) + CustomPropertyMetadata(ConstString propertyName, + Property::Index propertyKey, + Property::Value propertyValue, + const SceneGraph::PropertyBase* sceneGraphProperty) + : PropertyMetadata(std::move(propertyValue), sceneGraphProperty, true), + name(propertyName), + key(propertyKey), + childPropertyIndex(Property::INVALID_INDEX) { DALI_ASSERT_DEBUG( sceneGraphProperty && "Uninitialized scene-graph property" ); } @@ -278,13 +279,13 @@ public: * * @note The access mode MUST NOT be animatable otherwise this will debug assert. */ - CustomPropertyMetadata( std::string propertyName, - Property::Value propertyValue, - Property::AccessMode accessMode ) - : PropertyMetadata( std::move(propertyValue), nullptr, ( accessMode != Property::READ_ONLY ) ), - name( std::move(propertyName) ), - key( Property::INVALID_KEY ), - childPropertyIndex( Property::INVALID_INDEX ) + CustomPropertyMetadata(ConstString propertyName, + Property::Value propertyValue, + Property::AccessMode accessMode) + : PropertyMetadata(std::move(propertyValue), nullptr, (accessMode != Property::READ_ONLY)), + name(propertyName), + key(Property::INVALID_KEY), + childPropertyIndex(Property::INVALID_INDEX) { DALI_ASSERT_DEBUG( accessMode != Property::ANIMATABLE && "Event side only properties should not be animatable" ); } @@ -302,8 +303,7 @@ private: CustomPropertyMetadata& operator=( const CustomPropertyMetadata& ); public: // Data - - std::string name; ///< The name of the property. + ConstString name; ///< The name of the property. Property::Index key; ///< The key of the property. Property::Index childPropertyIndex; ///< The index as a child property. }; diff --git a/dali/internal/event/common/type-info-impl.cpp b/dali/internal/event/common/type-info-impl.cpp index 7230c36..7f52423 100644 --- a/dali/internal/event/common/type-info-impl.cpp +++ b/dali/internal/event/common/type-info-impl.cpp @@ -65,8 +65,8 @@ private: template 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; }; /** @@ -388,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 ) ) { @@ -405,9 +404,9 @@ 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 ) ) { @@ -423,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 @@ -498,7 +497,7 @@ void TypeInfo::AddProperty(std::string name, Property::Index index, Property::Ty if ( iter == mRegisteredProperties.end() ) { - mRegisteredProperties.push_back(RegisteredPropertyPair(index, RegisteredProperty(type, setFunc, getFunc, std::move(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 { @@ -523,7 +522,7 @@ void TypeInfo::AddProperty(std::string name, Property::Index index, Property::Ty if ( iter == mRegisteredProperties.end() ) { - mRegisteredProperties.push_back(RegisteredPropertyPair(index, RegisteredProperty(type, setFunc, getFunc, std::move(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 { @@ -540,7 +539,7 @@ void TypeInfo::AddAnimatableProperty(std::string name, Property::Index index, Pr if ( iter == mRegisteredProperties.end() ) { - mRegisteredProperties.push_back(RegisteredPropertyPair(index, RegisteredProperty(type, std::move(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 { @@ -555,7 +554,7 @@ void TypeInfo::AddAnimatableProperty(std::string name, Property::Index index, Pr if ( iter == mRegisteredProperties.end() ) { - mRegisteredProperties.push_back(RegisteredPropertyPair(index, RegisteredProperty(defaultValue.GetType(), std::move(name), Property::INVALID_INDEX, Property::INVALID_COMPONENT_INDEX))); + 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 @@ -581,7 +580,7 @@ void TypeInfo::AddAnimatablePropertyComponent(std::string name, Property::Index if ( iter == mRegisteredProperties.end() ) { - mRegisteredProperties.push_back(RegisteredPropertyPair(index, RegisteredProperty(type, std::move(name), baseIndex, componentIndex))); + mRegisteredProperties.push_back(RegisteredPropertyPair(index, RegisteredProperty(type, ConstString(name), baseIndex, componentIndex))); success = true; } } @@ -596,7 +595,7 @@ void TypeInfo::AddChildProperty(std::string name, Property::Index index, Propert if ( iter == mRegisteredChildProperties.end() ) { - mRegisteredChildProperties.push_back(RegisteredPropertyPair(index, RegisteredProperty(type, std::move(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 { @@ -617,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; @@ -625,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(mDefaultProperties[tableIndex].name == name) + if(mDefaultProperties[tableIndex].name == stringView) { index = mDefaultProperties[ tableIndex ].enumIndex; found = true; @@ -694,7 +694,7 @@ int32_t 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; @@ -715,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 ) ) @@ -733,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 @@ -958,9 +957,9 @@ void TypeInfo::SetProperty(BaseObject* object, Property::Index index, Property:: 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(&value)); } else { @@ -981,8 +980,7 @@ void TypeInfo::SetProperty(BaseObject* object, Property::Index index, Property:: 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(ConstString(name))); if ( iter != mRegisteredProperties.end() ) { DALI_ASSERT_ALWAYS( iter->second.setFunc && "Trying to write to a read-only property" ); @@ -1019,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(object), name.GetCString())); } else { @@ -1043,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(ConstString(name))); if( iter != mRegisteredProperties.end() ) { diff --git a/dali/internal/event/common/type-info-impl.h b/dali/internal/event/common/type-info-impl.h index 8ea06a4..616fe8d 100644 --- a/dali/internal/event/common/type-info-impl.h +++ b/dali/internal/event/common/type-info-impl.h @@ -22,12 +22,13 @@ #include // INTERNAL INCLUDES +#include +#include +#include #include #include -#include #include -#include -#include +#include namespace Dali { @@ -125,7 +126,7 @@ public: * @copydoc Dali::TypeInfo::GetPropertyName() const * this API exists to keep the old public API, which cannot be changed */ - const std::string& GetRegisteredPropertyName( Property::Index index ) const; + std::string_view GetRegisteredPropertyName(Property::Index index) const; /** * Returns the property name for given index @@ -133,7 +134,7 @@ public: * @param index of the property * @return name or empty string */ - std::string GetPropertyName( Property::Index index ) const; + std::string_view GetPropertyName(Property::Index index) const; /* * Add an action function @@ -226,7 +227,7 @@ public: * @param[in] name The name of the property. * @return The index associated with that name. */ - Property::Index GetPropertyIndex( const std::string& name ) const; + Property::Index GetPropertyIndex(ConstString name) const; /** * Given a property index, retrieve the index of its base property. @@ -272,14 +273,14 @@ public: * @param[in] name The name of the child property. * @return The index associated with that name. */ - Property::Index GetChildPropertyIndex( const std::string& name ) const; + Property::Index GetChildPropertyIndex(ConstString name) const; /** * Retrieve the name of the child property at the given index. * @param[in] index The property index. * @return The name of the child property. */ - const std::string& GetChildPropertyName( Property::Index index ) const; + std::string_view GetChildPropertyName(Property::Index index) const; /** * Retrieve the Property::Type of the child property at the given index. @@ -337,31 +338,31 @@ private: struct RegisteredProperty { - RegisteredProperty(Property::Type propType, std::string propName, Property::Index basePropertyIndex, int32_t componentIndex) + RegisteredProperty(Property::Type propType, ConstString propName, Property::Index basePropertyIndex, int32_t componentIndex) : type(propType), setFunc(nullptr), getFunc(nullptr), - name(std::move(propName)), + name(propName), basePropertyIndex(basePropertyIndex), componentIndex(componentIndex) { } - RegisteredProperty(Property::Type propType, Dali::TypeInfo::SetPropertyFunction set, Dali::TypeInfo::GetPropertyFunction get, std::string propName, Property::Index basePropertyIndex, int componentIndex) + RegisteredProperty(Property::Type propType, Dali::TypeInfo::SetPropertyFunction set, Dali::TypeInfo::GetPropertyFunction get, ConstString propName, Property::Index basePropertyIndex, int componentIndex) : type(propType), setFunc(set), getFunc(get), - name(std::move(propName)), + name(propName), basePropertyIndex(basePropertyIndex), componentIndex(componentIndex) { } - RegisteredProperty(Property::Type propType, Dali::CSharpTypeInfo::SetPropertyFunction set, Dali::CSharpTypeInfo::GetPropertyFunction get, std::string propName, Property::Index basePropertyIndex, int componentIndex) + RegisteredProperty(Property::Type propType, Dali::CSharpTypeInfo::SetPropertyFunction set, Dali::CSharpTypeInfo::GetPropertyFunction get, ConstString propName, Property::Index basePropertyIndex, int componentIndex) : type(propType), cSharpSetFunc(set), cSharpGetFunc(get), - name(std::move(propName)), + name(propName), basePropertyIndex(basePropertyIndex), componentIndex(componentIndex) { @@ -378,7 +379,7 @@ private: Dali::TypeInfo::GetPropertyFunction getFunc = nullptr; Dali::CSharpTypeInfo::GetPropertyFunction cSharpGetFunc; // only one field can be initialized but this will have same value anyways }; - std::string name; + ConstString name; Property::Index basePropertyIndex = Property::INVALID_INDEX; int32_t componentIndex = Property::INVALID_COMPONENT_INDEX; }; diff --git a/dali/public-api/object/handle.cpp b/dali/public-api/object/handle.cpp index b09c0e5..08b331b 100644 --- a/dali/public-api/object/handle.cpp +++ b/dali/public-api/object/handle.cpp @@ -67,7 +67,7 @@ uint32_t Handle::GetPropertyCount() const std::string Handle::GetPropertyName(Property::Index index) const { - return GetImplementation(*this).GetPropertyName(index); + return std::string(GetImplementation(*this).GetPropertyName(index)); } Property::Index Handle::GetPropertyIndex(Property::Key key) const @@ -100,19 +100,19 @@ void Handle::SetProperty(Property::Index index, Property::Value propertyValue) GetImplementation(*this).SetProperty(index, std::move(propertyValue)); } -Property::Index Handle::RegisterProperty(std::string name, Property::Value propertyValue) +Property::Index Handle::RegisterProperty(std::string_view name, Property::Value propertyValue) { - return GetImplementation(*this).RegisterProperty(std::move(name), std::move(propertyValue)); + return GetImplementation(*this).RegisterProperty(name, std::move(propertyValue)); } -Property::Index Handle::RegisterProperty(Property::Index key, std::string name, Property::Value propertyValue) +Property::Index Handle::RegisterProperty(Property::Index key, std::string_view name, Property::Value propertyValue) { - return GetImplementation(*this).RegisterProperty(std::move(name), key, std::move(propertyValue)); + return GetImplementation(*this).RegisterProperty(name, key, std::move(propertyValue)); } -Property::Index Handle::RegisterProperty(std::string name, Property::Value propertyValue, Property::AccessMode accessMode) +Property::Index Handle::RegisterProperty(std::string_view name, Property::Value propertyValue, Property::AccessMode accessMode) { - return GetImplementation(*this).RegisterProperty(std::move(name), std::move(propertyValue), accessMode); + return GetImplementation(*this).RegisterProperty(name, std::move(propertyValue), accessMode); } Property::Value Handle::GetProperty(Property::Index index) const diff --git a/dali/public-api/object/handle.h b/dali/public-api/object/handle.h index d7dc63f..eb65c5a 100644 --- a/dali/public-api/object/handle.h +++ b/dali/public-api/object/handle.h @@ -289,7 +289,7 @@ public: * - Property::ROTATION * @note If a property with the desired name already exists, then the value given is just set. */ - Property::Index RegisterProperty(std::string name, Property::Value propertyValue); + Property::Index RegisterProperty(std::string_view name, Property::Value propertyValue); /** * @brief Register a new animatable property with an integer key. @@ -329,9 +329,9 @@ public: * - Property::ROTATION * @note If a property with the desired name already exists, then the value given is just set. */ - Property::Index RegisterProperty(Property::Index key, - std::string name, - Property::Value propertyValue); + Property::Index RegisterProperty(Property::Index key, + std::string_view name, + Property::Value propertyValue); /** * @brief Registers a new property. @@ -356,7 +356,7 @@ public: * - Property::ROTATION * @note If a property with the desired name already exists, then the value given is just set. */ - Property::Index RegisterProperty(std::string name, Property::Value propertyValue, Property::AccessMode accessMode); + Property::Index RegisterProperty(std::string_view name, Property::Value propertyValue, Property::AccessMode accessMode); /** * @brief Retrieves a property value. diff --git a/dali/public-api/object/type-info.cpp b/dali/public-api/object/type-info.cpp index 50a1fc9..9d5c3cb 100644 --- a/dali/public-api/object/type-info.cpp +++ b/dali/public-api/object/type-info.cpp @@ -88,17 +88,17 @@ void TypeInfo::GetPropertyIndices(Property::IndexContainer& indices) const GetImplementation(*this).GetPropertyIndices(indices); } -const std::string& TypeInfo::GetPropertyName(Property::Index index) const +std::string_view TypeInfo::GetPropertyName(Property::Index index) const { return GetImplementation(*this).GetRegisteredPropertyName(index); } Property::Index TypeInfo::GetChildPropertyIndex(const std::string& name) const { - return GetImplementation(*this).GetChildPropertyIndex(name); + return GetImplementation(*this).GetChildPropertyIndex(Internal::ConstString(name)); } -const std::string& TypeInfo::GetChildPropertyName(Property::Index index) const +std::string_view TypeInfo::GetChildPropertyName(Property::Index index) const { return GetImplementation(*this).GetChildPropertyName(index); } diff --git a/dali/public-api/object/type-info.h b/dali/public-api/object/type-info.h index 164ab17..b278c82 100644 --- a/dali/public-api/object/type-info.h +++ b/dali/public-api/object/type-info.h @@ -240,7 +240,7 @@ public: * @exception DaliException If index is not valid. * @note this method only works for custom registered properties */ - const std::string& GetPropertyName(Property::Index index) const; + std::string_view GetPropertyName(Property::Index index) const; /** * @brief Given a child property name, retrieve the property index associated with it, @@ -258,7 +258,7 @@ public: * @param[in] index The property index * @return The name of the property at the given index, or empty string if it does not exist */ - const std::string& GetChildPropertyName(Property::Index index) const; + std::string_view GetChildPropertyName(Property::Index index) const; /** * @brief Given a child property index, retrieve the property name associated with it. -- 2.7.4