1 #ifndef DALI_INTERNAL_TYPE_INFO_H
2 #define DALI_INTERNAL_TYPE_INFO_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.
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/public-api/object/property.h>
29 #include <dali/devel-api/object/csharp-type-info.h>
30 #include <dali/internal/event/object/default-property-metadata.h>
37 class PropertyDetails;
41 * A TypeInfo class to support registered type creation, and introspection of available
42 * actions and signal connection.
43 * It also supports doing actions and connecting signal handlers. Note this is properly
44 * conducted through the BaseHandle interface which uses the TypeRegistry to walk
47 class TypeInfo : public BaseObject
53 * @param [name] the registered name
54 * @param [baseName] the base type registered name
55 * @param [creator] the creator function for this type
57 TypeInfo( const std::string& name, const std::string& baseName, Dali::TypeInfo::CreateFunction creator,
58 const Dali::PropertyDetails* defaultProperties, Property::Index defaultPropertyCount );
61 * Create TypeInfo for a csharp object
62 * @param [name] the registered name
63 * @param [baseName] the base type registered name
64 * @param [creator] the creator function for this type
66 TypeInfo( const std::string& name, const std::string& baseName, Dali::CSharpTypeInfo::CreateFunction creator );
74 * @copydoc Dali::TypeInfo::GetName
76 const std::string& GetName() const;
79 * @copydoc Dali::TypeInfo::GetBaseName
81 const std::string& GetBaseName() const;
84 * @copydoc TypeInfo::CreateFunction
86 BaseHandle CreateInstance() const;
89 * @copydoc Dali::TypeInfo::GetCreator
91 Dali::TypeInfo::CreateFunction GetCreator() const;
94 * @copydoc Dali::TypeInfo::GetActionCount
96 uint32_t GetActionCount() const;
99 * @copydoc Dali::TypeInfo::GetActionName
101 std::string GetActionName( uint32_t index ) const;
104 * @copydoc Dali::TypeInfo::GetSignalCount
106 uint32_t GetSignalCount() const;
109 * @copydoc Dali::TypeInfo::GetSignalName
111 std::string GetSignalName( uint32_t index ) const;
114 * @copydoc Dali::TypeInfo::GetPropertyCount
116 uint32_t GetPropertyCount() const;
119 * Adds the property indices to the container specified.
120 * @param[in/out] indices The container where the property indices are added.
122 void GetPropertyIndices( Property::IndexContainer& indices ) const;
125 * @copydoc Dali::TypeInfo::GetPropertyName() const
126 * this API exists to keep the old public API, which cannot be changed
128 const std::string& GetRegisteredPropertyName( Property::Index index ) const;
131 * Returns the property name for given index
133 * @param index of the property
134 * @return name or empty string
136 std::string GetPropertyName( Property::Index index ) const;
139 * Add an action function
141 void AddActionFunction( const std::string &actionName, Dali::TypeInfo::ActionFunction function );
144 * Add a function for connecting a signal.
145 * @param[in] signalName The name of the signal.
146 * @param[in] function The function used for connecting to the signal.
148 void AddConnectorFunction( const std::string& signalName, Dali::TypeInfo::SignalConnectorFunction function );
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 nullptr).
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::TypeInfo::SetPropertyFunction setFunc, Dali::TypeInfo::GetPropertyFunction getFunc );
161 * Adds an event-thread only 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.
165 * @param[in] setFunc The function to call to set the property (Can be nullptr).
166 * @param[in] getFunc The function to call to retrieve the value of the property.
168 void AddProperty( const std::string& name, Property::Index index, Property::Type type, Dali::CSharpTypeInfo::SetPropertyFunction setFunc, Dali::CSharpTypeInfo::GetPropertyFunction getFunc);
171 * Adds an animatable property to the type.
172 * @param[in] name The name of the property.
173 * @param[in] index The index of the property
174 * @param[in] type The Property::Type.
176 void AddAnimatableProperty( const std::string& name, Property::Index index, Property::Type type );
179 * Adds an animatable property with the given default value.
180 * @param[in] name The name of the property.
181 * @param[in] index The index of the property
182 * @param[in] type The Property::Type.
184 void AddAnimatableProperty( const std::string& name, Property::Index index, const Property::Value& defaultValue );
187 * Adds a component of an animatable property to the type.
188 * The animatable property must have been type-registered and must be a Vector2, Vector3 or Vector4 type.
189 * @param[in] name The name of the component.
190 * @param[in] index The index of the property
191 * @param[in] baseIndex The index of the base animatable property
192 * @param[in] component The index The index of the component.
194 void AddAnimatablePropertyComponent( const std::string& name, Property::Index index, Property::Index baseIndex, uint32_t componentIndex );
197 * Adds a child property to the type.
198 * @param[in] name The name of the property.
199 * @param[in] index The index of the property
200 * @param[in] type The Property::Type.
202 void AddChildProperty( const std::string& name, Property::Index index, Property::Type type );
205 * Do an action on base object
206 * @param [in] object The base object to act upon
207 * @param [in] actionName The name of the desired action
208 * @param [in] properties The arguments of the action
209 * @return bool If the action could be executed
211 bool DoActionTo(BaseObject *object, const std::string &actionName, const Property::Map &properties);
214 * Connects a callback function with the object's signals.
215 * @param[in] object The object providing the signal.
216 * @param[in] tracker Used to disconnect the signal.
217 * @param[in] signalName The signal to connect to.
218 * @param[in] functor A newly allocated FunctorDelegate.
219 * @return True if the signal was connected.
220 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
222 bool ConnectSignal( BaseObject* object, ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor );
225 * Given a property name, retrieve the index.
226 * @param[in] name The name of the property.
227 * @return The index associated with that name.
229 Property::Index GetPropertyIndex( const std::string& name ) const;
232 * Given a property index, retrieve the index of its base property.
233 * @param[in] index The index of the property.
234 * @return The index of the base property associated with the given property index.
236 Property::Index GetBasePropertyIndex( Property::Index index ) const;
239 * Given a property index, retrieve its component index.
240 * @param[in] index The index of the property.
241 * @return The component index associated with that property index.
243 int32_t GetComponentIndex( Property::Index index ) const;
246 * @param[in] index The property index.
247 * @return True, if writable, false otherwise.
249 bool IsPropertyWritable( Property::Index index ) const;
252 * @param[in] index The property index.
253 * @return True, if animatable, false otherwise.
255 bool IsPropertyAnimatable( Property::Index index ) const;
258 * @param[in] index The property index.
259 * @return True, if a constraint input, false otherwise.
261 bool IsPropertyAConstraintInput( Property::Index index ) const;
264 * Retrieve the Property::Type of the property at the given index.
265 * @param[in] index The property index.
266 * @return The Property::Type at that index.
268 Property::Type GetPropertyType( Property::Index index ) const;
271 * Given a child property name, retrieve the index.
272 * @param[in] name The name of the child property.
273 * @return The index associated with that name.
275 Property::Index GetChildPropertyIndex( const std::string& name ) const;
278 * Retrieve the name of the child property at the given index.
279 * @param[in] index The property index.
280 * @return The name of the child property.
282 const std::string& GetChildPropertyName( Property::Index index ) const;
285 * Retrieve the Property::Type of the child property at the given index.
286 * @param[in] index The property index.
287 * @return The Property::Type at that index.
289 Property::Type GetChildPropertyType( Property::Index index ) const;
292 * Retrive the child indices into the given container.
293 * @param[in,out] indices The container to put the child indices into
295 void GetChildPropertyIndices( Property::IndexContainer& indices ) const;
298 * Retrieve the default value of the property at the given index.
299 * @param[in] index The property index.
300 * @return The default property value at that index.
302 Property::Value GetPropertyDefaultValue( Property::Index index ) const;
305 * Sets the value of a property at the index specified for the given object.
306 * @param[in] object The object whose property is to be set.
307 * @param[in] index The property index.
308 * @param[in] value The value to set.
310 void SetProperty( BaseObject *object, Property::Index index, const Property::Value& value ) const;
313 * Sets the value of a property with the name specified for the given object.
314 * @param[in] object The object whose property is to be set.
315 * @param[in] name The property name.
316 * @param[in] value The value to set.
318 void SetProperty( BaseObject *object, const std::string& name, const Property::Value& value ) const;
321 * Retrieves the value of a property at the index specified for the given object.
322 * @param[in] object The object whose property is to be queried.
323 * @param[in] index The property index.
324 * @return The current value of the property.
326 Property::Value GetProperty( const BaseObject *object, Property::Index index ) const;
329 * Retrieves the value of a property with the name specified for the given object.
330 * @param[in] object The object whose property is to be queried.
331 * @param[in] name The property name.
332 * @return The current value of the property.
334 Property::Value GetProperty( const BaseObject *object, const std::string& name ) const;
338 struct RegisteredProperty
340 RegisteredProperty( Property::Type propType, const std::string& propName, Property::Index basePropertyIndex, int32_t componentIndex )
345 basePropertyIndex(basePropertyIndex),
346 componentIndex(componentIndex)
351 RegisteredProperty( Property::Type propType, Dali::TypeInfo::SetPropertyFunction set, Dali::TypeInfo::GetPropertyFunction get, const std::string& propName, Property::Index basePropertyIndex, int componentIndex )
356 basePropertyIndex(basePropertyIndex),
357 componentIndex(componentIndex)
361 RegisteredProperty( Property::Type propType, Dali::CSharpTypeInfo::SetPropertyFunction set, Dali::CSharpTypeInfo::GetPropertyFunction get, const std::string& propName, Property::Index basePropertyIndex, int componentIndex )
363 cSharpSetFunc( set ),
364 cSharpGetFunc( get ),
366 basePropertyIndex(basePropertyIndex),
367 componentIndex(componentIndex)
371 Property::Type type = Property::NONE;
374 Dali::TypeInfo::SetPropertyFunction setFunc = nullptr;
375 Dali::CSharpTypeInfo::SetPropertyFunction cSharpSetFunc; // only one field can be initialized but this will have same value anyways
379 Dali::TypeInfo::GetPropertyFunction getFunc = nullptr;
380 Dali::CSharpTypeInfo::GetPropertyFunction cSharpGetFunc; // only one field can be initialized but this will have same value anyways
383 Property::Index basePropertyIndex = Property::INVALID_INDEX;
384 int32_t componentIndex = Property::INVALID_COMPONENT_INDEX;
387 typedef std::pair<std::string, Dali::TypeInfo::SignalConnectorFunction > ConnectionPair;
388 typedef std::pair<std::string, Dali::TypeInfo::ActionFunction > ActionPair;
389 typedef std::pair<Property::Index, RegisteredProperty> RegisteredPropertyPair;
390 typedef std::pair<Property::Index, Property::Value> PropertyDefaultValuePair;
392 typedef std::vector< ActionPair > ActionContainer;
393 typedef std::vector< ConnectionPair > ConnectorContainer;
394 typedef std::vector< RegisteredPropertyPair > RegisteredPropertyContainer;
395 typedef std::vector< PropertyDefaultValuePair > PropertyDefaultValueContainer;
398 * Append properties from registeredProperties onto indices.
399 * @param[in,out] indices The vector to append indices onto
400 * @param[in] registeredProperties The container to retrive indices from
402 void AppendProperties( Dali::Property::IndexContainer& indices,
403 const TypeInfo::RegisteredPropertyContainer& registeredProperties ) const;
407 TypeRegistry& mTypeRegistry;
408 mutable Internal::TypeInfo* mBaseType; // allow changing from const methods, initialised inside constructor
409 std::string mTypeName;
410 std::string mBaseTypeName;
413 Dali::TypeInfo::CreateFunction mCreate = nullptr;
414 Dali::CSharpTypeInfo::CreateFunction mCSharpCreate; // only one field can be initialized but this will have same value anyways
416 ActionContainer mActions;
417 ConnectorContainer mSignalConnectors;
418 RegisteredPropertyContainer mRegisteredProperties;
419 RegisteredPropertyContainer mRegisteredChildProperties;
420 PropertyDefaultValueContainer mPropertyDefaultValues;
421 const Dali::PropertyDetails* mDefaultProperties = nullptr;
422 Property::Index mDefaultPropertyCount = 0;
423 bool mCSharpType = false; ///< Whether this type info is for a CSharp control (instead of C++)
426 } // namespace Internal
428 // Helpers for public-api forwarding methods
430 inline Internal::TypeInfo& GetImplementation(Dali::TypeInfo& typeInfo)
432 DALI_ASSERT_ALWAYS(typeInfo);
434 BaseObject& handle = typeInfo.GetBaseObject();
436 return static_cast<Internal::TypeInfo&>(handle);
439 inline const Internal::TypeInfo& GetImplementation(const Dali::TypeInfo& typeInfo)
441 DALI_ASSERT_ALWAYS(typeInfo);
443 const BaseObject& handle = typeInfo.GetBaseObject();
445 return static_cast<const Internal::TypeInfo&>(handle);
450 #endif // DALI_INTERNAL_TYPE_INFO_H