Merge "[ATSPI] Adds support for enumeration in Property::Value" into devel/master
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Mon, 2 Sep 2019 15:28:51 +0000 (15:28 +0000)
committerGerrit Code Review <gerrit@review.ap-northeast-2.compute.internal>
Mon, 2 Sep 2019 15:28:51 +0000 (15:28 +0000)
automated-tests/src/dali/utc-Dali-Scripting.cpp
dali/public-api/object/property-value.h

index 793a5ba..f305cf7 100644 (file)
@@ -123,6 +123,24 @@ void TestEnumStrings(
 
 } // anon namespace
 
+int UtcDaliValueFromEnum(void)
+{
+  enum class T {
+    None, V1 = 1, V2 = 2
+  };
+
+  Property::Value v1 = T::V1;
+  Property::Value v2 = T::V2;
+
+  T t = T::None;
+  DALI_TEST_CHECK( v1.Get<T>() == T::V1 );
+  DALI_TEST_CHECK( v2.Get<T>() == T::V2 );
+  DALI_TEST_CHECK( v1.Get(t) && t == T::V1 );
+  DALI_TEST_CHECK( v2.Get(t) && t == T::V2 );
+
+  END_TEST;
+}
+
 int UtcDaliScriptingNewImageNegative01(void)
 {
   // Invalid filename
index 9b0f203..800ca99 100755 (executable)
@@ -20,6 +20,7 @@
 
 // EXTERNAL INCLUDES
 #include <iosfwd>
+#include <type_traits>
 #include <utility>
 #include <initializer_list>
 
@@ -27,6 +28,7 @@
 #include <dali/public-api/object/property.h>
 #include <dali/public-api/math/rect.h>
 
+
 namespace Dali
 {
 /**
@@ -214,6 +216,17 @@ public:
   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 sets a type and initialize it.
    *
    * @SINCE_1_0.0
@@ -275,12 +288,12 @@ public:
   /**
    * @brief Retrieves a specific value.
    *
-   * Works on a best-effort approach; if value type is not convertible returns a default value of the type.
+   * Works on a best-effort approach; if value type is different returns a default value of the type.
    *
-   * @SINCE_1_0.0
+   * @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(); // value (zero) initialize
@@ -289,6 +302,43 @@ public:
   }
 
   /**
+   * @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
+   *
+   * @SINCE_1_4.36
+   * @return A value of type T
+   */
+  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 Retrieves an enumeration 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
+   */
+  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 Retrieves a boolean value.
    *
    * @SINCE_1_0.0