-#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.
*
*/
+// EXTERNAL INCLUDES
+#include <cstdint>
+
// INTERNAL INCLUDES
#include <dali/integration-api/bitmap.h>
+#include <dali/devel-api/scripting/enum-helper.h>
+#include <dali/internal/event/object/default-property-metadata.h>
namespace Dali
{
{
/**
- * @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.
*
- * 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 )
+ * Additionally, '-' and '_' can be used interchangeably as well.
+ * Returns if both strings have a ',' or a '\0' at the same point.
*
- * 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] );
+ * @param[in] first The first string.
+ * @param[in] second The string to compare it to.
+ * @param[out] size The size of the string.
+ *
+ * @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