END_TEST;
}
+int UtcDaliPropertyArrayInitializerListConstructor(void)
+{
+ Property::Array array{ 1, 2, "hello" };
+ DALI_TEST_EQUALS( 3u, array.Size(), TEST_LOCATION );
+ DALI_TEST_EQUALS( Property::INTEGER, array.GetElementAt( 0 ).GetType(), TEST_LOCATION );
+ DALI_TEST_EQUALS( Property::INTEGER, array.GetElementAt( 1 ).GetType(), TEST_LOCATION );
+ DALI_TEST_EQUALS( Property::STRING, array.GetElementAt( 2 ).GetType(), TEST_LOCATION );
+
+ END_TEST;
+}
END_TEST;
}
+
+int UtcDaliPropertyMapInitializerListConstructor(void)
+{
+ auto map = Property::Map{
+ {"number mapped to string", 1},
+ {10, "string mapped to number"},
+ {"string mapped", "to string"},
+ {100, 3},
+ };
+
+ DALI_TEST_CHECK( !map.Empty() ); // Should not be empty
+ DALI_TEST_EQUALS( 4, map.Count(), TEST_LOCATION ); // Should have four items
+
+ DALI_TEST_EQUALS( 1, map[ "number mapped to string" ].Get< int >(), TEST_LOCATION );
+ DALI_TEST_EQUALS( "string mapped to number", map[ 10 ].Get< std::string >(), TEST_LOCATION );
+ DALI_TEST_EQUALS( "to string", map[ "string mapped" ].Get< std::string >(), TEST_LOCATION );
+ DALI_TEST_EQUALS( 3, map[ 100 ].Get< int >(), TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliPropertyMapNestedInitializerListConstructor(void)
+{
+ auto map = Property::Map
+ {
+ {1, 1},
+ {2, {{2, 2}}},
+ {3, {{3, {{3, 3}}}}}
+ };
+
+ DALI_TEST_CHECK( !map.Empty() );
+ DALI_TEST_EQUALS( 3, map.Count(), TEST_LOCATION );
+
+ // Check first item
+ {
+ DALI_TEST_EQUALS( 1, map[ 1 ].Get< int >(), TEST_LOCATION );
+ }
+
+ // Check second item
+ {
+ auto& value1 = map[ 2 ];
+ DALI_TEST_EQUALS( Property::MAP, value1.GetType(), TEST_LOCATION );
+
+ auto& map2 = *(value1.GetMap());
+ DALI_TEST_EQUALS( 1, map2.Count(), TEST_LOCATION );
+
+ // check the value
+ DALI_TEST_EQUALS( 2, map2[ 2 ].Get< int >(), TEST_LOCATION );
+ }
+
+ // Check the third item
+ {
+ auto& value1 = map[ 3 ];
+ DALI_TEST_EQUALS( Property::MAP, value1.GetType(), TEST_LOCATION );
+
+ auto& map2 = *(value1.GetMap());
+ DALI_TEST_EQUALS( 1, map2.Count(), TEST_LOCATION );
+
+ auto& value2 = map2[ 3 ];
+ DALI_TEST_EQUALS( Property::MAP, value2.GetType(), TEST_LOCATION );
+
+ auto& map3 = *(value2.GetMap());
+ DALI_TEST_EQUALS( 1, map3.Count(), TEST_LOCATION );
+
+ // check the value
+ DALI_TEST_EQUALS( 3, map3[ 3 ].Get< int >(), TEST_LOCATION );
+ }
+
+ END_TEST;
+}
{
}
+Property::Array::Array( const std::initializer_list< Property::Value >& values )
+: Array()
+{
+ for( auto&& value : values )
+ {
+ PushBack( value );
+ }
+}
+
Property::Array::Array( const Property::Array& other )
: mImpl( new Impl )
{
*/
// EXTERNAL INCLUDES
+#include <initializer_list>
#include <string>
// INTERNAL INCLUDES
Array();
/**
+ * @brief Constructor from initializer_list.
+ *
+ * @SINCE_1_4.17
+ * @param[in] values An initializer_list of values
+ */
+ Array( const std::initializer_list< Value >& values );
+
+ /**
* @brief Copy Constructor.
*
* @SINCE_1_0.0
/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 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.
{
Property::Key::Key( const std::string& key )
-: type(Key::STRING),
+: type( Key::STRING ),
indexKey( Property::INVALID_INDEX ),
stringKey( key )
{
}
Property::Key::Key( Property::Index key )
-: type(Key::INDEX),
+: type( Key::INDEX ),
indexKey( key )
{
}
+Property::Key::Key( const char * key )
+: type( Key::STRING ),
+ indexKey( Property::INVALID_INDEX ),
+ stringKey( key )
+{
+}
+
bool Property::Key::operator== (const std::string& rhs)
{
bool result=false;
return result;
}
+bool Property::Key::operator== ( const char* rhs )
+{
+ return operator==( std::string( rhs ) );
+}
+
bool Property::Key::operator== (Property::Index rhs)
{
bool result=false;
return !operator==(rhs);
}
+bool Property::Key::operator!= ( const char* rhs )
+{
+ return !operator==(rhs);
+}
+
bool Property::Key::operator!= (Property::Index rhs)
{
return !operator==(rhs);
-#ifndef __DALI_PROPERTY_KEY_H__
-#define __DALI_PROPERTY_KEY_H__
+#ifndef DALI_PROPERTY_KEY_H
+#define DALI_PROPERTY_KEY_H
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 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[in] key The string key
*/
- explicit Key( const std::string& key );
+ Key( const std::string& key );
+
+ /**
+ * @brief Constructor
+ * @SINCE_1_4.16
+ *
+ * @param[in] key The string key as a const char *
+ */
+ Key( const char * key );
/**
* @brief Constructor
*
* @param[in] key The index key
*/
- explicit Key( Property::Index key );
+ Key( Property::Index key );
/**
* @brief The equality operator
bool operator== (const std::string& rhs);
/**
+ * @brief Constructor
+ * @SINCE_1_4.16
+ *
+ * @param[in] key The string key as a const char *
+ */
+ bool operator== ( const char * key );
+
+ /**
* @brief The equality operator
* @SINCE_1_2.7
*
/**
* @brief The inequality operator
+ * @SINCE_1_4.16
+ *
+ * @param[in] rhs A const char* key to compare against.
+ * @return true if the key is not equal or not a string key
+ */
+ bool operator!= ( const char* rhs );
+
+ /**
+ * @brief The inequality operator
* @SINCE_1_2.7
*
* @param[in] rhs An index key to compare against.
*/
} // namespace Dali
-#endif // __DALI_PROPERTY_KEY_H__
+#endif // DALI_PROPERTY_KEY_H
{
}
+Property::Map::Map( const std::initializer_list< KeyValuePair >& values ) : Map()
+{
+ for( auto&& value : values )
+ {
+ const auto& key = value.first;
+ switch( key.type )
+ {
+ case Property::Key::INDEX:
+ {
+ Property::Map::Insert( key.indexKey, value.second );
+ break;
+ }
+ case Property::Key::STRING:
+ {
+ Property::Map::Insert( key.stringKey, value.second );
+ break;
+ }
+ }
+ }
+}
+
Property::Map::Map( const Property::Map& other )
: mImpl( new Impl )
{
// EXTERNAL INCLUDES
#include <string>
#include <sstream>
+#include <initializer_list>
// INTERNAL INCLUDES
#include <dali/public-api/common/dali-common.h>
Map();
/**
+ * @brief Constructor from initializer_list.
+ *
+ * @SINCE_1_4.17
+ * @param[in] values An initializer_list of pairs of index and value.
+ */
+ Map( const std::initializer_list< KeyValuePair >& values );
+
+ /**
* @brief Copy Constructor.
*
* @SINCE_1_0.0
{
}
+ Impl( const std::initializer_list< KeyValuePair >& values )
+ : type( Property::MAP ),
+ mapValue( new Property::Map( values ) )
+ {
+ }
+
/**
* Destructor, takes care of releasing the dynamically allocated types
*/
{
}
+Property::Value::Value( const std::initializer_list< KeyValuePair >& values )
+: mImpl( new Impl( values ) )
+{
+}
+
Property::Value::Value( Type type )
: mImpl( nullptr )
{
-#ifndef __DALI_PROPERTY_VALUE_H__
-#define __DALI_PROPERTY_VALUE_H__
+#ifndef DALI_PROPERTY_VALUE_H
+#define DALI_PROPERTY_VALUE_H
/*
* Copyright (c) 2019 Samsung Electronics Co., Ltd.
// EXTERNAL INCLUDES
#include <iosfwd>
+#include <utility>
+#include <initializer_list>
// INTERNAL INCLUDES
#include <dali/public-api/object/property.h>
class Matrix;
struct Extents;
+typedef std::pair< Property::Key, Property::Value > KeyValuePair;
+
/**
* @brief A value-type representing a property value.
* @SINCE_1_0.0
Value( Property::Map&& mapValue );
/**
+ * @brief Create a map property value from an initializer_list.
+ *
+ * @SINCE_1_4.16
+ * @param [in] values An initializer_list of pairs of index and value.
+ */
+ Value( const std::initializer_list< KeyValuePair >& values );
+
+ /**
* @brief Creates an extents property value.
*
* @SINCE_1_2.62
*/
} // namespace Dali
-#endif // __DALI_PROPERTY_VALUE_H__
+#endif // DALI_PROPERTY_VALUE_H