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/devel-api/object/csharp-type-info.h>
26 #include <dali/internal/common/const-string.h>
27 #include <dali/internal/event/object/default-property-metadata.h>
28 #include <dali/public-api/object/base-handle.h>
29 #include <dali/public-api/object/base-object.h>
30 #include <dali/public-api/object/property.h>
31 #include <dali/public-api/object/type-info.h>
38 class PropertyDetails;
42 * A TypeInfo class to support registered type creation, and introspection of available
43 * actions and signal connection.
44 * It also supports doing actions and connecting signal handlers. Note this is properly
45 * conducted through the BaseHandle interface which uses the TypeRegistry to walk
48 class TypeInfo : public BaseObject
54 * @param [name] the registered name
55 * @param [baseName] the base type registered name
56 * @param [creator] the creator function for this type
58 TypeInfo( const std::string& name, const std::string& baseName, Dali::TypeInfo::CreateFunction creator,
59 const Dali::PropertyDetails* defaultProperties, Property::Index defaultPropertyCount );
62 * Create TypeInfo for a csharp object
63 * @param [name] the registered name
64 * @param [baseName] the base type registered name
65 * @param [creator] the creator function for this type
67 TypeInfo( const std::string& name, const std::string& baseName, Dali::CSharpTypeInfo::CreateFunction creator );
75 * @copydoc Dali::TypeInfo::GetName
77 const std::string& GetName() const;
80 * @copydoc Dali::TypeInfo::GetBaseName
82 const std::string& GetBaseName() const;
85 * @copydoc TypeInfo::CreateFunction
87 BaseHandle CreateInstance() const;
90 * @copydoc Dali::TypeInfo::GetCreator
92 Dali::TypeInfo::CreateFunction GetCreator() const;
95 * @copydoc Dali::TypeInfo::GetActionCount
97 uint32_t GetActionCount() const;
100 * @copydoc Dali::TypeInfo::GetActionName
102 std::string GetActionName( uint32_t index ) const;
105 * @copydoc Dali::TypeInfo::GetSignalCount
107 uint32_t GetSignalCount() const;
110 * @copydoc Dali::TypeInfo::GetSignalName
112 std::string GetSignalName( uint32_t index ) const;
115 * @copydoc Dali::TypeInfo::GetPropertyCount
117 uint32_t GetPropertyCount() const;
120 * Adds the property indices to the container specified.
121 * @param[in/out] indices The container where the property indices are added.
123 void GetPropertyIndices( Property::IndexContainer& indices ) const;
126 * @copydoc Dali::TypeInfo::GetPropertyName() const
127 * this API exists to keep the old public API, which cannot be changed
129 std::string_view GetRegisteredPropertyName(Property::Index index) const;
132 * Returns the property name for given index
134 * @param index of the property
135 * @return name or empty string
137 std::string_view GetPropertyName(Property::Index index) const;
140 * Add an action function
142 void AddActionFunction(std::string actionName, Dali::TypeInfo::ActionFunction function);
145 * Add a function for connecting a signal.
146 * @param[in] signalName The name of the signal.
147 * @param[in] function The function used for connecting to the signal.
149 void AddConnectorFunction(std::string signalName, Dali::TypeInfo::SignalConnectorFunction function);
152 * Adds an event-thread only property to the type.
153 * @param[in] name The name of the property.
154 * @param[in] index The index of the property.
155 * @param[in] type The Property::Type.
156 * @param[in] setFunc The function to call to set the property (Can be nullptr).
157 * @param[in] getFunc The function to call to retrieve the value of the property.
159 void AddProperty(std::string name, Property::Index index, Property::Type type, Dali::TypeInfo::SetPropertyFunction setFunc, Dali::TypeInfo::GetPropertyFunction getFunc);
162 * Adds an event-thread only property to the type.
163 * @param[in] name The name of the property.
164 * @param[in] index The index of the property.
165 * @param[in] type The Property::Type.
166 * @param[in] setFunc The function to call to set the property (Can be nullptr).
167 * @param[in] getFunc The function to call to retrieve the value of the property.
169 void AddProperty(std::string name, Property::Index index, Property::Type type, Dali::CSharpTypeInfo::SetPropertyFunction setFunc, Dali::CSharpTypeInfo::GetPropertyFunction getFunc);
172 * Adds an animatable property to the type.
173 * @param[in] name The name of the property.
174 * @param[in] index The index of the property
175 * @param[in] type The Property::Type.
177 void AddAnimatableProperty(std::string name, Property::Index index, Property::Type type);
180 * Adds an animatable property with the given default value.
181 * @param[in] name The name of the property.
182 * @param[in] index The index of the property
183 * @param[in] type The Property::Type.
185 void AddAnimatableProperty(std::string name, Property::Index index, Property::Value defaultValue);
188 * Adds a component of an animatable property to the type.
189 * The animatable property must have been type-registered and must be a Vector2, Vector3 or Vector4 type.
190 * @param[in] name The name of the component.
191 * @param[in] index The index of the property
192 * @param[in] baseIndex The index of the base animatable property
193 * @param[in] component The index The index of the component.
195 void AddAnimatablePropertyComponent(std::string name, Property::Index index, Property::Index baseIndex, uint32_t componentIndex);
198 * Adds a child property to the type.
199 * @param[in] name The name of the property.
200 * @param[in] index The index of the property
201 * @param[in] type The Property::Type.
203 void AddChildProperty(std::string name, Property::Index index, Property::Type type);
206 * Do an action on base object
207 * @param [in] object The base object to act upon
208 * @param [in] actionName The name of the desired action
209 * @param [in] properties The arguments of the action
210 * @return bool If the action could be executed
212 bool DoActionTo(BaseObject *object, const std::string &actionName, const Property::Map &properties);
215 * Connects a callback function with the object's signals.
216 * @param[in] object The object providing the signal.
217 * @param[in] tracker Used to disconnect the signal.
218 * @param[in] signalName The signal to connect to.
219 * @param[in] functor A newly allocated FunctorDelegate.
220 * @return True if the signal was connected.
221 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
223 bool ConnectSignal( BaseObject* object, ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor );
226 * Given a property name, retrieve the index.
227 * @param[in] name The name of the property.
228 * @return The index associated with that name.
230 Property::Index GetPropertyIndex(ConstString name) const;
233 * Given a property index, retrieve the index of its base property.
234 * @param[in] index The index of the property.
235 * @return The index of the base property associated with the given property index.
237 Property::Index GetBasePropertyIndex( Property::Index index ) const;
240 * Given a property index, retrieve its component index.
241 * @param[in] index The index of the property.
242 * @return The component index associated with that property index.
244 int32_t GetComponentIndex( Property::Index index ) const;
247 * @param[in] index The property index.
248 * @return True, if writable, false otherwise.
250 bool IsPropertyWritable( Property::Index index ) const;
253 * @param[in] index The property index.
254 * @return True, if animatable, false otherwise.
256 bool IsPropertyAnimatable( Property::Index index ) const;
259 * @param[in] index The property index.
260 * @return True, if a constraint input, false otherwise.
262 bool IsPropertyAConstraintInput( Property::Index index ) const;
265 * Retrieve the Property::Type of the property at the given index.
266 * @param[in] index The property index.
267 * @return The Property::Type at that index.
269 Property::Type GetPropertyType( Property::Index index ) const;
272 * Given a child property name, retrieve the index.
273 * @param[in] name The name of the child property.
274 * @return The index associated with that name.
276 Property::Index GetChildPropertyIndex(ConstString name) const;
279 * Retrieve the name of the child property at the given index.
280 * @param[in] index The property index.
281 * @return The name of the child property.
283 std::string_view GetChildPropertyName(Property::Index index) const;
286 * Retrieve the Property::Type of the child property at the given index.
287 * @param[in] index The property index.
288 * @return The Property::Type at that index.
290 Property::Type GetChildPropertyType( Property::Index index ) const;
293 * Retrive the child indices into the given container.
294 * @param[in,out] indices The container to put the child indices into
296 void GetChildPropertyIndices( Property::IndexContainer& indices ) const;
299 * Retrieve the default value of the property at the given index.
300 * @param[in] index The property index.
301 * @return The default property value at that index.
303 Property::Value GetPropertyDefaultValue( Property::Index index ) const;
306 * Sets the value of a property at the index specified for the given object.
307 * @param[in] object The object whose property is to be set.
308 * @param[in] index The property index.
309 * @param[in] value The value to set.
311 void SetProperty(BaseObject* object, Property::Index index, Property::Value value) const;
314 * Sets the value of a property with the name specified for the given object.
315 * @param[in] object The object whose property is to be set.
316 * @param[in] name The property name.
317 * @param[in] value The value to set.
319 void SetProperty(BaseObject* object, const std::string& name, Property::Value value) const;
322 * Retrieves the value of a property at the index specified for the given object.
323 * @param[in] object The object whose property is to be queried.
324 * @param[in] index The property index.
325 * @return The current value of the property.
327 Property::Value GetProperty( const BaseObject *object, Property::Index index ) const;
330 * Retrieves the value of a property with the name specified for the given object.
331 * @param[in] object The object whose property is to be queried.
332 * @param[in] name The property name.
333 * @return The current value of the property.
335 Property::Value GetProperty( const BaseObject *object, const std::string& name ) const;
339 struct RegisteredProperty
341 RegisteredProperty(Property::Type propType, ConstString propName, Property::Index basePropertyIndex, int32_t componentIndex)
346 basePropertyIndex(basePropertyIndex),
347 componentIndex(componentIndex)
351 RegisteredProperty(Property::Type propType, Dali::TypeInfo::SetPropertyFunction set, Dali::TypeInfo::GetPropertyFunction get, ConstString 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, ConstString propName, Property::Index basePropertyIndex, int componentIndex)
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 using ConnectionPair = std::pair<std::string, Dali::TypeInfo::SignalConnectorFunction>;
388 using ActionPair = std::pair<std::string, Dali::TypeInfo::ActionFunction>;
389 using RegisteredPropertyPair = std::pair<Property::Index, RegisteredProperty>;
390 using PropertyDefaultValuePair = std::pair<Property::Index, Property::Value>;
392 using ActionContainer = std::vector<ActionPair>;
393 using ConnectorContainer = std::vector<ConnectionPair>;
394 using RegisteredPropertyContainer = std::vector<RegisteredPropertyPair>;
395 using PropertyDefaultValueContainer = std::vector<PropertyDefaultValuePair>;
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