END_TEST;
}
-int UtcDaliHandleGetPropertyIndex(void)
+int UtcDaliHandleGetPropertyIndex01(void)
{
tet_infoline("Positive Test Dali::Handle::GetPropertyIndex()");
TestApplication application;
END_TEST;
}
+int UtcDaliHandleGetPropertyIndex02(void)
+{
+ tet_infoline("Positive Test Dali::Handle::GetPropertyIndex() int key");
+ TestApplication application;
+
+ Stage stage = Stage::GetCurrent();
+
+ Actor actor = Actor::New();
+ stage.Add( actor );
+
+ const unsigned int defaultPropertyCount = actor.GetPropertyCount();
+
+ application.SendNotification();
+ application.Render();
+
+ Property::Index key1 = CORE_PROPERTY_MAX_INDEX+1;
+ Property::Index key2 = CORE_PROPERTY_MAX_INDEX+2;
+
+ const Vector4 testColor(0.5f, 0.2f, 0.9f, 1.0f);
+ const float withFlake(99.f);
+
+ Property::Index index1 = actor.RegisterProperty( "MyPropertyOne", Vector3::ONE );
+ Property::Index index2 = actor.RegisterProperty( key1, "sideColor", testColor);
+ Property::Index index3 = actor.RegisterProperty( "MyPropertyTwo", Vector3::ONE );
+ Property::Index index4 = actor.RegisterProperty( key2, "iceCream", withFlake );
+ Property::Index index5 = actor.RegisterProperty( "MyPropertyThree", Vector3::ONE );
+
+ application.SendNotification();
+ application.Render();
+
+ // Test that we can get the property index from the integer key
+ Property::Index testIndex1 = actor.GetPropertyIndex( key1 );
+ Property::Index testIndex2 = actor.GetPropertyIndex( key2 );
+
+ DALI_TEST_EQUALS( index2, testIndex1, TEST_LOCATION );
+ DALI_TEST_EQUALS( index4, testIndex2, TEST_LOCATION );
+
+ // Test that we keep the same indices on the named properties
+ Property::Index testIndex = actor.GetPropertyIndex("MyPropertyOne");
+ DALI_TEST_EQUALS(testIndex, index1, TEST_LOCATION);
+ testIndex = actor.GetPropertyIndex("MyPropertyTwo");
+ DALI_TEST_EQUALS(testIndex, index3, TEST_LOCATION);
+ testIndex = actor.GetPropertyIndex("MyPropertyThree");
+ DALI_TEST_EQUALS(testIndex, index5, TEST_LOCATION);
+ testIndex = actor.GetPropertyIndex("sideColor");
+ DALI_TEST_EQUALS(testIndex, index2, TEST_LOCATION);
+ testIndex = actor.GetPropertyIndex("iceCream");
+ DALI_TEST_EQUALS(testIndex, index4, TEST_LOCATION);
+
+ DALI_TEST_EQUALS(defaultPropertyCount+5, actor.GetPropertyCount(), TEST_LOCATION);
+ END_TEST;
+}
+
+int UtcDaliHandleGetPropertyIndex03(void)
+{
+ TestApplication application;
+
+ Actor actor = Actor::New();
+
+ std::string myName("croydon");
+ Property::Index intKey = CORE_PROPERTY_MAX_INDEX+1;
+ Property::Value value( Color::GREEN );
+ Property::Index myIndex = actor.RegisterProperty( intKey, myName, value );
+
+ DALI_TEST_EQUALS( myIndex, actor.GetPropertyIndex( intKey ), TEST_LOCATION );
+
+ Property::Key key1(myName);
+ Property::Key key2(intKey);
+
+ DALI_TEST_EQUALS( myIndex, actor.GetPropertyIndex( key1 ), TEST_LOCATION );
+ DALI_TEST_EQUALS( myIndex, actor.GetPropertyIndex( key2 ), TEST_LOCATION );
+ END_TEST;
+}
+
+
int UtcDaliHandleIsPropertyWritable(void)
{
tet_infoline("Positive Test Dali::Handle::IsPropertyWritable()");
}
-int UtcDaliHandleGetPropertyIndex02(void)
-{
- tet_infoline("Positive Test Dali::Handle::GetPropertyIndex() int key");
- TestApplication application;
-
- Stage stage = Stage::GetCurrent();
-
- Actor actor = Actor::New();
- stage.Add( actor );
-
- const unsigned int defaultPropertyCount = actor.GetPropertyCount();
-
- application.SendNotification();
- application.Render();
-
- Property::Index key1 = CORE_PROPERTY_MAX_INDEX+1;
- Property::Index key2 = CORE_PROPERTY_MAX_INDEX+2;
-
- const Vector4 testColor(0.5f, 0.2f, 0.9f, 1.0f);
- const float withFlake(99.f);
-
- Property::Index index1 = actor.RegisterProperty( "MyPropertyOne", Vector3::ONE );
- Property::Index index2 = actor.RegisterProperty( key1, "sideColor", testColor);
- Property::Index index3 = actor.RegisterProperty( "MyPropertyTwo", Vector3::ONE );
- Property::Index index4 = actor.RegisterProperty( key2, "iceCream", withFlake );
- Property::Index index5 = actor.RegisterProperty( "MyPropertyThree", Vector3::ONE );
-
- application.SendNotification();
- application.Render();
-
- // Test that we can get the property index from the integer key
- Property::Index testIndex1 = actor.GetPropertyIndex( key1 );
- Property::Index testIndex2 = actor.GetPropertyIndex( key2 );
-
- DALI_TEST_EQUALS( index2, testIndex1, TEST_LOCATION );
- DALI_TEST_EQUALS( index4, testIndex2, TEST_LOCATION );
-
- // Test that we keep the same indices on the named properties
- Property::Index testIndex = actor.GetPropertyIndex("MyPropertyOne");
- DALI_TEST_EQUALS(testIndex, index1, TEST_LOCATION);
- testIndex = actor.GetPropertyIndex("MyPropertyTwo");
- DALI_TEST_EQUALS(testIndex, index3, TEST_LOCATION);
- testIndex = actor.GetPropertyIndex("MyPropertyThree");
- DALI_TEST_EQUALS(testIndex, index5, TEST_LOCATION);
- testIndex = actor.GetPropertyIndex("sideColor");
- DALI_TEST_EQUALS(testIndex, index2, TEST_LOCATION);
- testIndex = actor.GetPropertyIndex("iceCream");
- DALI_TEST_EQUALS(testIndex, index4, TEST_LOCATION);
-
- DALI_TEST_EQUALS(defaultPropertyCount+5, actor.GetPropertyCount(), TEST_LOCATION);
- END_TEST;
-}
int UtcDaliHandleGetProperty(void)
{
END_TEST;
}
-// deprecated API, only retrieve the value from string-value pairs
int UtcDaliPropertyMapGetValue(void)
{
Property::Map map;
map[ "hello" ] = 1;
map[ "world" ] = 2;
+ map[ Actor::Property::COLOR ] = Color::MAGENTA;
Property::Value& value = map.GetValue( 0 );
DALI_TEST_CHECK( value.Get<int>() == 1 );
value = 10; // Allows the actual changing of the value as we have a ref
DALI_TEST_CHECK( map[ "hello" ].Get<int>() == 10 );
+ Property::Value& value2 = map.GetValue( 2 );
+ DALI_TEST_CHECK( value2.Get<Vector4>() == Color::MAGENTA );
+ value2 = Color::CYAN;
+ DALI_TEST_EQUALS( map[ Actor::Property::COLOR].Get<Vector4>(), Color::CYAN, TEST_LOCATION);
+
// Out of bounds
try
{
- map.GetValue( 2 );
+ map.GetValue( 3 );
tet_result( TET_FAIL );
}
catch ( DaliException& e )
Property::Map map;
map[ "hello" ] = 1;
map[ "world" ] = 2;
+ map[ Actor::Property::COLOR ] = Color::MAGENTA;
DALI_TEST_CHECK( map.GetKey( 0 ) == "hello" );
DALI_TEST_CHECK( map.GetKey( 1 ) == "world" );
- // Out of bounds
+ // Wrong type
try
{
map.GetKey( 2 );
DALI_TEST_ASSERT( e, "position", TEST_LOCATION );
}
+ // Out of bounds
+ try
+ {
+ map.GetKey( 3 );
+ tet_result( TET_FAIL );
+ }
+ catch ( DaliException& e )
+ {
+ DALI_TEST_ASSERT( e, "position", TEST_LOCATION );
+ }
+
+ END_TEST;
+}
+
+
+int UtcDaliPropertyMapGetKeyAt(void)
+{
+ Property::Map map;
+ map[ "hello" ] = 1;
+ map[ "world" ] = 2;
+ map[ Actor::Property::COLOR ] = Color::MAGENTA;
+
+ DALI_TEST_CHECK( map.GetKeyAt( 0 ) == "hello" );
+ DALI_TEST_CHECK( map.GetKeyAt( 1 ) == "world" );
+ DALI_TEST_CHECK( map.GetKeyAt( 2 ) == Actor::Property::COLOR );
+
+ // Out of bounds
+ try
+ {
+ map.GetKey( 3 );
+ tet_result( TET_FAIL );
+ }
+ catch ( DaliException& e )
+ {
+ DALI_TEST_ASSERT( e, "position", TEST_LOCATION );
+ }
+
END_TEST;
}
-// deprecated API, only retrieve the string-value pairs
int UtcDaliPropertyMapGetPair(void)
{
Property::Map map;
map[ "hello" ] = 1;
map[ "world" ] = 2;
+ map[ Actor::Property::COLOR ] = Color::MAGENTA;
DALI_TEST_CHECK( map.GetPair( 0 ).first == "hello" );
DALI_TEST_CHECK( map.GetPair( 0 ).second.Get< int >() == 1 );
DALI_TEST_CHECK( map.GetPair( 1 ).first == "world" );
DALI_TEST_CHECK( map.GetPair( 1 ).second.Get< int >() == 2 );
- // Out of bounds
+ // Wrong Type
try
{
map.GetPair( 2 );
DALI_TEST_ASSERT( e, "position", TEST_LOCATION );
}
+ // Out of bounds
+ try
+ {
+ map.GetPair( 3 );
+ tet_result( TET_FAIL );
+ }
+ catch ( DaliException& e )
+ {
+ DALI_TEST_ASSERT( e, "position", TEST_LOCATION );
+ }
+
+ END_TEST;
+}
+
+int UtcDaliPropertyMapGetKeyValue(void)
+{
+ Property::Map map;
+ map[ "hello" ] = 1;
+ map[ "world" ] = 2;
+ map[ Actor::Property::COLOR ] = Color::MAGENTA;
+
+ DALI_TEST_CHECK( map.GetKeyValue( 0 ).first == "hello" );
+ DALI_TEST_CHECK( map.GetKeyValue( 0 ).second.Get< int >() == 1 );
+ DALI_TEST_CHECK( map.GetKeyValue( 1 ).first == "world" );
+ DALI_TEST_CHECK( map.GetKeyValue( 1 ).second.Get< int >() == 2 );
+ DALI_TEST_CHECK( map.GetKeyValue( 2 ).first == Actor::Property::COLOR );
+ DALI_TEST_CHECK( map.GetKeyValue( 2 ).second.Get< Vector4 >() == Color::MAGENTA );
+
+ // Out of bounds
+ try
+ {
+ map.GetPair( 3 );
+ tet_result( TET_FAIL );
+ }
+ catch ( DaliException& e )
+ {
+ DALI_TEST_ASSERT( e, "position", TEST_LOCATION );
+ }
+
END_TEST;
}
END_TEST;
}
+
+int UtcDaliPropertyKeyConstructorP(void)
+{
+ Property::Key key1( "aKey" );
+ DALI_TEST_EQUALS( key1.type, Property::Key::STRING, TEST_LOCATION );
+ DALI_TEST_EQUALS( key1.stringKey, "aKey", TEST_LOCATION );
+ DALI_TEST_EQUALS( key1.indexKey, Property::INVALID_INDEX, TEST_LOCATION );
+
+ Property::Key key2( Actor::Property::COLOR );
+ DALI_TEST_EQUALS( key2.type, Property::Key::INDEX, TEST_LOCATION );
+ DALI_TEST_EQUALS( key2.indexKey, (Dali::Property::Index)Actor::Property::COLOR, TEST_LOCATION );
+ END_TEST;
+}
+
+int UtcDaliPropertyKeyEqualityOperatorP(void)
+{
+ Property::Key key1( "aKey" );
+ Property::Key key2( 113 );
+
+ DALI_TEST_CHECK( key1 == "aKey" );
+ DALI_TEST_CHECK( ! (key1 == "notTheKey") );
+ DALI_TEST_CHECK( ! (key1 == 1) );
+
+ DALI_TEST_CHECK( key2 == 113 );
+ DALI_TEST_CHECK( ! (key2 == 0) );
+ DALI_TEST_CHECK( ! (key2 == "One hundred and thirteen" ) );
+
+ DALI_TEST_CHECK( ! (key1 == key2) );
+ DALI_TEST_CHECK( key1 != key2 );
+
+ Property::Key key1B( "aKey" );
+ Property::Key key2B( 113 );
+
+ DALI_TEST_CHECK( key1 == key1B );
+ DALI_TEST_CHECK( key2 == key2B );
+
+ END_TEST;
+}
+
+int UtcDaliPropertyKeyInequalityOperatorP(void)
+{
+ Property::Key key1( "aKey" );
+ Property::Key key2( 113 );
+
+ DALI_TEST_CHECK( key1 != "notTheKey" );
+ DALI_TEST_CHECK( key1 != 1 );
+
+ DALI_TEST_CHECK( key2 != 0 );
+ DALI_TEST_CHECK( key2 != "One hundred and thirteen" );
+
+ DALI_TEST_CHECK( key1 != key2 );
+
+ END_TEST;
+}
+
+
+int UtcDaliPropertyKeyOutputStream(void)
+{
+ Property::Key key1( "aKey" );
+ Property::Key key2( 113 );
+
+ std::ostringstream oss;
+ oss << key1;
+ DALI_TEST_EQUALS( oss.str(), "aKey", TEST_LOCATION );
+
+ std::ostringstream oss2;
+ oss2 << key2;
+ DALI_TEST_EQUALS( oss2.str(), "113", TEST_LOCATION );
+
+ END_TEST;
+}
END_TEST;
}
+int UtcDaliScriptingNewAnimation(void)
+{
+ TestApplication application;
+
+ Property::Map map;
+ map["actor"] = "Actor1";
+ map["property"] = "color";
+ map["value"] = Color::MAGENTA;
+ map["alphaFunction"] = "EASE_IN_OUT";
+
+ Property::Map timePeriod;
+ timePeriod["delay"] = 0.5f;
+ timePeriod["duration"] = 1.0f;
+ map["timePeriod"] = timePeriod;
+
+ Dali::AnimationData data;
+ Scripting::NewAnimation( map, data );
+
+ Actor actor = Actor::New();
+ actor.SetName("Actor1");
+ actor.SetColor(Color::CYAN);
+ Stage::GetCurrent().Add(actor);
+
+ Animation anim = data.CreateAnimation( actor, 0.5f );
+ anim.Play();
+
+ application.SendNotification();
+ application.Render(0);
+ application.Render(500); // Start animation
+ application.Render(500); // Halfway thru anim
+ application.SendNotification();
+ DALI_TEST_EQUALS( actor.GetCurrentColor(), (Color::MAGENTA+Color::CYAN)*0.5f, TEST_LOCATION);
+
+ application.Render(500); // Halfway thru anim
+ application.SendNotification();
+ DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::MAGENTA, TEST_LOCATION );
+
+ END_TEST;
+}
+
int UtcDaliScriptingNewActorChildren(void)
{
TestApplication application;
// Now set the properties, or create children
for ( unsigned int i = 0, mapCount = map.Count(); i < mapCount; ++i )
{
- const StringValuePair& pair( map.GetPair( i ) );
- const std::string& key( pair.first );
+ const KeyValuePair pair( map.GetKeyValue( i ) );
+ if( pair.first.type == Property::Key::INDEX )
+ {
+ continue;
+ }
+ const std::string& key( pair.first.stringKey );
if ( key == "type" )
{
continue;
// Now set the properties, or create children
for( unsigned int i = 0, animationMapCount = map.Count(); i < animationMapCount; ++i )
{
- const StringValuePair& pair( map.GetPair( i ) );
- const std::string& key( pair.first );
+ const KeyValuePair pair( map.GetKeyValue( i ) );
+ if( pair.first.type == Property::Key::INDEX )
+ {
+ continue; // We don't consider index keys.
+ }
+ const std::string& key( pair.first.stringKey );
+
const Property::Value& value( pair.second );
if( key == "actor" )
Property::Map timeMap = value.Get< Property::Map >();
for( unsigned int i = 0; i < timeMap.Count(); ++i )
{
- const StringValuePair& pair( timeMap.GetPair( i ) );
- if( pair.first == "delay" )
+ const KeyValuePair pair( timeMap.GetKeyValue( i ) );
+ if( pair.first.type == Property::Key::INDEX )
+ {
+ continue;
+ }
+ const std::string& key( pair.first.stringKey );
+
+ if( key == "delay" )
{
element->timePeriodDelay = pair.second.Get< float >();
}
- else if( pair.first == "duration" )
+ else if( key == "duration" )
{
element->timePeriodDuration = pair.second.Get< float >();
}
} // namespace scripting
} // namespace Dali
-
-
-
-
return index;
}
+Property::Index Object::GetPropertyIndex( Property::Key key ) const
+{
+ Property::Index index = Property::INVALID_INDEX;
+ if( key.type == Property::Key::INDEX )
+ {
+ index = GetPropertyIndex( key.indexKey );
+ }
+ else
+ {
+ index = GetPropertyIndex( key.stringKey );
+ }
+ return index;
+}
+
bool Object::IsPropertyWritable( Property::Index index ) const
{
DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
virtual Property::Index GetPropertyIndex( Property::Index key ) const;
/**
+ * @copydoc Dali::Handle::GetPropertyIndex()
+ */
+ virtual Property::Index GetPropertyIndex( Property::Key key ) const;
+
+ /**
* @copydoc Dali::Handle::IsPropertyWritable()
*/
virtual bool IsPropertyWritable( Property::Index index ) const;
for( size_t i = 0u; i < numComponents; ++i )
{
- StringValuePair component = mFormat.GetPair( i );
+ KeyValuePair component = mFormat.GetKeyValue( i );
// Get the name
- format->components[i].name = component.first;
+ if(component.first.type == Property::Key::INDEX)
+ {
+ continue;
+ }
+ format->components[i].name = component.first.stringKey;
// enums are stored in the map as int
Property::Type type = Property::Type( component.second.Get<int>() );
$(public_api_src_dir)/object/property-array.cpp \
$(public_api_src_dir)/object/property-conditions.cpp \
$(public_api_src_dir)/object/property-input.cpp \
+ $(public_api_src_dir)/object/property-key.cpp \
$(public_api_src_dir)/object/property-map.cpp \
$(public_api_src_dir)/object/property-notification.cpp \
$(public_api_src_dir)/object/property-types.cpp \
$(public_api_src_dir)/object/property-conditions.h \
$(public_api_src_dir)/object/property-index-ranges.h \
$(public_api_src_dir)/object/property-input.h \
+ $(public_api_src_dir)/object/property-key.h \
$(public_api_src_dir)/object/property-map.h \
$(public_api_src_dir)/object/property-notification-declarations.h \
$(public_api_src_dir)/object/property-notification.h \
return GetImplementation(*this).GetPropertyIndex( key );
}
+Property::Index Handle::GetPropertyIndex( Property::Key key ) const
+{
+ return GetImplementation(*this).GetPropertyIndex( key );
+}
+
bool Handle::IsPropertyWritable( Property::Index index ) const
{
return GetImplementation(*this).IsPropertyWritable( index );
Property::Index GetPropertyIndex( Property::Index key ) const;
/**
+ * @brief Query the index of a property using the given key from a Property::Map
+ * @SINCE_1_2.7
+ *
+ * @param[in] key The key of the property to search for.
+ * @return the matching property index of either the string key or the matching
+ * custom property index of the index key, or Property::INVALID_INDEX if no
+ * property matches the given key.
+ *
+ * @note See also, GetPropertyIndex(Property::Index) and GetPropertyIndex(const std::string&)
+ */
+ Property::Index GetPropertyIndex( Property::Key key ) const;
+
+ /**
* @brief Query whether a property can be set using SetProperty().
*
* @SINCE_1_0.0
--- /dev/null
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include <dali/public-api/object/property-key.h>
+
+
+namespace Dali
+{
+
+Property::Key::Key( const std::string& key )
+: type(Key::STRING),
+ indexKey( Property::INVALID_INDEX ),
+ stringKey( key )
+{
+}
+
+Property::Key::Key( Property::Index key )
+: type(Key::INDEX),
+ indexKey( key )
+{
+}
+
+bool Property::Key::operator== (const std::string& rhs)
+{
+ bool result=false;
+ if(type == Key::STRING)
+ {
+ result = (stringKey == rhs);
+ }
+ return result;
+}
+
+bool Property::Key::operator== (Property::Index rhs)
+{
+ bool result=false;
+ if(type == Key::INDEX)
+ {
+ result = (indexKey == rhs);
+ }
+ return result;
+}
+
+bool Property::Key::operator== (const Key& rhs)
+{
+ bool result=false;
+ if(type == Key::STRING && rhs.type == Key::STRING )
+ {
+ result = (stringKey == rhs.stringKey);
+ }
+ else if( type == Key::INDEX && rhs.type == Key::INDEX )
+ {
+ result = (indexKey == rhs.indexKey);
+ }
+ return result;
+}
+
+bool Property::Key::operator!= (const std::string& rhs)
+{
+ return !operator==(rhs);
+}
+
+bool Property::Key::operator!= (Property::Index rhs)
+{
+ return !operator==(rhs);
+}
+
+bool Property::Key::operator!= (const Key& rhs)
+{
+ return !operator==(rhs);
+}
+
+std::ostream& operator<<( std::ostream& stream, const Property::Key& key )
+{
+ if( key.type == Property::Key::INDEX )
+ {
+ stream << key.indexKey;
+ }
+ else
+ {
+ stream << key.stringKey;
+ }
+ return stream;
+}
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_PROPERTY_KEY_H__
+#define __DALI_PROPERTY_KEY_H__
+
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <string>
+#include <sstream>
+
+// INTERNAL INCLUDES
+#include <dali/public-api/common/dali-common.h>
+#include <dali/public-api/object/property.h>
+
+namespace Dali
+{
+/**
+ * @addtogroup dali_core_object
+ * @{
+ */
+
+/**
+ * @brief A key type which can be either a std::string or a Property::Index
+ * @SINCE_1_2.7
+ */
+struct DALI_IMPORT_API Property::Key
+{
+ /**
+ * @brief The type of key
+ * @SINCE_1_2.7
+ */
+ enum Type
+ {
+ INDEX, ///< The key is a Property::Index
+ STRING ///< The key is a string
+ } type; ///< The type of the key
+
+ Property::Index indexKey; ///< The index key.
+ std::string stringKey; ///< The string key.
+
+ /**
+ * @brief Constructor
+ * @SINCE_1_2.7
+ *
+ * @param[in] key The string key
+ */
+ explicit Key( const std::string& key );
+
+ /**
+ * @brief Constructor
+ * @SINCE_1_2.7
+ *
+ * @param[in] key The index key
+ */
+ explicit Key( Property::Index key );
+
+ /**
+ * @brief The equality operator
+ * @SINCE_1_2.7
+ *
+ * @param[in] rhs A string key to compare against.
+ * @return true if the key compares, or false if it isn't equal or of the wrong type
+ */
+ bool operator== (const std::string& rhs);
+
+ /**
+ * @brief The equality operator
+ * @SINCE_1_2.7
+ *
+ * @param[in] rhs An index key to compare against.
+ * @return true if the key compares, or false if it isn't equal or of the wrong type
+ */
+ bool operator== (Property::Index rhs);
+
+ /**
+ * @brief The equality operator
+ * @SINCE_1_2.7
+ *
+ * @param[in] rhs A key to compare against.
+ * @return true if the keys are of the same type and have the same value
+ */
+ bool operator== (const Key& rhs);
+
+ /**
+ * @brief The inequality operator
+ * @SINCE_1_2.7
+ *
+ * @param[in] rhs A string key to compare against.
+ * @return true if the key is not equal or not a string key
+ */
+ bool operator!= (const std::string& rhs);
+
+ /**
+ * @brief The inequality operator
+ * @SINCE_1_2.7
+ *
+ * @param[in] rhs An index key to compare against.
+ * @return true if the key is not equal, or not an index key
+ */
+ bool operator!= (Property::Index rhs);
+
+ /**
+ * @brief The inequality operator
+ * @SINCE_1_2.7
+ *
+ * @param[in] rhs A key to compare against.
+ * @return true if the keys are not of the same type or are not equal
+ */
+ bool operator!= (const Key& rhs);
+};
+
+/**
+ * @brief Convert the key into a string and append to an output stream.
+ *
+ * @SINCE_1_2.7
+ * @param [in] stream The output stream operator.
+ * @param [in] key the key to convert
+ * @return The output stream operator.
+ */
+DALI_IMPORT_API std::ostream& operator<<( std::ostream& stream, const Property::Key& key );
+
+
+/**
+ * @}
+ */
+} // namespace Dali
+
+#endif // __DALI_PROPERTY_KEY_H__
}; // unnamed namespace
+
struct Property::Map::Impl
{
StringValueContainer mStringValueContainer;
Property::Value& Property::Map::GetValue( SizeType position ) const
{
- DALI_ASSERT_ALWAYS( position < mImpl->mStringValueContainer.size() && "position out-of-bounds" );
+ SizeType numStringKeys = mImpl->mStringValueContainer.size();
+ SizeType numIndexKeys = mImpl->mIndexValueContainer.size();
+ DALI_ASSERT_ALWAYS( position < ( numStringKeys + numIndexKeys ) && "position out-of-bounds" );
- return mImpl->mStringValueContainer[ position ].second;
+ if( position < numStringKeys )
+ {
+ return mImpl->mStringValueContainer[ position ].second;
+ }
+ else
+ {
+ return mImpl->mIndexValueContainer[ position-numStringKeys ].second;
+ }
}
const std::string& Property::Map::GetKey( SizeType position ) const
{
- DALI_ASSERT_ALWAYS( position < mImpl->mStringValueContainer.size() && "position out-of-bounds" );
+ SizeType numStringKeys = mImpl->mStringValueContainer.size();
+ DALI_ASSERT_ALWAYS( position < numStringKeys && "position out-of-bounds" );
return mImpl->mStringValueContainer[ position ].first;
}
+Property::Key Property::Map::GetKeyAt( SizeType position ) const
+{
+ SizeType numStringKeys = mImpl->mStringValueContainer.size();
+ SizeType numIndexKeys = mImpl->mIndexValueContainer.size();
+ DALI_ASSERT_ALWAYS( position < ( numStringKeys + numIndexKeys ) && "position out-of-bounds" );
+
+ if( position < numStringKeys )
+ {
+ Key key(mImpl->mStringValueContainer[ position ].first);
+ return key;
+ }
+ else
+ {
+ Key key( mImpl->mIndexValueContainer[ position-numStringKeys ].first );
+ return key;
+ }
+}
+
StringValuePair& Property::Map::GetPair( SizeType position ) const
{
- DALI_ASSERT_ALWAYS( position < mImpl->mStringValueContainer.size() && "position out-of-bounds" );
+ SizeType numStringKeys = mImpl->mStringValueContainer.size();
+
+ DALI_ASSERT_ALWAYS( position < ( numStringKeys ) && "position out-of-bounds" );
return mImpl->mStringValueContainer[ position ];
}
+KeyValuePair Property::Map::GetKeyValue( SizeType position ) const
+{
+ SizeType numStringKeys = mImpl->mStringValueContainer.size();
+ SizeType numIndexKeys = mImpl->mIndexValueContainer.size();
+
+ DALI_ASSERT_ALWAYS( position < ( numStringKeys + numIndexKeys ) && "position out-of-bounds" );
+
+ if( position < numStringKeys )
+ {
+ Key key(mImpl->mStringValueContainer[ position ].first);
+ KeyValuePair keyValue(key, mImpl->mStringValueContainer[ position ].second );
+ return keyValue;
+ }
+ else
+ {
+ Key key( mImpl->mIndexValueContainer[ position-numStringKeys ].first );
+ KeyValuePair keyValue(key, mImpl->mIndexValueContainer[ position-numStringKeys ].second );
+ return keyValue;
+ }
+}
+
Property::Value* Property::Map::Find( const char* key ) const
{
for ( StringValueContainer::iterator iter = mImpl->mStringValueContainer.begin(), endIter = mImpl->mStringValueContainer.end(); iter != endIter; ++iter )
// EXTERNAL INCLUDES
#include <string>
+#include <sstream>
// INTERNAL INCLUDES
#include <dali/public-api/common/dali-common.h>
-#include <dali/public-api/object/property-value.h>
#include <dali/public-api/object/property.h>
+#include <dali/public-api/object/property-key.h>
+#include <dali/public-api/object/property-value.h>
namespace Dali
{
* @{
*/
+typedef std::pair< Property::Key, Property::Value > KeyValuePair;
typedef std::pair<std::string, Property::Value> StringValuePair;
/**
}
/**
- * DEPRECATED_1_1.39. Retrieve the value with key instead of position, Use Find( key ) instead.
- *
- * @brief Retrieve the value of the string-value pair at the specified position.
+ * @brief Retrieve the value at the specified position.
*
* @SINCE_1_0.0
* @return A reference to the value at the specified position.
const std::string& GetKey( SizeType position ) const;
/**
+ * @brief Retrieve the key at the specified position.
+ *
+ * @SINCE_1_2.7
+ * @return A copy of the key at the specified position.
+ *
+ * @note Will assert if position >= Count()
+ */
+ Key GetKeyAt( SizeType position ) const;
+
+ /**
* DEPRECATED_1_1.39 Position based retrieval is no longer supported after extending the key type to both Index and String.
*
* @brief Retrieve the key & the value at the specified position.
* @SINCE_1_0.0
* @return A reference to the pair of key and value at the specified position.
*
- * @note Will assert if position >= Count()
+ * @note Will assert if position >= Count() or key at position is an index key.
*/
StringValuePair& GetPair( SizeType position ) const;
/**
+ * @brief Retrieve the key & the value at the specified position.
+ *
+ * @SINCE_1_2.7
+ * @return A copy of the pair of key and value at the specified position.
+ *
+ * @note Will assert if position >= Count()
+ */
+ KeyValuePair GetKeyValue( SizeType position ) const;
+
+ /**
* @brief Finds the value for the specified key if it exists.
*
* @SINCE_1_0.0
*/
DALI_IMPORT_API std::ostream& operator<<( std::ostream& stream, const Property::Map& map );
-
/**
* @}
*/
class Value;
/**
+ * @brief A Key used by Map
+ */
+ struct Key;
+
+ /**
* @brief A Map of property values.
*/
class Map;