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