1 #ifndef __DALI_INTERNAL_TYPE_INFO_H__
2 #define __DALI_INTERNAL_TYPE_INFO_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.
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-info.h>
28 #include <dali/devel-api/object/csharp-type-info.h>
37 * A TypeInfo class to support registered type creation, and introspection of available
38 * actions and signal connection.
39 * It also supports doing actions and connecting signal handlers. Note this is properly
40 * conducted through the BaseHandle interface which uses the TypeRegistry to walk
43 class TypeInfo : public BaseObject
48 * @param [name] the registered name
49 * @param [baseName] the base type registered name
50 * @param [creator] the creator function for this type
52 TypeInfo(const std::string& name, const std::string& baseName, Dali::TypeInfo::CreateFunction creator);
55 * Create TypeInfo for a csharp object
56 * @param [name] the registered name
57 * @param [baseName] the base type registered name
58 * @param [creator] the creator function for this type
60 TypeInfo(const std::string& name, const std::string& baseName, Dali::CSharpTypeInfo::CreateFunction creator);
68 * @copydoc Dali::TypeInfo::GetName
70 const std::string& GetName() const;
73 * @copydoc Dali::TypeInfo::GetBaseName
75 const std::string& GetBaseName() const;
78 * @copydoc TypeInfo::CreateFunction
80 BaseHandle CreateInstance() const;
83 * @copydoc Dali::TypeInfo::GetCreator
85 Dali::TypeInfo::CreateFunction GetCreator() const;
88 * @copydoc Dali::TypeInfo::GetActionCount
90 size_t GetActionCount() const;
93 * @copydoc Dali::TypeInfo::GetActionName
95 std::string GetActionName(size_t index) const;
98 * @copydoc Dali::TypeInfo::GetSignalCount
100 size_t GetSignalCount() const;
103 * @copydoc Dali::TypeInfo::GetSignalName
105 std::string GetSignalName(size_t index) const;
108 * @copydoc Dali::TypeInfo::GetPropertyCount
110 uint32_t GetPropertyCount() const;
113 * Adds the property indices to the container specified.
114 * @param[in/out] indices The container where the property indices are added.
116 void GetPropertyIndices( Property::IndexContainer& indices ) const;
119 * @copydoc Dali::TypeInfo::GetPropertyName() const
121 const std::string& GetPropertyName( Property::Index index ) const;
124 * Add an action function
126 void AddActionFunction( const std::string &actionName, Dali::TypeInfo::ActionFunction function );
129 * Add a function for connecting a signal.
130 * @param[in] signalName The name of the signal.
131 * @param[in] function The function used for connecting to the signal.
133 void AddConnectorFunction( const std::string& signalName, Dali::TypeInfo::SignalConnectorFunction function );
136 * Adds an event-thread only property to the type.
137 * @param[in] name The name of the property.
138 * @param[in] index The index of the property.
139 * @param[in] type The Property::Type.
140 * @param[in] setFunc The function to call to set the property (Can be NULL).
141 * @param[in] getFunc The function to call to retrieve the value of the property.
143 void AddProperty( const std::string& name, Property::Index index, Property::Type type, Dali::TypeInfo::SetPropertyFunction setFunc, Dali::TypeInfo::GetPropertyFunction getFunc );
146 * Adds an event-thread only property to the type.
147 * @param[in] name The name of the property.
148 * @param[in] index The index of the property.
149 * @param[in] type The Property::Type.
150 * @param[in] setFunc The function to call to set the property (Can be NULL).
151 * @param[in] getFunc The function to call to retrieve the value of the property.
153 void AddProperty( const std::string& name, Property::Index index, Property::Type type, Dali::CSharpTypeInfo::SetPropertyFunction setFunc, Dali::CSharpTypeInfo::GetPropertyFunction getFunc);
156 * Adds an animatable property to the type.
157 * @param[in] name The name of the property.
158 * @param[in] index The index of the property
159 * @param[in] type The Property::Type.
161 void AddAnimatableProperty( const std::string& name, Property::Index index, Property::Type type );
164 * Adds an animatable property with the given default value.
165 * @param[in] name The name of the property.
166 * @param[in] index The index of the property
167 * @param[in] type The Property::Type.
169 void AddAnimatableProperty( const std::string& name, Property::Index index, const Property::Value& defaultValue );
172 * Adds a component of an animatable property to the type.
173 * The animatable property must have been type-registered and must be a Vector2, Vector3 or Vector4 type.
174 * @param[in] name The name of the component.
175 * @param[in] index The index of the property
176 * @param[in] baseIndex The index of the base animatable property
177 * @param[in] component The index The index of the component.
179 void AddAnimatablePropertyComponent( const std::string& name, Property::Index index, Property::Index baseIndex, uint32_t componentIndex );
182 * Adds a child property to the type.
183 * @param[in] name The name of the property.
184 * @param[in] index The index of the property
185 * @param[in] type The Property::Type.
187 void AddChildProperty( const std::string& name, Property::Index index, Property::Type type );
190 * Do an action on base object
191 * @param [in] object The base object to act upon
192 * @param [in] actionName The name of the desired action
193 * @param [in] properties The arguments of the action
194 * @return bool If the action could be executed
196 bool DoActionTo(BaseObject *object, const std::string &actionName, const Property::Map &properties);
199 * Connects a callback function with the object's signals.
200 * @param[in] object The object providing the signal.
201 * @param[in] tracker Used to disconnect the signal.
202 * @param[in] signalName The signal to connect to.
203 * @param[in] functor A newly allocated FunctorDelegate.
204 * @return True if the signal was connected.
205 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
207 bool ConnectSignal( BaseObject* object, ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor );
210 * Given a property name, retrieve the index.
211 * @param[in] name The name of the property.
212 * @return The index associated with that name.
214 Property::Index GetPropertyIndex( const std::string& name ) const;
217 * Given a property index, retrieve the index of its base property.
218 * @param[in] index The index of the property.
219 * @return The index of the base property associated with the given property index.
221 Property::Index GetBasePropertyIndex( Property::Index index ) const;
224 * Given a property index, retrieve its component index.
225 * @param[in] index The index of the property.
226 * @return The component index associated with that property index.
228 int32_t GetComponentIndex( Property::Index index ) const;
231 * Checks if there is a setter for the property. If there is then it is writable.
232 * @param[in] index The property index.
233 * @return True, if writable, false otherwise.
235 bool IsPropertyWritable( Property::Index index ) const;
238 * Retrieve the Property::Type of the property at the given index.
239 * @param[in] index The property index.
240 * @return The Property::Type at that index.
242 Property::Type GetPropertyType( Property::Index index ) const;
245 * Given a child property name, retrieve the index.
246 * @param[in] name The name of the child property.
247 * @return The index associated with that name.
249 Property::Index GetChildPropertyIndex( const std::string& name ) const;
252 * Retrieve the name of the child property at the given index.
253 * @param[in] index The property index.
254 * @return The name of the child property.
256 const std::string& GetChildPropertyName( Property::Index index ) const;
259 * Retrieve the Property::Type of the child property at the given index.
260 * @param[in] index The property index.
261 * @return The Property::Type at that index.
263 Property::Type GetChildPropertyType( Property::Index index ) const;
266 * Retrive the child indices into the given container.
267 * @param[in,out] indices The container to put the child indices into
269 void GetChildPropertyIndices( Property::IndexContainer& indices ) const;
272 * Retrieve the default value of the property at the given index.
273 * @param[in] index The property index.
274 * @return The default property value at that index.
276 Property::Value GetPropertyDefaultValue( Property::Index index ) const;
279 * Sets the value of a property at the index specified for the given object.
280 * @param[in] object The object whose property is to be set.
281 * @param[in] index The property index.
282 * @param[in] value The value to set.
284 void SetProperty( BaseObject *object, Property::Index index, const Property::Value& value ) const;
287 * Sets the value of a property with the name specified for the given object.
288 * @param[in] object The object whose property is to be set.
289 * @param[in] name The property name.
290 * @param[in] value The value to set.
292 void SetProperty( BaseObject *object, const std::string& name, const Property::Value& value ) const;
295 * Retrieves the value of a property at the index specified for the given object.
296 * @param[in] object The object whose property is to be queried.
297 * @param[in] index The property index.
298 * @return The current value of the property.
300 Property::Value GetProperty( const BaseObject *object, Property::Index index ) const;
303 * Retrieves the value of a property with the name specified for the given object.
304 * @param[in] object The object whose property is to be queried.
305 * @param[in] name The property name.
306 * @return The current value of the property.
308 Property::Value GetProperty( const BaseObject *object, const std::string& name ) const;
312 struct RegisteredProperty
315 : type( Property::NONE ),
319 basePropertyIndex(Property::INVALID_INDEX),
320 componentIndex(Property::INVALID_COMPONENT_INDEX)
324 RegisteredProperty( Property::Type propType, const std::string& propName, Property::Index basePropertyIndex, int32_t componentIndex )
329 basePropertyIndex(basePropertyIndex),
330 componentIndex(componentIndex)
335 RegisteredProperty( Property::Type propType, Dali::TypeInfo::SetPropertyFunction set, Dali::TypeInfo::GetPropertyFunction get, const std::string& propName, Property::Index basePropertyIndex, int componentIndex )
340 basePropertyIndex(basePropertyIndex),
341 componentIndex(componentIndex)
345 RegisteredProperty( Property::Type propType, Dali::CSharpTypeInfo::SetPropertyFunction set, Dali::CSharpTypeInfo::GetPropertyFunction get, const std::string& propName, Property::Index basePropertyIndex, int componentIndex )
347 cSharpSetFunc( set ),
348 cSharpGetFunc( get ),
350 basePropertyIndex(basePropertyIndex),
351 componentIndex(componentIndex)
359 Dali::TypeInfo::SetPropertyFunction setFunc;
360 Dali::CSharpTypeInfo::SetPropertyFunction cSharpSetFunc;
364 Dali::TypeInfo::GetPropertyFunction getFunc;
365 Dali::CSharpTypeInfo::GetPropertyFunction cSharpGetFunc;
368 Property::Index basePropertyIndex;
369 int32_t componentIndex;
372 typedef std::pair<std::string, Dali::TypeInfo::SignalConnectorFunction > ConnectionPair;
373 typedef std::pair<std::string, Dali::TypeInfo::ActionFunction > ActionPair;
374 typedef std::pair<Property::Index, RegisteredProperty> RegisteredPropertyPair;
375 typedef std::pair<Property::Index, Property::Value> PropertyDefaultValuePair;
377 typedef std::vector< ActionPair > ActionContainer;
378 typedef std::vector< ConnectionPair > ConnectorContainer;
379 typedef std::vector< RegisteredPropertyPair > RegisteredPropertyContainer;
380 typedef std::vector< PropertyDefaultValuePair > PropertyDefaultValueContainer;
384 * Append properties from registeredProperties onto indices.
385 * @param[in,out] indices The vector to append indices onto
386 * @param[in] registeredProperties The container to retrive indices from
388 void AppendProperties( Dali::Property::IndexContainer& indices,
389 const TypeInfo::RegisteredPropertyContainer& registeredProperties ) const;
393 std::string mTypeName;
394 std::string mBaseTypeName;
395 bool mCSharpType:1; ///< Whether this type info is for a CSharp control (instead of C++)
398 Dali::TypeInfo::CreateFunction mCreate;
399 Dali::CSharpTypeInfo::CreateFunction mCSharpCreate;
401 ActionContainer mActions;
402 ConnectorContainer mSignalConnectors;
403 RegisteredPropertyContainer mRegisteredProperties;
404 RegisteredPropertyContainer mRegisteredChildProperties;
405 PropertyDefaultValueContainer mPropertyDefaultValues;
408 } // namespace Internal
410 // Helpers for public-api forwarding methods
412 inline Internal::TypeInfo& GetImplementation(Dali::TypeInfo& typeInfo)
414 DALI_ASSERT_ALWAYS(typeInfo);
416 BaseObject& handle = typeInfo.GetBaseObject();
418 return static_cast<Internal::TypeInfo&>(handle);
421 inline const Internal::TypeInfo& GetImplementation(const Dali::TypeInfo& typeInfo)
423 DALI_ASSERT_ALWAYS(typeInfo);
425 const BaseObject& handle = typeInfo.GetBaseObject();
427 return static_cast<const Internal::TypeInfo&>(handle);