X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fevent%2Fcommon%2Fproperty-helper.h;h=2d9146f38bbec4c08ff007d1efaf8047813f7419;hb=e6f417dab998ffd3a524ae01119f0c209059541c;hp=04df69006434035a4a5c7eb8ee873c003753c143;hpb=933b6c4b896da1ae0fd81e8e7d12aba75b6b8c4c;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/event/common/property-helper.h b/dali/internal/event/common/property-helper.h index 04df690..2d9146f 100644 --- a/dali/internal/event/common/property-helper.h +++ b/dali/internal/event/common/property-helper.h @@ -1,8 +1,8 @@ -#ifndef __DALI_PROPERTY_HELPER_H__ -#define __DALI_PROPERTY_HELPER_H__ +#ifndef DALI_PROPERTY_HELPER_H +#define DALI_PROPERTY_HELPER_H /* - * Copyright (c) 2014 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. @@ -18,8 +18,13 @@ * */ +// EXTERNAL INCLUDES +#include + // INTERNAL INCLUDES #include +#include +#include namespace Dali { @@ -28,76 +33,54 @@ namespace Internal { /** - * @brief Structure for setting up default properties and their details. + * These macros are used to define a table of property details per object. + * Checking of the table index VS the property enum index happens during compile time. + * the macros define an instance of PropertyMetadata with the name that is passed to DALI_PROPERTY_TABLE_END */ -struct PropertyDetails -{ - const char* name; ///< The name of the property. - Property::Type type; ///< The property type. - bool writable:1; ///< Whether the property is writable - bool animatable:1; ///< Whether the property is animatable. - bool constraintInput:1; ///< Whether the property can be used as an input to a constraint. -#ifdef DEBUG_ENABLED - Property::Index enumIndex; ///< Used to check the index is correct within a debug build. -#endif -}; +#define DALI_PROPERTY_TABLE_BEGIN static constexpr Dali::PropertyDetails DEFAULT_PROPERTY_DETAILS[] = { -/** - * These macros are used to define a table of property details per Actor object. - * The index property is only compiled in for DEBUG_ENABLED builds and allows checking the table index VS the property enum index. - * DALI_PROPERTY_TABLE_END Forces a run-time check that will happen once. - */ -#define DALI_PROPERTY_TABLE_BEGIN const Internal::PropertyDetails DEFAULT_PROPERTY_DETAILS[] = { -#ifdef DEBUG_ENABLED -#define DALI_PROPERTY_TABLE_END( startIndex ) }; const int DEFAULT_PROPERTY_COUNT = sizeof( DEFAULT_PROPERTY_DETAILS ) / sizeof( Internal::PropertyDetails ); \ - struct PROPERTY_CHECK \ - { \ - PROPERTY_CHECK() \ - { \ - for( int i = 0; i < DEFAULT_PROPERTY_COUNT; i++ ) \ - { \ - if ( DEFAULT_PROPERTY_DETAILS[i].enumIndex != ( startIndex + i ) ) \ - { \ - DALI_LOG_ERROR( "Checking property failed: index:%d, enumIndex:%d == index+start:%d, (name:%s)\n", i, \ - DEFAULT_PROPERTY_DETAILS[i].enumIndex, (startIndex + i), DEFAULT_PROPERTY_DETAILS[i].name ); \ - DALI_ASSERT_DEBUG( false && "Property enumeration mismatch" ); \ - } \ - } \ - } \ - }; \ - static PROPERTY_CHECK PROPERTY_CHECK_INSTANCE; -#else -#define DALI_PROPERTY_TABLE_END( startIndex ) }; const int DEFAULT_PROPERTY_COUNT = sizeof( DEFAULT_PROPERTY_DETAILS ) / sizeof( Internal::PropertyDetails ); -#endif -#ifdef DEBUG_ENABLED -#define DALI_PROPERTY( text, type, writable, animatable, constraint, index ) { text, Dali::Property::type, writable, animatable, constraint, index }, -#else -#define DALI_PROPERTY( text, type, writable, animatable, constraint, index ) { text, Dali::Property::type, writable, animatable, constraint }, -#endif +#define DALI_PROPERTY_TABLE_END(startIndex, tableName) \ + }; \ + static constexpr auto tableName = GeneratePropertyMetadata(DEFAULT_PROPERTY_DETAILS); \ + static_assert(CheckPropertyMetadata(tableName, startIndex), "Property enumeration mismatch"); + +#define DALI_PROPERTY( text, type, writable, animatable, constraint, index ) { text, index, Dali::Property::type, writable, animatable, constraint }, /** - * Macros for creating enumeration to string tables. - * Example: + * @brief Case insensitive string comparison. + * + * Additionally, '-' and '_' can be used interchangeably as well. + * Returns if both strings have a ',' or a '\0' at the same point. * - * DALI_ENUM_TO_STRING_TABLE_BEGIN( SizeMode ) - * DALI_ENUM_TO_STRING( USE_OWN_SIZE ) - * DALI_ENUM_TO_STRING( SIZE_EQUAL_TO_PARENT ) - * DALI_ENUM_TO_STRING_TABLE_END( SizeMode ) + * @param[in] first The first string. + * @param[in] second The string to compare it to. + * @param[out] size The size of the string. * - * Creates: - * const Scripting::StringEnum< SizeMode > SizeModeTable[] = { - * { "USE_OWN_SIZE", USE_OWN_SIZE }, - * { "SIZE_EQUAL_TO_PARENT", SIZE_EQUAL_TO_PARENT }, - * }; const unsigned int SizeModeTableCount = sizeof( SizeModeTable ) / sizeof( SizeModeTable[0] ); + * @return true if strings are the same */ -#define DALI_ENUM_TO_STRING_TABLE_BEGIN( t ) const Scripting::StringEnum< t > t##Table[] = { -#define DALI_ENUM_TO_STRING_TABLE_END( t ) }; const unsigned int t##TableCount = sizeof( t##Table ) / sizeof( t##Table[0] ); -#define DALI_ENUM_TO_STRING( s ) { #s, s }, +bool CompareTokens( const char * first, const char * second, uint32_t& size ); +/** + * @brief Helper to adjust the current value of a variable from the given property-value + * @param[in] currentValue The current value of the property + * @param[in] value The relative value as a Property::Value + * @return true if value adjusted, false otherwise + */ +template< typename PropertyType > +bool AdjustValue( PropertyType& currentValue, const Property::Value& value ) +{ + PropertyType relativeValue; + if( value.Get( relativeValue ) ) + { + currentValue += relativeValue; + return true; + } + return false; +} + } // namespace Internal } // namespace Dali -#endif // __DALI_PROPERTY_HELPER_H__ - +#endif // DALI_PROPERTY_HELPER_H