1 #ifndef __DALI_INTERNAL_TYPE_INFO_H__
2 #define __DALI_INTERNAL_TYPE_INFO_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
24 #include <dali/public-api/object/base-handle.h>
25 #include <dali/public-api/object/base-object.h>
26 #include <dali/public-api/object/type-info.h>
35 * A TypeInfo class to support registered type creation, and introspection of available
36 * actions and signal connection.
37 * It also supports doing actions and connecting signal handlers. Note this is properly
38 * conducted through the BaseHandle interface which uses the TypeRegistry to walk
41 class TypeInfo : public BaseObject
46 * @param [name] the registered name
47 * @param [baseName] the base type registered name
48 * @param [creator] the creator function for this type
50 TypeInfo(const std::string &name, const std::string &baseName, Dali::TypeInfo::CreateFunction creator);
58 * @copydoc Dali::TypeInfo::GetName
60 const std::string& GetName();
63 * @copydoc Dali::TypeInfo::GetBaseName
65 const std::string& GetBaseName();
68 * @copydoc TypeInfo::CreateFunction
70 BaseHandle CreateInstance();
73 * @copydoc Dali::TypeInfo::GetCreator
75 Dali::TypeInfo::CreateFunction GetCreator();
78 * @copydoc Dali::TypeInfo::GetActions
80 Dali::TypeInfo::NameContainer GetActions();
83 * @copydoc Dali::TypeInfo::GetSignals
85 Dali::TypeInfo::NameContainer GetSignals();
88 * Adds the property indices to the container specified.
89 * @param[in/out] indices The container where the property indices are added.
91 void GetPropertyIndices( Property::IndexContainer& indices ) const;
94 * @copydoc Dali::TypeInfo::GetPropertyName() const
96 const std::string& GetPropertyName( Property::Index index ) const;
99 * Add an action function
101 void AddActionFunction( const std::string &actionName, Dali::TypeInfo::ActionFunction function );
104 * Add a function for connecting a signal.
105 * @param[in] signalName The name of the signal.
106 * @param[in] function The function used for connecting to the signal.
108 void AddConnectorFunction( const std::string& signalName, Dali::TypeInfo::SignalConnectorFunctionV2 function );
111 * Adds an event-thread only property to the type.
112 * @param[in] name The name of the property.
113 * @param[in] index The index of the property.
114 * @param[in] type The Property::Type.
115 * @param[in] setFunc The function to call to set the property (Can be NULL).
116 * @param[in] getFunc The function to call to retrieve the value of the property.
118 void AddProperty( const std::string& name, Property::Index index, Property::Type type, Dali::TypeInfo::SetPropertyFunction setFunc, Dali::TypeInfo::GetPropertyFunction getFunc );
121 * Do an action on base object
122 * @param [in] object The base object to act upon
123 * @param [in] actionName The name of the desired action
124 * @param [in] properties The arguments of the action
125 * @return bool If the action could be executed
127 bool DoActionTo(BaseObject *object, const std::string &actionName, const std::vector<Property::Value> &properties);
130 * Connects a callback function with the object's signals.
131 * @param[in] object The object providing the signal.
132 * @param[in] tracker Used to disconnect the signal.
133 * @param[in] signalName The signal to connect to.
134 * @param[in] functor A newly allocated FunctorDelegate.
135 * @return True if the signal was connected.
136 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
138 bool ConnectSignal( BaseObject* object, ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor );
141 * Retrieve the property count for this type.
142 * @return The total number of properties.
144 unsigned int GetPropertyCount() const;
147 * Given a property name, retrieve the index.
148 * @param[in] name The name of the property.
149 * @return The index associated with that name.
151 Property::Index GetPropertyIndex( const std::string& name ) const;
154 * Checks if there is a setter for the property. If there is then it is writable.
155 * @param[in] index The property index.
156 * @return True, if writable, false otherwise.
158 bool IsPropertyWritable( Property::Index index ) const;
161 * Retrieve the Property::Type of the property at the given index.
162 * @param[in] index The property index.
163 * @return The Property::Type at that index.
165 Property::Type GetPropertyType( Property::Index index ) const;
168 * Sets the value of a property at the index specified for the given object.
169 * @param[in] object The object whose property is to be set.
170 * @param[in] index The property index.
171 * @param[in] value The value to set.
173 void SetProperty( BaseObject *object, Property::Index index, const Property::Value& value );
176 * Sets the value of a property with the name specified for the given object.
177 * @param[in] object The object whose property is to be set.
178 * @param[in] name The property name.
179 * @param[in] value The value to set.
181 void SetProperty( BaseObject *object, const std::string& name, const Property::Value& value );
184 * Retrieves the value of a property at the index specified for the given object.
185 * @param[in] object The object whose property is to be queried.
186 * @param[in] index The property index.
187 * @return The current value of the property.
189 Property::Value GetProperty( const BaseObject *object, Property::Index index );
192 * Retrieves the value of a property with the name specified for the given object.
193 * @param[in] object The object whose property is to be queried.
194 * @param[in] name The property name.
195 * @return The current value of the property.
197 Property::Value GetProperty( const BaseObject *object, const std::string& name );
201 struct RegisteredProperty
204 : type( Property::NONE ),
211 RegisteredProperty( Property::Type propType, Dali::TypeInfo::SetPropertyFunction set, Dali::TypeInfo::GetPropertyFunction get, const std::string& propName )
220 Dali::TypeInfo::SetPropertyFunction setFunc;
221 Dali::TypeInfo::GetPropertyFunction getFunc;
225 typedef std::pair<std::string, Dali::TypeInfo::SignalConnectorFunctionV2 > ConnectionPairV2;
226 typedef std::pair<std::string, Dali::TypeInfo::ActionFunction > ActionPair;
227 typedef std::pair<Property::Index, RegisteredProperty> RegisteredPropertyPair;
229 typedef std::vector< ActionPair > ActionContainer;
230 typedef std::vector< ConnectionPairV2 > ConnectorContainerV2;
231 typedef std::vector< RegisteredPropertyPair > RegisteredPropertyContainer;
233 std::string mTypeName;
234 std::string mBaseTypeName;
235 Dali::TypeInfo::CreateFunction mCreate;
236 ActionContainer mActions;
237 ConnectorContainerV2 mSignalConnectors;
238 RegisteredPropertyContainer mRegisteredProperties;
241 } // namespace Internal
243 // Helpers for public-api forwarding methods
245 inline Internal::TypeInfo& GetImplementation(Dali::TypeInfo& typeInfo)
247 DALI_ASSERT_ALWAYS(typeInfo);
249 BaseObject& handle = typeInfo.GetBaseObject();
251 return static_cast<Internal::TypeInfo&>(handle);
254 inline const Internal::TypeInfo& GetImplementation(const Dali::TypeInfo& typeInfo)
256 DALI_ASSERT_ALWAYS(typeInfo);
258 const BaseObject& handle = typeInfo.GetBaseObject();
260 return static_cast<const Internal::TypeInfo&>(handle);