cb8d9a6f76e7739b026ae581487d7d9e9c388feb
[platform/core/uifw/dali-core.git] / dali / public-api / object / property-value.h
1 #ifndef __DALI_PROPERTY_VALUE_H__
2 #define __DALI_PROPERTY_VALUE_H__
3
4 /*
5  * Copyright (c) 2016 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 <iosfwd>
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/object/property.h>
26 #include <dali/public-api/math/rect.h>
27
28 #include <type_traits>
29
30 namespace Dali
31 {
32 /**
33  * @addtogroup dali_core_object
34  * @{
35  */
36
37 struct AngleAxis;
38 class Quaternion;
39 struct Vector2;
40 struct Vector3;
41 struct Vector4;
42 class Matrix3;
43 class Matrix;
44 struct Extents;
45
46 /**
47  * @brief A value-type representing a property value.
48  * @SINCE_1_0.0
49  */
50 class DALI_IMPORT_API Property::Value
51 {
52 public:
53
54   /**
55    * @brief Default constructor.
56    *
57    * This creates a property with type Property::NONE.
58    * @SINCE_1_0.0
59    */
60   Value();
61
62   /**
63    * @brief Creates a boolean property value.
64    *
65    * @SINCE_1_0.0
66    * @param[in] boolValue A boolean value
67    */
68   Value( bool boolValue );
69
70   /**
71    * @brief Creates an integer property value.
72    *
73    * @SINCE_1_0.0
74    * @param[in] integerValue An integer value
75    */
76   Value( int integerValue );
77
78   /**
79    * @brief Creates a float property value.
80    *
81    * @SINCE_1_0.0
82    * @param[in] floatValue A floating-point value
83    */
84   Value( float floatValue );
85
86   /**
87    * @brief Creates a Vector2 property value.
88    *
89    * @SINCE_1_0.0
90    * @param[in] vectorValue A vector of 2 floating-point values
91    */
92   Value( const Vector2& vectorValue );
93
94   /**
95    * @brief Creates a Vector3 property value.
96    *
97    * @SINCE_1_0.0
98    * @param[in] vectorValue A vector of 3 floating-point values
99    */
100   Value( const Vector3& vectorValue );
101
102   /**
103    * @brief Creates a Vector4 property value.
104    *
105    * @SINCE_1_0.0
106    * @param[in] vectorValue A vector of 4 floating-point values
107    */
108   Value( const Vector4& vectorValue );
109
110   /**
111    * @brief Creates a Matrix3 property value.
112    *
113    * @SINCE_1_0.0
114    * @param[in] matrixValue A matrix of 3x3 floating-point values
115    */
116   Value( const Matrix3& matrixValue );
117
118   /**
119    * @brief Creates a Matrix property value.
120    *
121    * @SINCE_1_0.0
122    * @param[in] matrixValue A matrix of 4x4 floating-point values
123    */
124   Value( const Matrix& matrixValue );
125
126   /**
127    * @brief Creates a Vector4 property value.
128    *
129    * @SINCE_1_0.0
130    * @param[in] vectorValue A vector of 4 integer values
131    */
132   Value( const Rect<int>& vectorValue );
133
134   /**
135    * @brief Creates an orientation property value.
136    *
137    * @SINCE_1_0.0
138    * @param[in] angleAxis An angle-axis representing the rotation
139    */
140   Value( const AngleAxis& angleAxis );
141
142   /**
143    * @brief Creates an orientation property value.
144    *
145    * @SINCE_1_0.0
146    * @param[in] quaternion A quaternion representing the rotation
147    */
148   Value( const Quaternion& quaternion );
149
150   /**
151    * @brief Creates an string property value.
152    *
153    * @SINCE_1_0.0
154    * @param[in] stringValue A string
155    */
156   Value( const std::string& stringValue );
157
158   /**
159    * @brief Creates a string property value.
160    *
161    * @SINCE_1_0.0
162    * @param[in] stringValue A string
163    */
164   Value( const char* stringValue );
165
166   /**
167    * @brief Creates an array property value.
168    *
169    * @SINCE_1_0.0
170    * @param[in] arrayValue An array
171    */
172   Value( Property::Array& arrayValue );
173
174   /**
175    * @brief Creates a map property value.
176    *
177    * @SINCE_1_0.0
178    * @param[in] mapValue An array
179    */
180   Value( Property::Map& mapValue );
181
182   /**
183    * @brief Creates an extents property value.
184    *
185    * @SINCE_1_2.62
186    * @param[in] extentsValue A collection of 4 uint16_t values
187    */
188   Value( const Extents& extentsValue );
189
190   /**
191    * @brief Creates an enumeration property value.
192    *
193    * @SINCE_1_2.62
194    * @param[in] extentsValue A collection of 4 uint16_t values
195    */
196   template <typename T, typename std::enable_if<std::is_enum<typename std::remove_reference<typename std::remove_cv<T>::type>::type>::value>::type* = nullptr>
197   Value(T t) : Value(static_cast<int>(t)) { }
198
199   /**
200    * @brief Explicitly sets a type and initialize it.
201    *
202    * @SINCE_1_0.0
203    * @param[in] type The property value type
204    */
205   explicit Value( Type type );
206
207   /**
208    * @brief Copy constructor.
209    *
210    * @SINCE_1_0.0
211    * @param[in] value The property value to copy
212    */
213   Value( const Value& value );
214
215   /**
216    * @brief Assigns a property value.
217    *
218    * @SINCE_1_0.0
219    * @param[in] value The property value to assign from
220    * @return a reference to this
221    */
222   Value& operator=( const Value& value );
223
224   /**
225    * @brief Non-virtual destructor.
226    *
227    * This class is not a base class.
228    * @SINCE_1_0.0
229    */
230   ~Value();
231
232   /**
233    * @brief Queries the type of this property value.
234    *
235    * @SINCE_1_0.0
236    * @return The type ID
237    */
238   Type GetType() const;
239
240   /**
241    * @brief Retrieves a specific value.
242    *
243    * Works on a best-effort approach; if value type is different returns a default value of the type.
244    *
245    * @SINCE_1_0.0
246    * @return A value of type T
247    */
248   template <typename T>
249   T DALI_INTERNAL Get() const
250   {
251     T temp = T(); // value (zero) initialize
252     Get( temp );
253     return temp;
254   }
255
256   /**
257    * @brief Retrieves an enumeration value.
258    *
259    * @SINCE_1_0.0
260    * @param[out] boolValue On return, an enumeration value
261    * @return @c true if the value is successfully retrieved, @c false if the type is different
262    * @pre GetType() is a type convertible to bool.
263    */
264   template <typename T, typename std::enable_if<std::is_enum<typename std::remove_reference<typename std::remove_cv<T>::type>::type>::value>::type* = nullptr>
265   bool Get(T &t) const
266   {
267     int temp = 0;
268     if (!Get(temp)) return false;
269     t = static_cast<T>(temp);
270     return true;
271   }
272   /**
273    * @brief Retrieves a boolean value.
274    *
275    * @SINCE_1_0.0
276    * @param[out] boolValue On return, a boolean value
277    * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
278    * @pre GetType() is a type convertible to bool.
279    */
280   bool Get( bool& boolValue ) const;
281
282   /**
283    * @brief Retrieves a floating-point value.
284    *
285    * @SINCE_1_0.0
286    * @param[out] floatValue On return, a floating-point value
287    * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
288    * @pre GetType() is a type convertible to float.
289    */
290   bool Get( float& floatValue ) const;
291
292   /**
293    * @brief Retrieves an integer value.
294    *
295    * @SINCE_1_0.0
296    * @param[out] integerValue On return, an integer value
297    * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
298    * @pre GetType() is a type convertible to int.
299    */
300   bool Get( int& integerValue ) const;
301
302   /**
303    * @brief Retrieves an integer rectangle.
304    *
305    * @SINCE_1_0.0
306    * @param[out] rect On return, an integer rectangle
307    * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
308    * @pre GetType() is a type convertible to Rect<int>.
309    */
310   bool Get( Rect<int>& rect ) const;
311
312   /**
313    * @brief Retrieves a vector value.
314    *
315    * @SINCE_1_0.0
316    * @param[out] vectorValue On return, a vector value
317    * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
318    * @pre GetType() is a type convertible to Vector2.
319    */
320   bool Get( Vector2& vectorValue ) const;
321
322   /**
323    * @brief Retrieves a vector value.
324    *
325    * @SINCE_1_0.0
326    * @param[out] vectorValue On return, a vector value
327    * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
328    * @pre GetType() is a type convertible to Vector3.
329    */
330   bool Get( Vector3& vectorValue ) const;
331
332   /**
333    * @brief Retrieves a vector value.
334    *
335    * @SINCE_1_0.0
336    * @param[out] vectorValue On return, a vector value
337    * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
338    * @pre GetType() is a type convertible to Vector4.
339    */
340   bool Get( Vector4& vectorValue ) const;
341
342   /**
343    * @brief Retrieves a matrix3 value.
344    *
345    * @SINCE_1_0.0
346    * @param[out] matrixValue On return, a matrix3 value
347    * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
348    * @pre GetType() is a type convertible to Matrix3.
349    */
350   bool Get( Matrix3& matrixValue ) const;
351
352   /**
353    * @brief Retrieves a matrix value.
354    *
355    * @SINCE_1_0.0
356    * @param[out] matrixValue On return, a matrix value
357    * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
358    * @pre GetType() is a type convertible to Matrix.
359    */
360   bool Get( Matrix& matrixValue ) const;
361
362   /**
363    * @brief Retrieves an angle-axis value.
364    *
365    * @SINCE_1_0.0
366    * @param[out] angleAxisValue On return, a angle-axis value
367    * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
368    * @pre GetType() is a type convertible to AngleAxis.
369    */
370   bool Get( AngleAxis& angleAxisValue ) const;
371
372   /**
373    * @brief Retrieves a quaternion value.
374    *
375    * @SINCE_1_0.0
376    * @param[out] quaternionValue On return, a quaternion value
377    * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
378    * @pre GetType() is a type convertible to Quaternion.
379    */
380   bool Get( Quaternion& quaternionValue ) const;
381
382   /**
383    * @brief Retrieves an string property value.
384    *
385    * @SINCE_1_0.0
386    * @param[out] stringValue A string
387    * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
388    * @pre GetType() is a type convertible to string.
389    */
390   bool Get( std::string& stringValue ) const;
391
392   /**
393    * @brief Retrieves an array property value.
394    *
395    * @SINCE_1_0.0
396    * @param[out] arrayValue The array as a vector Property Values
397    * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
398    * @pre GetType() returns Property::ARRAY.
399    */
400   bool Get( Property::Array& arrayValue ) const;
401
402   /**
403    * @brief Retrieves an map property value.
404    *
405    * @SINCE_1_0.0
406    * @param[out] mapValue The map as vector of string and Property Value pairs
407    * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
408    * @pre GetType() returns Property::MAP.
409    */
410   bool Get( Property::Map& mapValue ) const;
411
412   /**
413    * @brief Retrieves the Array API of the Property::Value without copying the contents of the map.
414    *
415    * @SINCE_1_0.0
416    * @return The Array API of the Property::Value or NULL if not a Property::Array
417    */
418   Property::Array* GetArray() const;
419
420   /**
421    * @brief Retrieves the Map API of the Property::Value without copying the contents of the map.
422    *
423    * @SINCE_1_0.0
424    * @return The Map API of the Property::Value or NULL if not a Property::Map
425    */
426   Property::Map* GetMap() const;
427
428   /**
429    * @brief Retrieves an extents.
430    *
431    * @SINCE_1_2.62
432    * @param[out] extentsValue Extents, a collection of 4 uint16_t
433    * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
434    * @pre GetType() is a type convertible to Extents.
435    */
436   bool Get( Extents& extentsValue ) const;
437
438   /**
439    * @brief Output to stream.
440    * @SINCE_1_0.0
441    */
442   friend std::ostream& operator<<( std::ostream& ouputStream, const Property::Value& value );
443
444 private:
445
446   struct DALI_INTERNAL Impl;
447   Impl* mImpl; ///< Pointer to the implementation
448
449 };
450
451 /**
452  * @brief Converts the value of the property into a string and append to an output stream.
453  *
454  * @SINCE_1_0.0
455  * @param[in] ouputStream The output stream operator
456  * @param[in] value The value to insert
457  * @return The output stream operator
458  */
459 DALI_IMPORT_API std::ostream& operator<<( std::ostream& ouputStream, const Property::Value& value );
460
461 /**
462  * @}
463  */
464 } // namespace Dali
465
466 #endif // __DALI_PROPERTY_VALUE_H__