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