refactor PropertyMetadata table.
[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  * Checking of the table index VS the property enum index happens during compile time.
38  * the macros define an instance of PropertyMetadata with the name that is passed to DALI_PROPERTY_TABLE_END
39  */
40 #define DALI_PROPERTY_TABLE_BEGIN static constexpr Dali::PropertyDetails DEFAULT_PROPERTY_DETAILS[] = {
41
42 #define DALI_PROPERTY_TABLE_END(startIndex, tableName)                                  \
43   };                                                                                    \
44   static constexpr auto tableName = GeneratePropertyMetadata(DEFAULT_PROPERTY_DETAILS); \
45   static_assert(CheckPropertyMetadata(tableName, startIndex), "Property enumeration mismatch");
46
47 #define DALI_PROPERTY( text, type, writable, animatable, constraint, index ) { text, index, Dali::Property::type, writable, animatable, constraint },
48
49 /**
50  * @brief Case insensitive string comparison.
51  *
52  * Additionally, '-' and '_' can be used interchangeably as well.
53  * Returns if both strings have a ',' or a '\0' at the same point.
54  *
55  * @param[in]   first   The first string.
56  * @param[in]   second  The string to compare it to.
57  * @param[out]  size    The size of the string.
58  *
59  * @return true if strings are the same
60  */
61 bool CompareTokens( const char * first, const char * second, uint32_t& size );
62
63
64 /**
65  * @brief Helper to adjust the current value of a variable from the given property-value
66  * @param[in] currentValue The current value of the property
67  * @param[in] value The relative value as a Property::Value
68  * @return true if value adjusted, false otherwise
69  */
70 template< typename PropertyType >
71 bool AdjustValue( PropertyType& currentValue, const Property::Value& value )
72 {
73   PropertyType relativeValue;
74   if( value.Get( relativeValue ) )
75   {
76     currentValue += relativeValue;
77     return true;
78   }
79   return false;
80 }
81
82 } // namespace Internal
83
84 } // namespace Dali
85
86 #endif // DALI_PROPERTY_HELPER_H