Make Dali::Vector movable & add use Modern C++ semantics on public & devel classes
[platform/core/uifw/dali-core.git] / dali / public-api / object / type-registry-helper.h
1 #ifndef DALI_TYPE_REGISTRY_HELPER_H
2 #define DALI_TYPE_REGISTRY_HELPER_H
3
4 /*
5  * Copyright (c) 2020 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 // INTERNAL INCLUDES
22 #include <dali/public-api/object/type-registry.h>
23
24 /**
25  * @brief Definition for macros that are used internally by the property macros.
26  * Use the the property macros in the section below this one (without the _INTERNAL postfix) when defining properties.
27  * These internal macros exist as to perform the compile-time check on the enumeration order, the __COUNTER__ macro is used twice.
28  * Using it twice within the same macro would result in two different values.
29  */
30 #define DALI_TOKEN_PASTE_EXPAND( x, y ) x ## y
31 #define DALI_TOKEN_PASTE( x, y ) DALI_TOKEN_PASTE_EXPAND(x, y)
32
33 #define DALI_PROPERTY_REGISTRATION_INTERNAL( count, typeRegistrationObject, objectNamespace, objectType, text, valueType, enumIndex ) \
34   Dali::PropertyRegistration DALI_TOKEN_PASTE( property, count ) ( typeRegistrationObject, text, objectNamespace::objectType::Property::enumIndex, Dali::Property::valueType, &objectType::SetProperty, &objectType::GetProperty ); \
35   static_assert( ( objectNamespace::objectType::Property::enumIndex - objectNamespace::objectType::PROPERTY_START_INDEX ) == count );
36
37 #define DALI_PROPERTY_REGISTRATION_INTERNAL_READ_ONLY( count, typeRegistrationObject, objectNamespace, objectType, text, valueType, enumIndex ) \
38   Dali::PropertyRegistration DALI_TOKEN_PASTE( property, count ) ( typeRegistrationObject, text, objectNamespace::objectType::Property::enumIndex, Dali::Property::valueType, NULL, &objectType::GetProperty ); \
39   static_assert( ( objectNamespace::objectType::Property::enumIndex - objectNamespace::objectType::PROPERTY_START_INDEX ) == count );
40
41 #define DALI_ANIMATABLE_PROPERTY_REGISTRATION_INTERNAL( count, typeRegistrationObject, objectNamespace, objectType, text, valueType, enumIndex) \
42   Dali::AnimatablePropertyRegistration DALI_TOKEN_PASTE( property, count ) ( typeRegistrationObject, text, objectNamespace::objectType::Property::enumIndex, Dali::Property::valueType );
43
44 #define DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT_INTERNAL( count, typeRegistrationObject, objectNamespace, objectType, text, value, enumIndex) \
45   Dali::AnimatablePropertyRegistration DALI_TOKEN_PASTE( property, count ) ( typeRegistrationObject, text, objectNamespace::objectType::Property::enumIndex, value );
46
47 #define DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION_INTERNAL( count, typeRegistrationObject, objectNamespace, objectType, text, enumIndex, baseEnumIndex, componentIndex) \
48   Dali::AnimatablePropertyComponentRegistration DALI_TOKEN_PASTE( property, count ) ( typeRegistrationObject, text, objectNamespace::objectType::Property::enumIndex, objectNamespace::objectType::Property::baseEnumIndex, componentIndex );
49
50 #define DALI_CHILD_PROPERTY_REGISTRATION_INTERNAL( count, typeRegistrationObject, objectNamespace, objectType, text, valueType, enumIndex ) \
51   Dali::ChildPropertyRegistration DALI_TOKEN_PASTE( property, count ) ( typeRegistrationObject, text, objectNamespace::objectType::ChildProperty::enumIndex, Property::valueType );
52
53 #define DALI_SIGNAL_REGISTRATION_INTERNAL( count, typeRegistrationObject, objectNamespace, objectType, text, textVariable ) \
54   const char* const textVariable = text; \
55   Dali::SignalConnectorType DALI_TOKEN_PASTE( signalConnector, count ) ( typeRegistrationObject, text, &objectNamespace::Internal::objectType::DoConnectSignal );
56
57 #define DALI_ACTION_REGISTRATION_INTERNAL( count, typeRegistrationObject, objectNamespace, objectType, text, textVariable ) \
58   const char* const textVariable = text; \
59   Dali::TypeAction DALI_TOKEN_PASTE( signalConnector, count ) ( typeRegistrationObject, text, &objectNamespace::Internal::objectType::DoAction );
60
61
62 /**
63  * @brief These macros are used to define properties for implementations of CustomActor.
64  * @SINCE_1_1.36
65  *
66  * These macros should be used when defining properties, signals and actions.
67  * They provide the following benefits:
68  * - A standard and consistent way to define properties.
69  * - Concise definition promotes readability, especially with large numbers of properties.
70  * - Provides a built-in compile-time check. This checks the order of the properties within the enumeration match the order of the property macros. Note: This check is not performed for animatable properties.
71  * - Enforces how properties are enumerated in the object handles header file.
72  *
73  * Note: The compile-type check will produce the following message on failure:
74  *       error: invalid application of 'sizeof' to incomplete type 'Dali::CompileTimeAssertBool<false>'
75  *
76  * Macro usage example:
77  *
78  * Within the your object's implementation cpp:
79  * @code
80  * #include <dali/public-api/object/type-registry-helper.h>
81  * ...
82  * DALI_TYPE_REGISTRATION_BEGIN( MyApp::MyCustomActor, Dali::CustomActor, Create )
83  * DALI_PROPERTY_REGISTRATION( MyApp, MyCustomActor, "myProperty", INTEGER, MY_PROPERTY )
84  * DALI_TYPE_REGISTRATION_END()
85  * @endcode
86  *
87  * Within your handle's header:
88  *
89  * @code
90  * #include <dali/public-api/common/dali-common.h>
91  *
92  *
93  * ///< @brief The start and end property ranges for this control.
94  * enum PropertyRange
95  * {
96  *   PROPERTY_START_INDEX = Dali::PROPERTY_REGISTRATION_START_INDEX,
97  *   PROPERTY_END_INDEX =   PROPERTY_START_INDEX + 1000
98  * };
99  *
100  * ///< @brief Enumeration for the instance of properties belonging to the Button class.
101  * struct Property
102  * {
103  *   enum
104  *   {
105  *     MY_PROPERTY = PROPERTY_START_INDEX    ///< @brief name "myProperty", type Integer
106  *   };
107  * };
108  * @endcode
109  *
110  * Using these macros have certain prerequisites on how the property enumeration is defined.
111  * Please see the Programming Guide (within the generated Doxygen) for full details.
112  */
113 #define DALI_TYPE_REGISTRATION_BEGIN( thisType, baseType, createFunction ) \
114   Dali::TypeRegistration typeRegistration( typeid( thisType ), typeid( baseType ), createFunction );
115
116 #define DALI_TYPE_REGISTRATION_BEGIN_CREATE( thisType, baseType, createFunction, createAtStartup ) \
117   Dali::TypeRegistration typeRegistration( typeid( thisType ), typeid( baseType ), createFunction, createAtStartup );
118
119 #define DALI_PROPERTY_REGISTRATION( objectNamespace, objectType, text, valueType, enumIndex ) \
120   DALI_PROPERTY_REGISTRATION_INTERNAL( __COUNTER__, typeRegistration, objectNamespace, objectType, text, valueType, enumIndex )
121
122 #define DALI_PROPERTY_REGISTRATION_READ_ONLY( objectNamespace, objectType, text, valueType, enumIndex ) \
123   DALI_PROPERTY_REGISTRATION_INTERNAL_READ_ONLY( __COUNTER__, typeRegistration, objectNamespace, objectType, text, valueType, enumIndex )
124
125 #define DALI_ANIMATABLE_PROPERTY_REGISTRATION( objectNamespace, objectType, text, valueType, enumIndex ) \
126   DALI_ANIMATABLE_PROPERTY_REGISTRATION_INTERNAL( __COUNTER__, typeRegistration, objectNamespace, objectType, text, valueType, enumIndex )
127
128 #define DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT( objectNamespace, objectType, text, value, enumIndex ) \
129   DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT_INTERNAL( __COUNTER__, typeRegistration, objectNamespace, objectType, text, value, enumIndex )
130
131 #define DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( objectNamespace, objectType, text, enumIndex, baseEnumIndex, componentIndex ) \
132   DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION_INTERNAL( __COUNTER__, typeRegistration, objectNamespace, objectType, text, enumIndex, baseEnumIndex, componentIndex )
133
134 #define DALI_CHILD_PROPERTY_REGISTRATION( objectNamespace, objectType, text, valueType, enumIndex ) \
135   DALI_CHILD_PROPERTY_REGISTRATION_INTERNAL( __COUNTER__, typeRegistration, objectNamespace, objectType, text, valueType, enumIndex )
136
137 #define DALI_SIGNAL_REGISTRATION( objectNamespace, objectType, text, textVariable ) \
138   DALI_SIGNAL_REGISTRATION_INTERNAL( __COUNTER__, typeRegistration, objectNamespace, objectType, text, textVariable )
139
140 #define DALI_ACTION_REGISTRATION( objectNamespace, objectType, text, textVariable ) \
141   DALI_ACTION_REGISTRATION_INTERNAL( __COUNTER__, typeRegistration, objectNamespace, objectType, text, textVariable )
142
143 #define DALI_TYPE_REGISTRATION_END( ) // This macro exists for consistency and readability.
144
145
146 #endif // DALI_TYPE_REGISTRY_HELPER_H