From 16cb8b3fafec2ae61ce0397318eb0cd28bedc9ea Mon Sep 17 00:00:00 2001 From: David Steele Date: Fri, 23 Mar 2018 18:26:23 +0000 Subject: [PATCH] Added TypeInfo::GetChildPropertyIndices Change-Id: I909a6ac928739a5563d3ad231686a2f43d5331c8 --- automated-tests/src/dali/utc-Dali-TypeRegistry.cpp | 36 ++++++++++++++++++++++ dali/internal/event/common/type-info-impl.cpp | 32 +++++++++++++++---- dali/internal/event/common/type-info-impl.h | 19 +++++++++++- dali/public-api/object/type-info.cpp | 6 ++++ dali/public-api/object/type-info.h | 9 ++++++ 5 files changed, 95 insertions(+), 7 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-TypeRegistry.cpp b/automated-tests/src/dali/utc-Dali-TypeRegistry.cpp index 7da76eb..fb2bb5b 100644 --- a/automated-tests/src/dali/utc-Dali-TypeRegistry.cpp +++ b/automated-tests/src/dali/utc-Dali-TypeRegistry.cpp @@ -2878,3 +2878,39 @@ int UtcDaliTypeInfoRegisterChildProperties02(void) END_TEST; } + + +int UtcDaliTypeInfoRegisterChildProperties03(void) +{ + TestApplication application; + TypeRegistry typeRegistry = TypeRegistry::Get(); + + tet_infoline( "Check registered child properties can be retrieved" ); + + auto customActorTypeInfo = typeRegistry.GetTypeInfo( typeid(CustomActor) ); + auto myCustomTypeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) ); + DALI_TEST_CHECK( customActorTypeInfo ); + DALI_TEST_CHECK( myCustomTypeInfo ); + + const Property::Index WIDTH_SPECIFICATION( CHILD_PROPERTY_REGISTRATION_START_INDEX ); + const Property::Index HEIGHT_SPECIFICATION( CHILD_PROPERTY_REGISTRATION_START_INDEX + 1); + const Property::Index MARGIN_SPECIFICATION( CHILD_PROPERTY_REGISTRATION_START_INDEX + 100); + + ChildPropertyRegistration( customActorTypeInfo.GetName(), "widthSpecification", WIDTH_SPECIFICATION, Property::INTEGER ); + ChildPropertyRegistration( customActorTypeInfo.GetName(), "heightSpecification", HEIGHT_SPECIFICATION, Property::INTEGER ); + ChildPropertyRegistration( myCustomTypeInfo.GetName(), "marginSpecification", MARGIN_SPECIFICATION, Property::EXTENTS ); + + Property::IndexContainer indices; + myCustomTypeInfo.GetChildPropertyIndices( indices ); + + auto result = std::find( indices.Begin(), indices.End(), WIDTH_SPECIFICATION ); + DALI_TEST_EQUALS( result != indices.End(), true, TEST_LOCATION ); + + result = std::find( indices.Begin(), indices.End(), HEIGHT_SPECIFICATION ); + DALI_TEST_EQUALS( result != indices.End(), true, TEST_LOCATION ); + + result = std::find( indices.Begin(), indices.End(), MARGIN_SPECIFICATION ); + DALI_TEST_EQUALS( result != indices.End(), true, TEST_LOCATION ); + + END_TEST; +} diff --git a/dali/internal/event/common/type-info-impl.cpp b/dali/internal/event/common/type-info-impl.cpp index e3f8d79..2b41f54 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) 2017 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 ); } } } diff --git a/dali/internal/event/common/type-info-impl.h b/dali/internal/event/common/type-info-impl.h index 325f4f6..3587ede 100644 --- a/dali/internal/event/common/type-info-impl.h +++ b/dali/internal/event/common/type-info-impl.h @@ -2,7 +2,7 @@ #define __DALI_INTERNAL_TYPE_INFO_H__ /* - * 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. @@ -268,6 +268,12 @@ public: Property::Type GetChildPropertyType( Property::Index index ) const; /** + * Retrive the child indices into the given container. + * @param[in,out] indices The container to put the child indices into + */ + void GetChildPropertyIndices( Property::IndexContainer& indices ) const; + + /** * Retrieve the default value of the property at the given index. * @param[in] index The property index. * @return The default property value at that index. @@ -378,6 +384,17 @@ private: typedef std::vector< RegisteredPropertyPair > RegisteredPropertyContainer; typedef std::vector< PropertyDefaultValuePair > PropertyDefaultValueContainer; + + /** + * Append properties from registeredProperties onto indices. + * @param[in,out] indices The vector to append indices onto + * @param[in] registeredProperties The container to retrive indices from + */ + void AppendProperties( Dali::Property::IndexContainer& indices, + const TypeInfo::RegisteredPropertyContainer& registeredProperties ) const; + +private: + std::string mTypeName; std::string mBaseTypeName; bool mCSharpType:1; ///< Whether this type info is for a CSharp control (instead of C++) diff --git a/dali/public-api/object/type-info.cpp b/dali/public-api/object/type-info.cpp index eb4c8b2..92f1b67 100644 --- a/dali/public-api/object/type-info.cpp +++ b/dali/public-api/object/type-info.cpp @@ -116,6 +116,12 @@ Property::Type TypeInfo::GetChildPropertyType( Property::Index index ) const return GetImplementation(*this).GetChildPropertyType( index ); } +void TypeInfo::GetChildPropertyIndices( Property::IndexContainer& indices ) const +{ + indices.Clear(); // We do not want to clear the container if called internally, so only clear here + GetImplementation(*this).GetChildPropertyIndices( indices ); +} + TypeInfo::TypeInfo(Internal::TypeInfo* internal) : BaseHandle(internal) { diff --git a/dali/public-api/object/type-info.h b/dali/public-api/object/type-info.h index 87a1958..290c2b9 100644 --- a/dali/public-api/object/type-info.h +++ b/dali/public-api/object/type-info.h @@ -205,6 +205,15 @@ public: void GetPropertyIndices( Property::IndexContainer& indices ) const; /** + * @brief Retrieves all the child property indices for this type. + * + * @SINCE_1_3.20 + * @param[out] indices Container of property indices + * @note The container will be cleared + */ + void GetChildPropertyIndices( Property::IndexContainer& indices ) const; + + /** * @brief Given a property index, retrieve the property name associated with it. * * @SINCE_1_0.0 -- 2.7.4