1 #ifndef DALI_TYPE_INFO_H
2 #define DALI_TYPE_INFO_H
5 * Copyright (c) 2020 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.
22 #include <cstdint> // uint32_t
25 #include <dali/public-api/common/vector-wrapper.h>
26 #include <dali/public-api/object/base-handle.h>
31 * @addtogroup dali_core_object
35 class ConnectionTrackerInterface;
36 class FunctorDelegate;
38 namespace Internal DALI_INTERNAL
44 * @brief TypeInfo class for instantiation of registered types and introspection of
45 * their actions and signals.
47 * See TypeRegistry for methods of type registration and TypeInfo retrieval.
50 class DALI_CORE_API TypeInfo : public BaseHandle
53 using CreateFunction = BaseHandle (*)(); ///< Function signature for creating an instance of the associated object type. @SINCE_1_0.0
55 using ActionFunction = bool (*)(BaseObject*, const std::string&, const Property::Map&); ///< Function signature for creating scriptable actions @SINCE_1_0.0
58 * @brief Connects a callback function with the object's signals.
61 * @param[in] object The object providing the signal
62 * @param[in] tracker Used to disconnect the signal
63 * @param[in] signalName The signal to connect to
64 * @param[in] functor A newly allocated FunctorDelegate
65 * @return True if the signal was connected
66 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
68 using SignalConnectorFunction = bool (*)(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
71 * @brief Callback to set an event-thread only property.
74 * @param[in] object The object whose property should be set
75 * @param[in] index The index of the property being set
76 * @param[in] value The new value of the property for the object specified
77 * @see PropertyRegistration.
79 using SetPropertyFunction = void (*)(BaseObject* object, Property::Index index, const Property::Value& value);
82 * @brief Callback to get the value of an event-thread only property.
85 * @param[in] object The object whose property value is required
86 * @param[in] index The index of the property required
87 * @return The current value of the property for the object specified
88 * @see PropertyRegistration.
90 using GetPropertyFunction = Property::Value (*)(BaseObject* object, Property::Index index);
93 * @brief Allows the creation of an empty TypeInfo handle.
101 * This is non-virtual since derived Handle types must not contain data or virtual methods.
107 * @brief This copy constructor is required for (smart) pointer semantics.
110 * @param[in] handle A reference to the copied handle
112 TypeInfo(const TypeInfo& handle);
115 * @brief This assignment operator is required for (smart) pointer semantics.
118 * @param[in] rhs A reference to the copied handle
119 * @return A reference to this
121 TypeInfo& operator=(const TypeInfo& rhs);
124 * @brief Move constructor.
127 * @param[in] rhs A reference to the moved handle
129 TypeInfo(TypeInfo&& rhs);
132 * @brief Move assignment operator.
135 * @param[in] rhs A reference to the moved handle
136 * @return A reference to this handle
138 TypeInfo& operator=(TypeInfo&& rhs);
141 * @brief Retrieves the type name for this type.
144 * @return String name
146 const std::string& GetName() const;
149 * @brief Retrieves the base type name for this type.
152 * @return String of base name
154 const std::string& GetBaseName() const;
157 * @brief Creates an object from this type.
160 * @return The BaseHandle for the newly created object
162 BaseHandle CreateInstance() const;
165 * @brief Retrieves the creator function for this type.
168 * @return The creator function
170 CreateFunction GetCreator() const;
173 * @brief Retrieves the number of actions for this type.
178 size_t GetActionCount() const;
181 * @brief Retrieves the action name for the index.
184 * @param[in] index Index to lookup
185 * @return Action name or empty string where index is invalid
187 std::string GetActionName(size_t index);
190 * @brief Retrieves the number of signals for this type.
195 size_t GetSignalCount() const;
198 * @brief Retrieves the signal name for the index.
201 * @param[in] index Index to lookup
202 * @return Signal name or empty string where index is invalid
204 std::string GetSignalName(size_t index);
207 * @brief Retrieves the number of event side type registered properties for this type.
212 size_t GetPropertyCount() const;
217 * @brief Retrieves all the property indices for this type.
220 * @param[out] indices Container of property indices
221 * @note The container will be cleared
223 void GetPropertyIndices(Property::IndexContainer& indices) const;
226 * @brief Retrieves all the child property indices for this type.
229 * @param[out] indices Container of property indices
230 * @note The container will be cleared
232 void GetChildPropertyIndices(Property::IndexContainer& indices) const;
235 * @brief Given a property index, retrieve the property name associated with it.
238 * @param[in] index The property index
239 * @return The name of the property at the given index
240 * @exception DaliException If index is not valid.
241 * @note this method only works for custom registered properties
243 const std::string& GetPropertyName(Property::Index index) const;
246 * @brief Given a child property name, retrieve the property index associated with it,
249 * @param[in] name The name of the property at the given index,
250 * @return The property index or Property::INVALID_INDEX
252 Property::Index GetChildPropertyIndex(const std::string& name) const;
255 * @brief Given a child property index, retrieve the property name associated with it.
258 * @param[in] index The property index
259 * @return The name of the property at the given index, or empty string if it does not exist
261 const std::string& GetChildPropertyName(Property::Index index) const;
264 * @brief Given a child property index, retrieve the property name associated with it.
267 * @param[in] index The property index
268 * @return The name of the property at the given index, or empty string if it does not exist
270 Property::Type GetChildPropertyType(Property::Index index) const;
272 public: // Not intended for application developers
275 * @brief This constructor is used by Dali Get() method.
278 * @param[in] typeInfo A pointer to a Dali resource
280 explicit DALI_INTERNAL TypeInfo(Internal::TypeInfo* typeInfo);
289 #endif // DALI_TYPE_INFO_H