1 #ifndef DALI_INTERNAL_TYPE_REGISTRY_H
2 #define DALI_INTERNAL_TYPE_REGISTRY_H
5 * Copyright (c) 2019 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/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>
35 class PropertyDetails;
38 * @copydoc Dali::TypeRegistry
40 class TypeRegistry : public Dali::BaseObject
44 // using intrusive pointer instead of handles internally as they are considerably cheaper
45 using TypeInfoPointer = IntrusivePtr<Dali::Internal::TypeInfo>;
48 * Get the TypeRegistry
50 static TypeRegistry *Get();
53 * @copydoc Dali::TypeRegistry::GetTypeInfo
55 TypeInfoPointer GetTypeInfo( const std::string &uniqueTypeName );
58 * @copydoc Dali::TypeRegistry::GetTypeInfo
60 TypeInfoPointer GetTypeInfo( const std::type_info& registerType );
63 * @copydoc Dali::TypeRegistry::GetTypeNameCount
65 uint32_t GetTypeNameCount() const;
68 * @copydoc Dali::TypeRegistry::GetTypeName
70 const std::string& GetTypeName(uint32_t index) const;
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.
81 std::string Register( const std::type_info& theTypeInfo, const std::type_info& baseTypeInfo,
82 Dali::TypeInfo::CreateFunction createInstance, bool callCreateOnInit );
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.
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 );
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.
110 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);
113 * @copydoc CSharpTypeRegistry::TypeRegistration( const std::string&, const std::type_info&, TypeInfo::CreateFunction );
115 void Register(std::string name, const std::type_info& baseTypeInfo, Dali::CSharpTypeInfo::CreateFunction createInstance);
118 * Register a signal connector function to a type
119 * @param [in] typeRegistration TypeRegistration object used to register the type
120 * @param [in] name Signal name
121 * @param [in] func Signal connector function
123 void RegisterSignal(TypeRegistration& typeRegistration, std::string name, Dali::TypeInfo::SignalConnectorFunction func);
126 * Register an action function to a type
127 * @param [in] registered TypeRegistration object used to register the type
128 * @param [in] name Action name
129 * @param [in] f Action function
130 * @return true if registered
132 bool RegisterAction(TypeRegistration& registered, std::string name, Dali::TypeInfo::ActionFunction f);
135 * Register an event-thread only property with a type
136 * @param [in] registered TypeRegistration object used to register the type
137 * @param [in] name Property name
138 * @param [in] index Property index
139 * @param [in] type Property type
140 * @param [in] setFunc The function to set the property (Can be NULL).
141 * @param [in] getFunc The function to get the value of a property.
142 * @return true if registered
144 bool RegisterProperty(TypeRegistration& registered, std::string name, Property::Index index, Property::Type type, Dali::TypeInfo::SetPropertyFunction setFunc, Dali::TypeInfo::GetPropertyFunction getFunc);
147 * Register an event-thread only property with a type (used by C# Custom controls)
148 * @param [in] objectName name of the object used to register the type
149 * @param [in] name Property name
150 * @param [in] index Property index
151 * @param [in] type Property type
152 * @param [in] setFunc The function to set the property (Can be NULL).
153 * @param [in] getFunc The function to get the value of a property.
154 * @return true if registered
156 bool RegisterProperty(const std::string& objectName, std::string name, Property::Index index, Property::Type type, Dali::CSharpTypeInfo::SetPropertyFunction setFunc, Dali::CSharpTypeInfo::GetPropertyFunction getFunc);
159 * Register a scene graph only property with a type
160 * @param [in] registered TypeRegistration object used to register the type
161 * @param [in] name Property name
162 * @param [in] index Property index
163 * @param [in] type Property type
164 * @return true if registered
166 bool RegisterAnimatableProperty(TypeRegistration& registered, std::string name, Property::Index index, Property::Type type);
169 * Register a scene graph only property with a default value
170 * @param [in] registered TypeRegistration object used to register the type
171 * @param [in] name Property name
172 * @param [in] index Property index
173 * @param [in] value Property default value
174 * @return true if registered
176 bool RegisterAnimatableProperty(TypeRegistration& registered, std::string name, Property::Index index, Property::Value defaultValue);
179 * Register a component of a scene graph only property that supports components (i.e. Vector2, Vector3 and Vector4)
180 * @param [in] registered TypeRegistration object used to register the type
181 * @param [in] name Component name
182 * @param [in] index Property index
183 * @param [in] baseIndex Base animatable property index
184 * @param [in] componentIndex Component index
185 * @return true if registered
187 bool RegisterAnimatablePropertyComponent(TypeRegistration& registered, std::string name, Property::Index index, Property::Index baseIndex, unsigned int componentIndex);
190 * Register a event-thread only property with a type and a default value
191 * @param [in] registeredType Name of a registered type on which to register the child property.
192 * @param [in] name Property name
193 * @param [in] index Property index
194 * @param [in] type Property type
195 * @return true if registered
197 bool RegisterChildProperty(const std::string& registeredType, std::string name, Property::Index index, Property::Type type);
200 * Register a event-thread only property with a type and a default value
201 * @param [in] registered TypeRegistration object used to register the type
202 * @param [in] name Property name
203 * @param [in] index Property index
204 * @param [in] type Property type
205 * @return true if registered
207 bool RegisterChildProperty(TypeRegistration& registered, std::string name, Property::Index index, Property::Type type);
210 * @copydoc Dali::Internal::TypeInfo::DoActionTo
211 * Walks all base types until it finds a doer.
213 bool DoActionTo( BaseObject * const object, const std::string &actionName, const Property::Map& properties);
216 * @copydoc Dali::BaseHandle::ConnectSignal()
218 bool ConnectSignal( BaseObject* object, ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor );
221 * Return the type info for a given BaseObject pointer
222 * @param [in] pBaseObject Pointer to a BaseObject
223 * @return TypeInfo for the BaseObject.
225 TypeInfoPointer GetTypeInfo(const Dali::BaseObject * const pBaseObject);
228 * Calls any type creation functions that have been flagged as initialization functions
230 void CallInitFunctions(void) const;
235 * Return the name derived from type_info used to register the type
236 * @param [in] registerType Type info for the type to be registered
237 * @return registered name
239 static std::string RegistrationName( const std::type_info& registerType );
243 * Mapping from type name to TypeInfo
245 std::vector< TypeInfoPointer > mRegistryLut;
247 std::vector< Dali::TypeInfo::CreateFunction > mInitFunctions;
251 ~TypeRegistry() override;
254 * @brief Undefined Copy Constructor
256 TypeRegistry(TypeRegistry &);
259 * @brief Undefined Assignment Operator
261 TypeRegistry& operator=(const TypeRegistry &);
265 } // namespace Internal
267 // Helpers for public-api forwarding methods
269 inline Internal::TypeRegistry& GetImplementation(Dali::TypeRegistry& typeRegistry)
271 DALI_ASSERT_ALWAYS(typeRegistry);
273 BaseObject& handle = typeRegistry.GetBaseObject();
275 return static_cast<Internal::TypeRegistry&>(handle);
278 inline const Internal::TypeRegistry& GetImplementation(const Dali::TypeRegistry& typeRegistry)
280 DALI_ASSERT_ALWAYS(typeRegistry);
282 const BaseObject& handle = typeRegistry.GetBaseObject();
284 return static_cast<const Internal::TypeRegistry&>(handle);
289 #endif // DALI_INTERNAL_TYPE_REGISTRY_H