1 #ifndef __DALI_INTERNAL_TYPE_REGISTRY_H__
2 #define __DALI_INTERNAL_TYPE_REGISTRY_H__
5 * Copyright (c) 2018 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 * Get the TypeRegistry
46 static TypeRegistry *Get();
49 * @copydoc Dali::TypeRegistry::GetTypeInfo
51 Dali::TypeInfo GetTypeInfo( const std::string &uniqueTypeName );
54 * @copydoc Dali::TypeRegistry::GetTypeInfo
56 Dali::TypeInfo GetTypeInfo( const std::type_info& registerType );
59 * @copydoc Dali::TypeRegistry::GetTypeNameCount
61 size_t GetTypeNameCount() const;
64 * @copydoc Dali::TypeRegistry::GetTypeName
66 std::string GetTypeName(size_t index) const;
71 * @param [in] theTypeInfo Type info for the type to be registered
72 * @param [in] baseTypeInfo Type info for its base class
73 * @param [in] createInstance Instance creation function
74 * @param [in] callCreateOnInit If true call createInstance on DALi initialisation
75 * @return the name of the registered type.
77 std::string Register( const std::type_info& theTypeInfo, const std::type_info& baseTypeInfo,
78 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,
92 Dali::TypeInfo::CreateFunction createInstance, bool callCreateOnInit,
93 const Dali::PropertyDetails* defaultProperties, Property::Index defaultPropertyCount );
98 * @param [in] theTypeInfo Type info for the type to be registered
99 * @param [in] baseTypeInfo Type info for its base class
100 * @param [in] createInstance Instance creation function
101 * @param [in] callCreateOnInit If true call createInstance on DALi initialisation
102 * @param [in] defaultProperties the table of default property metadata
103 * @param [in] defaultPropertyCount count of default properties
104 * @return the name of the registered type.
106 std::string Register( const std::string& name, const std::type_info& baseTypeInfo,
107 Dali::TypeInfo::CreateFunction createInstance, bool callCreateOnInit,
108 const Dali::PropertyDetails* defaultProperties = nullptr, Property::Index defaultPropertyCount = 0 );
111 * @copydoc CSharpTypeRegistry::TypeRegistration( const std::string&, const std::type_info&, TypeInfo::CreateFunction );
113 void Register( const std::string& name, const std::type_info& baseTypeInfo,
114 Dali::CSharpTypeInfo::CreateFunction createInstance );
117 * Register a signal connector function to a type
118 * @param [in] typeRegistration TypeRegistration object used to register the type
119 * @param [in] name Signal name
120 * @param [in] func Signal connector function
122 void RegisterSignal( TypeRegistration& typeRegistration, const std::string& name, Dali::TypeInfo::SignalConnectorFunction func );
125 * Register an action function to a type
126 * @param [in] registered TypeRegistration object used to register the type
127 * @param [in] name Action name
128 * @param [in] f Action function
129 * @return true if registered
131 bool RegisterAction( TypeRegistration& registered, const std::string& name, Dali::TypeInfo::ActionFunction f );
134 * Register an event-thread only property with a type
135 * @param [in] registered TypeRegistration object used to register the type
136 * @param [in] name Property name
137 * @param [in] index Property index
138 * @param [in] type Property type
139 * @param [in] setFunc The function to set the property (Can be NULL).
140 * @param [in] getFunc The function to get the value of a property.
141 * @return true if registered
143 bool RegisterProperty( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Type type, Dali::TypeInfo::SetPropertyFunction setFunc, Dali::TypeInfo::GetPropertyFunction getFunc );
146 * Register an event-thread only property with a type (used by C# Custom controls)
147 * @param [in] objectName name of the object used to register the type
148 * @param [in] name Property name
149 * @param [in] index Property index
150 * @param [in] type Property type
151 * @param [in] setFunc The function to set the property (Can be NULL).
152 * @param [in] getFunc The function to get the value of a property.
153 * @return true if registered
155 bool RegisterProperty( const std::string& objectName, const 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, const 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, const std::string& name, Property::Index index, const 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, const 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, const 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, const 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 Dali::TypeInfo 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< Dali::TypeInfo > mRegistryLut;
247 std::vector< Dali::TypeInfo::CreateFunction > mInitFunctions;
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__