Merge remote-tracking branch 'origin/tizen' into new_text
[platform/core/uifw/dali-core.git] / dali / internal / event / common / property-helper.h
1 #ifndef __DALI_PROPERTY_HELPER_H__
2 #define __DALI_PROPERTY_HELPER_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/integration-api/bitmap.h>
23
24 namespace Dali
25 {
26
27 namespace Internal
28 {
29
30 /**
31  * @brief Structure for setting up default properties and their details.
32  */
33 struct PropertyDetails
34 {
35   const char* name;             ///< The name of the property.
36   Property::Type type;          ///< The property type.
37   bool writable:1;              ///< Whether the property is writable
38   bool animatable:1;            ///< Whether the property is animatable.
39   bool constraintInput:1;       ///< Whether the property can be used as an input to a constraint.
40 #ifdef DEBUG_ENABLED
41   Property::Index enumIndex;    ///< Used to check the index is correct within a debug build.
42 #endif
43 };
44
45 /**
46  * These macros are used to define a table of property details per Actor object.
47  * The index property is only compiled in for DEBUG_ENABLED builds and allows checking the table index VS the property enum index.
48  * DALI_PROPERTY_TABLE_END Forces a run-time check that will happen once.
49  */
50 #define DALI_PROPERTY_TABLE_BEGIN const Internal::PropertyDetails DEFAULT_PROPERTY_DETAILS[] = {
51 #ifdef DEBUG_ENABLED
52 #define DALI_PROPERTY_TABLE_END( startIndex )   }; const int DEFAULT_PROPERTY_COUNT = sizeof( DEFAULT_PROPERTY_DETAILS ) / sizeof( Internal::PropertyDetails ); \
53   struct PROPERTY_CHECK \
54   { \
55     PROPERTY_CHECK() \
56     { \
57       for( int i = 0; i < DEFAULT_PROPERTY_COUNT; i++ ) \
58       { \
59         if ( DEFAULT_PROPERTY_DETAILS[i].enumIndex != ( startIndex + i ) ) \
60         { \
61           DALI_LOG_ERROR( "Checking property failed: index:%d, enumIndex:%d == index+start:%d, (name:%s)\n", i, \
62                           DEFAULT_PROPERTY_DETAILS[i].enumIndex, (startIndex + i), DEFAULT_PROPERTY_DETAILS[i].name ); \
63           DALI_ASSERT_DEBUG( false && "Property enumeration mismatch" ); \
64         } \
65       } \
66     } \
67   }; \
68   static PROPERTY_CHECK PROPERTY_CHECK_INSTANCE;
69 #else
70 #define DALI_PROPERTY_TABLE_END( startIndex )   }; const int DEFAULT_PROPERTY_COUNT = sizeof( DEFAULT_PROPERTY_DETAILS ) / sizeof( Internal::PropertyDetails );
71 #endif
72 #ifdef DEBUG_ENABLED
73 #define DALI_PROPERTY( text, type, writable, animatable, constraint, index ) { text, Dali::Property::type, writable, animatable, constraint, index },
74 #else
75 #define DALI_PROPERTY( text, type, writable, animatable, constraint, index ) { text, Dali::Property::type, writable, animatable, constraint },
76 #endif
77
78 /**
79  * Macros for creating enumeration to string tables.
80  * Example:
81  *
82  * DALI_ENUM_TO_STRING_TABLE_BEGIN( SizeMode )
83  * DALI_ENUM_TO_STRING( USE_OWN_SIZE )
84  * DALI_ENUM_TO_STRING( SIZE_EQUAL_TO_PARENT )
85  * DALI_ENUM_TO_STRING_TABLE_END( SizeMode )
86  *
87  * Creates:
88  * const Scripting::StringEnum< SizeMode > SizeModeTable[] = {
89  * { "USE_OWN_SIZE", USE_OWN_SIZE },
90  * { "SIZE_EQUAL_TO_PARENT", SIZE_EQUAL_TO_PARENT },
91  * }; const unsigned int SizeModeTableCount = sizeof( SizeModeTable ) / sizeof( SizeModeTable[0] );
92  */
93 #define DALI_ENUM_TO_STRING_TABLE_BEGIN( t ) const Scripting::StringEnum< t > t##Table[] = {
94 #define DALI_ENUM_TO_STRING_TABLE_END( t )   }; const unsigned int t##TableCount = sizeof( t##Table ) / sizeof( t##Table[0] );
95 #define DALI_ENUM_TO_STRING( s ) { #s, s },
96
97
98 } // namespace Internal
99
100 } // namespace Dali
101
102 #endif // __DALI_PROPERTY_HELPER_H__
103