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