(Scripting) Helper method for bit-mask enum properties & moved enum-string macros...
[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) 2016 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 #include <dali/devel-api/scripting/enum-helper.h>
24
25 namespace Dali
26 {
27
28 namespace Internal
29 {
30
31 /**
32  * @brief Structure for setting up default properties and their details.
33  */
34 struct PropertyDetails
35 {
36   const char* name;             ///< The name of the property.
37   Property::Type type;          ///< The property type.
38   bool writable:1;              ///< Whether the property is writable
39   bool animatable:1;            ///< Whether the property is animatable.
40   bool constraintInput:1;       ///< Whether the property can be used as an input to a constraint.
41 #ifdef DEBUG_ENABLED
42   Property::Index enumIndex;    ///< Used to check the index is correct within a debug build.
43 #endif
44 };
45
46 /**
47  * These macros are used to define a table of property details per Actor object.
48  * The index property is only compiled in for DEBUG_ENABLED builds and allows checking the table index VS the property enum index.
49  * DALI_PROPERTY_TABLE_END Forces a run-time check that will happen once.
50  */
51 #define DALI_PROPERTY_TABLE_BEGIN const Internal::PropertyDetails DEFAULT_PROPERTY_DETAILS[] = {
52 #ifdef DEBUG_ENABLED
53 #define DALI_PROPERTY_TABLE_END( startIndex )   }; const int DEFAULT_PROPERTY_COUNT = sizeof( DEFAULT_PROPERTY_DETAILS ) / sizeof( Internal::PropertyDetails ); \
54   struct PROPERTY_CHECK \
55   { \
56     PROPERTY_CHECK() \
57     { \
58       for( int i = 0; i < DEFAULT_PROPERTY_COUNT; i++ ) \
59       { \
60         if ( DEFAULT_PROPERTY_DETAILS[i].enumIndex != ( startIndex + i ) ) \
61         { \
62           DALI_LOG_ERROR( "Checking property failed: index:%d, enumIndex:%d == index+start:%d, (name:%s)\n", i, \
63                           DEFAULT_PROPERTY_DETAILS[i].enumIndex, (startIndex + i), DEFAULT_PROPERTY_DETAILS[i].name ); \
64           DALI_ASSERT_DEBUG( false && "Property enumeration mismatch" ); \
65         } \
66       } \
67     } \
68   }; \
69   static PROPERTY_CHECK PROPERTY_CHECK_INSTANCE;
70 #else
71 #define DALI_PROPERTY_TABLE_END( startIndex )   }; const int DEFAULT_PROPERTY_COUNT = sizeof( DEFAULT_PROPERTY_DETAILS ) / sizeof( Internal::PropertyDetails );
72 #endif
73 #ifdef DEBUG_ENABLED
74 #define DALI_PROPERTY( text, type, writable, animatable, constraint, index ) { text, Dali::Property::type, writable, animatable, constraint, index },
75 #else
76 #define DALI_PROPERTY( text, type, writable, animatable, constraint, index ) { text, Dali::Property::type, writable, animatable, constraint },
77 #endif
78
79 /**
80  * @brief Case insensitive string comparison.
81  *
82  * Additionally, '-' and '_' can be used interchangeably as well.
83  * Returns if both strings have a ',' or a '\0' at the same point.
84  *
85  * @param[in]   first   The first string.
86  * @param[in]   second  The string to compare it to.
87  * @param[out]  size    The size of the string.
88  *
89  * @return true if strings are the same
90  */
91 bool CompareTokens( const char * first, const char * second, size_t& size );
92
93 } // namespace Internal
94
95 } // namespace Dali
96
97 #endif // DALI_PROPERTY_HELPER_H