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 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( 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 );
115 * @copydoc CSharpTypeRegistry::TypeRegistration( const std::string&, const std::type_info&, TypeInfo::CreateFunction );
117 void Register( const std::string& name, const std::type_info& baseTypeInfo,
118 Dali::CSharpTypeInfo::CreateFunction createInstance );
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
126 void RegisterSignal( TypeRegistration& typeRegistration, const std::string& name, Dali::TypeInfo::SignalConnectorFunction func );
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
135 bool RegisterAction( TypeRegistration& registered, const std::string& name, Dali::TypeInfo::ActionFunction f );
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
147 bool RegisterProperty( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Type type, Dali::TypeInfo::SetPropertyFunction setFunc, Dali::TypeInfo::GetPropertyFunction getFunc );
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
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 );
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
170 bool RegisterAnimatableProperty( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Type type );
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
180 bool RegisterAnimatableProperty( TypeRegistration& registered, const std::string& name, Property::Index index, const Property::Value& defaultValue );
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
191 bool RegisterAnimatablePropertyComponent( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Index baseIndex, unsigned int componentIndex );
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
201 bool RegisterChildProperty( const std::string& registeredType, const std::string& name, Property::Index index, Property::Type type );
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
211 bool RegisterChildProperty( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Type type );
214 * @copydoc Dali::Internal::TypeInfo::DoActionTo
215 * Walks all base types until it finds a doer.
217 bool DoActionTo( BaseObject * const object, const std::string &actionName, const Property::Map& properties);
220 * @copydoc Dali::BaseHandle::ConnectSignal()
222 bool ConnectSignal( BaseObject* object, ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor );
225 * Return the type info for a given BaseObject pointer
226 * @param [in] pBaseObject Pointer to a BaseObject
227 * @return TypeInfo for the BaseObject.
229 TypeInfoPointer GetTypeInfo(const Dali::BaseObject * const pBaseObject);
232 * Calls any type creation functions that have been flagged as initialization functions
234 void CallInitFunctions(void) const;
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
243 static std::string RegistrationName( const std::type_info& registerType );
247 * Mapping from type name to TypeInfo
249 std::vector< TypeInfoPointer > mRegistryLut;
251 std::vector< Dali::TypeInfo::CreateFunction > mInitFunctions;
258 * @brief Undefined Copy Constructor
260 TypeRegistry(TypeRegistry &);
263 * @brief Undefined Assignment Operator
265 TypeRegistry& operator=(const TypeRegistry &);
269 } // namespace Internal
271 // Helpers for public-api forwarding methods
273 inline Internal::TypeRegistry& GetImplementation(Dali::TypeRegistry& typeRegistry)
275 DALI_ASSERT_ALWAYS(typeRegistry);
277 BaseObject& handle = typeRegistry.GetBaseObject();
279 return static_cast<Internal::TypeRegistry&>(handle);
282 inline const Internal::TypeRegistry& GetImplementation(const Dali::TypeRegistry& typeRegistry)
284 DALI_ASSERT_ALWAYS(typeRegistry);
286 const BaseObject& handle = typeRegistry.GetBaseObject();
288 return static_cast<const Internal::TypeRegistry&>(handle);
293 #endif // DALI_INTERNAL_TYPE_REGISTRY_H