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