1 #ifndef DALI_PROPERTY_VALUE_H
2 #define DALI_PROPERTY_VALUE_H
5 * Copyright (c) 2020 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 <initializer_list>
24 #include <type_traits>
28 #include <dali/public-api/math/rect.h>
29 #include <dali/public-api/object/property.h>
34 * @addtogroup dali_core_object
47 using KeyValuePair = std::pair<Property::Key, Property::Value>;
50 * @brief A value-type representing a property value.
53 class DALI_CORE_API Property::Value
57 * @brief Default constructor.
59 * This creates a property with type Property::NONE.
65 * @brief Creates a boolean property value.
68 * @param[in] boolValue A boolean value
70 Value(bool boolValue);
73 * @brief Creates an integer property value.
76 * @param[in] integerValue An integer value
78 Value(int32_t integerValue);
81 * @brief Creates a float property value.
84 * @param[in] floatValue A floating-point value
86 Value(float floatValue);
89 * @brief Creates a Vector2 property value.
92 * @param[in] vectorValue A vector of 2 floating-point values
94 Value(const Vector2& vectorValue);
97 * @brief Creates a Vector3 property value.
100 * @param[in] vectorValue A vector of 3 floating-point values
102 Value(const Vector3& vectorValue);
105 * @brief Creates a Vector4 property value.
108 * @param[in] vectorValue A vector of 4 floating-point values
110 Value(const Vector4& vectorValue);
113 * @brief Creates a Matrix3 property value.
116 * @param[in] matrixValue A matrix of 3x3 floating-point values
118 Value(const Matrix3& matrixValue);
121 * @brief Creates a Matrix property value.
124 * @param[in] matrixValue A matrix of 4x4 floating-point values
126 Value(const Matrix& matrixValue);
129 * @brief Creates a Vector4 property value.
132 * @param[in] vectorValue A vector of 4 integer values
134 Value(const Rect<int32_t>& vectorValue);
137 * @brief Creates a Vector4 property value.
140 * @param[in] vectorValue A vector of 4 float values
142 Value(const Rect<float>& vectorValue);
145 * @brief Creates an orientation property value.
148 * @param[in] angleAxis An angle-axis representing the rotation
150 Value(const AngleAxis& angleAxis);
153 * @brief Creates an orientation property value.
156 * @param[in] quaternion A quaternion representing the rotation
158 Value(const Quaternion& quaternion);
161 * @brief Creates an string property value.
164 * @param[in] stringValue A string
166 Value(const std::string& stringValue);
169 * @brief Creates a string property value.
172 * @param[in] stringValue A string
174 Value(const char* stringValue);
177 * @brief Creates an array property value.
180 * @param[in] arrayValue An array
182 Value(Property::Array& arrayValue);
185 * @brief Creates an array property value.
188 * @param[in] arrayValue An r-value array
190 Value(Property::Array&& arrayValue);
193 * @brief Creates a map property value.
196 * @param[in] mapValue A map
198 Value(Property::Map& mapValue);
201 * @brief Creates a map property value.
204 * @param[in] mapValue An r-value map
206 Value(Property::Map&& mapValue);
209 * @brief Create a map property value from an initializer_list.
212 * @param [in] values An initializer_list of pairs of index and value.
214 Value(const std::initializer_list<KeyValuePair>& values);
217 * @brief Creates an extents property value.
220 * @param[in] extentsValue A collection of 4 uint16_t values
222 Value(const Extents& extentsValue);
225 * @brief Creates an enumeration property value.
228 * @param[in] enumValue An enumeration value
230 template<typename T, typename std::enable_if<std::is_enum<T>::value>::type* = nullptr>
232 : Value(static_cast<int32_t>(enumValue))
237 * @brief Explicitly sets a type and initialize it.
240 * @param[in] type The property value type
242 explicit Value(Type type);
245 * @brief Copy constructor.
248 * @param[in] value The property value to copy
250 Value(const Value& value);
253 * @brief Move constructor.
255 * A move constructor enables the resources owned by an rvalue object to be moved into an lvalue without copying.
257 * @param[in] value The property value to move from
259 Value(Value&& value);
262 * @brief Assigns a property value.
265 * @param[in] value The property value to assign from
266 * @return a reference to this
268 Value& operator=(const Value& value);
271 * @brief Move assignment operator.
274 * @param[in] value The property value to move from
275 * @return a reference to this
277 Value& operator=(Value&& value);
280 * @brief Non-virtual destructor.
282 * This class is not a base class.
288 * @brief Queries the type of this property value.
291 * @return The type ID
293 Type GetType() const;
296 * @brief Retrieves a specific value.
298 * Works on a best-effort approach; if value type is different returns a default value of the type.
301 * @return A value of type T
303 template<typename T, typename std::enable_if<!std::is_enum<T>::value>::type* = nullptr>
304 T DALI_INTERNAL Get() const
306 T temp = T(); // value (zero) initialize
312 * @brief Retrieves a specific value.
314 * Works on a best-effort approach; if value type is different returns a default value of the type.
315 * Specialization for enumeration values
318 * @return A value of type T
320 template<typename T, typename std::enable_if<std::is_enum<T>::value>::type* = nullptr>
321 T DALI_INTERNAL Get() const
323 int32_t temp = 0; // value (zero) initialize
325 return static_cast<T>(temp);
329 * @brief Retrieves an enumeration value.
332 * @param[out] enumValue On return, an enumeration value
333 * @return @c true if the value is successfully retrieved, @c false if the type is different
334 * @pre GetType() is any enumeration
336 template<typename T, typename std::enable_if<std::is_enum<T>::value>::type* = nullptr>
337 bool DALI_INTERNAL Get(T& enumValue) const
344 enumValue = static_cast<T>(temp);
349 * @brief Retrieves a boolean value.
352 * @param[out] boolValue On return, a boolean value
353 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
354 * @pre GetType() is a type convertible to bool.
356 bool Get(bool& boolValue) const;
359 * @brief Retrieves a floating-point value.
362 * @param[out] floatValue On return, a floating-point value
363 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
364 * @pre GetType() is a type convertible to float.
366 bool Get(float& floatValue) const;
369 * @brief Retrieves an integer value.
372 * @param[out] integerValue On return, an integer value
373 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
374 * @pre GetType() is a type convertible to int.
376 bool Get(int32_t& integerValue) const;
379 * @brief Retrieves an integer rectangle.
382 * @param[out] rect On return, an integer rectangle
383 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
384 * @pre GetType() is a type convertible to Rect<int>.
386 bool Get(Rect<int32_t>& rect) const;
389 * @brief Retrieves a vector value.
392 * @param[out] vectorValue On return, a vector value
393 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
394 * @pre GetType() is a type convertible to Vector2.
396 bool Get(Vector2& vectorValue) const;
399 * @brief Retrieves a vector value.
402 * @param[out] vectorValue On return, a vector value
403 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
404 * @pre GetType() is a type convertible to Vector3.
406 bool Get(Vector3& vectorValue) const;
409 * @brief Retrieves a vector value.
412 * @param[out] vectorValue On return, a vector value
413 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
414 * @pre GetType() is a type convertible to Vector4.
416 bool Get(Vector4& vectorValue) const;
419 * @brief Retrieves a matrix3 value.
422 * @param[out] matrixValue On return, a matrix3 value
423 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
424 * @pre GetType() is a type convertible to Matrix3.
426 bool Get(Matrix3& matrixValue) const;
429 * @brief Retrieves a matrix value.
432 * @param[out] matrixValue On return, a matrix value
433 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
434 * @pre GetType() is a type convertible to Matrix.
436 bool Get(Matrix& matrixValue) const;
439 * @brief Retrieves an angle-axis value.
442 * @param[out] angleAxisValue On return, a angle-axis value
443 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
444 * @pre GetType() is a type convertible to AngleAxis.
446 bool Get(AngleAxis& angleAxisValue) const;
449 * @brief Retrieves a quaternion value.
452 * @param[out] quaternionValue On return, a quaternion value
453 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
454 * @pre GetType() is a type convertible to Quaternion.
456 bool Get(Quaternion& quaternionValue) const;
459 * @brief Retrieves an string property value.
462 * @param[out] stringValue A string
463 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
464 * @pre GetType() is a type convertible to string.
466 bool Get(std::string& stringValue) const;
469 * @brief Retrieves an array property value.
472 * @param[out] arrayValue The array as a vector Property Values
473 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
474 * @pre GetType() returns Property::ARRAY.
476 bool Get(Property::Array& arrayValue) const;
479 * @brief Retrieves an map property value.
482 * @param[out] mapValue The map as vector of string and Property Value pairs
483 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
484 * @pre GetType() returns Property::MAP.
486 bool Get(Property::Map& mapValue) const;
489 * @brief Retrieves the Array API of the Property::Value without copying the contents of the map.
492 * @return The Array API of the Property::Value or NULL if not a Property::Array
494 Property::Array* GetArray() const;
497 * @brief Retrieves the Map API of the Property::Value without copying the contents of the map.
500 * @return The Map API of the Property::Value or NULL if not a Property::Map
502 Property::Map* GetMap() const;
505 * @brief Retrieves an extents.
508 * @param[out] extentsValue Extents, a collection of 4 uint16_t
509 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
510 * @pre GetType() is a type convertible to Extents.
512 bool Get(Extents& extentsValue) const;
515 * @brief Output to stream.
518 friend DALI_CORE_API std::ostream& operator<<(std::ostream& ouputStream, const Property::Value& value);
521 struct DALI_INTERNAL Impl;
522 Impl* mImpl; ///< Pointer to the implementation
526 * @brief Converts the value of the property into a string and append to an output stream.
529 * @param[in] ouputStream The output stream operator
530 * @param[in] value The value to insert
531 * @return The output stream operator
533 DALI_CORE_API std::ostream& operator<<(std::ostream& ouputStream, const Property::Value& value);
540 #endif // DALI_PROPERTY_VALUE_H