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