Support for ASTC compressed textures wrapped in KTX files
[platform/core/uifw/dali-core.git] / dali / public-api / object / property-map.cpp
index 5c70cbf..fdf1cef 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2015 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.
 // CLASS HEADER
 #include <dali/public-api/object/property-map.h>
 
-// EXTERNAL INCLUDES
-#include <vector>
-
 // INTERNAL INCLUDES
-#include <dali/public-api/common/constants.h>
-#include <dali/public-api/object/property.h>
+#include <dali/public-api/common/vector-wrapper.h>
 
 namespace Dali
 {
 
 namespace
 {
-typedef std::vector< Property::StringValuePair > Container;
+typedef std::vector< StringValuePair > Container;
 }; // unnamed namespace
 
 struct Property::Map::Impl
@@ -54,7 +50,7 @@ Property::Map::~Map()
   delete mImpl;
 }
 
-unsigned int Property::Map::Count() const
+Property::Map::SizeType Property::Map::Count() const
 {
   return mImpl->mContainer.size();
 }
@@ -64,28 +60,38 @@ bool Property::Map::Empty() const
   return mImpl->mContainer.empty();
 }
 
-Property::Value& Property::Map::GetValue( unsigned int position ) const
+void Property::Map::Insert( const char* key, const Value& value )
+{
+  mImpl->mContainer.push_back( std::make_pair( key, value ) );
+}
+
+void Property::Map::Insert( const std::string& key, const Value& value )
+{
+  mImpl->mContainer.push_back( std::make_pair( key, value ) );
+}
+
+Property::Value& Property::Map::GetValue( SizeType position ) const
 {
   DALI_ASSERT_ALWAYS( position < Count() && "position out-of-bounds" );
 
   return mImpl->mContainer[ position ].second;
 }
 
-const std::string& Property::Map::GetKey( unsigned int position ) const
+const std::string& Property::Map::GetKey( SizeType position ) const
 {
   DALI_ASSERT_ALWAYS( position < Count() && "position out-of-bounds" );
 
   return mImpl->mContainer[ position ].first;
 }
 
-Property::StringValuePair& Property::Map::GetPair( unsigned int position ) const
+StringValuePair& Property::Map::GetPair( SizeType position ) const
 {
   DALI_ASSERT_ALWAYS( position < Count() && "position out-of-bounds" );
 
   return mImpl->mContainer[ position ];
 }
 
-Property::Value* Property::Map::Find( const std::string& key ) const
+Property::Value* Property::Map::Find( const char* key ) const
 {
   for ( Container::iterator iter = mImpl->mContainer.begin(), endIter = mImpl->mContainer.end(); iter != endIter; ++iter )
   {
@@ -97,6 +103,25 @@ Property::Value* Property::Map::Find( const std::string& key ) const
   return NULL; // Not found
 }
 
+Property::Value* Property::Map::Find( const std::string& key ) const
+{
+  return Find( key.c_str() );
+
+}
+
+Property::Value* Property::Map::Find( const std::string& key, Property::Type type ) const
+{
+  for ( Container::iterator iter = mImpl->mContainer.begin(), endIter = mImpl->mContainer.end(); iter != endIter; ++iter )
+  {
+    // test type first to shortcut eval (possibly reducing string compares)
+    if( (iter->second.GetType() == type) && (iter->first == key) )
+    {
+      return &iter->second;
+    }
+  }
+  return NULL; // Not found
+}
+
 void Property::Map::Clear()
 {
   mImpl->mContainer.clear();
@@ -134,10 +159,6 @@ const Property::Value& Property::Map::operator[]( const std::string& key ) const
   }
 
   DALI_ASSERT_ALWAYS( ! "Invalid Key" );
-
-  // Should not reach here
-  static Value value;
-  return value;
 }
 
 Property::Value& Property::Map::operator[]( const std::string& key )
@@ -151,7 +172,7 @@ Property::Value& Property::Map::operator[]( const std::string& key )
   }
 
   // Create and return reference to new value
-  mImpl->mContainer.push_back( StringValuePair( key, Value() ) );
+  mImpl->mContainer.push_back( std::make_pair( key, Property::Value() ) );
   return (mImpl->mContainer.end() - 1)->second;
 }