-#ifndef __DALI_PROPERTY_VALUE_H__
-#define __DALI_PROPERTY_VALUE_H__
+#ifndef DALI_PROPERTY_VALUE_H
+#define DALI_PROPERTY_VALUE_H
/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
// EXTERNAL INCLUDES
+#include <initializer_list>
#include <iosfwd>
+#include <type_traits>
+#include <utility>
// INTERNAL INCLUDES
-#include <dali/public-api/object/property.h>
#include <dali/public-api/math/rect.h>
+#include <dali/public-api/object/property.h>
namespace Dali
{
+/**
+ * @addtogroup dali_core_object
+ * @{
+ */
struct AngleAxis;
class Quaternion;
struct Vector4;
class Matrix3;
class Matrix;
+struct Extents;
+
+using KeyValuePair = std::pair<Property::Key, Property::Value>;
/**
* @brief A value-type representing a property value.
+ * @SINCE_1_0.0
*/
-class DALI_IMPORT_API Property::Value
+class DALI_CORE_API Property::Value
{
public:
-
- friend std::ostream& operator<< (std::ostream& ouputStream, const Property::Value& value);
-
/**
* @brief Default constructor.
*
* This creates a property with type Property::NONE.
+ * @SINCE_1_0.0
*/
Value();
/**
- * @brief Create a boolean property value.
+ * @brief Creates a boolean property value.
*
- * @param [in] boolValue A boolean value.
+ * @SINCE_1_0.0
+ * @param[in] boolValue A boolean value
*/
Value(bool boolValue);
/**
- * @brief Create an integer property value.
+ * @brief Creates an integer property value.
*
- * @param [in] integerValue An integer value.
+ * @SINCE_1_0.0
+ * @param[in] integerValue An integer value
*/
- Value(int integerValue);
+ Value(int32_t integerValue);
/**
- * @brief Create an unsigned integer property value.
+ * @brief Creates a float property value.
*
- * @param [in] unsignedIntegerValue An unsigned integer value.
- */
- Value(unsigned int unsignedIntegerValue);
-
- /**
- * @brief Create a float property value.
- *
- * @param [in] floatValue A floating-point value.
+ * @SINCE_1_0.0
+ * @param[in] floatValue A floating-point value
*/
Value(float floatValue);
/**
- * @brief Create a Vector2 property value.
+ * @brief Creates a Vector2 property value.
*
- * @param [in] vectorValue A vector of 2 floating-point values.
+ * @SINCE_1_0.0
+ * @param[in] vectorValue A vector of 2 floating-point values
*/
Value(const Vector2& vectorValue);
/**
- * @brief Create a Vector3 property value.
+ * @brief Creates a Vector3 property value.
*
- * @param [in] vectorValue A vector of 3 floating-point values.
+ * @SINCE_1_0.0
+ * @param[in] vectorValue A vector of 3 floating-point values
*/
Value(const Vector3& vectorValue);
/**
- * @brief Create a Vector4 property value.
+ * @brief Creates a Vector4 property value.
*
- * @param [in] vectorValue A vector of 4 floating-point values.
+ * @SINCE_1_0.0
+ * @param[in] vectorValue A vector of 4 floating-point values
*/
Value(const Vector4& vectorValue);
/**
- * @brief Create a Matrix3 property value.
+ * @brief Creates a Matrix3 property value.
*
- * @param [in] matrixValue A matrix of 3x3 floating-point values.
+ * @SINCE_1_0.0
+ * @param[in] matrixValue A matrix of 3x3 floating-point values
*/
Value(const Matrix3& matrixValue);
/**
- * @brief Create a Matrix property value.
+ * @brief Creates a Matrix property value.
*
- * @param [in] matrixValue A matrix of 4x4 floating-point values.
+ * @SINCE_1_0.0
+ * @param[in] matrixValue A matrix of 4x4 floating-point values
*/
Value(const Matrix& matrixValue);
/**
- * @brief Create a Vector4 property value.
+ * @brief Creates a Vector4 property value.
+ *
+ * @SINCE_1_0.0
+ * @param[in] vectorValue A vector of 4 integer values
+ */
+ Value(const Rect<int32_t>& vectorValue);
+
+ /**
+ * @brief Creates a Vector4 property value.
*
- * @param [in] vectorValue A vector of 4 integer values.
+ * @SINCE_1_9.14
+ * @param[in] vectorValue A vector of 4 float values
*/
- Value(const Rect<int>& vectorValue);
+ Value(const Rect<float>& vectorValue);
/**
- * @brief Create an orientation property value.
+ * @brief Creates an orientation property value.
*
- * @param [in] angleAxis An angle-axis representing the rotation.
+ * @SINCE_1_0.0
+ * @param[in] angleAxis An angle-axis representing the rotation
*/
Value(const AngleAxis& angleAxis);
/**
- * @brief Create an orientation property value.
+ * @brief Creates an orientation property value.
*
- * @param [in] quaternion A quaternion representing the rotation.
+ * @SINCE_1_0.0
+ * @param[in] quaternion A quaternion representing the rotation
*/
Value(const Quaternion& quaternion);
/**
- * @brief Create an string property value.
+ * @brief Creates an string property value.
*
- * @param [in] stringValue A string.
+ * @SINCE_1_0.0
+ * @param[in] stringValue A string
*/
- Value(const std::string& stringValue);
+ Value(std::string stringValue);
/**
- * @brief Create an string property value.
+ * @brief Creates a string property value.
*
- * @param [in] stringValue A string.
+ * @SINCE_1_0.0
+ * @param[in] stringValue A string
*/
Value(const char* stringValue);
/**
- * @brief Copy a property value.
+ * @brief Creates an array property value.
*
- * @param [in] value The property value to copy.
+ * @SINCE_1_9.30
+ * @param[in] arrayValue A property array
*/
- Value(const Value& value);
+ Value(Property::Array arrayValue);
+
+ /**
+ * @brief Creates a map property value.
+ *
+ * @SINCE_1_9.30
+ * @param[in] mapValue A property map
+ */
+ Value(Property::Map mapValue);
/**
- * @brief Create an array property value.
+ * @brief Create a map property value from an initializer_list.
*
- * @param [in] arrayValue An array
+ * @SINCE_1_4.16
+ * @param [in] values An initializer_list of pairs of index and value.
*/
- Value(Property::Array& arrayValue);
+ Value(const std::initializer_list<KeyValuePair>& values);
/**
- * @brief Create a map property value.
+ * @brief Creates an extents property value.
*
- * @param [in] mapValue An array
+ * @SINCE_1_2.62
+ * @param[in] extentsValue A collection of 4 uint16_t values
*/
- Value(Property::Map& mapValue);
+ Value(const Extents& extentsValue);
+
+ /**
+ * @brief Creates an enumeration property value.
+ *
+ * @SINCE_1_4.36
+ * @param[in] enumValue An enumeration value
+ */
+ template<typename T, typename std::enable_if<std::is_enum<T>::value>::type* = nullptr>
+ Value(T enumValue)
+ : Value(static_cast<int32_t>(enumValue))
+ {
+ }
/**
- * @brief Explicitly set a type and initialize it.
+ * @brief Explicitly sets a type and initialize it.
*
- * @param [in] type The property value type.
+ * @SINCE_1_0.0
+ * @param[in] type The property value type
*/
explicit Value(Type type);
/**
- * @brief Assign a property value.
+ * @brief Copy constructor.
+ *
+ * @SINCE_1_0.0
+ * @param[in] value The property value to copy
+ */
+ Value(const Value& value);
+
+ /**
+ * @brief Move constructor.
+ *
+ * A move constructor enables the resources owned by an rvalue object to be moved into an lvalue without copying.
+ * @SINCE_1_4.16
+ * @param[in] value The property value to move from
+ */
+ Value(Value&& value) noexcept;
+
+ /**
+ * @brief Assigns a property value.
*
- * @param [in] value The property value to assign from.
+ * @SINCE_1_0.0
+ * @param[in] value The property value to assign from
* @return a reference to this
*/
Value& operator=(const Value& value);
/**
+ * @brief Move assignment operator.
+ *
+ * @SINCE_1_4.16
+ * @param[in] value The property value to move from
+ * @return a reference to this
+ */
+ Value& operator=(Value&& value) noexcept;
+
+ /**
* @brief Non-virtual destructor.
+ *
+ * This class is not a base class.
+ * @SINCE_1_0.0
*/
~Value();
/**
- * @brief Query the type of this property value.
+ * @brief Queries the type of this property value.
*
- * @return The type ID.
+ * @SINCE_1_0.0
+ * @return The type ID
*/
Type GetType() const;
/**
- * @brief Retrieve a specific value.
+ * @brief Retrieves a specific value.
*
- * @pre GetType() returns the Property::Type for type T.
- * @return A value of type T.
+ * Works on a best-effort approach; if value type is different returns a default value of the type.
+ *
+ * @SINCE_1_4.36
+ * @return A value of type T
*/
- template <typename T>
+ template<typename T, typename std::enable_if<!std::is_enum<T>::value>::type* = nullptr>
T DALI_INTERNAL Get() const
{
- T temp;
+ T temp = T(); // value (zero) initialize
Get(temp);
return temp;
}
/**
- * @brief Retrieve a boolean value.
+ * @brief Retrieves a specific value.
+ *
+ * Works on a best-effort approach; if value type is different returns a default value of the type.
+ * Specialization for enumeration values
*
- * @pre GetType() returns Property::BOOLEAN.
- * @param [out] boolValue On return, a boolean value.
+ * @SINCE_1_4.36
+ * @return A value of type T
*/
- void Get(bool& boolValue) const;
+ template<typename T, typename std::enable_if<std::is_enum<T>::value>::type* = nullptr>
+ T DALI_INTERNAL Get() const
+ {
+ int32_t temp = 0; // value (zero) initialize
+ Get(temp);
+ return static_cast<T>(temp);
+ }
/**
- * @brief Retrieve a floating-point value.
+ * @brief Retrieves an enumeration value.
*
- * @pre GetType() returns Property::FLOAT.
- * @param [out] floatValue On return, a floating-point value.
+ * @SINCE_1_4.36
+ * @param[out] enumValue On return, an enumeration value
+ * @return @c true if the value is successfully retrieved, @c false if the type is different
+ * @pre GetType() is any enumeration
*/
- void Get(float& floatValue) const;
+ template<typename T, typename std::enable_if<std::is_enum<T>::value>::type* = nullptr>
+ bool DALI_INTERNAL Get(T& enumValue) const
+ {
+ int32_t temp = 0;
+ if(!Get(temp))
+ {
+ return false;
+ }
+ enumValue = static_cast<T>(temp);
+ return true;
+ }
/**
- * @brief Retrieve an integer value.
+ * @brief Retrieves a boolean value.
*
- * @pre GetType() returns Property::INTEGER.
- * @param [out] integerValue On return, an integer value.
+ * @SINCE_1_0.0
+ * @param[out] boolValue On return, a boolean value
+ * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
+ * @pre GetType() is a type convertible to bool.
*/
- void Get(int& integerValue) const;
+ bool Get(bool& boolValue) const;
/**
- * @brief Retrieve an unsigned integer value.
+ * @brief Retrieves a floating-point value.
*
- * @pre GetType() returns Property::UNSIGNED_INTEGER.
- * @param [out] unsignedIntegerValue On return, an unsigned integer value.
+ * @SINCE_1_0.0
+ * @param[out] floatValue On return, a floating-point value
+ * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
+ * @pre GetType() is a type convertible to float.
*/
- void Get(unsigned int& unsignedIntegerValue) const;
+ bool Get(float& floatValue) const;
/**
- * @brief Retrieve an integer rectangle.
+ * @brief Retrieves an integer value.
*
- * @pre GetType() returns Property::RECTANGLE.
- * @param [out] rect On return, an integer rectangle.
+ * @SINCE_1_0.0
+ * @param[out] integerValue On return, an integer value
+ * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
+ * @pre GetType() is a type convertible to int.
*/
- void Get(Rect<int>& rect) const;
+ bool Get(int32_t& integerValue) const;
/**
- * @brief Retrieve a vector value.
+ * @brief Retrieves an integer rectangle.
*
- * @pre GetType() returns Property::VECTOR2.
- * @param [out] vectorValue On return, a vector value.
+ * @SINCE_1_0.0
+ * @param[out] rect On return, an integer rectangle
+ * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
+ * @pre GetType() is a type convertible to Rect<int>.
*/
- void Get(Vector2& vectorValue) const;
+ bool Get(Rect<int32_t>& rect) const;
/**
- * @brief Retrieve a vector value.
+ * @brief Retrieves a vector value.
*
- * @pre GetType() returns Property::VECTOR3.
- * @param [out] vectorValue On return, a vector value.
+ * @SINCE_1_0.0
+ * @param[out] vectorValue On return, a vector value
+ * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
+ * @pre GetType() is a type convertible to Vector2.
*/
- void Get(Vector3& vectorValue) const;
+ bool Get(Vector2& vectorValue) const;
/**
- * @brief Retrieve a vector value.
+ * @brief Retrieves a vector value.
*
- * @pre GetType() returns Property::VECTOR4.
- * @param [out] vectorValue On return, a vector value.
+ * @SINCE_1_0.0
+ * @param[out] vectorValue On return, a vector value
+ * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
+ * @pre GetType() is a type convertible to Vector3.
*/
- void Get(Vector4& vectorValue) const;
+ bool Get(Vector3& vectorValue) const;
/**
- * @brief Retrieve a matrix3 value.
+ * @brief Retrieves a vector value.
*
- * @pre GetType() returns Property::MATRIX3.
- * @param [out] matrixValue On return, a matrix3 value.
+ * @SINCE_1_0.0
+ * @param[out] vectorValue On return, a vector value
+ * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
+ * @pre GetType() is a type convertible to Vector4.
*/
- void Get(Matrix3& matrixValue) const;
+ bool Get(Vector4& vectorValue) const;
/**
- * @brief Retrieve a matrix value.
+ * @brief Retrieves a matrix3 value.
*
- * @pre GetType() returns Property::MATRIX.
- * @param [out] matrixValue On return, a matrix value.
+ * @SINCE_1_0.0
+ * @param[out] matrixValue On return, a matrix3 value
+ * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
+ * @pre GetType() is a type convertible to Matrix3.
*/
- void Get(Matrix& matrixValue) const;
+ bool Get(Matrix3& matrixValue) const;
/**
- * @brief Retrieve an angle-axis value.
+ * @brief Retrieves a matrix value.
*
- * @pre GetType() returns Property::ROTATION.
- * @param [out] angleAxisValue On return, a angle-axis value.
+ * @SINCE_1_0.0
+ * @param[out] matrixValue On return, a matrix value
+ * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
+ * @pre GetType() is a type convertible to Matrix.
*/
- void Get(AngleAxis& angleAxisValue) const;
+ bool Get(Matrix& matrixValue) const;
/**
- * @brief Retrieve a quaternion value.
+ * @brief Retrieves an angle-axis value.
*
- * @pre GetType() returns Property::ROTATION.
- * @param [out] quaternionValue On return, a quaternion value.
+ * @SINCE_1_0.0
+ * @param[out] angleAxisValue On return, a angle-axis value
+ * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
+ * @pre GetType() is a type convertible to AngleAxis.
*/
- void Get(Quaternion& quaternionValue) const;
+ bool Get(AngleAxis& angleAxisValue) const;
/**
- * @brief Retrieve an string property value.
+ * @brief Retrieves a quaternion value.
*
- * @pre GetType() returns Property::STRING.
- * @param [out] stringValue A string.
+ * @SINCE_1_0.0
+ * @param[out] quaternionValue On return, a quaternion value
+ * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
+ * @pre GetType() is a type convertible to Quaternion.
*/
- void Get(std::string& stringValue) const;
+ bool Get(Quaternion& quaternionValue) const;
/**
- * @brief Retrieve an array property value.
+ * @brief Retrieves an string property value.
*
- * @pre GetType() returns Property::ARRAY.
- * @param [out] arrayValue The array as a vector Property Values
+ * @SINCE_1_0.0
+ * @param[out] stringValue A string
+ * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
+ * @pre GetType() is a type convertible to string.
*/
- void Get(Property::Array& arrayValue) const;
+ bool Get(std::string& stringValue) const;
/**
- * @brief Retrieve an map property value.
+ * @brief Retrieves an array property value.
*
- * @pre GetType() returns Property::MAP.
- * @param [out] mapValue The map as vector of string and Property Value pairs
+ * @SINCE_1_0.0
+ * @param[out] arrayValue The array as a vector Property Values
+ * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
+ * @pre GetType() returns Property::ARRAY.
*/
- void Get(Property::Map& mapValue) const;
+ bool Get(Property::Array& arrayValue) const;
/**
- * @brief Retrieve a property value from the internal map.
+ * @brief Retrieves an map property value.
*
+ * @SINCE_1_0.0
+ * @param[out] mapValue The map as vector of string and Property Value pairs
+ * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
* @pre GetType() returns Property::MAP.
- * @param [in] key A string.
- * @return Property value if available at key or Invalid
*/
- Property::Value& GetValue(const std::string& key) const;
+ bool Get(Property::Map& mapValue) const;
/**
- * @brief Retrieve a property value from the internal map.
+ * @brief Retrieves the Array API of the Property::Value without copying the contents of the array.
*
- * @param [in] key A string.
- * @return true if the key exists, false if not a map or key does not exist
+ * @SINCE_1_9.32
+ * @return The Array API of the Property::Value or NULL if not a Property::Array
*/
- bool HasKey(const std::string& key) const;
+ const Property::Array* GetArray() const;
/**
- * @brief Retrieve a property value from the internal array or map.
+ * @brief Retrieves the Array API of the Property::Value without copying the contents of the array.
*
- * @pre GetType() returns Property::ARRAY or Property::MAP.
- * @param [in] index The item index.
- * @return Key at the index or empty if index is out of range
+ * @SINCE_1_9.32
+ * @return The Array API of the Property::Value or NULL if not a Property::Array
*/
- const std::string& GetKey(const int index) const;
+ Property::Array* GetArray();
/**
- * @brief Set a property value in the map.
+ * @brief Retrieves the Map API of the Property::Value without copying the contents of the map.
*
- * @pre GetType() returns Property::MAP.
- * @param [in] key A string key.
- * @param [in] value The value to set.
- * @return Property value if available at key
+ * @SINCE_1_9.32
+ * @return The Map API of the Property::Value or NULL if not a Property::Map
*/
- void SetValue(const std::string& key, const Property::Value &value);
+ const Property::Map* GetMap() const;
/**
- * @brief Retrieve a property value from the internal array or map.
+ * @brief Retrieves the Map API of the Property::Value without copying the contents of the map.
*
- * @pre GetType() returns Property::ARRAY or Property::MAP.
- * @param [in] index The item index.
- * @return Property value if available at index or Invalid
+ * @SINCE_1_9.32
+ * @return The Map API of the Property::Value or NULL if not a Property::Map
*/
- Property::Value& GetItem(const int index) const;
+ Property::Map* GetMap();
/**
- * @brief Retrieve a property value from the internal array or map.
+ * @brief Retrieves an extents.
*
- * @pre GetType() returns Property::ARRAY or Property::MAP.
- * @param [in] index The item index.
- * @param [out] key The key of the index (Applicable only for Property::MAP).
- * @return Property value if available at index or Invalid
+ * @SINCE_1_2.62
+ * @param[out] extentsValue Extents, a collection of 4 uint16_t
+ * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
+ * @pre GetType() is a type convertible to Extents.
*/
- Property::Value& GetItem(const int index, std::string& key) const;
+ bool Get(Extents& extentsValue) const;
/**
- * @brief Set a property value in the array or map.
- *
- * @pre GetType() returns Property::ARRAY or Property::MAP.
- * @pre index < GetSize()
- * @param [in] index The property value index
- * @param [in] value The value to set.
- * @return Property value if index < GetSize()
+ * @brief Output to stream.
+ * @SINCE_1_0.0
*/
- void SetItem(const int index, const Property::Value &value);
+ friend DALI_CORE_API std::ostream& operator<<(std::ostream& ouputStream, const Property::Value& value);
+
+private:
+ /// @cond internal
+ struct DALI_INTERNAL Impl;
/**
- * @brief Set a property value in the array.
- *
- * @pre GetType() returns Property::ARRAY.
- * @param [in] value The value to set.
- * @return THe index of the item just added
+ * @brief Retrieves an already constructed Impl object from the storage buffer.
+ * @return A const reference to the Impl object
*/
- int AppendItem(const Property::Value &value);
+ DALI_INTERNAL const Impl& Read() const;
/**
- * @brief Retrieve the length of the array or map.
- *
- * Zero if neither.
- * @pre GetType() returns Property::ARRAY or Property::MAP
- * @return The length of the array
+ * @brief Retrieves an already constructed Impl object from the storage buffer.
+ * @return A non const reference to the Impl object
*/
- int GetSize() const;
+ DALI_INTERNAL Impl& Write();
-private:
+ /**
+ * @brief An aligned storage buffer to create Impl object inplace.
+ */
+ struct DALI_INTERNAL Storage
+ {
+ alignas(sizeof(Impl*)) unsigned char buffer[16];
+ };
- struct DALI_INTERNAL Impl;
- Impl* mImpl; ///< Pointer to the implementation
+ Storage mStorage;
+ /// @endcond
};
/**
- * @brief Convert the value of the property into a string and append to an output stream.
+ * @brief Converts the value of the property into a string and append to an output stream.
*
- * @param [in] ouputStream The output stream operator.
- * @param [in] value The value to insert
- * @return The output stream operator.
+ * @SINCE_1_0.0
+ * @param[in] ouputStream The output stream operator
+ * @param[in] value The value to insert
+ * @return The output stream operator
*/
-DALI_IMPORT_API std::ostream& operator<< (std::ostream& ouputStream, const Property::Value& value);
-
+DALI_CORE_API std::ostream& operator<<(std::ostream& ouputStream, const Property::Value& value);
+/**
+ * @}
+ */
} // namespace Dali
-#endif // __DALI_PROPERTY_VALUE_H__
+#endif // DALI_PROPERTY_VALUE_H