1 #ifndef __DALI_INTERNAL_TYPE_REGISTRY_H__
2 #define __DALI_INTERNAL_TYPE_REGISTRY_H__
5 * Copyright (c) 2016 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/common/map-wrapper.h>
23 #include <dali/devel-api/object/csharp-type-info.h>
24 #include <dali/public-api/object/type-registry.h>
25 #include <dali/public-api/object/base-handle.h>
26 #include <dali/public-api/object/base-object.h>
27 #include <dali/internal/event/common/type-info-impl.h>
35 ////////////////////////////////////////////////////////////////////////////////
39 * @copydoc Dali::TypeRegistry
41 class TypeRegistry : public Dali::BaseObject
45 * Get the TypeRegistry
47 static TypeRegistry *Get();
50 * @copydoc Dali::TypeRegistry::GetTypeInfo
52 Dali::TypeInfo GetTypeInfo( const std::string &uniqueTypeName );
55 * @copydoc Dali::TypeRegistry::GetTypeInfo
57 Dali::TypeInfo GetTypeInfo( const std::type_info& registerType );
60 * @copydoc Dali::TypeRegistry::GetTypeNameCount
62 size_t GetTypeNameCount() const;
65 * @copydoc Dali::TypeRegistry::GetTypeName
67 std::string GetTypeName(size_t index) const;
70 * Register a creation function under a unique name.
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 true if the name could be registered.
77 bool Register( const std::type_info& theTypeInfo, const std::type_info& baseTypeInfo,
78 Dali::TypeInfo::CreateFunction createInstance, bool callCreateOnInit );
81 * Register a creation function under a unique name.
82 * @param [in] name The name type to be registered (must be unique)
83 * @param [in] baseTypeInfo Type info for its base class
84 * @param [in] createInstance Instance creation function
85 * @param [in] callCreateOnInit If true call createInstance on dali initialisation
86 * @return true if the name could be registered.
88 bool Register( const std::string& name, const std::type_info& baseTypeInfo,
89 Dali::TypeInfo::CreateFunction createInstance, bool callCreateOnInit );
92 * Register a creation function under a unique name (used by C# Custom controls).
93 * @param [in] name The name type to be registered (must be unique)
94 * @param [in] baseTypeInfo Type info for its base class
95 * @param [in] createInstance Instance creation function
96 * @param [in] callCreateOnInit If true call createInstance on dali initialisation
97 * @return true if the name could be registered.
99 bool Register( const std::string& name, const std::type_info& baseTypeInfo,
100 Dali::CSharpTypeInfo::CreateFunction createInstance, bool callCreateOnInit );
103 * Register a signal connector function to a type
104 * @param [in] typeRegistration TypeRegistration object used to register the type
105 * @param [in] name Signal name
106 * @param [in] func Signal connector function
108 void RegisterSignal( TypeRegistration& typeRegistration, const std::string& name, Dali::TypeInfo::SignalConnectorFunction func );
111 * Register an action function to a type
112 * @param [in] registered TypeRegistration object used to register the type
113 * @param [in] name Action name
114 * @param [in] f Action function
115 * @return true if registered
117 bool RegisterAction( TypeRegistration ®istered, const std::string &name, Dali::TypeInfo::ActionFunction f);
120 * Register an event-thread only property with a type
121 * @param [in] registered TypeRegistration object used to register the type
122 * @param [in] name Property name
123 * @param [in] index Property index
124 * @param [in] type Property type
125 * @param [in] setFunc The function to set the property (Can be NULL).
126 * @param [in] getFunc The function to get the value of a property.
127 * @return true if registered
129 bool RegisterProperty( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Type type, Dali::TypeInfo::SetPropertyFunction setFunc, Dali::TypeInfo::GetPropertyFunction getFunc );
132 * Register an event-thread only property with a type (used by C# Custom controls)
133 * @param [in] objectName name of the object used to register the type
134 * @param [in] name Property name
135 * @param [in] index Property index
136 * @param [in] type Property type
137 * @param [in] setFunc The function to set the property (Can be NULL).
138 * @param [in] getFunc The function to get the value of a property.
139 * @return true if registered
141 bool RegisterProperty( const std::string& objectName, const std::string& name, Property::Index index, Property::Type type, Dali::CSharpTypeInfo::SetPropertyFunction setFunc, Dali::CSharpTypeInfo::GetPropertyFunction getFunc );
145 * Register a scene graph only property with a type
146 * @param [in] registered TypeRegistration object used to register the type
147 * @param [in] name Property name
148 * @param [in] index Property index
149 * @param [in] type Property type
150 * @return true if registered
152 bool RegisterAnimatableProperty( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Type type );
155 * Register a scene graph only property with a default value
156 * @param [in] registered TypeRegistration object used to register the type
157 * @param [in] name Property name
158 * @param [in] index Property index
159 * @param [in] value Property default value
160 * @return true if registered
162 bool RegisterAnimatableProperty( TypeRegistration& registered, const std::string& name, Property::Index index, const Property::Value& defaultValue );
165 * Register a component of a scene graph only property that supports components (i.e. Vector2, Vector3 and Vector4)
166 * @param [in] registered TypeRegistration object used to register the type
167 * @param [in] name Component name
168 * @param [in] index Property index
169 * @param [in] baseIndex Base animatable property index
170 * @param [in] componentIndex Component index
171 * @return true if registered
173 bool RegisterAnimatablePropertyComponent( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Index baseIndex, unsigned int componentIndex );
176 * Register a event-thread only property with a type and a default value
177 * @param [in] registered TypeRegistration object used to register the type
178 * @param [in] name Property name
179 * @param [in] index Property index
180 * @param [in] type Property type
181 * @return true if registered
183 bool RegisterChildProperty( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Type type );
186 * @copydoc Dali::Internal::TypeInfo::DoActionTo
187 * Walks all base types until it finds a doer.
189 bool DoActionTo( BaseObject * const object, const std::string &actionName, const Property::Map& properties);
192 * @copydoc Dali::BaseHandle::ConnectSignal()
194 bool ConnectSignal( BaseObject* object, ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor );
197 * Return the type info for a given BaseObject pointer
198 * @param [in] pBaseObject Pointer to a BaseObject
199 * @return TypeInfo for the BaseObject.
201 Dali::TypeInfo GetTypeInfo(const Dali::BaseObject * const pBaseObject);
204 * Calls any type creation functions that have been flagged as initialization functions
206 void CallInitFunctions(void) const;
211 * Return the name derived from type_info used to register the type
212 * @param [in] registerType Type info for the type to be registered
213 * @return registered name
215 static std::string RegistrationName( const std::type_info& registerType );
219 * Map from type name to TypeInfo
221 typedef std::map<std::string, Dali::TypeInfo> RegistryMap;
222 RegistryMap mRegistryLut;
224 typedef std::vector<Dali::TypeInfo::CreateFunction> InitFunctions;
225 InitFunctions mInitFunctions;
227 typedef std::vector<Dali::CSharpTypeInfo::CreateFunction> CSharpInitFunctions;
228 CSharpInitFunctions mCSharpInitFunctions;
235 * @brief Undefined Copy Constructor
237 TypeRegistry(TypeRegistry &);
240 * @brief Undefined Assignment Operator
242 TypeRegistry& operator=(const TypeRegistry &);
246 } // namespace Internal
248 // Helpers for public-api forwarding methods
250 inline Internal::TypeRegistry& GetImplementation(Dali::TypeRegistry& typeRegistry)
252 DALI_ASSERT_ALWAYS(typeRegistry);
254 BaseObject& handle = typeRegistry.GetBaseObject();
256 return static_cast<Internal::TypeRegistry&>(handle);
259 inline const Internal::TypeRegistry& GetImplementation(const Dali::TypeRegistry& typeRegistry)
261 DALI_ASSERT_ALWAYS(typeRegistry);
263 const BaseObject& handle = typeRegistry.GetBaseObject();
265 return static_cast<const Internal::TypeRegistry&>(handle);
270 #endif // __DALI_INTERNAL_TYPE_REGISTRY_H__