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 size_t GetPropertyCount() const;
113 * @copydoc Dali::TypeInfo::GetPropertyName
115 std::string GetPropertyName(size_t index) const;
118 * Adds the property indices to the container specified.
119 * @param[in/out] indices The container where the property indices are added.
121 void GetPropertyIndices( Property::IndexContainer& indices ) const;
124 * @copydoc Dali::TypeInfo::GetPropertyName() const
126 const std::string& GetPropertyName( Property::Index index ) const;
129 * Add an action function
131 void AddActionFunction( const std::string &actionName, Dali::TypeInfo::ActionFunction function );
134 * Add a function for connecting a signal.
135 * @param[in] signalName The name of the signal.
136 * @param[in] function The function used for connecting to the signal.
138 void AddConnectorFunction( const std::string& signalName, Dali::TypeInfo::SignalConnectorFunction function );
141 * Adds an event-thread only property to the type.
142 * @param[in] name The name of the property.
143 * @param[in] index The index of the property.
144 * @param[in] type The Property::Type.
145 * @param[in] setFunc The function to call to set the property (Can be NULL).
146 * @param[in] getFunc The function to call to retrieve the value of the property.
148 void AddProperty( const std::string& name, Property::Index index, Property::Type type, Dali::TypeInfo::SetPropertyFunction setFunc, Dali::TypeInfo::GetPropertyFunction getFunc );
151 * Adds an event-thread only property to the type.
152 * @param[in] name The name of the property.
153 * @param[in] index The index of the property.
154 * @param[in] type The Property::Type.
155 * @param[in] setFunc The function to call to set the property (Can be NULL).
156 * @param[in] getFunc The function to call to retrieve the value of the property.
158 void AddProperty( const std::string& name, Property::Index index, Property::Type type, Dali::CSharpTypeInfo::SetPropertyFunction setFunc, Dali::CSharpTypeInfo::GetPropertyFunction getFunc);
161 * Adds an animatable property to the type.
162 * @param[in] name The name of the property.
163 * @param[in] index The index of the property
164 * @param[in] type The Property::Type.
166 void AddAnimatableProperty( const std::string& name, Property::Index index, Property::Type type );
169 * Adds an animatable property with the given default value.
170 * @param[in] name The name of the property.
171 * @param[in] index The index of the property
172 * @param[in] type The Property::Type.
174 void AddAnimatableProperty( const std::string& name, Property::Index index, const Property::Value& defaultValue );
177 * Adds a component of an animatable property to the type.
178 * The animatable property must have been type-registered and must be a Vector2, Vector3 or Vector4 type.
179 * @param[in] name The name of the component.
180 * @param[in] index The index of the property
181 * @param[in] baseIndex The index of the base animatable property
182 * @param[in] component The index The index of the component.
184 void AddAnimatablePropertyComponent( const std::string& name, Property::Index index, Property::Index baseIndex, unsigned int componentIndex );
187 * Adds a child property to the type.
188 * @param[in] name The name of the property.
189 * @param[in] index The index of the property
190 * @param[in] type The Property::Type.
192 void AddChildProperty( const std::string& name, Property::Index index, Property::Type type );
195 * Do an action on base object
196 * @param [in] object The base object to act upon
197 * @param [in] actionName The name of the desired action
198 * @param [in] properties The arguments of the action
199 * @return bool If the action could be executed
201 bool DoActionTo(BaseObject *object, const std::string &actionName, const Property::Map &properties);
204 * Connects a callback function with the object's signals.
205 * @param[in] object The object providing the signal.
206 * @param[in] tracker Used to disconnect the signal.
207 * @param[in] signalName The signal to connect to.
208 * @param[in] functor A newly allocated FunctorDelegate.
209 * @return True if the signal was connected.
210 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
212 bool ConnectSignal( BaseObject* object, ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor );
215 * Given a property name, retrieve the index.
216 * @param[in] name The name of the property.
217 * @return The index associated with that name.
219 Property::Index GetPropertyIndex( const std::string& name ) const;
222 * Given a property index, retrieve the index of its base property.
223 * @param[in] index The index of the property.
224 * @return The index of the base property associated with the given property index.
226 Property::Index GetBasePropertyIndex( Property::Index index ) const;
229 * Given a property index, retrieve its component index.
230 * @param[in] index The index of the property.
231 * @return The component index associated with that property index.
233 int GetComponentIndex( Property::Index index ) const;
236 * Checks if there is a setter for the property. If there is then it is writable.
237 * @param[in] index The property index.
238 * @return True, if writable, false otherwise.
240 bool IsPropertyWritable( Property::Index index ) const;
243 * Retrieve the Property::Type of the property at the given index.
244 * @param[in] index The property index.
245 * @return The Property::Type at that index.
247 Property::Type GetPropertyType( Property::Index index ) const;
250 * Given a child property name, retrieve the index.
251 * @param[in] name The name of the child property.
252 * @return The index associated with that name.
254 Property::Index GetChildPropertyIndex( const std::string& name ) const;
257 * Retrieve the name of the child property at the given index.
258 * @param[in] index The property index.
259 * @return The name of the child property.
261 const std::string& GetChildPropertyName( Property::Index index ) const;
264 * Retrieve the Property::Type of the child property at the given index.
265 * @param[in] index The property index.
266 * @return The Property::Type at that index.
268 Property::Type GetChildPropertyType( Property::Index index ) const;
271 * Retrive the child indices into the given container.
272 * @param[in,out] indices The container to put the child indices into
274 void GetChildPropertyIndices( Property::IndexContainer& indices ) const;
277 * Retrieve the default value of the property at the given index.
278 * @param[in] index The property index.
279 * @return The default property value at that index.
281 Property::Value GetPropertyDefaultValue( Property::Index index ) const;
284 * Sets the value of a property at the index specified for the given object.
285 * @param[in] object The object whose property is to be set.
286 * @param[in] index The property index.
287 * @param[in] value The value to set.
289 void SetProperty( BaseObject *object, Property::Index index, const Property::Value& value ) const;
292 * Sets the value of a property with the name specified for the given object.
293 * @param[in] object The object whose property is to be set.
294 * @param[in] name The property name.
295 * @param[in] value The value to set.
297 void SetProperty( BaseObject *object, const std::string& name, const Property::Value& value ) const;
300 * Retrieves the value of a property at the index specified for the given object.
301 * @param[in] object The object whose property is to be queried.
302 * @param[in] index The property index.
303 * @return The current value of the property.
305 Property::Value GetProperty( const BaseObject *object, Property::Index index ) const;
308 * Retrieves the value of a property with the name specified for the given object.
309 * @param[in] object The object whose property is to be queried.
310 * @param[in] name The property name.
311 * @return The current value of the property.
313 Property::Value GetProperty( const BaseObject *object, const std::string& name ) const;
317 struct RegisteredProperty
320 : type( Property::NONE ),
324 basePropertyIndex(Property::INVALID_INDEX),
325 componentIndex(Property::INVALID_COMPONENT_INDEX)
329 RegisteredProperty( Property::Type propType, const std::string& propName, Property::Index basePropertyIndex, int componentIndex )
334 basePropertyIndex(basePropertyIndex),
335 componentIndex(componentIndex)
340 RegisteredProperty( Property::Type propType, Dali::TypeInfo::SetPropertyFunction set, Dali::TypeInfo::GetPropertyFunction get, const std::string& propName, Property::Index basePropertyIndex, int componentIndex )
345 basePropertyIndex(basePropertyIndex),
346 componentIndex(componentIndex)
350 RegisteredProperty( Property::Type propType, Dali::CSharpTypeInfo::SetPropertyFunction set, Dali::CSharpTypeInfo::GetPropertyFunction get, const std::string& propName, Property::Index basePropertyIndex, int componentIndex )
352 cSharpSetFunc( set ),
353 cSharpGetFunc( get ),
355 basePropertyIndex(basePropertyIndex),
356 componentIndex(componentIndex)
364 Dali::TypeInfo::SetPropertyFunction setFunc;
365 Dali::CSharpTypeInfo::SetPropertyFunction cSharpSetFunc;
369 Dali::TypeInfo::GetPropertyFunction getFunc;
370 Dali::CSharpTypeInfo::GetPropertyFunction cSharpGetFunc;
373 Property::Index basePropertyIndex;
377 typedef std::pair<std::string, Dali::TypeInfo::SignalConnectorFunction > ConnectionPair;
378 typedef std::pair<std::string, Dali::TypeInfo::ActionFunction > ActionPair;
379 typedef std::pair<Property::Index, RegisteredProperty> RegisteredPropertyPair;
380 typedef std::pair<Property::Index, Property::Value> PropertyDefaultValuePair;
382 typedef std::vector< ActionPair > ActionContainer;
383 typedef std::vector< ConnectionPair > ConnectorContainer;
384 typedef std::vector< RegisteredPropertyPair > RegisteredPropertyContainer;
385 typedef std::vector< PropertyDefaultValuePair > PropertyDefaultValueContainer;
389 * Append properties from registeredProperties onto indices.
390 * @param[in,out] indices The vector to append indices onto
391 * @param[in] registeredProperties The container to retrive indices from
393 void AppendProperties( Dali::Property::IndexContainer& indices,
394 const TypeInfo::RegisteredPropertyContainer& registeredProperties ) const;
398 std::string mTypeName;
399 std::string mBaseTypeName;
400 bool mCSharpType:1; ///< Whether this type info is for a CSharp control (instead of C++)
403 Dali::TypeInfo::CreateFunction mCreate;
404 Dali::CSharpTypeInfo::CreateFunction mCSharpCreate;
406 ActionContainer mActions;
407 ConnectorContainer mSignalConnectors;
408 RegisteredPropertyContainer mRegisteredProperties;
409 RegisteredPropertyContainer mRegisteredChildProperties;
410 PropertyDefaultValueContainer mPropertyDefaultValues;
413 } // namespace Internal
415 // Helpers for public-api forwarding methods
417 inline Internal::TypeInfo& GetImplementation(Dali::TypeInfo& typeInfo)
419 DALI_ASSERT_ALWAYS(typeInfo);
421 BaseObject& handle = typeInfo.GetBaseObject();
423 return static_cast<Internal::TypeInfo&>(handle);
426 inline const Internal::TypeInfo& GetImplementation(const Dali::TypeInfo& typeInfo)
428 DALI_ASSERT_ALWAYS(typeInfo);
430 const BaseObject& handle = typeInfo.GetBaseObject();
432 return static_cast<const Internal::TypeInfo&>(handle);