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