*
* It enables lookup of keys via case-insensitive match.
*/
+
+
+typedef std::vector<std::string> 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<typename EntryType>
class Dictionary
{
*/
typedef typename Elements::const_iterator iterator;
-
/**
* Constructor
*/
}
/**
- * 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<EntryType>& 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() )
{
* 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() )
* 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;
}
* 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
*/
{
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();
+ }
};