[Tizen] Implement partial update
[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 #include <dali/internal/event/object/default-property-metadata.h>
28
29 namespace Dali
30 {
31
32 namespace Internal
33 {
34
35 /**
36  * These macros are used to define a table of property details per object.
37  * The index property is only compiled in for DEBUG_ENABLED builds and allows checking the table index VS the property enum index.
38  * DALI_PROPERTY_TABLE_END Forces a run-time check that will happen once.
39  * the macros define an instance of PropertyMetadata with the name that is passed to DALI_PROPERTY_TABLE_END
40  */
41 #define DALI_PROPERTY_TABLE_BEGIN const Dali::PropertyDetails DEFAULT_PROPERTY_DETAILS[] = {
42 #ifdef DEBUG_ENABLED
43 #define DALI_PROPERTY_TABLE_END( startIndex, constantName )   }; const Property::Index DEFAULT_PROPERTY_COUNT = static_cast<Property::Index>( sizeof( DEFAULT_PROPERTY_DETAILS ) / sizeof( Dali::PropertyDetails ) ); \
44   struct PROPERTY_CHECK \
45   { \
46     PROPERTY_CHECK() \
47     { \
48       for( int i = 0; i < DEFAULT_PROPERTY_COUNT; i++ ) \
49       { \
50         if ( DEFAULT_PROPERTY_DETAILS[i].enumIndex != ( startIndex + i ) ) \
51         { \
52           DALI_LOG_ERROR( "Checking property failed: index:%d, enumIndex:%d == index+start:%d, (name:%s)\n", i, \
53                           DEFAULT_PROPERTY_DETAILS[i].enumIndex, (startIndex + i), DEFAULT_PROPERTY_DETAILS[i].name ); \
54           DALI_ASSERT_DEBUG( false && "Property enumeration mismatch" ); \
55         } \
56       } \
57     } \
58   }; \
59   constexpr Dali::DefaultPropertyMetadata constantName{ DEFAULT_PROPERTY_DETAILS, DEFAULT_PROPERTY_COUNT }; \
60   static PROPERTY_CHECK PROPERTY_CHECK_INSTANCE;
61 #else
62 #define DALI_PROPERTY_TABLE_END( startIndex, constantName )   }; const Property::Index DEFAULT_PROPERTY_COUNT = static_cast<Property::Index>( sizeof( DEFAULT_PROPERTY_DETAILS ) / sizeof( Dali::PropertyDetails ) );\
63   constexpr Dali::DefaultPropertyMetadata constantName{ DEFAULT_PROPERTY_DETAILS, DEFAULT_PROPERTY_COUNT };
64 #endif
65 #define DALI_PROPERTY( text, type, writable, animatable, constraint, index ) { text, index, Dali::Property::type, writable, animatable, constraint },
66
67 /**
68  * @brief Case insensitive string comparison.
69  *
70  * Additionally, '-' and '_' can be used interchangeably as well.
71  * Returns if both strings have a ',' or a '\0' at the same point.
72  *
73  * @param[in]   first   The first string.
74  * @param[in]   second  The string to compare it to.
75  * @param[out]  size    The size of the string.
76  *
77  * @return true if strings are the same
78  */
79 bool CompareTokens( const char * first, const char * second, uint32_t& size );
80
81
82 /**
83  * @brief Helper to adjust the current value of a variable from the given property-value
84  * @param[in] currentValue The current value of the property
85  * @param[in] value The relative value as a Property::Value
86  * @return true if value adjusted, false otherwise
87  */
88 template< typename PropertyType >
89 bool AdjustValue( PropertyType& currentValue, const Property::Value& value )
90 {
91   PropertyType relativeValue;
92   if( value.Get( relativeValue ) )
93   {
94     currentValue += relativeValue;
95     return true;
96   }
97   return false;
98 }
99
100 } // namespace Internal
101
102 } // namespace Dali
103
104 #endif // DALI_PROPERTY_HELPER_H