(Scripting) Helper method for bit-mask enum properties & moved enum-string macros...
[platform/core/uifw/dali-core.git] / dali / devel-api / scripting / scripting.h
index e688435..ad4539b 100644 (file)
@@ -24,6 +24,7 @@
 #include <dali/devel-api/animation/animation-data.h>
 #include <dali/public-api/images/image.h>
 #include <dali/public-api/shader-effects/shader-effect.h>
+#include <dali/public-api/object/property-array.h>
 #include <dali/public-api/object/property-map.h>
 #include <dali/public-api/object/property-value.h>
 
@@ -101,23 +102,23 @@ bool GetEnumeration( const char* value, const StringEnum* table, unsigned int ta
  * @brief Gets the enumeration value from an enumeration property.
  * An enumeration property is a property that can be set with either an INTEGER or STRING.
  *
- * @param[in]  PropertyValue The property containing the int or string value.
+ * @param[in]  propertyValue The property containing the int or string value.
  * @param[in]  table       A pointer to an array with the enumeration to string equivalents.
  * @param[in]  tableCount  Number of items in the array.
  * @param[out] result      The enum value. This is not modified if the enumeration could not be converted.
  * @return     True if the value was found successfully AND the value has changed. This is to allow the caller to do nothing if there is no change.
  */
 template< typename T >
-bool GetEnumerationProperty( const Property::Value& PropertyValue, const StringEnum* table, unsigned int tableCount, T& result )
+bool GetEnumerationProperty( const Property::Value& propertyValue, const StringEnum* table, unsigned int tableCount, T& result )
 {
   int newValue;
   bool set = false;
-  Property::Type type = PropertyValue.GetType();
+  Property::Type type = propertyValue.GetType();
 
   if( type == Property::INTEGER )
   {
     // Attempt to fetch the property as an INTEGER type.
-    if( PropertyValue.Get( newValue ) )
+    if( propertyValue.Get( newValue ) )
     {
       // Success.
       set = true;
@@ -127,7 +128,7 @@ bool GetEnumerationProperty( const Property::Value& PropertyValue, const StringE
   {
     // Attempt to fetch the property as an STRING type, and convert it from string to enumeration value.
     std::string propertyString;
-    if( table && PropertyValue.Get( propertyString ) && EnumStringToInteger( propertyString.c_str(), table, tableCount, newValue ) )
+    if( table && propertyValue.Get( propertyString ) && EnumStringToInteger( propertyString.c_str(), table, tableCount, newValue ) )
     {
       // Success.
       set = true;
@@ -146,6 +147,64 @@ bool GetEnumerationProperty( const Property::Value& PropertyValue, const StringE
 }
 
 /**
+ * @brief Gets the enumeration value from a bitmask enumeration property.
+ * An enumeration property is a property that can be set with either an INTEGER, STRING or an ARRAY of STRING.
+ *
+ * @param[in]  propertyValue The property containing the int, string or and array of string values.
+ * @param[in]  table       A pointer to an array with the enumeration to string equivalents.
+ * @param[in]  tableCount  Number of items in the array.
+ * @param[out] result      The enum value. This is not modified if the enumeration could not be converted.
+ * @return     True if the value was found successfully AND the value has changed. This is to allow the caller to do nothing if there is no change.
+ */
+template< typename T >
+bool GetBitmaskEnumerationProperty( const Property::Value& propertyValue, const Scripting::StringEnum* table, unsigned int tableCount, T& result )
+{
+  bool returnValue = true;
+
+  // Evaluate as a single INTEGER or STRING first.
+  if( !GetEnumerationProperty( propertyValue, table, tableCount, result ) )
+  {
+    // If not, then check if it's an ARRAY
+    if ( propertyValue.GetType() == Property::ARRAY )
+    {
+      int newValue = 0;
+      Property::Array array;
+      propertyValue.Get( array );
+      for( Property::Array::SizeType i = 0; i < array.Count(); ++i )
+      {
+        Property::Value currentValue = array[ i ];
+        // Use an initial value of -1 so any successful property conversion
+        // causes a change (and true to be returned).
+        T current = static_cast< T >( -1 );
+        if( GetEnumerationProperty( currentValue, table, tableCount, current ) )
+        {
+          newValue |= current;
+        }
+        else
+        {
+          // We hit an invalid type.
+          returnValue = false;
+          break;
+        }
+      }
+
+      // If we didn't hit an invalid type and the value has changed, update the result.
+      if( returnValue && ( result != static_cast<T>( newValue ) ) )
+      {
+        result = static_cast<T>( newValue );
+      }
+    }
+    else
+    {
+      // Property type was not ARRAY, and the single property evaluation also failed.
+      returnValue = false;
+    }
+  }
+
+  return returnValue;
+}
+
+/**
  * @brief Chooses the appropriate string for the provided enumeration from the given table.
  *
  * @param[in]  value       The enumeration.