2368d578b31ce0c6c03fbce45fadf6ba00b5b1f2
[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) 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 // 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    * Get the TypeRegistry
45    */
46   static TypeRegistry *Get();
47
48   /**
49    * @copydoc Dali::TypeRegistry::GetTypeInfo
50    */
51   Dali::TypeInfo GetTypeInfo( const std::string &uniqueTypeName );
52
53   /**
54    * @copydoc Dali::TypeRegistry::GetTypeInfo
55    */
56   Dali::TypeInfo GetTypeInfo( const std::type_info& registerType );
57
58   /**
59    * @copydoc Dali::TypeRegistry::GetTypeNameCount
60    */
61   size_t GetTypeNameCount() const;
62
63   /**
64    * @copydoc Dali::TypeRegistry::GetTypeName
65    */
66   std::string GetTypeName(size_t index) const;
67
68   /**
69    * Register a type
70    *
71    * @param [in] theTypeInfo Type info for the type to be registered
72    * @param [in] baseTypeInfo Type info for its base class
73    * @param [in] createInstance Instance creation function
74    * @param [in] callCreateOnInit If true call createInstance on DALi initialisation
75    * @return the name of the registered type.
76    */
77   std::string Register( const std::type_info& theTypeInfo, const std::type_info& baseTypeInfo,
78                         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,
92                         Dali::TypeInfo::CreateFunction createInstance, bool callCreateOnInit,
93                         const Dali::PropertyDetails* defaultProperties, Property::Index defaultPropertyCount );
94
95   /**
96    * Register a type
97    *
98    * @param [in] theTypeInfo Type info for the type to be registered
99    * @param [in] baseTypeInfo Type info for its base class
100    * @param [in] createInstance Instance creation function
101    * @param [in] callCreateOnInit If true call createInstance on DALi initialisation
102    * @param [in] defaultProperties the table of default property metadata
103    * @param [in] defaultPropertyCount count of default properties
104    * @return the name of the registered type.
105    */
106   std::string Register( const std::string& name, const std::type_info& baseTypeInfo,
107                         Dali::TypeInfo::CreateFunction createInstance, bool callCreateOnInit,
108                         const Dali::PropertyDetails* defaultProperties = nullptr, Property::Index defaultPropertyCount = 0 );
109
110   /**
111    * @copydoc CSharpTypeRegistry::TypeRegistration( const std::string&, const std::type_info&, TypeInfo::CreateFunction );
112    */
113   void Register( const std::string& name, const std::type_info& baseTypeInfo,
114                  Dali::CSharpTypeInfo::CreateFunction createInstance );
115
116   /**
117    * Register a signal connector function to a type
118    * @param [in] typeRegistration TypeRegistration object used to register the type
119    * @param [in] name Signal name
120    * @param [in] func Signal connector function
121    */
122   void RegisterSignal( TypeRegistration& typeRegistration, const std::string& name, Dali::TypeInfo::SignalConnectorFunction func );
123
124   /**
125    * Register an action function to a type
126    * @param [in] registered TypeRegistration object used to register the type
127    * @param [in] name Action name
128    * @param [in] f Action function
129    * @return true if registered
130    */
131   bool RegisterAction( TypeRegistration& registered, const std::string& name, Dali::TypeInfo::ActionFunction f );
132
133   /**
134    * Register an event-thread only property with a type
135    * @param [in] registered TypeRegistration object used to register the type
136    * @param [in] name Property name
137    * @param [in] index Property index
138    * @param [in] type Property type
139    * @param [in] setFunc The function to set the property (Can be NULL).
140    * @param [in] getFunc The function to get the value of a property.
141    * @return true if registered
142    */
143   bool RegisterProperty( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Type type, Dali::TypeInfo::SetPropertyFunction setFunc, Dali::TypeInfo::GetPropertyFunction getFunc );
144
145   /**
146    * Register an event-thread only property with a type (used by C# Custom controls)
147    * @param [in] objectName name of the object used to register the type
148    * @param [in] name Property name
149    * @param [in] index Property index
150    * @param [in] type Property type
151    * @param [in] setFunc The function to set the property (Can be NULL).
152    * @param [in] getFunc The function to get the value of a property.
153    * @return true if registered
154    */
155   bool RegisterProperty( const std::string& objectName, const std::string& name, Property::Index index, Property::Type type, Dali::CSharpTypeInfo::SetPropertyFunction setFunc, Dali::CSharpTypeInfo::GetPropertyFunction getFunc );
156
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, const 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, const std::string& name, Property::Index index, const 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, const 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, const 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, const 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   Dali::TypeInfo 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< Dali::TypeInfo > mRegistryLut;
246
247   std::vector< Dali::TypeInfo::CreateFunction > mInitFunctions;
248
249 private:
250   TypeRegistry();
251   ~TypeRegistry();
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__