use modern construct 'nullptr' instead of 'NULL' or '0'
[platform/core/uifw/dali-core.git] / dali / public-api / object / property-map.cpp
index 61329a8..d458109 100644 (file)
@@ -31,8 +31,8 @@ namespace
 {
 typedef std::vector< StringValuePair > StringValueContainer;
 
-typedef std::pair< Property::Index, Property::Value > IndexValuePair;
-typedef std::vector< IndexValuePair > IndexValueContainer;
+using IndexValuePair      = std::pair<Property::Index, Property::Value>;
+using IndexValueContainer = std::vector<IndexValuePair>;
 
 }; // unnamed namespace
 
@@ -48,6 +48,27 @@ Property::Map::Map()
 {
 }
 
+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 )
 {
@@ -184,14 +205,14 @@ Property::Value* Property::Map::Find( const char* key ) const
 {
   DALI_ASSERT_DEBUG( mImpl && "Cannot use an object previously used as an r-value" );
 
-  for ( StringValueContainer::iterator iter = mImpl->mStringValueContainer.begin(), endIter = mImpl->mStringValueContainer.end(); iter != endIter; ++iter )
+  for( auto&& iter : mImpl->mStringValueContainer )
   {
-    if ( iter->first == key )
+    if ( iter.first == key )
     {
-      return &iter->second;
+      return &iter.second;
     }
   }
-  return NULL; // Not found
+  return nullptr; // Not found
 }
 
 Property::Value* Property::Map::Find( const std::string& key ) const
@@ -203,14 +224,14 @@ Property::Value* Property::Map::Find( Property::Index key ) const
 {
   DALI_ASSERT_DEBUG( mImpl && "Cannot use an object previously used as an r-value" );
 
-  for ( IndexValueContainer::iterator iter = mImpl->mIndexValueContainer.begin(), endIter = mImpl->mIndexValueContainer.end(); iter != endIter; ++iter )
+  for( auto&& iter : mImpl->mIndexValueContainer )
   {
-    if ( iter->first == key )
+    if ( iter.first == key )
     {
-      return &iter->second;
+      return &iter.second;
     }
   }
-  return NULL; // Not found
+  return nullptr; // Not found
 }
 
 Property::Value* Property::Map::Find( Property::Index indexKey, const std::string& stringKey ) const
@@ -227,28 +248,28 @@ Property::Value* Property::Map::Find( const std::string& key, Property::Type typ
 {
   DALI_ASSERT_DEBUG( mImpl && "Cannot use an object previously used as an r-value" );
 
-  for ( StringValueContainer::iterator iter = mImpl->mStringValueContainer.begin(), endIter = mImpl->mStringValueContainer.end(); iter != endIter; ++iter )
+  for( auto&& iter : mImpl->mStringValueContainer )
   {
-    if( (iter->second.GetType() == type) && (iter->first == key) )
+    if( (iter.second.GetType() == type) && (iter.first == key) )
     {
-      return &iter->second;
+      return &iter.second;
     }
   }
-  return NULL; // Not found
+  return nullptr; // Not found
 }
 
 Property::Value* Property::Map::Find( Property::Index key, Property::Type type ) const
 {
   DALI_ASSERT_DEBUG( mImpl && "Cannot use an object previously used as an r-value" );
 
-  for ( IndexValueContainer::iterator iter = mImpl->mIndexValueContainer.begin(), endIter = mImpl->mIndexValueContainer.end(); iter != endIter; ++iter )
+  for( auto&& iter : mImpl->mIndexValueContainer )
   {
-    if( (iter->second.GetType() == type) && (iter->first == key) )
+    if( (iter.second.GetType() == type) && (iter.first == key) )
     {
-      return &iter->second;
+      return &iter.second;
     }
   }
-  return NULL; // Not found
+  return nullptr; // Not found
 }
 
 void Property::Map::Clear()
@@ -268,14 +289,14 @@ void Property::Map::Merge( const Property::Map& from )
   {
     if ( Count() )
     {
-      for ( StringValueContainer::const_iterator iter = from.mImpl->mStringValueContainer.begin(), endIter = from.mImpl->mStringValueContainer.end(); iter != endIter; ++iter )
+      for( auto&& iter : from.mImpl->mStringValueContainer )
       {
-        (*this)[iter->first] = iter->second;
+        (*this)[iter.first] = iter.second;
       }
 
-      for ( IndexValueContainer::const_iterator iter = from.mImpl->mIndexValueContainer.begin(), endIter = from.mImpl->mIndexValueContainer.end(); iter != endIter; ++iter )
+      for( auto&& iter : from.mImpl->mIndexValueContainer )
       {
-        (*this)[iter->first] = iter->second;
+        (*this)[iter.first] = iter.second;
       }
     }
     else
@@ -290,11 +311,11 @@ const Property::Value& Property::Map::operator[]( const std::string& key ) const
 {
   DALI_ASSERT_DEBUG( mImpl && "Cannot use an object previously used as an r-value" );
 
-  for ( StringValueContainer::const_iterator iter = mImpl->mStringValueContainer.begin(), endIter = mImpl->mStringValueContainer.end(); iter != endIter; ++iter )
+  for( auto&& iter : mImpl->mStringValueContainer )
   {
-    if ( iter->first == key )
+    if ( iter.first == key )
     {
-      return iter->second;
+      return iter.second;
     }
   }
 
@@ -305,11 +326,11 @@ Property::Value& Property::Map::operator[]( const std::string& key )
 {
   DALI_ASSERT_DEBUG( mImpl && "Cannot use an object previously used as an r-value" );
 
-  for ( StringValueContainer::iterator iter = mImpl->mStringValueContainer.begin(), endIter = mImpl->mStringValueContainer.end(); iter != endIter; ++iter )
+  for( auto&& iter : mImpl->mStringValueContainer )
   {
-    if ( iter->first == key )
+    if ( iter.first == key )
     {
-      return iter->second;
+      return iter.second;
     }
   }
 
@@ -322,11 +343,11 @@ const Property::Value& Property::Map::operator[]( Property::Index key ) const
 {
   DALI_ASSERT_DEBUG( mImpl && "Cannot use an object previously used as an r-value" );
 
-  for ( IndexValueContainer::const_iterator iter = mImpl->mIndexValueContainer.begin(), endIter = mImpl->mIndexValueContainer.end(); iter != endIter; ++iter )
+  for( auto&& iter : mImpl->mIndexValueContainer )
   {
-    if ( iter->first == key )
+    if ( iter.first == key )
     {
-      return iter->second;
+      return iter.second;
     }
   }
 
@@ -337,11 +358,11 @@ Property::Value& Property::Map::operator[]( Property::Index key )
 {
   DALI_ASSERT_DEBUG( mImpl && "Cannot use an object previously used as an r-value" );
 
-  for ( IndexValueContainer::iterator iter = mImpl->mIndexValueContainer.begin(), endIter = mImpl->mIndexValueContainer.end(); iter != endIter; ++iter )
+  for( auto&& iter : mImpl->mIndexValueContainer )
   {
-    if ( iter->first == key )
+    if ( iter.first == key )
     {
-      return iter->second;
+      return iter.second;
     }
   }
 
@@ -381,23 +402,23 @@ std::ostream& operator<<( std::ostream& stream, const Property::Map& map )
   {
     int32_t count = 0;
     // Output the String-Value pairs
-    for ( StringValueContainer::iterator iter = map.mImpl->mStringValueContainer.begin(), endIter = map.mImpl->mStringValueContainer.end(); iter != endIter; ++iter )
+    for( auto&& iter : map.mImpl->mStringValueContainer )
     {
       if( count++ > 0 )
       {
         stream<<", ";
       }
-      stream<< iter->first << ":"<<iter->second;
+      stream<< iter.first << ":" << iter.second;
     }
 
     // Output the Index-Value pairs
-    for ( IndexValueContainer::iterator iter = map.mImpl->mIndexValueContainer.begin(), endIter = map.mImpl->mIndexValueContainer.end(); iter != endIter; ++iter )
+    for( auto&& iter : map.mImpl->mIndexValueContainer )
     {
       if( count++ > 0 )
       {
         stream<<", ";
       }
-      stream<< iter->first << ":"<<iter->second;
+      stream<< iter.first << ":" << iter.second;
     }
   }