1 #ifndef __DALI_PROPERTY_VALUE_H__
2 #define __DALI_PROPERTY_VALUE_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/object/property.h>
23 #include <dali/public-api/math/rect.h>
37 * @brief A value-type representing a property value.
39 class DALI_IMPORT_API Property::Value
44 * @brief Default constructor.
46 * This creates a property with type Property::NONE.
51 * @brief Create a boolean property value.
53 * @param [in] boolValue A boolean value.
55 Value(bool boolValue);
58 * @brief Create a float property value.
60 * @param [in] floatValue A floating-point value.
62 Value(float floatValue);
65 * @brief Create an integer property value.
67 * @param [in] integerValue An integer value.
69 Value(int integerValue);
72 * @brief Create an unsigned integer property value.
74 * @param [in] unsignedIntegerValue An unsinged integer value.
76 Value(unsigned int unsignedIntegerValue);
79 * @brief Create a Vector2 property value.
81 * @param [in] vectorValue A vector of 2 floating-point values.
83 Value(const Vector2& vectorValue);
86 * @brief Create a Vector3 property value.
88 * @param [in] vectorValue A vector of 3 floating-point values.
90 Value(const Vector3& vectorValue);
93 * @brief Create a Vector4 property value.
95 * @param [in] vectorValue A vector of 4 floating-point values.
97 Value(const Vector4& vectorValue);
100 * @brief Create a Matrix3 property value.
102 * @param [in] matrixValue A matrix of 3x3 floating-point values.
104 Value(const Matrix3& matrixValue);
107 * @brief Create a Matrix property value.
109 * @param [in] matrixValue A matrix of 4x4 floating-point values.
111 Value(const Matrix& matrixValue);
114 * @brief Create a Vector4 property value.
116 * @param [in] vectorValue A vector of 4 integer values.
118 Value(const Rect<int>& vectorValue);
121 * @brief Create an rotation property value.
123 * @param [in] angleAxis An angle-axis representing the rotation.
125 Value(const AngleAxis& angleAxis);
128 * @brief Create an rotation property value.
130 * @param [in] quaternion A quaternion representing the rotation.
132 Value(const Quaternion& quaternion);
135 * @brief Create an string property value.
137 * @param [in] stringValue A string.
139 Value(const std::string& stringValue);
142 * @brief Create an string property value.
144 * @param [in] stringValue A string.
146 Value(const char* stringValue);
149 * @brief Copy a property value.
151 * @param [in] value The property value to copy.
153 Value(const Value& value);
156 * @brief Create an array property value.
158 * @param [in] arrayValue An array
160 Value(Property::Array& arrayValue);
163 * @brief Create a map property value.
165 * @param [in] mapValue An array
167 Value(Property::Map& mapValue);
170 * @brief Explicitly set a type and initialize it.
172 * @param [in] type The property value type.
174 explicit Value(Type type);
177 * @brief Assign a property value.
179 * @param [in] value The property value to assign from.
180 * @return a reference to this
182 Value& operator=(const Value& value);
185 * @brief Non-virtual destructor.
190 * @brief Query the type of this property value.
192 * @return The type ID.
194 Type GetType() const;
197 * @brief Retrieve a specific value.
199 * @pre GetType() returns the Property::Type for type T.
200 * @return A value of type T.
202 template <typename T>
203 T DALI_INTERNAL Get() const
211 * @brief Retrieve a boolean value.
213 * @pre GetType() returns Property::BOOLEAN.
214 * @param [out] boolValue On return, a boolean value.
216 void Get(bool& boolValue) const;
219 * @brief Retrieve a floating-point value.
221 * @pre GetType() returns Property::FLOAT.
222 * @param [out] floatValue On return, a floating-point value.
224 void Get(float& floatValue) const;
227 * @brief Retrieve an integer value.
229 * @pre GetType() returns Property::INTEGER.
230 * @param [out] integerValue On return, an integer value.
232 void Get(int& integerValue) const;
235 * @brief Retrieve an unsigned integer value.
237 * @pre GetType() returns Property::UNSIGNED_INTEGER.
238 * @param [out] unsignedIntegerValue On return, an unsigned integer value.
240 void Get(unsigned int& unsignedIntegerValue) const;
243 * @brief Retrieve an integer rectangle.
245 * @pre GetType() returns Property::RECTANGLE.
246 * @param [out] rect On return, an integer rectangle.
248 void Get(Rect<int>& rect) const;
251 * @brief Retrieve a vector value.
253 * @pre GetType() returns Property::VECTOR2.
254 * @param [out] vectorValue On return, a vector value.
256 void Get(Vector2& vectorValue) const;
259 * @brief Retrieve a vector value.
261 * @pre GetType() returns Property::VECTOR3.
262 * @param [out] vectorValue On return, a vector value.
264 void Get(Vector3& vectorValue) const;
267 * @brief Retrieve a vector value.
269 * @pre GetType() returns Property::VECTOR4.
270 * @param [out] vectorValue On return, a vector value.
272 void Get(Vector4& vectorValue) const;
275 * @brief Retrieve a matrix3 value.
277 * @pre GetType() returns Property::MATRIX3.
278 * @param [out] matrixValue On return, a matrix3 value.
280 void Get(Matrix3& matrixValue) const;
283 * @brief Retrieve a matrix value.
285 * @pre GetType() returns Property::MATRIX.
286 * @param [out] matrixValue On return, a matrix value.
288 void Get(Matrix& matrixValue) const;
291 * @brief Retrieve an angle-axis value.
293 * @pre GetType() returns Property::ROTATION.
294 * @param [out] angleAxisValue On return, a angle-axis value.
296 void Get(AngleAxis& angleAxisValue) const;
299 * @brief Retrieve a quaternion value.
301 * @pre GetType() returns Property::ROTATION.
302 * @param [out] quaternionValue On return, a quaternion value.
304 void Get(Quaternion& quaternionValue) const;
307 * @brief Retrieve an string property value.
309 * @pre GetType() returns Property::STRING.
310 * @param [out] stringValue A string.
312 void Get(std::string& stringValue) const;
315 * @brief Retrieve an array property value.
317 * @pre GetType() returns Property::ARRAY.
318 * @param [out] arrayValue The array as a vector Property Values
320 void Get(Property::Array& arrayValue) const;
323 * @brief Retrieve an map property value.
325 * @pre GetType() returns Property::MAP.
326 * @param [out] mapValue The map as vector of string and Property Value pairs
328 void Get(Property::Map& mapValue) const;
331 * @brief Retrieve a property value from the internal map.
333 * @pre GetType() returns Property::MAP.
334 * @param [in] key A string.
335 * @return Property value if available at key or Invalid
337 Property::Value& GetValue(const std::string& key) const;
340 * @brief Retrieve a property value from the internal map.
342 * @param [in] key A string.
343 * @return true if the key exists, false if not a map or key does not exist
345 bool HasKey(const std::string& key) const;
348 * @brief Retrieve a property value from the internal array or map.
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
354 const std::string& GetKey(const int index) const;
357 * @brief Set a property value in the map.
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
364 void SetValue(const std::string& key, const Property::Value &value);
367 * @brief Retrieve a property value from the internal array or map.
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
373 Property::Value& GetItem(const int index) const;
376 * @brief Retrieve a property value from the internal array or map.
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
383 Property::Value& GetItem(const int index, std::string& key) const;
386 * @brief Set a property value in the array or map.
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()
394 void SetItem(const int index, const Property::Value &value);
397 * @brief Set a property value in the array.
399 * @pre GetType() returns Property::ARRAY.
400 * @param [in] value The value to set.
401 * @return THe index of the item just added
403 int AppendItem(const Property::Value &value);
406 * @brief Retrieve the length of the array or map.
409 * @pre GetType() returns Property::ARRAY or Property::MAP
410 * @return The length of the array
416 struct DALI_INTERNAL Impl;
417 Impl* mImpl; ///< Pointer to the implementation
422 #endif // __DALI_PROPERTY_VALUE_H__