[dali_1.2.28] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / public-api / object / property-map.cpp
index f892aae..ebd95a8 100644 (file)
@@ -18,6 +18,9 @@
 // CLASS HEADER
 #include <dali/public-api/object/property-map.h>
 
+// EXTERNAL INCLUDES
+#include <dali/integration-api/debug.h>
+
 // INTERNAL INCLUDES
 #include <dali/public-api/common/vector-wrapper.h>
 
@@ -33,6 +36,7 @@ typedef std::vector< IndexValuePair > IndexValueContainer;
 
 }; // unnamed namespace
 
+
 struct Property::Map::Impl
 {
   StringValueContainer mStringValueContainer;
@@ -83,25 +87,80 @@ void Property::Map::Insert( Property::Index key, const Value& value )
 
 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" );
+  DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: GetKey() is deprecated and will be removed from next release.\n" );
+
+  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" );
+  DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: GetPair() is deprecated and will be removed from next release.\n" );
+
+  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 )
@@ -131,6 +190,16 @@ Property::Value* Property::Map::Find( Property::Index key ) const
   return NULL; // Not found
 }
 
+Property::Value* Property::Map::Find( Property::Index indexKey, const std::string& stringKey ) const
+{
+  Property::Value* valuePtr = Find( indexKey );
+  if( !valuePtr )
+  {
+    valuePtr = Find( stringKey );
+  }
+  return valuePtr;
+}
+
 Property::Value* Property::Map::Find( const std::string& key, Property::Type type ) const
 {
   for ( StringValueContainer::iterator iter = mImpl->mStringValueContainer.begin(), endIter = mImpl->mStringValueContainer.end(); iter != endIter; ++iter )