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