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