extern int UtcDaliScriptingNewActorChildren(void);
extern int UtcDaliScriptingCreatePropertyMapActor(void);
extern int UtcDaliScriptingCreatePropertyMapImage(void);
+extern int UtcDaliScriptingGetEnumerationTemplates(void);
extern int UtcDaliSplineGetYFromMonotonicX(void);
extern int utcDaliSplineGetKnot01(void);
extern int utcDaliSplineGetKnot02(void);
{"UtcDaliScriptingNewActorChildren", UtcDaliScriptingNewActorChildren, utc_dali_unmanaged_startup, utc_dali_unmanaged_cleanup},
{"UtcDaliScriptingCreatePropertyMapActor", UtcDaliScriptingCreatePropertyMapActor, utc_dali_unmanaged_startup, utc_dali_unmanaged_cleanup},
{"UtcDaliScriptingCreatePropertyMapImage", UtcDaliScriptingCreatePropertyMapImage, utc_dali_unmanaged_startup, utc_dali_unmanaged_cleanup},
+ {"UtcDaliScriptingGetEnumerationTemplates", UtcDaliScriptingGetEnumerationTemplates, utc_dali_unmanaged_startup, utc_dali_unmanaged_cleanup},
{"UtcDaliSplineGetYFromMonotonicX", UtcDaliSplineGetYFromMonotonicX, utc_dali_unmanaged_startup, utc_dali_unmanaged_cleanup},
{"utcDaliSplineGetKnot01", utcDaliSplineGetKnot01, utc_dali_unmanaged_startup, utc_dali_unmanaged_cleanup},
{"utcDaliSplineGetKnot02", utcDaliSplineGetKnot02, utc_dali_unmanaged_startup, utc_dali_unmanaged_cleanup},
namespace
{
-struct StringEnum
-{
- const char * string;
- int value;
-};
-
-const StringEnum COLOR_MODE_VALUES[] =
+const StringEnum< int > COLOR_MODE_VALUES[] =
{
{ "USE_OWN_COLOR", USE_OWN_COLOR },
{ "USE_PARENT_COLOR", USE_PARENT_COLOR },
};
const unsigned int COLOR_MODE_VALUES_COUNT = sizeof( COLOR_MODE_VALUES ) / sizeof( COLOR_MODE_VALUES[0] );
-const StringEnum POSITION_INHERITANCE_MODE_VALUES[] =
+const StringEnum< int > POSITION_INHERITANCE_MODE_VALUES[] =
{
{ "INHERIT_PARENT_POSITION", INHERIT_PARENT_POSITION },
{ "USE_PARENT_POSITION", USE_PARENT_POSITION },
};
const unsigned int POSITION_INHERITANCE_MODE_VALUES_COUNT = sizeof( POSITION_INHERITANCE_MODE_VALUES ) / sizeof( POSITION_INHERITANCE_MODE_VALUES[0] );
-const StringEnum DRAW_MODE_VALUES[] =
+const StringEnum< int > DRAW_MODE_VALUES[] =
{
{ "NORMAL", DrawMode::NORMAL },
{ "OVERLAY", DrawMode::OVERLAY },
template< typename T, typename X >
void TestEnumStrings(
Property::Map& map, // The map used to create instance of type X
- const StringEnum* values, // An array of string values
+ const StringEnum< int >* values, // An array of string values
unsigned int num, // Number of items in the array
T ( X::*method )() const, // The member method of X to call to get the enum
X ( *creator ) ( const Property::Value& ) // The method which creates an instance of type X
void TestEnumStrings(
const char * const keyName, // The name of the key to check
TestApplication& application, // Reference to the application class
- const StringEnum* values, // An array of string values
+ const StringEnum< int >* values, // An array of string values
unsigned int num, // Number of items in the array
void ( Actor::*method )( T ) // The Actor member method to set the enumeration
)
// load-policy
map.push_back( Property::StringValuePair( "load-policy", "" ) );
{
- const StringEnum values[] =
+ const StringEnum< int > values[] =
{
{ "IMMEDIATE", Image::Immediate },
{ "ON_DEMAND", Image::OnDemand }
// release-policy
map.push_back( Property::StringValuePair( "release-policy", "" ) );
{
- const StringEnum values[] =
+ const StringEnum< int > values[] =
{
{ "UNUSED", Image::Unused },
{ "NEVER", Image::Never }
// pixel-format
map.push_back( Property::StringValuePair( "pixel-format", "" ) );
{
- const StringEnum values[] =
+ const StringEnum< int > values[] =
{
{ "A8", Pixel::A8 },
{ "L8", Pixel::L8 },
// scaling-mode
map.push_back( Property::StringValuePair( "scaling-mode", "" ) );
{
- const StringEnum values[] =
+ const StringEnum< int > values[] =
{
{ "SHRINK_TO_FIT", ImageAttributes::ShrinkToFit },
{ "SCALE_TO_FILL", ImageAttributes::ScaleToFill },
}
END_TEST;
}
+
+int UtcDaliScriptingGetEnumerationTemplates(void)
+{
+ TestApplication application;
+
+ const Scripting::StringEnum< int > myTable[] =
+ {
+ { "ONE", 1 },
+ { "TWO", 2 },
+ { "THREE", 3 },
+ { "FOUR", 4 },
+ { "FIVE", 5 },
+ };
+ const unsigned int myTableCount = sizeof( myTable ) / sizeof( myTable[0] );
+
+ for ( unsigned int i = 0; i < myTableCount; ++i )
+ {
+ tet_printf("Checking: %s\n", myTable[ i ].string );
+ DALI_TEST_EQUALS( myTable[ i ].value, GetEnumeration( myTable[ i ].string, myTable, myTableCount ), TEST_LOCATION );
+ }
+
+ for ( unsigned int i = 0; i < myTableCount; ++i )
+ {
+ tet_printf("Checking: %d\n", myTable[ i ].value );
+ DALI_TEST_EQUALS( myTable[ i ].string, GetEnumerationName( myTable[ i ].value, myTable, myTableCount ), TEST_LOCATION );
+ }
+
+ END_TEST;
+}
namespace
{
-// Helpers for converting strings to the enumerations and vice versa
-
-template< typename T >
-struct StringEnum
-{
- const std::string string;
- const T value;
-};
+// Tables used here for converting strings to the enumerations and vice versa
const StringEnum< ColorMode > COLOR_MODE_TABLE[] =
{
};
const unsigned int IMAGE_SCALING_MODE_TABLE_COUNT = sizeof( IMAGE_SCALING_MODE_TABLE ) / sizeof( IMAGE_SCALING_MODE_TABLE[0] );
-template< typename T >
-T GetEnumeration( const std::string& value, const StringEnum< T >* table, const unsigned int tableCount )
-{
- T v( table->value );
- bool set( false );
-
- for ( unsigned int i = 0; ( i < tableCount ) && ( !set ); ++i )
- {
- set = SetIfEqual(value, table->string, v, table->value );
- ++table;
- }
-
- if ( !set )
- {
- DALI_ASSERT_ALWAYS( !"Unknown enumeration string" );
- }
-
- return v;
-}
-
-template< typename T >
-const std::string& GetEnumerationName( const T& value, const StringEnum< T >* table, const unsigned int tableCount )
-{
- for ( unsigned int i = 0; i < tableCount; ++i )
- {
- if ( value == table[i].value )
- {
- return table[i].string;
- break;
- }
- }
-
- return String::EMPTY;
-}
-
} // unnamed namespace
bool CompareEnums(const std::string& a, const std::string& b)
}
-const std::string& GetColorMode( ColorMode value )
+std::string GetColorMode( ColorMode value )
{
return GetEnumerationName< ColorMode >( value, COLOR_MODE_TABLE, COLOR_MODE_TABLE_COUNT );
}
}
-const std::string& GetPositionInheritanceMode( PositionInheritanceMode value )
+std::string GetPositionInheritanceMode( PositionInheritanceMode value )
{
return GetEnumerationName< PositionInheritanceMode >( value, POSITION_INHERITANCE_MODE_TABLE, POSITION_INHERITANCE_MODE_TABLE_COUNT );
}
}
-const std::string& GetDrawMode( DrawMode::Type value )
+std::string GetDrawMode( DrawMode::Type value )
{
return GetEnumerationName< DrawMode::Type >( value, DRAW_MODE_TABLE, DRAW_MODE_TABLE_COUNT );
}
{
/**
+ * @brief Template structure which stores an enumeration and its string equivalent.
+ */
+template< typename T >
+struct StringEnum
+{
+ const char* string; ///< The string representation
+ const T value; ///< The actual enumeration
+};
+
+/**
* @brief Permissive comparison for string enums.
*
* Case insensitive and ignores '_', '-' in either string when comparing.
* @param[in] b The input string
* @param[in] set The variable to set
* @param[in] value The value to set
- * @return true if the strings pass the permissve compare
+ * @return true if the strings pass the permissive compare
*/
template <typename T>
bool SetIfEqual(const std::string& a, const std::string& b, T& set, T value)
}
/**
+ * @brief Chooses the appropriate enumeration for the provided string from the given table.
+ *
+ * @param[in] value The string equivalent (case-insensitive).
+ * @param[in] table A pointer to an array with the enumeration to string equivalents.
+ * @param[in] tableCount Number of items in the array.
+ *
+ * @return The equivalent enumeration for the given string.
+ */
+template< typename T >
+T GetEnumeration( const std::string& value, const StringEnum< T >* table, const unsigned int tableCount )
+{
+ T retVal( table->value );
+ bool set( false );
+
+ for ( unsigned int i = 0; ( i < tableCount ) && ( !set ); ++i )
+ {
+ set = SetIfEqual( value, table->string, retVal, table->value );
+ ++table;
+ }
+
+ if ( !set )
+ {
+ DALI_ASSERT_ALWAYS( !"Unknown enumeration string" );
+ }
+
+ return retVal;
+}
+
+/**
+ * @brief Chooses the appropriate string for the provided enumeration from the given table.
+ *
+ * @param[in] value The enumeration.
+ * @param[in] table A pointer to an array with the enumeration to string equivalents.
+ * @param[in] tableCount Number of items in the array.
+ *
+ * @return The equivalent enumeration for the given string.
+ */
+template< typename T >
+std::string GetEnumerationName( const T& value, const StringEnum< T >* table, const unsigned int tableCount )
+{
+ std::string string( String::EMPTY );
+
+ for ( unsigned int i = 0; i < tableCount; ++i )
+ {
+ if ( value == table[ i ].value )
+ {
+ string = table[ i ].string;
+ break;
+ }
+ }
+
+ return string;
+}
+
+/**
* @brief Takes a string and returns the appropriate color mode.
*
* @param[in] value The input string
* @param[in] value The color mode
* @return The corresponding string.
*/
-const std::string& GetColorMode( ColorMode value );
+std::string GetColorMode( ColorMode value );
/**
* @brief Takes a string and returns the appropriate position inheritance mode.
* @param[in] value The position-inheritance-mode.
* @return The corresponding string.
*/
-const std::string& GetPositionInheritanceMode( PositionInheritanceMode value );
+std::string GetPositionInheritanceMode( PositionInheritanceMode value );
/**
* @brief Takes a string and returns the appropriate draw mode.
* @param[in] value The draw-mode.
* @return The corresponding string.
*/
-const std::string& GetDrawMode( DrawMode::Type value );
+std::string GetDrawMode( DrawMode::Type value );
/**
* @brief Takes a string and returns the appropriate anchor-point or parent-origin constant.