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