X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Fpublic-api%2Fobject%2Fproperty-map.cpp;h=fdf1cefb1b1d9e3e0c4fae0ab56ef8bf53bdf577;hb=833b78a75e78b8247e09fe303b12f2a335871eae;hp=5c70cbf8a6d04e3b2e0482ef92d53f4d09744465;hpb=4b5fdf6db51a31926c43a7649bf22b00a8958069;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/public-api/object/property-map.cpp b/dali/public-api/object/property-map.cpp index 5c70cbf..fdf1cef 100644 --- a/dali/public-api/object/property-map.cpp +++ b/dali/public-api/object/property-map.cpp @@ -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. @@ -18,19 +18,15 @@ // CLASS HEADER #include -// EXTERNAL INCLUDES -#include - // INTERNAL INCLUDES -#include -#include +#include 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; }