-#ifndef __DALI_SCRIPTING_H__
-#define __DALI_SCRIPTING_H__
+#ifndef DALI_SCRIPTING_H
+#define DALI_SCRIPTING_H
/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 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.
* @param[out] integerEnum The value of the enum.
* @return true if one or more enums in value.
*/
-DALI_IMPORT_API bool EnumStringToInteger( const char* const value, const StringEnum* const table, unsigned int tableCount, unsigned int& integerEnum );
+DALI_IMPORT_API bool EnumStringToInteger( const char* const value, const StringEnum* const table, unsigned int tableCount, int& integerEnum );
/**
* @brief Chooses the appropriate enumeration for the provided string from the given table.
bool retVal( false );
if( table )
{
- unsigned int integerEnum = 0;
+ int integerEnum = 0;
// check to avoid crash, not asserting on purpose, error is logged instead
if( EnumStringToInteger( value, table, tableCount, integerEnum ) )
{
}
/**
+ * @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] 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 )
+{
+ int newValue;
+ bool set = false;
+ Property::Type type = PropertyValue.GetType();
+
+ if( type == Property::INTEGER )
+ {
+ // Attempt to fetch the property as an INTEGER type.
+ if( PropertyValue.Get( newValue ) )
+ {
+ // Success.
+ set = true;
+ }
+ }
+ else if( type == Property::STRING )
+ {
+ // 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 ) )
+ {
+ // Success.
+ set = true;
+ }
+ }
+
+ // If the property was converted OK, AND the value has changed, update the result and return true.
+ if( set && ( result != static_cast<T>( newValue ) ) )
+ {
+ result = static_cast<T>( newValue );
+ return true;
+ }
+
+ // No change.
+ return false;
+}
+
+/**
* @brief Chooses the appropriate string for the provided enumeration from the given table.
*
* @param[in] value The enumeration.
} // namespace Dali
-#endif // __DALI_SCRIPTING_H__
+#endif // DALI_SCRIPTING_H