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