1 #ifndef DALI_INTERNAL_TYPE_REGISTRY_H
2 #define DALI_INTERNAL_TYPE_REGISTRY_H
5 * Copyright (c) 2021 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/event/common/type-info-impl.h>
24 #include <dali/internal/event/object/default-property-metadata.h>
25 #include <dali/public-api/object/base-handle.h>
26 #include <dali/public-api/object/base-object.h>
27 #include <dali/public-api/object/type-registry.h>
33 class PropertyDetails;
36 * @copydoc Dali::TypeRegistry
38 class TypeRegistry : public Dali::BaseObject
41 // using intrusive pointer instead of handles internally as they are considerably cheaper
42 using TypeInfoPointer = IntrusivePtr<Dali::Internal::TypeInfo>;
45 * Get the TypeRegistry
47 static TypeRegistry* Get();
50 * @copydoc Dali::TypeRegistry::GetTypeInfo
52 TypeInfoPointer GetTypeInfo(const std::string& uniqueTypeName);
55 * @copydoc Dali::TypeRegistry::GetTypeInfo
57 TypeInfoPointer GetTypeInfo(const std::type_info& registerType);
60 * @copydoc Dali::TypeRegistry::GetTypeNameCount
62 uint32_t GetTypeNameCount() const;
65 * @copydoc Dali::TypeRegistry::GetTypeName
67 const std::string& GetTypeName(uint32_t index) const;
72 * @param [in] theTypeInfo Type info for the type to be registered
73 * @param [in] baseTypeInfo Type info for its base class
74 * @param [in] createInstance Instance creation function
75 * @param [in] callCreateOnInit If true call createInstance on DALi initialisation
76 * @return the name of the registered type.
78 std::string Register(const std::type_info& theTypeInfo, const std::type_info& baseTypeInfo, Dali::TypeInfo::CreateFunction createInstance, bool callCreateOnInit);
83 * @param [in] theTypeInfo Type info for the type to be registered
84 * @param [in] baseTypeInfo Type info for its base class
85 * @param [in] createInstance Instance creation function
86 * @param [in] callCreateOnInit If true call createInstance on DALi initialisation
87 * @param [in] defaultProperties the table of default property metadata
88 * @param [in] defaultPropertyCount count of default properties
89 * @return the name of the registered type.
91 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);
96 * @param [in] theTypeInfo Type info for the type to be registered
97 * @param [in] baseTypeInfo Type info for its base class
98 * @param [in] createInstance Instance creation function
99 * @param [in] callCreateOnInit If true call createInstance on DALi initialisation
100 * @param [in] defaultProperties the table of default property metadata
101 * @param [in] defaultPropertyCount count of default properties
102 * @return the name of the registered type.
104 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);
107 * @copydoc CSharpTypeRegistry::TypeRegistration( const std::string&, const std::type_info&, TypeInfo::CreateFunction );
109 void Register(std::string name, const std::type_info& baseTypeInfo, Dali::CSharpTypeInfo::CreateFunction createInstance);
112 * Register a signal connector function to a type
113 * @param [in] typeRegistration TypeRegistration object used to register the type
114 * @param [in] name Signal name
115 * @param [in] func Signal connector function
117 void RegisterSignal(TypeRegistration& typeRegistration, std::string name, Dali::TypeInfo::SignalConnectorFunction func);
120 * Register an action function to a type
121 * @param [in] registered TypeRegistration object used to register the type
122 * @param [in] name Action name
123 * @param [in] f Action function
124 * @return true if registered
126 bool RegisterAction(TypeRegistration& registered, std::string name, Dali::TypeInfo::ActionFunction f);
129 * Register an event-thread only property with a type
130 * @param [in] registered TypeRegistration object used to register the type
131 * @param [in] name Property name
132 * @param [in] index Property index
133 * @param [in] type Property type
134 * @param [in] setFunc The function to set the property (Can be NULL).
135 * @param [in] getFunc The function to get the value of a property.
136 * @return true if registered
138 bool RegisterProperty(TypeRegistration& registered, std::string name, Property::Index index, Property::Type type, Dali::TypeInfo::SetPropertyFunction setFunc, Dali::TypeInfo::GetPropertyFunction getFunc);
141 * Register an event-thread only property with a type (used by C# Custom controls)
142 * @param [in] objectName name of the object used to register the type
143 * @param [in] name Property name
144 * @param [in] index Property index
145 * @param [in] type Property type
146 * @param [in] setFunc The function to set the property (Can be NULL).
147 * @param [in] getFunc The function to get the value of a property.
148 * @return true if registered
150 bool RegisterProperty(const std::string& objectName, std::string name, Property::Index index, Property::Type type, Dali::CSharpTypeInfo::SetPropertyFunction setFunc, Dali::CSharpTypeInfo::GetPropertyFunction getFunc);
153 * Register a scene graph only property with a type
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] type Property type
158 * @return true if registered
160 bool RegisterAnimatableProperty(TypeRegistration& registered, std::string name, Property::Index index, Property::Type type);
163 * Register a scene graph only property with a default value
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] value Property default value
168 * @return true if registered
170 bool RegisterAnimatableProperty(TypeRegistration& registered, std::string name, Property::Index index, Property::Value defaultValue);
173 * Register a component of a scene graph only property that supports components (i.e. Vector2, Vector3 and Vector4)
174 * @param [in] registered TypeRegistration object used to register the type
175 * @param [in] name Component name
176 * @param [in] index Property index
177 * @param [in] baseIndex Base animatable property index
178 * @param [in] componentIndex Component index
179 * @return true if registered
181 bool RegisterAnimatablePropertyComponent(TypeRegistration& registered, std::string name, Property::Index index, Property::Index baseIndex, unsigned int componentIndex);
184 * Register a event-thread only property with a type and a default value
185 * @param [in] registeredType Name of a registered type on which to register the child property.
186 * @param [in] name Property name
187 * @param [in] index Property index
188 * @param [in] type Property type
189 * @return true if registered
191 bool RegisterChildProperty(const std::string& registeredType, std::string name, Property::Index index, Property::Type type);
194 * Register a event-thread only property with a type and a default value
195 * @param [in] registered TypeRegistration object used to register the type
196 * @param [in] name Property name
197 * @param [in] index Property index
198 * @param [in] type Property type
199 * @return true if registered
201 bool RegisterChildProperty(TypeRegistration& registered, std::string name, Property::Index index, Property::Type type);
204 * @copydoc Dali::Internal::TypeInfo::DoActionTo
205 * Walks all base types until it finds a doer.
207 bool DoActionTo(BaseObject* const object, const std::string& actionName, const Property::Map& properties);
210 * @copydoc Dali::BaseHandle::ConnectSignal()
212 bool ConnectSignal(BaseObject* object, ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor);
215 * Return the type info for a given BaseObject pointer
216 * @param [in] pBaseObject Pointer to a BaseObject
217 * @return TypeInfo for the BaseObject.
219 TypeInfoPointer GetTypeInfo(const Dali::BaseObject* const pBaseObject);
222 * Calls any type creation functions that have been flagged as initialization functions
224 void CallInitFunctions(void) const;
228 * Return the name derived from type_info used to register the type
229 * @param [in] registerType Type info for the type to be registered
230 * @return registered name
232 static std::string RegistrationName(const std::type_info& registerType);
236 * Mapping from type name to TypeInfo
238 std::vector<TypeInfoPointer> mRegistryLut;
240 std::vector<Dali::TypeInfo::CreateFunction> mInitFunctions;
244 ~TypeRegistry() override;
247 * @brief Undefined Copy Constructor
249 TypeRegistry(TypeRegistry&);
252 * @brief Undefined Assignment Operator
254 TypeRegistry& operator=(const TypeRegistry&);
257 } // namespace Internal
259 // Helpers for public-api forwarding methods
261 inline Internal::TypeRegistry& GetImplementation(Dali::TypeRegistry& typeRegistry)
263 DALI_ASSERT_ALWAYS(typeRegistry);
265 BaseObject& handle = typeRegistry.GetBaseObject();
267 return static_cast<Internal::TypeRegistry&>(handle);
270 inline const Internal::TypeRegistry& GetImplementation(const Dali::TypeRegistry& typeRegistry)
272 DALI_ASSERT_ALWAYS(typeRegistry);
274 const BaseObject& handle = typeRegistry.GetBaseObject();
276 return static_cast<const Internal::TypeRegistry&>(handle);
281 #endif // DALI_INTERNAL_TYPE_REGISTRY_H