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.
25 #include <dali/public-api/object/property.h>
26 #include <dali/public-api/math/rect.h>
40 * @brief A value-type representing a property value.
42 class DALI_IMPORT_API Property::Value
46 friend std::ostream& operator<< (std::ostream& ouputStream, const Property::Value& value);
49 * @brief Default constructor.
51 * This creates a property with type Property::NONE.
56 * @brief Create a boolean property value.
58 * @param [in] boolValue A boolean value.
60 Value(bool boolValue);
63 * @brief Create a float property value.
65 * @param [in] floatValue A floating-point value.
67 Value(float floatValue);
70 * @brief Create an integer property value.
72 * @param [in] integerValue An integer value.
74 Value(int integerValue);
77 * @brief Create an unsigned integer property value.
79 * @param [in] unsignedIntegerValue An unsinged integer value.
81 Value(unsigned int unsignedIntegerValue);
84 * @brief Create a Vector2 property value.
86 * @param [in] vectorValue A vector of 2 floating-point values.
88 Value(const Vector2& vectorValue);
91 * @brief Create a Vector3 property value.
93 * @param [in] vectorValue A vector of 3 floating-point values.
95 Value(const Vector3& vectorValue);
98 * @brief Create a Vector4 property value.
100 * @param [in] vectorValue A vector of 4 floating-point values.
102 Value(const Vector4& vectorValue);
105 * @brief Create a Matrix3 property value.
107 * @param [in] matrixValue A matrix of 3x3 floating-point values.
109 Value(const Matrix3& matrixValue);
112 * @brief Create a Matrix property value.
114 * @param [in] matrixValue A matrix of 4x4 floating-point values.
116 Value(const Matrix& matrixValue);
119 * @brief Create a Vector4 property value.
121 * @param [in] vectorValue A vector of 4 integer values.
123 Value(const Rect<int>& vectorValue);
126 * @brief Create an orientation property value.
128 * @param [in] angleAxis An angle-axis representing the rotation.
130 Value(const AngleAxis& angleAxis);
133 * @brief Create an orientation property value.
135 * @param [in] quaternion A quaternion representing the rotation.
137 Value(const Quaternion& quaternion);
140 * @brief Create an string property value.
142 * @param [in] stringValue A string.
144 Value(const std::string& stringValue);
147 * @brief Create an string property value.
149 * @param [in] stringValue A string.
151 Value(const char* stringValue);
154 * @brief Copy a property value.
156 * @param [in] value The property value to copy.
158 Value(const Value& value);
161 * @brief Create an array property value.
163 * @param [in] arrayValue An array
165 Value(Property::Array& arrayValue);
168 * @brief Create a map property value.
170 * @param [in] mapValue An array
172 Value(Property::Map& mapValue);
175 * @brief Explicitly set a type and initialize it.
177 * @param [in] type The property value type.
179 explicit Value(Type type);
182 * @brief Assign a property value.
184 * @param [in] value The property value to assign from.
185 * @return a reference to this
187 Value& operator=(const Value& value);
190 * @brief Non-virtual destructor.
195 * @brief Query the type of this property value.
197 * @return The type ID.
199 Type GetType() const;
202 * @brief Retrieve a specific value.
204 * @pre GetType() returns the Property::Type for type T.
205 * @return A value of type T.
207 template <typename T>
208 T DALI_INTERNAL Get() const
216 * @brief Retrieve a boolean value.
218 * @pre GetType() returns Property::BOOLEAN.
219 * @param [out] boolValue On return, a boolean value.
221 void Get(bool& boolValue) const;
224 * @brief Retrieve a floating-point value.
226 * @pre GetType() returns Property::FLOAT.
227 * @param [out] floatValue On return, a floating-point value.
229 void Get(float& floatValue) const;
232 * @brief Retrieve an integer value.
234 * @pre GetType() returns Property::INTEGER.
235 * @param [out] integerValue On return, an integer value.
237 void Get(int& integerValue) const;
240 * @brief Retrieve an unsigned integer value.
242 * @pre GetType() returns Property::UNSIGNED_INTEGER.
243 * @param [out] unsignedIntegerValue On return, an unsigned integer value.
245 void Get(unsigned int& unsignedIntegerValue) const;
248 * @brief Retrieve an integer rectangle.
250 * @pre GetType() returns Property::RECTANGLE.
251 * @param [out] rect On return, an integer rectangle.
253 void Get(Rect<int>& rect) const;
256 * @brief Retrieve a vector value.
258 * @pre GetType() returns Property::VECTOR2.
259 * @param [out] vectorValue On return, a vector value.
261 void Get(Vector2& vectorValue) const;
264 * @brief Retrieve a vector value.
266 * @pre GetType() returns Property::VECTOR3.
267 * @param [out] vectorValue On return, a vector value.
269 void Get(Vector3& vectorValue) const;
272 * @brief Retrieve a vector value.
274 * @pre GetType() returns Property::VECTOR4.
275 * @param [out] vectorValue On return, a vector value.
277 void Get(Vector4& vectorValue) const;
280 * @brief Retrieve a matrix3 value.
282 * @pre GetType() returns Property::MATRIX3.
283 * @param [out] matrixValue On return, a matrix3 value.
285 void Get(Matrix3& matrixValue) const;
288 * @brief Retrieve a matrix value.
290 * @pre GetType() returns Property::MATRIX.
291 * @param [out] matrixValue On return, a matrix value.
293 void Get(Matrix& matrixValue) const;
296 * @brief Retrieve an angle-axis value.
298 * @pre GetType() returns Property::ROTATION.
299 * @param [out] angleAxisValue On return, a angle-axis value.
301 void Get(AngleAxis& angleAxisValue) const;
304 * @brief Retrieve a quaternion value.
306 * @pre GetType() returns Property::ROTATION.
307 * @param [out] quaternionValue On return, a quaternion value.
309 void Get(Quaternion& quaternionValue) const;
312 * @brief Retrieve an string property value.
314 * @pre GetType() returns Property::STRING.
315 * @param [out] stringValue A string.
317 void Get(std::string& stringValue) const;
320 * @brief Retrieve an array property value.
322 * @pre GetType() returns Property::ARRAY.
323 * @param [out] arrayValue The array as a vector Property Values
325 void Get(Property::Array& arrayValue) const;
328 * @brief Retrieve an map property value.
330 * @pre GetType() returns Property::MAP.
331 * @param [out] mapValue The map as vector of string and Property Value pairs
333 void Get(Property::Map& mapValue) const;
336 * @brief Retrieve a property value from the internal map.
338 * @pre GetType() returns Property::MAP.
339 * @param [in] key A string.
340 * @return Property value if available at key or Invalid
342 Property::Value& GetValue(const std::string& key) const;
345 * @brief Retrieve a property value from the internal map.
347 * @param [in] key A string.
348 * @return true if the key exists, false if not a map or key does not exist
350 bool HasKey(const std::string& key) const;
353 * @brief Retrieve a property value from the internal array or map.
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
359 const std::string& GetKey(const int index) const;
362 * @brief Set a property value in the map.
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
369 void SetValue(const std::string& key, const Property::Value &value);
372 * @brief Retrieve a property value from the internal array or map.
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
378 Property::Value& GetItem(const int index) const;
381 * @brief Retrieve a property value from the internal array or map.
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
388 Property::Value& GetItem(const int index, std::string& key) const;
391 * @brief Set a property value in the array or map.
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()
399 void SetItem(const int index, const Property::Value &value);
402 * @brief Set a property value in the array.
404 * @pre GetType() returns Property::ARRAY.
405 * @param [in] value The value to set.
406 * @return THe index of the item just added
408 int AppendItem(const Property::Value &value);
411 * @brief Retrieve the length of the array or map.
414 * @pre GetType() returns Property::ARRAY or Property::MAP
415 * @return The length of the array
421 struct DALI_INTERNAL Impl;
422 Impl* mImpl; ///< Pointer to the implementation
426 * @brief Convert the value of the property into a string and append to an output stream.
428 * @param [in] ouputStream The output stream operator.
429 * @param [in] value The value to insert
430 * @return The output stream operator.
432 DALI_IMPORT_API std::ostream& operator<< (std::ostream& ouputStream, const Property::Value& value);
437 #endif // __DALI_PROPERTY_VALUE_H__