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 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::GetActions
81 void GetActions( Dali::TypeInfo::NameContainer& container ) const;
84 * @copydoc Dali::TypeInfo::GetSignals
86 void GetSignals( Dali::TypeInfo::NameContainer& container) const;
89 * @copydoc Dali::TypeInfo::GetProperties
91 void GetProperties( Dali::TypeInfo::NameContainer& container) const;
94 * Adds the property indices to the container specified.
95 * @param[in/out] indices The container where the property indices are added.
97 void GetPropertyIndices( Property::IndexContainer& indices ) const;
100 * @copydoc Dali::TypeInfo::GetPropertyName() const
102 const std::string& GetPropertyName( Property::Index index ) const;
105 * Add an action function
107 void AddActionFunction( const std::string &actionName, Dali::TypeInfo::ActionFunction function );
110 * Add a function for connecting a signal.
111 * @param[in] signalName The name of the signal.
112 * @param[in] function The function used for connecting to the signal.
114 void AddConnectorFunction( const std::string& signalName, Dali::TypeInfo::SignalConnectorFunctionV2 function );
117 * Adds an event-thread only property to the type.
118 * @param[in] name The name of the property.
119 * @param[in] index The index of the property.
120 * @param[in] type The Property::Type.
121 * @param[in] setFunc The function to call to set the property (Can be NULL).
122 * @param[in] getFunc The function to call to retrieve the value of the property.
124 void AddProperty( const std::string& name, Property::Index index, Property::Type type, Dali::TypeInfo::SetPropertyFunction setFunc, Dali::TypeInfo::GetPropertyFunction getFunc );
127 * Do an action on base object
128 * @param [in] object The base object to act upon
129 * @param [in] actionName The name of the desired action
130 * @param [in] properties The arguments of the action
131 * @return bool If the action could be executed
133 bool DoActionTo(BaseObject *object, const std::string &actionName, const std::vector<Property::Value> &properties);
136 * Connects a callback function with the object's signals.
137 * @param[in] object The object providing the signal.
138 * @param[in] tracker Used to disconnect the signal.
139 * @param[in] signalName The signal to connect to.
140 * @param[in] functor A newly allocated FunctorDelegate.
141 * @return True if the signal was connected.
142 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
144 bool ConnectSignal( BaseObject* object, ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor );
147 * Retrieve the property count for this type.
148 * @return The total number of properties.
150 unsigned int GetPropertyCount() const;
153 * Given a property name, retrieve the index.
154 * @param[in] name The name of the property.
155 * @return The index associated with that name.
157 Property::Index GetPropertyIndex( const std::string& name ) const;
160 * Checks if there is a setter for the property. If there is then it is writable.
161 * @param[in] index The property index.
162 * @return True, if writable, false otherwise.
164 bool IsPropertyWritable( Property::Index index ) const;
167 * Retrieve the Property::Type of the property at the given index.
168 * @param[in] index The property index.
169 * @return The Property::Type at that index.
171 Property::Type GetPropertyType( Property::Index index ) const;
174 * Sets the value of a property at the index specified for the given object.
175 * @param[in] object The object whose property is to be set.
176 * @param[in] index The property index.
177 * @param[in] value The value to set.
179 void SetProperty( BaseObject *object, Property::Index index, const Property::Value& value ) const;
182 * Sets the value of a property with the name specified for the given object.
183 * @param[in] object The object whose property is to be set.
184 * @param[in] name The property name.
185 * @param[in] value The value to set.
187 void SetProperty( BaseObject *object, const std::string& name, const Property::Value& value ) const;
190 * Retrieves the value of a property at the index specified for the given object.
191 * @param[in] object The object whose property is to be queried.
192 * @param[in] index The property index.
193 * @return The current value of the property.
195 Property::Value GetProperty( const BaseObject *object, Property::Index index ) const;
198 * Retrieves the value of a property with the name specified for the given object.
199 * @param[in] object The object whose property is to be queried.
200 * @param[in] name The property name.
201 * @return The current value of the property.
203 Property::Value GetProperty( const BaseObject *object, const std::string& name ) const;
207 struct RegisteredProperty
210 : type( Property::NONE ),
217 RegisteredProperty( Property::Type propType, Dali::TypeInfo::SetPropertyFunction set, Dali::TypeInfo::GetPropertyFunction get, const std::string& propName )
226 Dali::TypeInfo::SetPropertyFunction setFunc;
227 Dali::TypeInfo::GetPropertyFunction getFunc;
231 typedef std::pair<std::string, Dali::TypeInfo::SignalConnectorFunctionV2 > ConnectionPairV2;
232 typedef std::pair<std::string, Dali::TypeInfo::ActionFunction > ActionPair;
233 typedef std::pair<Property::Index, RegisteredProperty> RegisteredPropertyPair;
235 typedef std::vector< ActionPair > ActionContainer;
236 typedef std::vector< ConnectionPairV2 > ConnectorContainerV2;
237 typedef std::vector< RegisteredPropertyPair > RegisteredPropertyContainer;
239 std::string mTypeName;
240 std::string mBaseTypeName;
241 Dali::TypeInfo::CreateFunction mCreate;
242 ActionContainer mActions;
243 ConnectorContainerV2 mSignalConnectors;
244 RegisteredPropertyContainer mRegisteredProperties;
247 } // namespace Internal
249 // Helpers for public-api forwarding methods
251 inline Internal::TypeInfo& GetImplementation(Dali::TypeInfo& typeInfo)
253 DALI_ASSERT_ALWAYS(typeInfo);
255 BaseObject& handle = typeInfo.GetBaseObject();
257 return static_cast<Internal::TypeInfo&>(handle);
260 inline const Internal::TypeInfo& GetImplementation(const Dali::TypeInfo& typeInfo)
262 DALI_ASSERT_ALWAYS(typeInfo);
264 const BaseObject& handle = typeInfo.GetBaseObject();
266 return static_cast<const Internal::TypeInfo&>(handle);