X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fbuilder%2Fdictionary.h;h=65c7e18336566e2d24e486790c5713f5fa9fcaa8;hp=22d2afe49e7ede67cf0f1c62eb5744eda0fffb3d;hb=66e34be8b6c5d6e9c567e2eea8f4ed0bc9085b4b;hpb=50550b5dd051c5baebd26365991b50f155031dc8 diff --git a/dali-toolkit/internal/builder/dictionary.h b/dali-toolkit/internal/builder/dictionary.h index 22d2afe..65c7e18 100644 --- a/dali-toolkit/internal/builder/dictionary.h +++ b/dali-toolkit/internal/builder/dictionary.h @@ -18,11 +18,13 @@ */ #include + #include +#include namespace Dali { -extern bool CaseInsensitiveStringCompare( const std::string& a, const std::string& b ); +extern bool CaseInsensitiveStringCompare(std::string_view a, std::string_view b); namespace Toolkit { @@ -36,6 +38,23 @@ namespace Internal * * It enables lookup of keys via case-insensitive match. */ + + +typedef std::vector DictionaryKeys; +inline void Merge( DictionaryKeys& toDict, const DictionaryKeys& fromDict ) +{ + for( DictionaryKeys::const_iterator fromIter = fromDict.begin(); fromIter != fromDict.end(); ++fromIter ) + { + const std::string& fromKey = (*fromIter); + DictionaryKeys::iterator toIter = std::find( toDict.begin(), toDict.end(), fromKey ); + if( toIter == toDict.end() ) + { + toDict.push_back( fromKey ); + } + } +} + + template class Dictionary { @@ -62,7 +81,6 @@ public: */ typedef typename Elements::const_iterator iterator; - /** * Constructor */ @@ -105,46 +123,57 @@ public: } /** - * Find the element in the dictionary pointed at by key, and - * return a pointer to it, or NULL. + * Remove a key value pair from the dictionary. */ - EntryType* Find( const std::string& key ) const + void Remove( const std::string& name ) { - EntryType* result=NULL; - - if( ! key.empty() ) + for( typename Elements::iterator iter = container.begin(); iter != container.end(); ++iter ) { - for( typename Elements::iterator iter = container.begin(); iter != container.end(); ++iter ) + if( iter->key == name ) { - if( iter->key == key ) - { - result = &(iter->entry); - break; - } + container.erase( iter ); + break; } } - return result; } /** - * Find the element in the dictionary pointed at by key, and - * return a pointer to it, or NULL + * Remove a key value pair from the dictionary. */ - EntryType* Find( const char* key ) const + void Remove( const char* name ) { - if( key != NULL ) + if( name != NULL ) { - std::string theKey(key); - return Find(theKey); + std::string theName(name); + Remove(theName); + } + } + + void Merge( const Dictionary& dictionary ) + { + for( typename Elements::const_iterator fromIter = dictionary.container.begin(); fromIter != dictionary.container.end(); ++fromIter ) + { + bool found=false; + for( typename Elements::iterator toIter = container.begin(); toIter != container.end(); ++toIter ) + { + if( fromIter->key == toIter->key ) + { + found=true; + toIter->entry = fromIter->entry; + } + } + if( !found ) + { + container.push_back( Element(fromIter->key, fromIter->entry) ); + } } - return NULL; } /** - * Find the element in the dictionary pointed at by key using a case + * Find the element in the dictionary pointed at by key, and * insensitive search, and return a const pointer to it, or NULL */ - const EntryType* FindCaseInsensitiveC( const std::string& key ) const + const EntryType* FindConst( const std::string& key ) const { if( ! key.empty() ) { @@ -164,7 +193,7 @@ public: * Find the element in the dictionary pointed at by key using a case * insensitive search, and return a non-const pointer to it, or NULL */ - EntryType* FindCaseInsensitive( const std::string& key ) const + EntryType* Find( const std::string& key ) const { EntryType* result = NULL; if( ! key.empty() ) @@ -185,12 +214,12 @@ public: * Find the element in the dictionary pointed at by key using a case * insensitive search, and return a const pointer to it, or NULL */ - const EntryType* FindCaseInsensitiveC( const char* key ) const + const EntryType* FindConst( const char* key ) const { if( key != NULL ) { std::string theKey(key); - return FindCaseInsensitiveC( theKey ); + return FindConst( theKey ); } return NULL; } @@ -199,16 +228,15 @@ public: * Find the element in the dictionary pointed at by key using a case * insensitive search, and return a non-const pointer to it, or NULL */ - EntryType* FindCaseInsensitive( const char* key ) const + EntryType* Find( const char* key ) const { if( key != NULL ) { std::string theKey(key); - return FindCaseInsensitive( theKey ); + return Find( theKey ); } return NULL; } - /** * Return an iterator pointing at the first entry in the dictionary */ @@ -224,6 +252,20 @@ public: { return container.end(); } + + void GetKeys( DictionaryKeys& keys ) const + { + keys.clear(); + for( typename Elements::const_iterator iter = container.begin(); iter != container.end(); ++iter ) + { + keys.push_back( (*iter).key ); + } + } + + void Clear() + { + container.clear(); + } };