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