946e125c96ccdd40094b37fad7d35874ccc9e1a0
[platform/core/uifw/dali-core.git] / dali / internal / event / common / type-registry-impl.h
1 #ifndef DALI_INTERNAL_TYPE_REGISTRY_H
2 #define DALI_INTERNAL_TYPE_REGISTRY_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 // INTERNAL INCLUDES
22 #include <dali/devel-api/object/csharp-type-info.h>
23 #include <dali/internal/event/common/type-info-impl.h>
24 #include <dali/internal/event/object/default-property-metadata.h>
25 #include <dali/public-api/object/base-handle.h>
26 #include <dali/public-api/object/base-object.h>
27 #include <dali/public-api/object/type-registry.h>
28
29 namespace Dali
30 {
31 namespace Internal
32 {
33 class PropertyDetails;
34
35 /*
36 * @copydoc Dali::TypeRegistry
37 */
38 class TypeRegistry : public Dali::BaseObject
39 {
40 public:
41   // using intrusive pointer instead of handles internally as they are considerably cheaper
42   using TypeInfoPointer = IntrusivePtr<Dali::Internal::TypeInfo>;
43
44   /**
45    * Get the TypeRegistry
46    */
47   static TypeRegistry* Get();
48
49   /**
50    * @copydoc Dali::TypeRegistry::GetTypeInfo
51    */
52   TypeInfoPointer GetTypeInfo(const std::string& uniqueTypeName);
53
54   /**
55    * @copydoc Dali::TypeRegistry::GetTypeInfo
56    */
57   TypeInfoPointer GetTypeInfo(const std::type_info& registerType);
58
59   /**
60    * @copydoc Dali::TypeRegistry::GetTypeNameCount
61    */
62   uint32_t GetTypeNameCount() const;
63
64   /**
65    * @copydoc Dali::TypeRegistry::GetTypeName
66    */
67   const std::string& GetTypeName(uint32_t index) const;
68
69   /**
70    * Register a type
71    *
72    * @param [in] theTypeInfo Type info for the type to be registered
73    * @param [in] baseTypeInfo Type info for its base class
74    * @param [in] createInstance Instance creation function
75    * @param [in] callCreateOnInit If true call createInstance on DALi initialisation
76    * @return the name of the registered type.
77    */
78   std::string Register(const std::type_info& theTypeInfo, const std::type_info& baseTypeInfo, Dali::TypeInfo::CreateFunction createInstance, bool callCreateOnInit);
79
80   /**
81    * Register a type
82    *
83    * @param [in] theTypeInfo Type info for the type to be registered
84    * @param [in] baseTypeInfo Type info for its base class
85    * @param [in] createInstance Instance creation function
86    * @param [in] callCreateOnInit If true call createInstance on DALi initialisation
87    * @param [in] defaultProperties the table of default property metadata
88    * @param [in] defaultPropertyCount count of default properties
89    * @return the name of the registered type.
90    */
91   std::string Register(const std::type_info& theTypeInfo, const std::type_info& baseTypeInfo, Dali::TypeInfo::CreateFunction createInstance, bool callCreateOnInit, const Dali::PropertyDetails* defaultProperties, Property::Index defaultPropertyCount);
92
93   /**
94    * Register a type
95    *
96    * @param [in] theTypeInfo Type info for the type to be registered
97    * @param [in] baseTypeInfo Type info for its base class
98    * @param [in] createInstance Instance creation function
99    * @param [in] callCreateOnInit If true call createInstance on DALi initialisation
100    * @param [in] defaultProperties the table of default property metadata
101    * @param [in] defaultPropertyCount count of default properties
102    * @return the name of the registered type.
103    */
104   std::string Register(std::string name, const std::type_info& baseTypeInfo, Dali::TypeInfo::CreateFunction createInstance, bool callCreateOnInit, const Dali::PropertyDetails* defaultProperties = nullptr, Property::Index defaultPropertyCount = 0);
105
106   /**
107    * @copydoc CSharpTypeRegistry::TypeRegistration( const std::string&, const std::type_info&, TypeInfo::CreateFunction );
108    */
109   void Register(std::string name, const std::type_info& baseTypeInfo, Dali::CSharpTypeInfo::CreateFunction createInstance);
110
111   /**
112    * Register a signal connector function to a type
113    * @param [in] typeRegistration TypeRegistration object used to register the type
114    * @param [in] name Signal name
115    * @param [in] func Signal connector function
116    */
117   void RegisterSignal(TypeRegistration& typeRegistration, std::string name, Dali::TypeInfo::SignalConnectorFunction func);
118
119   /**
120    * Register an action function to a type
121    * @param [in] registered TypeRegistration object used to register the type
122    * @param [in] name Action name
123    * @param [in] f Action function
124    * @return true if registered
125    */
126   bool RegisterAction(TypeRegistration& registered, std::string name, Dali::TypeInfo::ActionFunction f);
127
128   /**
129    * Register an event-thread only property with a type
130    * @param [in] registered TypeRegistration object used to register the type
131    * @param [in] name Property name
132    * @param [in] index Property index
133    * @param [in] type Property type
134    * @param [in] setFunc The function to set the property (Can be NULL).
135    * @param [in] getFunc The function to get the value of a property.
136    * @return true if registered
137    */
138   bool RegisterProperty(TypeRegistration& registered, std::string name, Property::Index index, Property::Type type, Dali::TypeInfo::SetPropertyFunction setFunc, Dali::TypeInfo::GetPropertyFunction getFunc);
139
140   /**
141    * Register an event-thread only property with a type (used by C# Custom controls)
142    * @param [in] objectName name of the object used to register the type
143    * @param [in] name Property name
144    * @param [in] index Property index
145    * @param [in] type Property type
146    * @param [in] setFunc The function to set the property (Can be NULL).
147    * @param [in] getFunc The function to get the value of a property.
148    * @return true if registered
149    */
150   bool RegisterProperty(const std::string& objectName, std::string name, Property::Index index, Property::Type type, Dali::CSharpTypeInfo::SetPropertyFunction setFunc, Dali::CSharpTypeInfo::GetPropertyFunction getFunc);
151
152   /**
153    * Register a scene graph only property with a type
154    * @param [in] registered TypeRegistration object used to register the type
155    * @param [in] name Property name
156    * @param [in] index Property index
157    * @param [in] type Property type
158    * @return true if registered
159    */
160   bool RegisterAnimatableProperty(TypeRegistration& registered, std::string name, Property::Index index, Property::Type type);
161
162   /**
163    * Register a scene graph only property with a default value
164    * @param [in] registered TypeRegistration object used to register the type
165    * @param [in] name Property name
166    * @param [in] index Property index
167    * @param [in] value Property default value
168    * @return true if registered
169    */
170   bool RegisterAnimatableProperty(TypeRegistration& registered, std::string name, Property::Index index, Property::Value defaultValue);
171
172   /**
173    * Register a component of a scene graph only property that supports components (i.e. Vector2, Vector3 and Vector4)
174    * @param [in] registered TypeRegistration object used to register the type
175    * @param [in] name Component name
176    * @param [in] index Property index
177    * @param [in] baseIndex Base animatable property index
178    * @param [in] componentIndex Component index
179    * @return true if registered
180    */
181   bool RegisterAnimatablePropertyComponent(TypeRegistration& registered, std::string name, Property::Index index, Property::Index baseIndex, unsigned int componentIndex);
182
183   /**
184    * Register a event-thread only property with a type and a default value
185    * @param [in] registeredType Name of a registered type on which to register the child property.
186    * @param [in] name Property name
187    * @param [in] index Property index
188    * @param [in] type Property type
189    * @return true if registered
190    */
191   bool RegisterChildProperty(const std::string& registeredType, std::string name, Property::Index index, Property::Type type);
192
193   /**
194    * Register a event-thread only property with a type and a default value
195    * @param [in] registered TypeRegistration object used to register the type
196    * @param [in] name Property name
197    * @param [in] index Property index
198    * @param [in] type Property type
199    * @return true if registered
200    */
201   bool RegisterChildProperty(TypeRegistration& registered, std::string name, Property::Index index, Property::Type type);
202
203   /**
204    * @copydoc Dali::Internal::TypeInfo::DoActionTo
205    * Walks all base types until it finds a doer.
206    */
207   bool DoActionTo(BaseObject* const object, const std::string& actionName, const Property::Map& properties);
208
209   /**
210    * @copydoc Dali::BaseHandle::ConnectSignal()
211    */
212   bool ConnectSignal(BaseObject* object, ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor);
213
214   /**
215    * Return the type info for a given BaseObject pointer
216    * @param [in] pBaseObject Pointer to a BaseObject
217    * @return TypeInfo for the BaseObject.
218    */
219   TypeInfoPointer GetTypeInfo(const Dali::BaseObject* const pBaseObject);
220
221   /**
222    * Calls any type creation functions that have been flagged as initialization functions
223    */
224   void CallInitFunctions(void) const;
225
226 public:
227   /*
228    * Return the name derived from type_info used to register the type
229    * @param [in] registerType Type info for the type to be registered
230    * @return registered name
231    */
232   static std::string RegistrationName(const std::type_info& registerType);
233
234 private:
235   /*
236    * Mapping from type name to TypeInfo
237    */
238   std::vector<TypeInfoPointer> mRegistryLut;
239
240   std::vector<Dali::TypeInfo::CreateFunction> mInitFunctions;
241
242 private:
243   TypeRegistry();
244   ~TypeRegistry() override;
245
246   /**
247    * @brief Undefined Copy Constructor
248    */
249   TypeRegistry(TypeRegistry&);
250
251   /**
252    * @brief Undefined Assignment Operator
253    */
254   TypeRegistry& operator=(const TypeRegistry&);
255 };
256
257 } // namespace Internal
258
259 // Helpers for public-api forwarding methods
260
261 inline Internal::TypeRegistry& GetImplementation(Dali::TypeRegistry& typeRegistry)
262 {
263   DALI_ASSERT_ALWAYS(typeRegistry);
264
265   BaseObject& handle = typeRegistry.GetBaseObject();
266
267   return static_cast<Internal::TypeRegistry&>(handle);
268 }
269
270 inline const Internal::TypeRegistry& GetImplementation(const Dali::TypeRegistry& typeRegistry)
271 {
272   DALI_ASSERT_ALWAYS(typeRegistry);
273
274   const BaseObject& handle = typeRegistry.GetBaseObject();
275
276   return static_cast<const Internal::TypeRegistry&>(handle);
277 }
278
279 } // namespace Dali
280
281 #endif // DALI_INTERNAL_TYPE_REGISTRY_H