mirror of
https://github.com/taglib/taglib.git
synced 2025-06-03 00:58:12 -04:00
Map: Add method value() to look up without creating entry
This commit is contained in:
parent
05486d00bf
commit
a4bb904a01
@ -153,6 +153,14 @@ namespace TagLib {
|
||||
*/
|
||||
Map<Key, T> &erase(const Key &key);
|
||||
|
||||
/*!
|
||||
* Returns the value associated with \a key.
|
||||
*
|
||||
* If the map does not contain \a key, it returns defaultValue.
|
||||
* If no defaultValue is specified, it returns a default-constructed value.
|
||||
*/
|
||||
const T value(const Key &key, const T &defaultValue = T()) const;
|
||||
|
||||
/*!
|
||||
* Returns a reference to the value associated with \a key.
|
||||
*
|
||||
|
@ -155,6 +155,13 @@ unsigned int Map<Key, T>::size() const
|
||||
return static_cast<unsigned int>(d->map.size());
|
||||
}
|
||||
|
||||
template <class Key, class T>
|
||||
const T Map<Key, T>::value(const Key &key, const T &defaultValue) const
|
||||
{
|
||||
ConstIterator it = d->map.find(key);
|
||||
return it != d->map.end() ? it->second : defaultValue;
|
||||
}
|
||||
|
||||
template <class Key, class T>
|
||||
const T &Map<Key, T>::operator[](const Key &key) const
|
||||
{
|
||||
|
@ -117,6 +117,12 @@ PropertyMap &PropertyMap::merge(const PropertyMap &other)
|
||||
return *this;
|
||||
}
|
||||
|
||||
const StringList PropertyMap::value(const String &key,
|
||||
const StringList &defaultValue) const
|
||||
{
|
||||
return SimplePropertyMap::value(key.upper(), defaultValue);
|
||||
}
|
||||
|
||||
const StringList &PropertyMap::operator[](const String &key) const
|
||||
{
|
||||
return SimplePropertyMap::operator[](key.upper());
|
||||
|
@ -191,6 +191,15 @@ namespace TagLib {
|
||||
*/
|
||||
PropertyMap &merge(const PropertyMap &other);
|
||||
|
||||
/*!
|
||||
* Returns the value associated with \a key.
|
||||
*
|
||||
* If the map does not contain \a key, it returns defaultValue.
|
||||
* If no defaultValue is specified, it returns an empty string list.
|
||||
*/
|
||||
const StringList value(const String &key,
|
||||
const StringList &defaultValue = StringList()) const;
|
||||
|
||||
/*!
|
||||
* Returns a reference to the value associated with \a key.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user