2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/public-api/object/property-map.h>
25 #include <dali/public-api/common/constants.h>
26 #include <dali/public-api/object/property.h>
33 typedef std::vector< Property::StringValuePair > Container;
34 }; // unnamed namespace
36 struct Property::Map::Impl
46 Property::Map::Map( const Property::Map& other )
49 mImpl->mContainer = other.mImpl->mContainer;
57 unsigned int Property::Map::Count() const
59 return mImpl->mContainer.size();
62 bool Property::Map::Empty() const
64 return mImpl->mContainer.empty();
67 Property::Value& Property::Map::GetValue( unsigned int position ) const
69 DALI_ASSERT_ALWAYS( position < Count() && "position out-of-bounds" );
71 return mImpl->mContainer[ position ].second;
74 const std::string& Property::Map::GetKey( unsigned int position ) const
76 DALI_ASSERT_ALWAYS( position < Count() && "position out-of-bounds" );
78 return mImpl->mContainer[ position ].first;
81 Property::StringValuePair& Property::Map::GetPair( unsigned int position ) const
83 DALI_ASSERT_ALWAYS( position < Count() && "position out-of-bounds" );
85 return mImpl->mContainer[ position ];
88 Property::Value* Property::Map::Find( const std::string& key ) const
90 for ( Container::iterator iter = mImpl->mContainer.begin(), endIter = mImpl->mContainer.end(); iter != endIter; ++iter )
92 if ( iter->first == key )
97 return NULL; // Not found
100 void Property::Map::Clear()
102 mImpl->mContainer.clear();
105 void Property::Map::Merge( const Property::Map& from )
107 // Ensure we're not attempting to merge with ourself
112 for ( unsigned int i = 0, count = from.Count(); i < count; ++i )
114 StringValuePair& pair( from.GetPair( i ) );
115 (*this)[ pair.first ] = pair.second;
120 // If we're empty, then just copy
126 const Property::Value& Property::Map::operator[]( const std::string& key ) const
128 for ( Container::const_iterator iter = mImpl->mContainer.begin(), endIter = mImpl->mContainer.end(); iter != endIter; ++iter )
130 if ( iter->first == key )
136 DALI_ASSERT_ALWAYS( ! "Invalid Key" );
139 Property::Value& Property::Map::operator[]( const std::string& key )
141 for ( Container::iterator iter = mImpl->mContainer.begin(), endIter = mImpl->mContainer.end(); iter != endIter; ++iter )
143 if ( iter->first == key )
149 // Create and return reference to new value
150 mImpl->mContainer.push_back( StringValuePair( key, Value() ) );
151 return (mImpl->mContainer.end() - 1)->second;
154 Property::Map& Property::Map::operator=( const Property::Map& other )
160 mImpl->mContainer = other.mImpl->mContainer;