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