1 #ifndef DALI_INTERNAL_TYPE_INFO_H
2 #define DALI_INTERNAL_TYPE_INFO_H
5 * Copyright (c) 2021 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>
37 class PropertyDetails;
41 * A TypeInfo class to support registered type creation, and introspection of available
42 * actions and signal connection.
43 * It also supports doing actions and connecting signal handlers. Note this is properly
44 * conducted through the BaseHandle interface which uses the TypeRegistry to walk
47 class TypeInfo : public BaseObject
52 * @param [name] the registered name
53 * @param [baseName] the base type registered name
54 * @param [creator] the creator function for this type
56 TypeInfo(const std::string& name, const std::string& baseName, Dali::TypeInfo::CreateFunction creator, const Dali::PropertyDetails* defaultProperties, Property::Index defaultPropertyCount);
59 * Create TypeInfo for a csharp object
60 * @param [name] the registered name
61 * @param [baseName] the base type registered name
62 * @param [creator] the creator function for this type
64 TypeInfo(const std::string& name, const std::string& baseName, Dali::CSharpTypeInfo::CreateFunction creator);
72 * @copydoc Dali::TypeInfo::GetName
74 const std::string& GetName() const;
77 * @copydoc Dali::TypeInfo::GetBaseName
79 const std::string& GetBaseName() const;
82 * @copydoc TypeInfo::CreateFunction
84 BaseHandle CreateInstance() const;
87 * @copydoc Dali::TypeInfo::GetCreator
89 Dali::TypeInfo::CreateFunction GetCreator() const;
92 * @copydoc Dali::TypeInfo::GetActionCount
94 uint32_t GetActionCount() const;
97 * @copydoc Dali::TypeInfo::GetActionName
99 std::string GetActionName(uint32_t index) const;
102 * @copydoc Dali::TypeInfo::GetSignalCount
104 uint32_t GetSignalCount() const;
107 * @copydoc Dali::TypeInfo::GetSignalName
109 std::string GetSignalName(uint32_t index) const;
112 * @copydoc Dali::TypeInfo::GetPropertyCount
114 uint32_t GetPropertyCount() const;
117 * Adds the property indices to the container specified.
118 * @param[in/out] indices The container where the property indices are added.
120 void GetPropertyIndices(Property::IndexContainer& indices) const;
123 * @copydoc Dali::TypeInfo::GetPropertyName() const
124 * this API exists to keep the old public API, which cannot be changed
126 std::string_view GetRegisteredPropertyName(Property::Index index) const;
129 * Returns the property name for given index
131 * @param index of the property
132 * @return name or empty string
134 std::string_view GetPropertyName(Property::Index index) const;
137 * Add an action function
139 void AddActionFunction(std::string actionName, Dali::TypeInfo::ActionFunction function);
142 * Add a function for connecting a signal.
143 * @param[in] signalName The name of the signal.
144 * @param[in] function The function used for connecting to the signal.
146 void AddConnectorFunction(std::string signalName, Dali::TypeInfo::SignalConnectorFunction function);
149 * Adds an event-thread only property to the type.
150 * @param[in] name The name of the property.
151 * @param[in] index The index of the property.
152 * @param[in] type The Property::Type.
153 * @param[in] setFunc The function to call to set the property (Can be nullptr).
154 * @param[in] getFunc The function to call to retrieve the value of the property.
156 void AddProperty(std::string name, Property::Index index, Property::Type type, Dali::TypeInfo::SetPropertyFunction setFunc, Dali::TypeInfo::GetPropertyFunction getFunc);
159 * Adds an event-thread only property to the type.
160 * @param[in] name The name of the property.
161 * @param[in] index The index of the property.
162 * @param[in] type The Property::Type.
163 * @param[in] setFunc The function to call to set the property (Can be nullptr).
164 * @param[in] getFunc The function to call to retrieve the value of the property.
166 void AddProperty(std::string name, Property::Index index, Property::Type type, Dali::CSharpTypeInfo::SetPropertyFunction setFunc, Dali::CSharpTypeInfo::GetPropertyFunction getFunc);
169 * Adds an animatable property to the type.
170 * @param[in] name The name of the property.
171 * @param[in] index The index of the property
172 * @param[in] type The Property::Type.
174 void AddAnimatableProperty(std::string name, Property::Index index, Property::Type type);
177 * Adds an animatable property with the given default value.
178 * @param[in] name The name of the property.
179 * @param[in] index The index of the property
180 * @param[in] type The Property::Type.
182 void AddAnimatableProperty(std::string name, Property::Index index, Property::Value defaultValue);
185 * Adds a component of an animatable property to the type.
186 * The animatable property must have been type-registered and must be a Vector2, Vector3 or Vector4 type.
187 * @param[in] name The name of the component.
188 * @param[in] index The index of the property
189 * @param[in] baseIndex The index of the base animatable property
190 * @param[in] component The index The index of the component.
192 void AddAnimatablePropertyComponent(std::string name, Property::Index index, Property::Index baseIndex, uint32_t componentIndex);
195 * Adds a child property to the type.
196 * @param[in] name The name of the property.
197 * @param[in] index The index of the property
198 * @param[in] type The Property::Type.
200 void AddChildProperty(std::string name, Property::Index index, Property::Type type);
203 * Do an action on base object
204 * @param [in] object The base object to act upon
205 * @param [in] actionName The name of the desired action
206 * @param [in] properties The arguments of the action
207 * @return bool If the action could be executed
209 bool DoActionTo(BaseObject* object, const std::string& actionName, const Property::Map& properties);
212 * Connects a callback function with the object's signals.
213 * @param[in] object The object providing the signal.
214 * @param[in] tracker Used to disconnect the signal.
215 * @param[in] signalName The signal to connect to.
216 * @param[in] functor A newly allocated FunctorDelegate.
217 * @return True if the signal was connected.
218 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
220 bool ConnectSignal(BaseObject* object, ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor);
223 * Given a property name, retrieve the index.
224 * @param[in] name The name of the property.
225 * @return The index associated with that name.
227 Property::Index GetPropertyIndex(ConstString name) const;
230 * Given a property index, retrieve the index of its base property.
231 * @param[in] index The index of the property.
232 * @return The index of the base property associated with the given property index.
234 Property::Index GetBasePropertyIndex(Property::Index index) const;
237 * Given a property index, retrieve its component index.
238 * @param[in] index The index of the property.
239 * @return The component index associated with that property index.
241 int32_t GetComponentIndex(Property::Index index) const;
244 * @param[in] index The property index.
245 * @return True, if writable, false otherwise.
247 bool IsPropertyWritable(Property::Index index) const;
250 * @param[in] index The property index.
251 * @return True, if animatable, false otherwise.
253 bool IsPropertyAnimatable(Property::Index index) const;
256 * @param[in] index The property index.
257 * @return True, if a constraint input, false otherwise.
259 bool IsPropertyAConstraintInput(Property::Index index) const;
262 * Retrieve the Property::Type of the property at the given index.
263 * @param[in] index The property index.
264 * @return The Property::Type at that index.
266 Property::Type GetPropertyType(Property::Index index) const;
269 * Given a child property name, retrieve the index.
270 * @param[in] name The name of the child property.
271 * @return The index associated with that name.
273 Property::Index GetChildPropertyIndex(ConstString name) const;
276 * Retrieve the name of the child property at the given index.
277 * @param[in] index The property index.
278 * @return The name of the child property.
280 std::string_view GetChildPropertyName(Property::Index index) const;
283 * Retrieve the Property::Type of the child property at the given index.
284 * @param[in] index The property index.
285 * @return The Property::Type at that index.
287 Property::Type GetChildPropertyType(Property::Index index) const;
290 * Retrive the child indices into the given container.
291 * @param[in,out] indices The container to put the child indices into
293 void GetChildPropertyIndices(Property::IndexContainer& indices) const;
296 * Retrieve the default value of the property at the given index.
297 * @param[in] index The property index.
298 * @return The default property value at that index.
300 Property::Value GetPropertyDefaultValue(Property::Index index) const;
303 * Sets the value of a property at the index specified for the given object.
304 * @param[in] object The object whose property is to be set.
305 * @param[in] index The property index.
306 * @param[in] value The value to set.
308 void SetProperty(BaseObject* object, Property::Index index, Property::Value value) const;
311 * Sets the value of a property with the name specified for the given object.
312 * @param[in] object The object whose property is to be set.
313 * @param[in] name The property name.
314 * @param[in] value The value to set.
316 void SetProperty(BaseObject* object, const std::string& name, Property::Value value) const;
319 * Retrieves the value of a property at the index specified for the given object.
320 * @param[in] object The object whose property is to be queried.
321 * @param[in] index The property index.
322 * @return The current value of the property.
324 Property::Value GetProperty(const BaseObject* object, Property::Index index) const;
327 * Retrieves the value of a property with the name specified for the given object.
328 * @param[in] object The object whose property is to be queried.
329 * @param[in] name The property name.
330 * @return The current value of the property.
332 Property::Value GetProperty(const BaseObject* object, const std::string& name) const;
335 struct RegisteredProperty
337 RegisteredProperty(Property::Type propType, ConstString propName, Property::Index basePropertyIndex, int32_t componentIndex)
342 basePropertyIndex(basePropertyIndex),
343 componentIndex(componentIndex)
347 RegisteredProperty(Property::Type propType, Dali::TypeInfo::SetPropertyFunction set, Dali::TypeInfo::GetPropertyFunction get, ConstString propName, Property::Index basePropertyIndex, int componentIndex)
352 basePropertyIndex(basePropertyIndex),
353 componentIndex(componentIndex)
357 RegisteredProperty(Property::Type propType, Dali::CSharpTypeInfo::SetPropertyFunction set, Dali::CSharpTypeInfo::GetPropertyFunction get, ConstString propName, Property::Index basePropertyIndex, int componentIndex)
362 basePropertyIndex(basePropertyIndex),
363 componentIndex(componentIndex)
367 Property::Type type = Property::NONE;
370 Dali::TypeInfo::SetPropertyFunction setFunc = nullptr;
371 Dali::CSharpTypeInfo::SetPropertyFunction cSharpSetFunc; // only one field can be initialized but this will have same value anyways
375 Dali::TypeInfo::GetPropertyFunction getFunc = nullptr;
376 Dali::CSharpTypeInfo::GetPropertyFunction cSharpGetFunc; // only one field can be initialized but this will have same value anyways
379 Property::Index basePropertyIndex = Property::INVALID_INDEX;
380 int32_t componentIndex = Property::INVALID_COMPONENT_INDEX;
383 using ConnectionPair = std::pair<std::string, Dali::TypeInfo::SignalConnectorFunction>;
384 using ActionPair = std::pair<std::string, Dali::TypeInfo::ActionFunction>;
385 using RegisteredPropertyPair = std::pair<Property::Index, RegisteredProperty>;
386 using PropertyDefaultValuePair = std::pair<Property::Index, Property::Value>;
388 using ActionContainer = std::vector<ActionPair>;
389 using ConnectorContainer = std::vector<ConnectionPair>;
390 using RegisteredPropertyContainer = std::vector<RegisteredPropertyPair>;
391 using PropertyDefaultValueContainer = std::vector<PropertyDefaultValuePair>;
394 * Append properties from registeredProperties onto indices.
395 * @param[in,out] indices The vector to append indices onto
396 * @param[in] registeredProperties The container to retrive indices from
398 void AppendProperties(Dali::Property::IndexContainer& indices,
399 const TypeInfo::RegisteredPropertyContainer& registeredProperties) const;
402 TypeRegistry& mTypeRegistry;
403 mutable Internal::TypeInfo* mBaseType; // allow changing from const methods, initialised inside constructor
404 std::string mTypeName;
405 std::string mBaseTypeName;
408 Dali::TypeInfo::CreateFunction mCreate = nullptr;
409 Dali::CSharpTypeInfo::CreateFunction mCSharpCreate; // only one field can be initialized but this will have same value anyways
411 ActionContainer mActions;
412 ConnectorContainer mSignalConnectors;
413 RegisteredPropertyContainer mRegisteredProperties;
414 RegisteredPropertyContainer mRegisteredChildProperties;
415 PropertyDefaultValueContainer mPropertyDefaultValues;
416 const Dali::PropertyDetails* mDefaultProperties = nullptr;
417 Property::Index mDefaultPropertyCount = 0;
418 bool mCSharpType = false; ///< Whether this type info is for a CSharp control (instead of C++)
421 } // namespace Internal
423 // Helpers for public-api forwarding methods
425 inline Internal::TypeInfo& GetImplementation(Dali::TypeInfo& typeInfo)
427 DALI_ASSERT_ALWAYS(typeInfo);
429 BaseObject& handle = typeInfo.GetBaseObject();
431 return static_cast<Internal::TypeInfo&>(handle);
434 inline const Internal::TypeInfo& GetImplementation(const Dali::TypeInfo& typeInfo)
436 DALI_ASSERT_ALWAYS(typeInfo);
438 const BaseObject& handle = typeInfo.GetBaseObject();
440 return static_cast<const Internal::TypeInfo&>(handle);
445 #endif // DALI_INTERNAL_TYPE_INFO_H