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