[dali_2.0.3] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / public-api / object / type-info.h
1 #ifndef DALI_TYPE_INFO_H
2 #define DALI_TYPE_INFO_H
3
4 /*
5  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <cstdint> // uint32_t
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/common/vector-wrapper.h>
26 #include <dali/public-api/object/base-handle.h>
27
28 namespace Dali
29 {
30 /**
31  * @addtogroup dali_core_object
32  * @{
33  */
34
35 class ConnectionTrackerInterface;
36 class FunctorDelegate;
37
38 namespace Internal DALI_INTERNAL
39 {
40 class TypeInfo;
41 };
42
43 /**
44  * @brief TypeInfo class for instantiation of registered types and introspection of
45  * their actions and signals.
46  *
47  * See TypeRegistry for methods of type registration and TypeInfo retrieval.
48  * @SINCE_1_0.0
49  */
50 class DALI_CORE_API TypeInfo : public BaseHandle
51 {
52 public:
53   using CreateFunction = BaseHandle (*)(); ///< Function signature for creating an instance of the associated object type. @SINCE_1_0.0
54
55   using ActionFunction = bool (*)(BaseObject*, const std::string&, const Property::Map&); ///< Function signature for creating scriptable actions @SINCE_1_0.0
56
57   /**
58    * @brief Connects a callback function with the object's signals.
59    *
60    * @SINCE_1_0.0
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.
67    */
68   using SignalConnectorFunction = bool (*)(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
69
70   /**
71    * @brief Callback to set an event-thread only property.
72    *
73    * @SINCE_1_0.0
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.
78    */
79   using SetPropertyFunction = void (*)(BaseObject* object, Property::Index index, const Property::Value& value);
80
81   /**
82    * @brief Callback to get the value of an event-thread only property.
83    *
84    * @SINCE_1_0.0
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.
89    */
90   using GetPropertyFunction = Property::Value (*)(BaseObject* object, Property::Index index);
91
92   /**
93    * @brief Allows the creation of an empty TypeInfo handle.
94    * @SINCE_1_0.0
95    */
96   TypeInfo();
97
98   /**
99    * @brief Destructor.
100    *
101    * This is non-virtual since derived Handle types must not contain data or virtual methods.
102    * @SINCE_1_0.0
103    */
104   ~TypeInfo();
105
106   /**
107    * @brief This copy constructor is required for (smart) pointer semantics.
108    *
109    * @SINCE_1_0.0
110    * @param[in] handle A reference to the copied handle
111    */
112   TypeInfo(const TypeInfo& handle);
113
114   /**
115    * @brief This assignment operator is required for (smart) pointer semantics.
116    *
117    * @SINCE_1_0.0
118    * @param[in] rhs A reference to the copied handle
119    * @return A reference to this
120    */
121   TypeInfo& operator=(const TypeInfo& rhs);
122
123   /**
124    * @brief Move constructor.
125    *
126    * @SINCE_1_9.22
127    * @param[in] rhs A reference to the moved handle
128    */
129   TypeInfo(TypeInfo&& rhs);
130
131   /**
132    * @brief Move assignment operator.
133    *
134    * @SINCE_1_9.22
135    * @param[in] rhs A reference to the moved handle
136    * @return A reference to this handle
137    */
138   TypeInfo& operator=(TypeInfo&& rhs);
139
140   /**
141    * @brief Retrieves the type name for this type.
142    *
143    * @SINCE_1_0.0
144    * @return String name
145    */
146   const std::string& GetName() const;
147
148   /**
149    * @brief Retrieves the base type name for this type.
150    *
151    * @SINCE_1_0.0
152    * @return String of base name
153    */
154   const std::string& GetBaseName() const;
155
156   /**
157    * @brief Creates an object from this type.
158    *
159    * @SINCE_1_0.0
160    * @return The BaseHandle for the newly created object
161    */
162   BaseHandle CreateInstance() const;
163
164   /**
165    * @brief Retrieves the creator function for this type.
166    *
167    * @SINCE_1_0.0
168    * @return The creator function
169    */
170   CreateFunction GetCreator() const;
171
172   /**
173    * @brief Retrieves the number of actions for this type.
174    *
175    * @SINCE_1_0.0
176    * @return The count
177    */
178   size_t GetActionCount() const;
179
180   /**
181    * @brief Retrieves the action name for the index.
182    *
183    * @SINCE_1_0.0
184    * @param[in] index Index to lookup
185    * @return Action name or empty string where index is invalid
186    */
187   std::string GetActionName(size_t index);
188
189   /**
190    * @brief Retrieves the number of signals for this type.
191    *
192    * @SINCE_1_0.0
193    * @return The count
194    */
195   size_t GetSignalCount() const;
196
197   /**
198    * @brief Retrieves the signal name for the index.
199    *
200    * @SINCE_1_0.0
201    * @param[in] index Index to lookup
202    * @return Signal name or empty string where index is invalid
203    */
204   std::string GetSignalName(size_t index);
205
206   /**
207    * @brief Retrieves the number of event side type registered properties for this type.
208    *
209    * @SINCE_1_0.0
210    * @return The count
211    */
212   size_t GetPropertyCount() const;
213
214   // Properties
215
216   /**
217    * @brief Retrieves all the property indices for this type.
218    *
219    * @SINCE_1_0.0
220    * @param[out] indices Container of property indices
221    * @note The container will be cleared
222    */
223   void GetPropertyIndices(Property::IndexContainer& indices) const;
224
225   /**
226    * @brief Retrieves all the child property indices for this type.
227    *
228    * @SINCE_1_3.20
229    * @param[out] indices Container of property indices
230    * @note The container will be cleared
231    */
232   void GetChildPropertyIndices(Property::IndexContainer& indices) const;
233
234   /**
235    * @brief Given a property index, retrieve the property name associated with it.
236    *
237    * @SINCE_1_0.0
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
242    */
243   const std::string& GetPropertyName(Property::Index index) const;
244
245   /**
246    * @brief Given a child property name, retrieve the property index associated with it,
247    *
248    * @SINCE_1_3.20
249    * @param[in] name The name of the property at the given index,
250    * @return The property index or Property::INVALID_INDEX
251    */
252   Property::Index GetChildPropertyIndex(const std::string& name) const;
253
254   /**
255    * @brief Given a child property index, retrieve the property name associated with it.
256    *
257    * @SINCE_1_3.20
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
260    */
261   const std::string& GetChildPropertyName(Property::Index index) const;
262
263   /**
264    * @brief Given a child property index, retrieve the property name associated with it.
265    *
266    * @SINCE_1_3.20
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
269    */
270   Property::Type GetChildPropertyType(Property::Index index) const;
271
272 public: // Not intended for application developers
273   /// @cond internal
274   /**
275    * @brief This constructor is used by Dali Get() method.
276    *
277    * @SINCE_1_0.0
278    * @param[in] typeInfo A pointer to a Dali resource
279    */
280   explicit DALI_INTERNAL TypeInfo(Internal::TypeInfo* typeInfo);
281   /// @endcond
282 };
283
284 /**
285  * @}
286  */
287 } // namespace Dali
288
289 #endif // DALI_TYPE_INFO_H