1 #ifndef DALI_INTERNAL_TYPE_INFO_H
2 #define DALI_INTERNAL_TYPE_INFO_H
3 #define USE_INDEXED_MAP_CONTAINER_AT_TYPE_INFO /// For safety. If some problem occured, just remove this define.
6 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
26 #ifdef USE_INDEXED_MAP_CONTAINER_AT_TYPE_INFO
27 #include <dali/internal/common/indexed-const-string-map.h>
28 #include <dali/internal/common/indexed-integer-map.h>
31 #include <dali/devel-api/object/csharp-type-info.h>
32 #include <dali/internal/common/const-string.h>
33 #include <dali/internal/event/object/default-property-metadata.h>
34 #include <dali/public-api/object/base-handle.h>
35 #include <dali/public-api/object/base-object.h>
36 #include <dali/public-api/object/property.h>
37 #include <dali/public-api/object/type-info.h>
43 class PropertyDetails;
47 * A TypeInfo class to support registered type creation, and introspection of available
48 * actions and signal connection.
49 * It also supports doing actions and connecting signal handlers. Note this is properly
50 * conducted through the BaseHandle interface which uses the TypeRegistry to walk
53 class TypeInfo : public BaseObject
58 * @param [name] the registered name
59 * @param [baseName] the base type registered name
60 * @param [creator] the creator function for this type
62 TypeInfo(const std::string& name, const std::string& baseName, Dali::TypeInfo::CreateFunction creator, const Dali::PropertyDetails* defaultProperties, Property::Index defaultPropertyCount);
65 * Create TypeInfo for a csharp object
66 * @param [name] the registered name
67 * @param [baseName] the base type registered name
68 * @param [creator] the creator function for this type
70 TypeInfo(const std::string& name, const std::string& baseName, Dali::CSharpTypeInfo::CreateFunction creator);
78 * @copydoc Dali::TypeInfo::GetName
80 const std::string& GetName() const;
83 * @copydoc Dali::TypeInfo::GetBaseName
85 const std::string& GetBaseName() const;
88 * @copydoc TypeInfo::CreateFunction
90 BaseHandle CreateInstance() const;
93 * @copydoc Dali::TypeInfo::GetCreator
95 Dali::TypeInfo::CreateFunction GetCreator() const;
98 * @copydoc Dali::TypeInfo::GetActionCount
100 uint32_t GetActionCount() const;
103 * @copydoc Dali::TypeInfo::GetActionName
105 std::string GetActionName(uint32_t index) const;
108 * @copydoc Dali::TypeInfo::GetSignalCount
110 uint32_t GetSignalCount() const;
113 * @copydoc Dali::TypeInfo::GetSignalName
115 std::string GetSignalName(uint32_t index) const;
118 * @copydoc Dali::TypeInfo::GetPropertyCount
120 uint32_t GetPropertyCount() const;
123 * Adds the property indices to the container specified.
124 * @param[in/out] indices The container where the property indices are added.
126 void GetPropertyIndices(Property::IndexContainer& indices) const;
129 * @copydoc Dali::TypeInfo::GetPropertyName() const
130 * this API exists to keep the old public API, which cannot be changed
132 std::string_view GetRegisteredPropertyName(Property::Index index) const;
135 * Returns the property name for given index
137 * @param index of the property
138 * @return name or empty string
140 std::string_view GetPropertyName(Property::Index index) const;
143 * Add an action function
145 void AddActionFunction(std::string actionName, Dali::TypeInfo::ActionFunction function);
148 * Add a function for connecting a signal.
149 * @param[in] signalName The name of the signal.
150 * @param[in] function The function used for connecting to the signal.
152 void AddConnectorFunction(std::string signalName, Dali::TypeInfo::SignalConnectorFunction function);
155 * Adds an event-thread only property to the type.
156 * @param[in] name The name of the property.
157 * @param[in] index The index of the property.
158 * @param[in] type The Property::Type.
159 * @param[in] setFunc The function to call to set the property (Can be nullptr).
160 * @param[in] getFunc The function to call to retrieve the value of the property.
162 void AddProperty(std::string name, Property::Index index, Property::Type type, Dali::TypeInfo::SetPropertyFunction setFunc, Dali::TypeInfo::GetPropertyFunction getFunc);
165 * Adds an event-thread only property to the type.
166 * @param[in] name The name of the property.
167 * @param[in] index The index of the property.
168 * @param[in] type The Property::Type.
169 * @param[in] setFunc The function to call to set the property (Can be nullptr).
170 * @param[in] getFunc The function to call to retrieve the value of the property.
172 void AddProperty(std::string name, Property::Index index, Property::Type type, Dali::CSharpTypeInfo::SetPropertyFunction setFunc, Dali::CSharpTypeInfo::GetPropertyFunction getFunc);
175 * Adds an animatable property to the type.
176 * @param[in] name The name of the property.
177 * @param[in] index The index of the property
178 * @param[in] type The Property::Type.
180 void AddAnimatableProperty(std::string name, Property::Index index, Property::Type type);
183 * Adds an animatable property with the given default value.
184 * @param[in] name The name of the property.
185 * @param[in] index The index of the property
186 * @param[in] type The Property::Type.
188 void AddAnimatableProperty(std::string name, Property::Index index, Property::Value defaultValue);
191 * Adds a component of an animatable property to the type.
192 * The animatable property must have been type-registered and must be a Vector2, Vector3 or Vector4 type.
193 * @param[in] name The name of the component.
194 * @param[in] index The index of the property
195 * @param[in] baseIndex The index of the base animatable property
196 * @param[in] component The index The index of the component.
198 void AddAnimatablePropertyComponent(std::string name, Property::Index index, Property::Index baseIndex, uint32_t componentIndex);
201 * Adds a child property to the type.
202 * @param[in] name The name of the property.
203 * @param[in] index The index of the property
204 * @param[in] type The Property::Type.
206 void AddChildProperty(std::string name, Property::Index index, Property::Type type);
209 * Do an action on base object
210 * @param [in] object The base object to act upon
211 * @param [in] actionName The name of the desired action
212 * @param [in] properties The arguments of the action
213 * @return bool If the action could be executed
215 bool DoActionTo(BaseObject* object, const std::string& actionName, const Property::Map& properties);
218 * Connects a callback function with the object's signals.
219 * @param[in] object The object providing the signal.
220 * @param[in] tracker Used to disconnect the signal.
221 * @param[in] signalName The signal to connect to.
222 * @param[in] functor A newly allocated FunctorDelegate.
223 * @return True if the signal was connected.
224 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
226 bool ConnectSignal(BaseObject* object, ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor);
229 * Given a property name, retrieve the index.
230 * @param[in] name The name of the property.
231 * @return The index associated with that name.
233 Property::Index GetPropertyIndex(ConstString name) const;
236 * Given a property index, retrieve the index of its base property.
237 * @param[in] index The index of the property.
238 * @return The index of the base property associated with the given property index.
240 Property::Index GetBasePropertyIndex(Property::Index index) const;
243 * Given a property index, retrieve its component index.
244 * @param[in] index The index of the property.
245 * @return The component index associated with that property index.
247 int32_t GetComponentIndex(Property::Index index) const;
250 * @param[in] index The property index.
251 * @return True, if writable, false otherwise.
253 bool IsPropertyWritable(Property::Index index) const;
256 * @param[in] index The property index.
257 * @return True, if animatable, false otherwise.
259 bool IsPropertyAnimatable(Property::Index index) const;
262 * @param[in] index The property index.
263 * @return True, if a constraint input, false otherwise.
265 bool IsPropertyAConstraintInput(Property::Index index) const;
268 * Retrieve the Property::Type of the property at the given index.
269 * @param[in] index The property index.
270 * @return The Property::Type at that index.
272 Property::Type GetPropertyType(Property::Index index) const;
275 * Given a child property name, retrieve the index.
276 * @param[in] name The name of the child property.
277 * @return The index associated with that name.
279 Property::Index GetChildPropertyIndex(ConstString name) const;
282 * Retrieve the name of the child property at the given index.
283 * @param[in] index The property index.
284 * @return The name of the child property.
286 std::string_view GetChildPropertyName(Property::Index index) const;
289 * Retrieve the Property::Type of the child property at the given index.
290 * @param[in] index The property index.
291 * @return The Property::Type at that index.
293 Property::Type GetChildPropertyType(Property::Index index) const;
296 * Retrive the child indices into the given container.
297 * @param[in,out] indices The container to put the child indices into
299 void GetChildPropertyIndices(Property::IndexContainer& indices) const;
302 * Retrieve the default value of the property at the given index.
303 * @param[in] index The property index.
304 * @return The default property value at that index.
306 Property::Value GetPropertyDefaultValue(Property::Index index) const;
309 * Sets the value of a property at the index specified for the given object.
310 * @param[in] object The object whose property is to be set.
311 * @param[in] index The property index.
312 * @param[in] value The value to set.
314 void SetProperty(BaseObject* object, Property::Index index, Property::Value value) const;
317 * Sets the value of a property with the name specified for the given object.
318 * @param[in] object The object whose property is to be set.
319 * @param[in] name The property name.
320 * @param[in] value The value to set.
322 void SetProperty(BaseObject* object, const std::string& name, Property::Value value) const;
325 * Retrieves the value of a property at the index specified for the given object.
326 * @param[in] object The object whose property is to be queried.
327 * @param[in] index The property index.
328 * @return The current value of the property.
330 Property::Value GetProperty(const BaseObject* object, Property::Index index) const;
333 * Retrieves the value of a property with the name specified for the given object.
334 * @param[in] object The object whose property is to be queried.
335 * @param[in] name The property name.
336 * @return The current value of the property.
338 Property::Value GetProperty(const BaseObject* object, const std::string& name) const;
341 struct RegisteredProperty
343 RegisteredProperty(Property::Type propType, ConstString propName, Property::Index basePropertyIndex, int32_t componentIndex)
348 basePropertyIndex(basePropertyIndex),
349 componentIndex(componentIndex)
353 RegisteredProperty(Property::Type propType, Dali::TypeInfo::SetPropertyFunction set, Dali::TypeInfo::GetPropertyFunction get, ConstString propName, Property::Index basePropertyIndex, int componentIndex)
358 basePropertyIndex(basePropertyIndex),
359 componentIndex(componentIndex)
363 RegisteredProperty(Property::Type propType, Dali::CSharpTypeInfo::SetPropertyFunction set, Dali::CSharpTypeInfo::GetPropertyFunction get, ConstString propName, Property::Index basePropertyIndex, int componentIndex)
368 basePropertyIndex(basePropertyIndex),
369 componentIndex(componentIndex)
373 Property::Type type = Property::NONE;
376 Dali::TypeInfo::SetPropertyFunction setFunc = nullptr;
377 Dali::CSharpTypeInfo::SetPropertyFunction cSharpSetFunc; // only one field can be initialized but this will have same value anyways
381 Dali::TypeInfo::GetPropertyFunction getFunc = nullptr;
382 Dali::CSharpTypeInfo::GetPropertyFunction cSharpGetFunc; // only one field can be initialized but this will have same value anyways
385 Property::Index basePropertyIndex = Property::INVALID_INDEX;
386 int32_t componentIndex = Property::INVALID_COMPONENT_INDEX;
389 using ActionPair = std::pair<std::string, Dali::TypeInfo::ActionFunction>;
390 using ConnectionPair = std::pair<std::string, Dali::TypeInfo::SignalConnectorFunction>;
391 #ifdef USE_INDEXED_MAP_CONTAINER_AT_TYPE_INFO
392 using RegisteredPropertyPair = std::pair<std::uint32_t, RegisteredProperty>;
393 using PropertyDefaultValuePair = std::pair<std::uint32_t, Property::Value>;
395 using RegisteredPropertyPair = std::pair<Property::Index, RegisteredProperty>;
396 using PropertyDefaultValuePair = std::pair<Property::Index, Property::Value>;
399 #ifdef USE_INDEXED_MAP_CONTAINER_AT_TYPE_INFO
400 using ActionContainer = Dali::Internal::IndexedConstStringMap<Dali::TypeInfo::ActionFunction>;
401 using ConnectorContainer = Dali::Internal::IndexedConstStringMap<Dali::TypeInfo::SignalConnectorFunction>;
402 using RegisteredPropertyContainer = Dali::Internal::IndexedIntegerMap<RegisteredProperty>;
403 using PropertyDefaultValueContainer = Dali::Internal::IndexedIntegerMap<Property::Value>;
405 using ActionContainer = std::vector<ActionPair>;
406 using ConnectorContainer = std::vector<ConnectionPair>;
407 using RegisteredPropertyContainer = std::vector<RegisteredPropertyPair>;
408 using PropertyDefaultValueContainer = std::vector<PropertyDefaultValuePair>;
412 * Append properties from registeredProperties onto indices.
413 * @param[in,out] indices The vector to append indices onto
414 * @param[in] registeredProperties The container to retrive indices from
416 void AppendProperties(Dali::Property::IndexContainer& indices,
417 const TypeInfo::RegisteredPropertyContainer& registeredProperties) const;
420 TypeRegistry& mTypeRegistry;
421 mutable Internal::TypeInfo* mBaseType; // allow changing from const methods, initialised inside constructor
422 std::string mTypeName;
423 std::string mBaseTypeName;
426 Dali::TypeInfo::CreateFunction mCreate = nullptr;
427 Dali::CSharpTypeInfo::CreateFunction mCSharpCreate; // only one field can be initialized but this will have same value anyways
429 ActionContainer mActions;
430 ConnectorContainer mSignalConnectors;
431 RegisteredPropertyContainer mRegisteredProperties;
432 RegisteredPropertyContainer mRegisteredChildProperties;
433 PropertyDefaultValueContainer mPropertyDefaultValues;
434 const Dali::PropertyDetails* mDefaultProperties = nullptr;
435 Property::Index mDefaultPropertyCount = 0;
436 bool mCSharpType = false; ///< Whether this type info is for a CSharp control (instead of C++)
439 } // namespace Internal
441 // Helpers for public-api forwarding methods
443 inline Internal::TypeInfo& GetImplementation(Dali::TypeInfo& typeInfo)
445 DALI_ASSERT_ALWAYS(typeInfo);
447 BaseObject& handle = typeInfo.GetBaseObject();
449 return static_cast<Internal::TypeInfo&>(handle);
452 inline const Internal::TypeInfo& GetImplementation(const Dali::TypeInfo& typeInfo)
454 DALI_ASSERT_ALWAYS(typeInfo);
456 const BaseObject& handle = typeInfo.GetBaseObject();
458 return static_cast<const Internal::TypeInfo&>(handle);
463 #endif // DALI_INTERNAL_TYPE_INFO_H