1 #ifndef DALI_INTERNAL_TYPE_REGISTRY_H
2 #define DALI_INTERNAL_TYPE_REGISTRY_H
5 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
34 class PropertyDetails;
37 * @copydoc Dali::TypeRegistry
39 class TypeRegistry : public Dali::BaseObject
42 // using intrusive pointer instead of handles internally as they are considerably cheaper
43 using TypeInfoPointer = IntrusivePtr<Dali::Internal::TypeInfo>;
46 * Get the TypeRegistry
48 static TypeRegistry* Get();
51 * @copydoc Dali::TypeRegistry::GetTypeInfo
53 TypeInfoPointer GetTypeInfo(const std::string& uniqueTypeName);
56 * @copydoc Dali::TypeRegistry::GetTypeInfo
58 TypeInfoPointer GetTypeInfo(const std::type_info& registerType);
61 * @copydoc Dali::TypeRegistry::GetTypeNameCount
63 uint32_t GetTypeNameCount() const;
66 * @copydoc Dali::TypeRegistry::GetTypeName
68 const std::string& GetTypeName(uint32_t index) const;
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.
79 std::string Register(const std::type_info& theTypeInfo, const std::type_info& baseTypeInfo, Dali::TypeInfo::CreateFunction createInstance, bool callCreateOnInit);
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.
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);
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.
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);
108 * @copydoc CSharpTypeRegistry::TypeRegistration( const std::string&, const std::type_info&, TypeInfo::CreateFunction );
110 void Register(std::string name, const std::type_info& baseTypeInfo, Dali::CSharpTypeInfo::CreateFunction createInstance);
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
118 void RegisterSignal(TypeRegistration& typeRegistration, std::string name, Dali::TypeInfo::SignalConnectorFunction func);
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
127 bool RegisterAction(TypeRegistration& registered, std::string name, Dali::TypeInfo::ActionFunction f);
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
139 bool RegisterProperty(TypeRegistration& registered, std::string name, Property::Index index, Property::Type type, Dali::TypeInfo::SetPropertyFunction setFunc, Dali::TypeInfo::GetPropertyFunction getFunc);
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
151 bool RegisterProperty(const std::string& objectName, std::string name, Property::Index index, Property::Type type, Dali::CSharpTypeInfo::SetPropertyFunction setFunc, Dali::CSharpTypeInfo::GetPropertyFunction getFunc);
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
161 bool RegisterAnimatableProperty(TypeRegistration& registered, std::string name, Property::Index index, Property::Type type);
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
171 bool RegisterAnimatableProperty(TypeRegistration& registered, std::string name, Property::Index index, Property::Value defaultValue);
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
182 bool RegisterAnimatablePropertyComponent(TypeRegistration& registered, std::string name, Property::Index index, Property::Index baseIndex, unsigned int componentIndex);
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
192 bool RegisterChildProperty(const std::string& registeredType, std::string name, Property::Index index, Property::Type type);
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
202 bool RegisterChildProperty(TypeRegistration& registered, std::string name, Property::Index index, Property::Type type);
205 * @copydoc Dali::Internal::TypeInfo::DoActionTo
206 * Walks all base types until it finds a doer.
208 bool DoActionTo(BaseObject* const object, const std::string& actionName, const Property::Map& properties);
211 * @copydoc Dali::BaseHandle::ConnectSignal()
213 bool ConnectSignal(BaseObject* object, ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor);
216 * Return the type info for a given BaseObject pointer
217 * @param [in] pBaseObject Pointer to a BaseObject
218 * @return TypeInfo for the BaseObject.
220 TypeInfoPointer GetTypeInfo(const Dali::BaseObject* const pBaseObject);
223 * Calls any type creation functions that have been flagged as initialization functions
225 void CallInitFunctions(void) const;
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
233 static std::string RegistrationName(const std::type_info& registerType);
237 * Mapping from type name to TypeInfo
239 Dali::Internal::IndexedConstStringMap<TypeInfoPointer> mRegistryLut;
241 std::vector<Dali::TypeInfo::CreateFunction> mInitFunctions;
245 ~TypeRegistry() override;
248 * @brief Undefined Copy Constructor
250 TypeRegistry(TypeRegistry&);
253 * @brief Undefined Assignment Operator
255 TypeRegistry& operator=(const TypeRegistry&);
258 } // namespace Internal
260 // Helpers for public-api forwarding methods
262 inline Internal::TypeRegistry& GetImplementation(Dali::TypeRegistry& typeRegistry)
264 DALI_ASSERT_ALWAYS(typeRegistry);
266 BaseObject& handle = typeRegistry.GetBaseObject();
268 return static_cast<Internal::TypeRegistry&>(handle);
271 inline const Internal::TypeRegistry& GetImplementation(const Dali::TypeRegistry& typeRegistry)
273 DALI_ASSERT_ALWAYS(typeRegistry);
275 const BaseObject& handle = typeRegistry.GetBaseObject();
277 return static_cast<const Internal::TypeRegistry&>(handle);
282 #endif // DALI_INTERNAL_TYPE_REGISTRY_H