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