refactor PropertyMetadata table.
[platform/core/uifw/dali-core.git] / dali / internal / event / object / default-property-metadata.h
1 #ifndef DALI_DEFAULT_PROPERTY_METADATA_H
2 #define DALI_DEFAULT_PROPERTY_METADATA_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 <string_view>
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/object/property.h>
26
27 namespace Dali
28 {
29 /**
30  * @addtogroup dali_core_object
31  * @{
32  */
33
34 /**
35  * @brief Structure for setting up default properties and their details.
36  */
37 struct PropertyDetails
38 {
39   std::string_view name;       ///< The name of the property.
40   Property::Index enumIndex;  ///< Used to check the index is correct within a debug build.
41   Property::Type type;        ///< The property type.
42   bool writable;              ///< Whether the property is writable
43   bool animatable;            ///< Whether the property is animatable.
44   bool constraintInput;       ///< Whether the property can be used as an input to a constraint.
45 };
46
47 /**
48  * Struct to capture the address of the default property table and count of them.
49  */
50 struct DefaultPropertyMetadata
51 {
52   const PropertyDetails* propertyTable; ///< address of the table defining property meta-data.
53   const Property::Index  propertyCount; ///< count of the default properties.
54 };
55
56 inline constexpr bool CheckPropertyMetadata(const DefaultPropertyMetadata& table, Property::Index startIndex) noexcept
57 {
58   for(int i = 0; i < table.propertyCount; i++)
59   {
60     if(table.propertyTable[i].enumIndex != startIndex + i)
61       return false;
62   }
63   return true;
64 }
65
66 template<size_t N>
67 inline constexpr DefaultPropertyMetadata GeneratePropertyMetadata(const PropertyDetails (&array)[N]) noexcept
68 {
69   return {array, N};
70 }
71
72 } // namespace Dali
73
74 #endif // DALI_DEFAULT_PROPERTY_METADATA_H