/**
* These macros are used to define a table of property details per 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.
+ * 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
*/
-#define DALI_PROPERTY_TABLE_BEGIN const Dali::PropertyDetails DEFAULT_PROPERTY_DETAILS[] = {
-#ifdef DEBUG_ENABLED
-#define DALI_PROPERTY_TABLE_END( startIndex, constantName ) }; const Property::Index DEFAULT_PROPERTY_COUNT = static_cast<Property::Index>( sizeof( DEFAULT_PROPERTY_DETAILS ) / sizeof( Dali::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" ); \
- } \
- } \
- } \
- }; \
- constexpr Dali::DefaultPropertyMetadata constantName{ DEFAULT_PROPERTY_DETAILS, DEFAULT_PROPERTY_COUNT }; \
- static PROPERTY_CHECK PROPERTY_CHECK_INSTANCE;
-#else
-#define DALI_PROPERTY_TABLE_END( startIndex, constantName ) }; const Property::Index DEFAULT_PROPERTY_COUNT = static_cast<Property::Index>( sizeof( DEFAULT_PROPERTY_DETAILS ) / sizeof( Dali::PropertyDetails ) );\
- constexpr Dali::DefaultPropertyMetadata constantName{ DEFAULT_PROPERTY_DETAILS, DEFAULT_PROPERTY_COUNT };
-#endif
+#define DALI_PROPERTY_TABLE_BEGIN static constexpr Dali::PropertyDetails DEFAULT_PROPERTY_DETAILS[] = {
+
+#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 },
/**
// default or custom
if ( mDefaultProperties && ( index < DEFAULT_PROPERTY_MAX_COUNT ) )
{
- const char* name = nullptr;
+ std::string_view name;
if( GetDefaultPropertyField( mDefaultProperties, mDefaultPropertyCount,index, &Dali::PropertyDetails::name, name ) )
{
propertyName = name;
{
for( Property::Index tableIndex = 0; tableIndex < mDefaultPropertyCount; ++tableIndex )
{
- if( 0 == name.compare( mDefaultProperties[ tableIndex ].name ) )
+ if(mDefaultProperties[tableIndex].name == name)
{
index = mDefaultProperties[ tableIndex ].enumIndex;
found = true;
*
*/
+// EXTERNAL INCLUDES
+#include <string_view>
+
// INTERNAL INCLUDES
#include <dali/public-api/object/property.h>
*/
struct PropertyDetails
{
- const char* name; ///< The name of the property.
+ std::string_view name; ///< The name of the property.
Property::Index enumIndex; ///< Used to check the index is correct within a debug build.
Property::Type type; ///< The property type.
bool writable; ///< Whether the property is writable
struct DefaultPropertyMetadata
{
const PropertyDetails* propertyTable; ///< address of the table defining property meta-data.
- Property::Index propertyCount; ///< count of the default properties.
+ const Property::Index propertyCount; ///< count of the default properties.
};
+inline constexpr bool CheckPropertyMetadata(const DefaultPropertyMetadata& table, Property::Index startIndex) noexcept
+{
+ for(int i = 0; i < table.propertyCount; i++)
+ {
+ if(table.propertyTable[i].enumIndex != startIndex + i)
+ return false;
+ }
+ return true;
+}
+
+template<size_t N>
+inline constexpr DefaultPropertyMetadata GeneratePropertyMetadata(const PropertyDetails (&array)[N]) noexcept
+{
+ return {array, N};
+}
+
} // namespace Dali
#endif // DALI_DEFAULT_PROPERTY_METADATA_H