Purge underscored header file barriers
[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) 2019 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   // using intrusive pointer instead of handles internally as they are considerably cheaper
45   using TypeInfoPointer = IntrusivePtr<Dali::Internal::TypeInfo>;
46
47   /**
48    * Get the TypeRegistry
49    */
50   static TypeRegistry *Get();
51
52   /**
53    * @copydoc Dali::TypeRegistry::GetTypeInfo
54    */
55   TypeInfoPointer GetTypeInfo( const std::string &uniqueTypeName );
56
57   /**
58    * @copydoc Dali::TypeRegistry::GetTypeInfo
59    */
60   TypeInfoPointer GetTypeInfo( const std::type_info& registerType );
61
62   /**
63    * @copydoc Dali::TypeRegistry::GetTypeNameCount
64    */
65   uint32_t GetTypeNameCount() const;
66
67   /**
68    * @copydoc Dali::TypeRegistry::GetTypeName
69    */
70   std::string GetTypeName( uint32_t index ) const;
71
72   /**
73    * Register a type
74    *
75    * @param [in] theTypeInfo Type info for the type to be registered
76    * @param [in] baseTypeInfo Type info for its base class
77    * @param [in] createInstance Instance creation function
78    * @param [in] callCreateOnInit If true call createInstance on DALi initialisation
79    * @return the name of the registered type.
80    */
81   std::string Register( const std::type_info& theTypeInfo, const std::type_info& baseTypeInfo,
82                         Dali::TypeInfo::CreateFunction createInstance, bool callCreateOnInit );
83
84   /**
85    * Register a type
86    *
87    * @param [in] theTypeInfo Type info for the type to be registered
88    * @param [in] baseTypeInfo Type info for its base class
89    * @param [in] createInstance Instance creation function
90    * @param [in] callCreateOnInit If true call createInstance on DALi initialisation
91    * @param [in] defaultProperties the table of default property metadata
92    * @param [in] defaultPropertyCount count of default properties
93    * @return the name of the registered type.
94    */
95   std::string Register( const std::type_info& theTypeInfo, const std::type_info& baseTypeInfo,
96                         Dali::TypeInfo::CreateFunction createInstance, bool callCreateOnInit,
97                         const Dali::PropertyDetails* defaultProperties, Property::Index defaultPropertyCount );
98
99   /**
100    * Register a type
101    *
102    * @param [in] theTypeInfo Type info for the type to be registered
103    * @param [in] baseTypeInfo Type info for its base class
104    * @param [in] createInstance Instance creation function
105    * @param [in] callCreateOnInit If true call createInstance on DALi initialisation
106    * @param [in] defaultProperties the table of default property metadata
107    * @param [in] defaultPropertyCount count of default properties
108    * @return the name of the registered type.
109    */
110   std::string Register( const std::string& name, const std::type_info& baseTypeInfo,
111                         Dali::TypeInfo::CreateFunction createInstance, bool callCreateOnInit,
112                         const Dali::PropertyDetails* defaultProperties = nullptr, Property::Index defaultPropertyCount = 0 );
113
114   /**
115    * @copydoc CSharpTypeRegistry::TypeRegistration( const std::string&, const std::type_info&, TypeInfo::CreateFunction );
116    */
117   void Register( const std::string& name, const std::type_info& baseTypeInfo,
118                  Dali::CSharpTypeInfo::CreateFunction createInstance );
119
120   /**
121    * Register a signal connector function to a type
122    * @param [in] typeRegistration TypeRegistration object used to register the type
123    * @param [in] name Signal name
124    * @param [in] func Signal connector function
125    */
126   void RegisterSignal( TypeRegistration& typeRegistration, const std::string& name, Dali::TypeInfo::SignalConnectorFunction func );
127
128   /**
129    * Register an action function to a type
130    * @param [in] registered TypeRegistration object used to register the type
131    * @param [in] name Action name
132    * @param [in] f Action function
133    * @return true if registered
134    */
135   bool RegisterAction( TypeRegistration& registered, const std::string& name, Dali::TypeInfo::ActionFunction f );
136
137   /**
138    * Register an event-thread only property with a type
139    * @param [in] registered TypeRegistration object used to register the type
140    * @param [in] name Property name
141    * @param [in] index Property index
142    * @param [in] type Property type
143    * @param [in] setFunc The function to set the property (Can be NULL).
144    * @param [in] getFunc The function to get the value of a property.
145    * @return true if registered
146    */
147   bool RegisterProperty( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Type type, Dali::TypeInfo::SetPropertyFunction setFunc, Dali::TypeInfo::GetPropertyFunction getFunc );
148
149   /**
150    * Register an event-thread only property with a type (used by C# Custom controls)
151    * @param [in] objectName name of the object used to register the type
152    * @param [in] name Property name
153    * @param [in] index Property index
154    * @param [in] type Property type
155    * @param [in] setFunc The function to set the property (Can be NULL).
156    * @param [in] getFunc The function to get the value of a property.
157    * @return true if registered
158    */
159   bool RegisterProperty( const std::string& objectName, const std::string& name, Property::Index index, Property::Type type, Dali::CSharpTypeInfo::SetPropertyFunction setFunc, Dali::CSharpTypeInfo::GetPropertyFunction getFunc );
160
161
162   /**
163    * Register a scene graph only property with a type
164    * @param [in] registered TypeRegistration object used to register the type
165    * @param [in] name Property name
166    * @param [in] index Property index
167    * @param [in] type Property type
168    * @return true if registered
169    */
170   bool RegisterAnimatableProperty( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Type type );
171
172   /**
173    * Register a scene graph only property with a default value
174    * @param [in] registered TypeRegistration object used to register the type
175    * @param [in] name Property name
176    * @param [in] index Property index
177    * @param [in] value Property default value
178    * @return true if registered
179    */
180   bool RegisterAnimatableProperty( TypeRegistration& registered, const std::string& name, Property::Index index, const Property::Value& defaultValue );
181
182   /**
183    * Register a component of a scene graph only property that supports components (i.e. Vector2, Vector3 and Vector4)
184    * @param [in] registered TypeRegistration object used to register the type
185    * @param [in] name Component name
186    * @param [in] index Property index
187    * @param [in] baseIndex Base animatable property index
188    * @param [in] componentIndex Component index
189    * @return true if registered
190    */
191   bool RegisterAnimatablePropertyComponent( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Index baseIndex, unsigned int componentIndex );
192
193   /**
194    * Register a event-thread only property with a type and a default value
195    * @param [in] registeredType Name of a registered type on which to register the child property.
196    * @param [in] name Property name
197    * @param [in] index Property index
198    * @param [in] type Property type
199    * @return true if registered
200    */
201   bool RegisterChildProperty( const std::string& registeredType, const std::string& name, Property::Index index, Property::Type type );
202
203   /**
204    * Register a event-thread only property with a type and a default value
205    * @param [in] registered TypeRegistration object used to register the type
206    * @param [in] name Property name
207    * @param [in] index Property index
208    * @param [in] type Property type
209    * @return true if registered
210    */
211   bool RegisterChildProperty( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Type type );
212
213   /**
214    * @copydoc Dali::Internal::TypeInfo::DoActionTo
215    * Walks all base types until it finds a doer.
216    */
217   bool DoActionTo( BaseObject * const object, const std::string &actionName, const Property::Map& properties);
218
219   /**
220    * @copydoc Dali::BaseHandle::ConnectSignal()
221    */
222   bool ConnectSignal( BaseObject* object, ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor );
223
224   /**
225    * Return the type info for a given BaseObject pointer
226    * @param [in] pBaseObject Pointer to a BaseObject
227    * @return TypeInfo for the BaseObject.
228    */
229   TypeInfoPointer GetTypeInfo(const Dali::BaseObject * const pBaseObject);
230
231   /**
232    * Calls any type creation functions that have been flagged as initialization functions
233    */
234   void CallInitFunctions(void) const;
235
236 public:
237
238   /*
239    * Return the name derived from type_info used to register the type
240    * @param [in] registerType Type info for the type to be registered
241    * @return registered name
242    */
243   static std::string RegistrationName( const std::type_info& registerType );
244
245 private:
246   /*
247    * Mapping from type name to TypeInfo
248    */
249   std::vector< TypeInfoPointer > mRegistryLut;
250
251   std::vector< Dali::TypeInfo::CreateFunction > mInitFunctions;
252
253 private:
254   TypeRegistry();
255   ~TypeRegistry();
256
257   /**
258    * @brief Undefined Copy Constructor
259    */
260   TypeRegistry(TypeRegistry &);
261
262   /**
263    * @brief Undefined Assignment Operator
264    */
265   TypeRegistry& operator=(const TypeRegistry &);
266 };
267
268
269 } // namespace Internal
270
271 // Helpers for public-api forwarding methods
272
273 inline Internal::TypeRegistry& GetImplementation(Dali::TypeRegistry& typeRegistry)
274 {
275   DALI_ASSERT_ALWAYS(typeRegistry);
276
277   BaseObject& handle = typeRegistry.GetBaseObject();
278
279   return static_cast<Internal::TypeRegistry&>(handle);
280 }
281
282 inline const Internal::TypeRegistry& GetImplementation(const Dali::TypeRegistry& typeRegistry)
283 {
284   DALI_ASSERT_ALWAYS(typeRegistry);
285
286   const BaseObject& handle = typeRegistry.GetBaseObject();
287
288   return static_cast<const Internal::TypeRegistry&>(handle);
289 }
290
291 } // namespace Dali
292
293 #endif // DALI_INTERNAL_TYPE_REGISTRY_H