1 #ifndef __DALI_INTERNAL_TYPE_INFO_H__
2 #define __DALI_INTERNAL_TYPE_INFO_H__
5 * Copyright (c) 2015 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>
36 * A TypeInfo class to support registered type creation, and introspection of available
37 * actions and signal connection.
38 * It also supports doing actions and connecting signal handlers. Note this is properly
39 * conducted through the BaseHandle interface which uses the TypeRegistry to walk
42 class TypeInfo : public BaseObject
47 * @param [name] the registered name
48 * @param [baseName] the base type registered name
49 * @param [creator] the creator function for this type
51 TypeInfo(const std::string &name, const std::string &baseName, Dali::TypeInfo::CreateFunction creator);
59 * @copydoc Dali::TypeInfo::GetName
61 const std::string& GetName() const;
64 * @copydoc Dali::TypeInfo::GetBaseName
66 const std::string& GetBaseName() const;
69 * @copydoc TypeInfo::CreateFunction
71 BaseHandle CreateInstance() const;
74 * @copydoc Dali::TypeInfo::GetCreator
76 Dali::TypeInfo::CreateFunction GetCreator() const;
79 * @copydoc Dali::TypeInfo::GetActionCount
81 size_t GetActionCount() const;
84 * @copydoc Dali::TypeInfo::GetActionName
86 std::string GetActionName(size_t index) const;
89 * @copydoc Dali::TypeInfo::GetSignalCount
91 size_t GetSignalCount() const;
94 * @copydoc Dali::TypeInfo::GetSignalName
96 std::string GetSignalName(size_t index) const;
99 * @copydoc Dali::TypeInfo::GetPropertyCount
101 size_t GetPropertyCount() const;
104 * @copydoc Dali::TypeInfo::GetPropertyName
106 std::string GetPropertyName(size_t index) const;
109 * Adds the property indices to the container specified.
110 * @param[in/out] indices The container where the property indices are added.
112 void GetPropertyIndices( Property::IndexContainer& indices ) const;
115 * @copydoc Dali::TypeInfo::GetPropertyName() const
117 const std::string& GetPropertyName( Property::Index index ) const;
120 * Add an action function
122 void AddActionFunction( const std::string &actionName, Dali::TypeInfo::ActionFunction function );
125 * Add a function for connecting a signal.
126 * @param[in] signalName The name of the signal.
127 * @param[in] function The function used for connecting to the signal.
129 void AddConnectorFunction( const std::string& signalName, Dali::TypeInfo::SignalConnectorFunction function );
132 * Adds an event-thread only property to the type.
133 * @param[in] name The name of the property.
134 * @param[in] index The index of the property.
135 * @param[in] type The Property::Type.
136 * @param[in] setFunc The function to call to set the property (Can be NULL).
137 * @param[in] getFunc The function to call to retrieve the value of the property.
139 void AddProperty( const std::string& name, Property::Index index, Property::Type type, Dali::TypeInfo::SetPropertyFunction setFunc, Dali::TypeInfo::GetPropertyFunction getFunc );
142 * Adds an animatable property to the type.
143 * @param[in] name The name of the property.
144 * @param[in] index The index of the property
145 * @param[in] type The Property::Type.
147 void AddAnimatableProperty( const std::string& name, Property::Index index, Property::Type type );
150 * Adds an animatable property with the given default value.
151 * @param[in] name The name of the property.
152 * @param[in] index The index of the property
153 * @param[in] type The Property::Type.
155 void AddAnimatableProperty( const std::string& name, Property::Index index, const Property::Value& defaultValue );
158 * Adds a component of an animatable property to the type.
159 * The animatable property must have been type-registered and must be a Vector2, Vector3 or Vector4 type.
160 * @param[in] name The name of the component.
161 * @param[in] index The index of the property
162 * @param[in] baseIndex The index of the base animatable property
163 * @param[in] component The index The index of the component.
165 void AddAnimatablePropertyComponent( const std::string& name, Property::Index index, Property::Index baseIndex, unsigned int componentIndex );
168 * Do an action on base object
169 * @param [in] object The base object to act upon
170 * @param [in] actionName The name of the desired action
171 * @param [in] properties The arguments of the action
172 * @return bool If the action could be executed
174 bool DoActionTo(BaseObject *object, const std::string &actionName, const Property::Map &properties);
177 * Connects a callback function with the object's signals.
178 * @param[in] object The object providing the signal.
179 * @param[in] tracker Used to disconnect the signal.
180 * @param[in] signalName The signal to connect to.
181 * @param[in] functor A newly allocated FunctorDelegate.
182 * @return True if the signal was connected.
183 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
185 bool ConnectSignal( BaseObject* object, ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor );
188 * Given a property name, retrieve the index.
189 * @param[in] name The name of the property.
190 * @return The index associated with that name.
192 Property::Index GetPropertyIndex( const std::string& name ) const;
195 * Given a property index, retrieve the index of its base property.
196 * @param[in] index The index of the property.
197 * @return The index of the base property associated with the given property index.
199 Property::Index GetBasePropertyIndex( Property::Index index ) const;
202 * Given a property index, retrieve its component index.
203 * @param[in] index The index of the property.
204 * @return The component index associated with that property index.
206 int GetComponentIndex( Property::Index index ) const;
209 * Checks if there is a setter for the property. If there is then it is writable.
210 * @param[in] index The property index.
211 * @return True, if writable, false otherwise.
213 bool IsPropertyWritable( Property::Index index ) const;
216 * Retrieve the Property::Type of the property at the given index.
217 * @param[in] index The property index.
218 * @return The Property::Type at that index.
220 Property::Type GetPropertyType( Property::Index index ) const;
223 * Retrieve the default value of the property at the given index.
224 * @param[in] index The property index.
225 * @return The default property value at that index.
227 Property::Value GetPropertyDefaultValue( Property::Index index ) const;
230 * Sets the value of a property at the index specified for the given object.
231 * @param[in] object The object whose property is to be set.
232 * @param[in] index The property index.
233 * @param[in] value The value to set.
235 void SetProperty( BaseObject *object, Property::Index index, const Property::Value& value ) const;
238 * Sets the value of a property with the name specified for the given object.
239 * @param[in] object The object whose property is to be set.
240 * @param[in] name The property name.
241 * @param[in] value The value to set.
243 void SetProperty( BaseObject *object, const std::string& name, const Property::Value& value ) const;
246 * Retrieves the value of a property at the index specified for the given object.
247 * @param[in] object The object whose property is to be queried.
248 * @param[in] index The property index.
249 * @return The current value of the property.
251 Property::Value GetProperty( const BaseObject *object, Property::Index index ) const;
254 * Retrieves the value of a property with the name specified for the given object.
255 * @param[in] object The object whose property is to be queried.
256 * @param[in] name The property name.
257 * @return The current value of the property.
259 Property::Value GetProperty( const BaseObject *object, const std::string& name ) const;
263 struct RegisteredProperty
266 : type( Property::NONE ),
270 basePropertyIndex(Property::INVALID_INDEX),
271 componentIndex(Property::INVALID_COMPONENT_INDEX)
275 RegisteredProperty( Property::Type propType, Dali::TypeInfo::SetPropertyFunction set, Dali::TypeInfo::GetPropertyFunction get, const std::string& propName, Property::Index basePropertyIndex, int componentIndex )
280 basePropertyIndex(basePropertyIndex),
281 componentIndex(componentIndex)
286 Dali::TypeInfo::SetPropertyFunction setFunc;
287 Dali::TypeInfo::GetPropertyFunction getFunc;
289 Property::Index basePropertyIndex;
293 typedef std::pair<std::string, Dali::TypeInfo::SignalConnectorFunction > ConnectionPair;
294 typedef std::pair<std::string, Dali::TypeInfo::ActionFunction > ActionPair;
295 typedef std::pair<Property::Index, RegisteredProperty> RegisteredPropertyPair;
296 typedef std::pair<Property::Index, Property::Value> PropertyDefaultValuePair;
298 typedef std::vector< ActionPair > ActionContainer;
299 typedef std::vector< ConnectionPair > ConnectorContainer;
300 typedef std::vector< RegisteredPropertyPair > RegisteredPropertyContainer;
301 typedef std::vector< PropertyDefaultValuePair > PropertyDefaultValueContainer;
303 std::string mTypeName;
304 std::string mBaseTypeName;
305 Dali::TypeInfo::CreateFunction mCreate;
306 ActionContainer mActions;
307 ConnectorContainer mSignalConnectors;
308 RegisteredPropertyContainer mRegisteredProperties;
309 PropertyDefaultValueContainer mPropertyDefaultValues;
312 } // namespace Internal
314 // Helpers for public-api forwarding methods
316 inline Internal::TypeInfo& GetImplementation(Dali::TypeInfo& typeInfo)
318 DALI_ASSERT_ALWAYS(typeInfo);
320 BaseObject& handle = typeInfo.GetBaseObject();
322 return static_cast<Internal::TypeInfo&>(handle);
325 inline const Internal::TypeInfo& GetImplementation(const Dali::TypeInfo& typeInfo)
327 DALI_ASSERT_ALWAYS(typeInfo);
329 const BaseObject& handle = typeInfo.GetBaseObject();
331 return static_cast<const Internal::TypeInfo&>(handle);