removal of unnecessary exports; math & object.. 15 exports less
[platform/core/uifw/dali-core.git] / dali / public-api / object / handle.h
1 #ifndef __DALI_HANDLE_H__
2 #define __DALI_HANDLE_H__
3
4 /*
5  * Copyright (c) 2014 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 <string>
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/common/dali-common.h>
26 #include <dali/public-api/object/base-handle.h>
27 #include <dali/public-api/object/property-types.h>
28 #include <dali/public-api/object/property-value.h>
29 #include <dali/public-api/object/property-notification-declarations.h>
30 #include <dali/public-api/object/ref-object.h>
31
32 namespace Dali
33 {
34
35 class PropertyNotification;
36 class PropertyCondition;
37
38 namespace Internal DALI_INTERNAL
39 {
40 class Object;
41 }
42
43 /**
44  * @brief Dali::Handle is a handle to an internal property owning Dali object.
45  */
46 class DALI_IMPORT_API Handle : public BaseHandle
47 {
48 public:
49
50   /**
51    * @brief An Handle's capabilities can be queried using Handle::Supports()
52    */
53   enum Capability
54   {
55     /**
56      * @brief Some objects support dynamic property creation at run-time.
57      *
58      * New properties are registered by calling RegisterProperty() with an unused property name.
59      */
60     DYNAMIC_PROPERTIES = 0x01,
61   };
62
63 public:
64
65   /**
66    * @brief This constructor is used by Dali New() methods.
67    *
68    * @param [in] handle A pointer to a newly allocated Dali resource
69    */
70   Handle(Dali::Internal::Object* handle);
71
72   /**
73    * @brief This constructor provides an uninitialized Dali::Handle.
74    *
75    * This should be initialized with a Dali New() method before use.
76    * Methods called on an uninitialized Dali::Handle will assert.
77    * @code
78    * Handle handle; // uninitialized
79    * handle.SomeMethod(); // unsafe! This will assert
80    *
81    * handle = SomeClass::New(); // now initialized
82    * handle.SomeMethod(); // safe
83    * @endcode
84    */
85   Handle();
86
87   /**
88    * @brief Dali::Handle is intended as a base class
89    *
90    * This is non-virtual since derived Handle types must not contain data or virtual methods.
91    */
92   ~Handle();
93
94   /**
95    * @brief This copy constructor is required for (smart) pointer semantics.
96    *
97    * @param [in] handle A reference to the copied handle
98    */
99   Handle(const Handle& handle);
100
101   /**
102    * @brief This assignment operator is required for (smart) pointer semantics.
103    *
104    * @param [in] rhs  A reference to the copied handle
105    * @return A reference to this
106    */
107   Handle& operator=(const Handle& rhs);
108
109   /**
110    * @brief This method is defined to allow assignment of the NULL value,
111    * and will throw an exception if passed any other value.
112    *
113    * Assigning to NULL is an alias for Reset().
114    * @param [in] rhs  A NULL pointer
115    * @return A reference to this handle
116    */
117   Handle& operator=(BaseHandle::NullType* rhs);
118
119   /**
120    * @brief Downcast to a handle.
121    *
122    * If not the returned handle is left uninitialized.
123    * @param[in] handle to An object
124    * @return handle or an uninitialized handle
125    */
126   static Handle DownCast( BaseHandle handle );
127
128 public:
129
130   /**
131    * @brief Query whether an handle supports a given capability.
132    *
133    * @param[in] capability The queried capability.
134    * @return True if the capability is supported.
135    */
136   bool Supports(Capability capability) const;
137
138   /**
139    * @brief Query how many properties are provided by an handle.
140    *
141    * This may vary between instances of a class, if dynamic properties are supported.
142    * @return The number of properties.
143    */
144   unsigned int GetPropertyCount() const;
145
146   /**
147    * @brief Query the name of a property.
148    *
149    * @param [in] index The index of the property.
150    * @return The name of the property.
151    */
152   const std::string& GetPropertyName(Property::Index index) const;
153
154   /**
155    * @brief Query the index of a property.
156    *
157    * @param [in] name The name of the property.
158    * @return The index of the property, or Property::INVALID_INDEX if no property exists with the given name.
159    */
160   Property::Index GetPropertyIndex(std::string name) const;
161
162   /**
163    * @brief Query whether a property can be set using SetProperty().
164    *
165    * @pre Property::INVALID_INDEX < index.
166    * @param [in] index The index of the property.
167    * @return True if the property is writable.
168    */
169   bool IsPropertyWritable(Property::Index index) const;
170
171   /**
172    * @brief Query whether a writable property can be the target of an animation or constraint.
173    *
174    * @param [in] index The index of the property.
175    * @return True if the property is animatable.
176    */
177   bool IsPropertyAnimatable(Property::Index index) const;
178
179   /**
180    * @brief Query whether a property can be used as in input to a constraint.
181    *
182    * @param [in] index The index of the property.
183    * @return True if the property can be used as a constraint input.
184    */
185   bool IsPropertyAConstraintInput(Property::Index index) const;
186
187   /**
188    * @brief Query the type of a property.
189    *
190    * @param [in] index The index of the property.
191    * @return The type of the property.
192    */
193   Property::Type GetPropertyType(Property::Index index) const;
194
195   /**
196    * @brief Set the value of an existing property.
197    *
198    * @pre Handle::IsPropertyWritable(index) returns true.
199    * @pre The property types match i.e. propertyValue.GetType() is equal to GetPropertyType(index).
200    * @param [in] index The index of the property.
201    * @param [in] propertyValue The new value of the property.
202    */
203   void SetProperty(Property::Index index, Property::Value propertyValue);
204
205   /**
206    * @brief Register a new animatable property.
207    *
208    * @pre The handle supports dynamic properties i.e. Supports(Handle::DYNAMIC_PROPERTIES) returns true.
209    * @pre name is unused i.e. GetPropertyIndex(name) returns PropertyIndex::INVALID.
210    * @note Only the following types can be animated:
211    *       - Property::BOOLEAN
212    *       - Property::FLOAT
213    *       - Property::INTEGER
214    *       - Property::VECTOR2
215    *       - Property::VECTOR3
216    *       - Property::VECTOR4
217    *       - Property::MATRIX3
218    *       - Property::MATRIX
219    *       - Property::ROTATION
220    * @param [in] name The name of the property.
221    * @param [in] propertyValue The new value of the property.
222    * @return The index of the property
223    */
224   Property::Index RegisterProperty(std::string name, Property::Value propertyValue);
225
226   /**
227    * @brief Register a new property.
228    *
229    * Properties can be set as non animatable using property attributes.
230    * @pre The handle supports dynamic properties i.e. Supports(Handle::DYNAMIC_PROPERTIES) returns true.
231    * @pre name is unused i.e. GetPropertyIndex(name) returns PropertyIndex::INVALID.
232    * @note Only the following types can be animated:
233    *       - Property::BOOLEAN
234    *       - Property::FLOAT
235    *       - Property::INTEGER
236    *       - Property::VECTOR2
237    *       - Property::VECTOR3
238    *       - Property::VECTOR4
239    *       - Property::MATRIX3
240    *       - Property::MATRIX
241    *       - Property::ROTATION
242    * @param [in] name The name of the property.
243    * @param [in] propertyValue The new value of the property.
244    * @param [in] accessMode The property access mode (writable, animatable etc).
245    * @return The index of the property
246    */
247   Property::Index RegisterProperty(std::string name, Property::Value propertyValue, Property::AccessMode accessMode);
248
249   /**
250    * @brief Retrieve a property value.
251    *
252    * @param [in] index The index of the property.
253    * @return The property value.
254    */
255   Property::Value GetProperty(Property::Index index) const;
256
257   /**
258    * @brief Convenience function for obtaining a property of a known type.
259    *
260    * @pre The property types match i.e. PropertyTypes::Get<T>() is equal to GetPropertyType(index).
261    * @param [in] index The index of the property.
262    * @return The property value.
263    */
264   template <typename T>
265   T GetProperty(Property::Index index) const
266   {
267     Property::Value value = GetProperty(index);
268
269     return T( value.Get<T>() );
270   }
271
272   /**
273    * @brief Retrieve all the property indices for this object (including custom properties).
274    *
275    * @param[out] indices A container of property indices for this object.
276    * @note the added container is cleared
277    */
278   void GetPropertyIndices( Property::IndexContainer& indices ) const;
279
280   /**
281    * @brief Add a property notification to this object.
282    *
283    * @param [in] index The index of the property.
284    * @param [in] condition The notification will be triggered when this condition is satisfied.
285    *
286    * @return A handle to the newly created PropertyNotification
287    */
288   PropertyNotification AddPropertyNotification(Property::Index index,
289                                                const PropertyCondition& condition);
290
291   /**
292    * @brief Add a property notification to this object.
293    *
294    * @param [in] index The index of the property.
295    * @param [in] componentIndex Index to the component of a complex property such as a Vector
296    * @param [in] condition The notification will be triggered when this condition is satisfied.
297    *
298    * @return A handle to the newly created PropertyNotification
299    */
300   PropertyNotification AddPropertyNotification(Property::Index index,
301                                                int componentIndex,
302                                                const PropertyCondition& condition);
303
304   /**
305    * @brief Remove a property notification from this object.
306    *
307    * @param [in] propertyNotification The propertyNotification to be removed.
308    */
309   void RemovePropertyNotification(Dali::PropertyNotification propertyNotification);
310
311   /**
312    * @brief Remove all property notifications from this object.
313    */
314   void RemovePropertyNotifications();
315
316 };
317
318 } // namespace Dali
319
320 #endif // __DALI_HANDLE_H__