Merge "Enabling animation of Renderer properties when offstage" 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) 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    * @return true if the name could be registered.
97    */
98   bool Register( const std::string& name, const std::type_info& baseTypeInfo,
99                  Dali::CSharpTypeInfo::CreateFunction createInstance );
100
101   /*
102    * Register a signal connector function to a type
103    * @param [in] typeRegistration TypeRegistration object used to register the type
104    * @param [in] name Signal name
105    * @param [in] func Signal connector function
106    */
107   void RegisterSignal( TypeRegistration& typeRegistration, const std::string& name, Dali::TypeInfo::SignalConnectorFunction func );
108
109   /*
110    * Register an action function to a type
111    * @param [in] registered TypeRegistration object used to register the type
112    * @param [in] name Action name
113    * @param [in] f Action function
114    * @return true if registered
115    */
116   bool RegisterAction( TypeRegistration &registered, const std::string &name, Dali::TypeInfo::ActionFunction f);
117
118   /**
119    * Register an event-thread only property with a type
120    * @param [in] registered TypeRegistration object used to register the type
121    * @param [in] name Property name
122    * @param [in] index Property index
123    * @param [in] type Property type
124    * @param [in] setFunc The function to set the property (Can be NULL).
125    * @param [in] getFunc The function to get the value of a property.
126    * @return true if registered
127    */
128   bool RegisterProperty( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Type type, Dali::TypeInfo::SetPropertyFunction setFunc, Dali::TypeInfo::GetPropertyFunction getFunc );
129
130   /**
131    * Register an event-thread only property with a type (used by C# Custom controls)
132    * @param [in] objectName name of the object used to register the type
133    * @param [in] name Property name
134    * @param [in] index Property index
135    * @param [in] type Property type
136    * @param [in] setFunc The function to set the property (Can be NULL).
137    * @param [in] getFunc The function to get the value of a property.
138    * @return true if registered
139    */
140   bool RegisterProperty( const std::string& objectName, const std::string& name, Property::Index index, Property::Type type, Dali::CSharpTypeInfo::SetPropertyFunction setFunc, Dali::CSharpTypeInfo::GetPropertyFunction getFunc );
141
142
143   /**
144    * Register a scene graph only property with a type
145    * @param [in] registered TypeRegistration object used to register the type
146    * @param [in] name Property name
147    * @param [in] index Property index
148    * @param [in] type Property type
149    * @return true if registered
150    */
151   bool RegisterAnimatableProperty( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Type type );
152
153   /**
154    * Register a scene graph only property with a default value
155    * @param [in] registered TypeRegistration object used to register the type
156    * @param [in] name Property name
157    * @param [in] index Property index
158    * @param [in] value Property default value
159    * @return true if registered
160    */
161   bool RegisterAnimatableProperty( TypeRegistration& registered, const std::string& name, Property::Index index, const Property::Value& defaultValue );
162
163   /**
164    * Register a component of a scene graph only property that supports components (i.e. Vector2, Vector3 and Vector4)
165    * @param [in] registered TypeRegistration object used to register the type
166    * @param [in] name Component name
167    * @param [in] index Property index
168    * @param [in] baseIndex Base animatable property index
169    * @param [in] componentIndex Component index
170    * @return true if registered
171    */
172   bool RegisterAnimatablePropertyComponent( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Index baseIndex, unsigned int componentIndex );
173
174   /**
175    * Register a event-thread only property with a type and a default value
176    * @param [in] registered TypeRegistration object used to register the type
177    * @param [in] name Property name
178    * @param [in] index Property index
179    * @param [in] type Property type
180    * @return true if registered
181    */
182   bool RegisterChildProperty( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Type type );
183
184   /*
185    * @copydoc Dali::Internal::TypeInfo::DoActionTo
186    * Walks all base types until it finds a doer.
187    */
188   bool DoActionTo( BaseObject * const object, const std::string &actionName, const Property::Map& properties);
189
190   /**
191    * @copydoc Dali::BaseHandle::ConnectSignal()
192    */
193   bool ConnectSignal( BaseObject* object, ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor );
194
195   /*
196    * Return the type info for a given BaseObject pointer
197    * @param [in] pBaseObject Pointer to a BaseObject
198    * @return TypeInfo for the BaseObject.
199    */
200   Dali::TypeInfo GetTypeInfo(const Dali::BaseObject * const pBaseObject);
201
202   /*
203    * Calls any type creation functions that have been flagged as initialization functions
204    */
205   void CallInitFunctions(void) const;
206
207 public:
208
209   /*
210    * Return the name derived from type_info used to register the type
211    * @param [in] registerType Type info for the type to be registered
212    * @return registered name
213    */
214   static std::string RegistrationName( const std::type_info& registerType );
215
216 private:
217   /*
218    * Map from type name to TypeInfo
219    */
220   typedef std::map<std::string, Dali::TypeInfo> RegistryMap;
221   RegistryMap mRegistryLut;
222
223   typedef std::vector<Dali::TypeInfo::CreateFunction> InitFunctions;
224   InitFunctions mInitFunctions;
225
226 private:
227   TypeRegistry();
228   ~TypeRegistry();
229
230   /**
231    * @brief Undefined Copy Constructor
232    */
233   TypeRegistry(TypeRegistry &);
234
235   /**
236    * @brief Undefined Assignment Operator
237    */
238   TypeRegistry& operator=(const TypeRegistry &);
239 };
240
241
242 } // namespace Internal
243
244 // Helpers for public-api forwarding methods
245
246 inline Internal::TypeRegistry& GetImplementation(Dali::TypeRegistry& typeRegistry)
247 {
248   DALI_ASSERT_ALWAYS(typeRegistry);
249
250   BaseObject& handle = typeRegistry.GetBaseObject();
251
252   return static_cast<Internal::TypeRegistry&>(handle);
253 }
254
255 inline const Internal::TypeRegistry& GetImplementation(const Dali::TypeRegistry& typeRegistry)
256 {
257   DALI_ASSERT_ALWAYS(typeRegistry);
258
259   const BaseObject& handle = typeRegistry.GetBaseObject();
260
261   return static_cast<const Internal::TypeRegistry&>(handle);
262 }
263
264 } // namespace Dali
265
266 #endif // __DALI_INTERNAL_TYPE_REGISTRY_H__