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