55746bfc5f88f05c3521249e519ce2033b0c16a8
[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 // INTERNAL INCLUDES
22 #include <dali/public-api/object/property.h>
23 #include <dali/public-api/math/rect.h>
24
25 namespace Dali
26 {
27
28 struct AngleAxis;
29 class Quaternion;
30 struct Vector2;
31 struct Vector3;
32 struct Vector4;
33 class Matrix3;
34 class Matrix;
35
36 /**
37  * @brief A value-type representing a property value.
38  */
39 class DALI_IMPORT_API Property::Value
40 {
41 public:
42
43   /**
44    * @brief Default constructor.
45    *
46    * This creates a property with type Property::NONE.
47    */
48   Value();
49
50   /**
51    * @brief Create a boolean property value.
52    *
53    * @param [in] boolValue A boolean value.
54    */
55   Value(bool boolValue);
56
57   /**
58    * @brief Create a float property value.
59    *
60    * @param [in] floatValue A floating-point value.
61    */
62   Value(float floatValue);
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 an unsigned integer property value.
73    *
74    * @param [in] unsignedIntegerValue An unsinged integer value.
75    */
76   Value(unsigned int unsignedIntegerValue);
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 Copy a property value.
150    *
151    * @param [in] value The property value to copy.
152    */
153   Value(const Value& value);
154
155   /**
156    * @brief Create an array property value.
157    *
158    * @param [in] arrayValue An array
159    */
160   Value(Property::Array& arrayValue);
161
162   /**
163    * @brief Create a map property value.
164    *
165    * @param [in] mapValue An array
166    */
167   Value(Property::Map& mapValue);
168
169   /**
170    * @brief Explicitly set a type and initialize it.
171    *
172    * @param [in] type The property value type.
173    */
174   explicit Value(Type type);
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   ~Value();
188
189   /**
190    * @brief Query the type of this property value.
191    *
192    * @return The type ID.
193    */
194   Type GetType() const;
195
196   /**
197    * @brief Retrieve a specific value.
198    *
199    * @pre GetType() returns the Property::Type for type T.
200    * @return A value of type T.
201    */
202   template <typename T>
203   T DALI_INTERNAL Get() const
204   {
205     T temp;
206     Get(temp);
207     return temp;
208   }
209
210   /**
211    * @brief Retrieve a boolean value.
212    *
213    * @pre GetType() returns Property::BOOLEAN.
214    * @param [out] boolValue On return, a boolean value.
215    */
216   void Get(bool& boolValue) const;
217
218   /**
219    * @brief Retrieve a floating-point value.
220    *
221    * @pre GetType() returns Property::FLOAT.
222    * @param [out] floatValue On return, a floating-point value.
223    */
224   void Get(float& floatValue) const;
225
226   /**
227    * @brief Retrieve an integer value.
228    *
229    * @pre GetType() returns Property::INTEGER.
230    * @param [out] integerValue On return, an integer value.
231    */
232   void Get(int& integerValue) const;
233
234   /**
235    * @brief Retrieve an unsigned integer value.
236    *
237    * @pre GetType() returns Property::UNSIGNED_INTEGER.
238    * @param [out] unsignedIntegerValue On return, an unsigned integer value.
239    */
240   void Get(unsigned int& unsignedIntegerValue) const;
241
242   /**
243    * @brief Retrieve an integer rectangle.
244    *
245    * @pre GetType() returns Property::RECTANGLE.
246    * @param [out] rect On return, an integer rectangle.
247    */
248   void Get(Rect<int>& rect) const;
249
250   /**
251    * @brief Retrieve a vector value.
252    *
253    * @pre GetType() returns Property::VECTOR2.
254    * @param [out] vectorValue On return, a vector value.
255    */
256   void 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    */
264   void Get(Vector3& vectorValue) const;
265
266   /**
267    * @brief Retrieve a vector value.
268    *
269    * @pre GetType() returns Property::VECTOR4.
270    * @param [out] vectorValue On return, a vector value.
271    */
272   void Get(Vector4& vectorValue) const;
273
274   /**
275    * @brief Retrieve a matrix3 value.
276    *
277    * @pre GetType() returns Property::MATRIX3.
278    * @param [out] matrixValue On return, a matrix3 value.
279    */
280   void Get(Matrix3& matrixValue) const;
281
282   /**
283    * @brief Retrieve a matrix value.
284    *
285    * @pre GetType() returns Property::MATRIX.
286    * @param [out] matrixValue On return, a matrix value.
287    */
288   void Get(Matrix& matrixValue) const;
289
290   /**
291    * @brief Retrieve an angle-axis value.
292    *
293    * @pre GetType() returns Property::ROTATION.
294    * @param [out] angleAxisValue On return, a angle-axis value.
295    */
296   void Get(AngleAxis& angleAxisValue) const;
297
298   /**
299    * @brief Retrieve a quaternion value.
300    *
301    * @pre GetType() returns Property::ROTATION.
302    * @param [out] quaternionValue On return, a quaternion value.
303    */
304   void Get(Quaternion& quaternionValue) const;
305
306   /**
307    * @brief Retrieve an string property value.
308    *
309    * @pre GetType() returns Property::STRING.
310    * @param [out] stringValue A string.
311    */
312   void Get(std::string& stringValue) const;
313
314   /**
315    * @brief Retrieve an array property value.
316    *
317    * @pre GetType() returns Property::ARRAY.
318    * @param [out] arrayValue The array as a vector Property Values
319    */
320   void Get(Property::Array& arrayValue) const;
321
322   /**
323    * @brief Retrieve an map property value.
324    *
325    * @pre GetType() returns Property::MAP.
326    * @param [out] mapValue The map as vector of string and Property Value pairs
327    */
328   void Get(Property::Map& mapValue) const;
329
330   /**
331    * @brief Retrieve a property value from the internal map.
332    *
333    * @pre GetType() returns Property::MAP.
334    * @param [in] key A string.
335    * @return Property value if available at key or Invalid
336    */
337   Property::Value& GetValue(const std::string& key) const;
338
339   /**
340    * @brief Retrieve a property value from the internal map.
341    *
342    * @param [in] key A string.
343    * @return true if the key exists, false if not a map or key does not exist
344    */
345   bool HasKey(const std::string& key) const;
346
347   /**
348    * @brief Retrieve a property value from the internal array or map.
349    *
350    * @pre GetType() returns Property::ARRAY or Property::MAP.
351    * @param [in] index The item index.
352    * @return Key at the index or empty if index is out of range
353    */
354   const std::string& GetKey(const int index) const;
355
356   /**
357    * @brief Set a property value in the map.
358    *
359    * @pre GetType() returns Property::MAP.
360    * @param [in] key A string key.
361    * @param [in] value The value to set.
362    * @return Property value if available at key
363    */
364   void SetValue(const std::string& key, const Property::Value &value);
365
366   /**
367    * @brief Retrieve a property value from the internal array or map.
368    *
369    * @pre GetType() returns Property::ARRAY or Property::MAP.
370    * @param [in] index The item index.
371    * @return Property value if available at index or Invalid
372    */
373   Property::Value& GetItem(const int index) const;
374
375   /**
376    * @brief Retrieve a property value from the internal array or map.
377    *
378    * @pre GetType() returns Property::ARRAY or Property::MAP.
379    * @param [in] index The item index.
380    * @param [out] key The key of the index (Applicable only for Property::MAP).
381    * @return Property value if available at index or Invalid
382    */
383   Property::Value& GetItem(const int index, std::string& key) const;
384
385   /**
386    * @brief Set a property value in the array or map.
387    *
388    * @pre GetType() returns Property::ARRAY or Property::MAP.
389    * @pre index < GetSize()
390    * @param [in] index The property value index
391    * @param [in] value The value to set.
392    * @return Property value if index < GetSize()
393    */
394   void SetItem(const int index, const Property::Value &value);
395
396   /**
397    * @brief Set a property value in the array.
398    *
399    * @pre GetType() returns Property::ARRAY.
400    * @param [in] value The value to set.
401    * @return THe index of the item just added
402    */
403   int AppendItem(const Property::Value &value);
404
405   /**
406    * @brief Retrieve the length of the array or map.
407    *
408    * Zero if neither.
409    * @pre GetType() returns Property::ARRAY or Property::MAP
410    * @return The length of the array
411    */
412   int GetSize() const;
413
414 private:
415
416   struct DALI_INTERNAL Impl;
417   Impl* mImpl; ///< Pointer to the implementation
418 };
419
420 } // namespace Dali
421
422 #endif // __DALI_PROPERTY_VALUE_H__