Add unsupportedData() to PropertyMap, simplified [] behavior.

This commit is contained in:
Michael Helmling 2012-01-17 18:09:30 +01:00
parent d11189b975
commit 18ae797df4
2 changed files with 29 additions and 11 deletions

View File

@ -43,7 +43,11 @@ bool PropertyMap::insert(const String &key, const StringList &values)
if (realKey.isNull())
return false;
supertype::operator[](realKey).append(values);
Iterator result = supertype::find(realKey);
if (result == end())
supertype::insert(realKey, values);
else
supertype::operator[](realKey).append(values);
return true;
}
@ -102,13 +106,14 @@ const StringList &PropertyMap::operator[](const String &key) const
StringList &PropertyMap::operator[](const String &key)
{
String realKey = prepareKey(key);
if (realKey.isNull())
return supertype::operator[](realKey); // invalid case
if (!supertype::contains(realKey))
supertype::insert(realKey, StringList());
return supertype::operator[](realKey);
}
StringList &PropertyMap::unsupportedData()
{
return unsupported;
}
String PropertyMap::prepareKey(const String &proposed) const {
if (proposed.isEmpty())
return String::null;

View File

@ -41,7 +41,7 @@ namespace TagLib {
*
*/
class PropertyMap: public Map<String,StringList>
class TAGLIB_EXPORT PropertyMap: public Map<String,StringList>
{
public:
@ -93,25 +93,38 @@ namespace TagLib {
/*!
* Returns a reference to the value associated with \a key.
*
* \note: This has undefined behavior if the key is not valid.
* \note: This has undefined behavior if the key is not valid or not
* present in the map.
*/
const StringList &operator[](const String &key) const;
/*!
* Returns a reference to the value associated with \a key.
*
* If \a key is not present in the map, an empty list is inserted and
* returned.
*
* \note: This has undefined behavior if the key is not valid.
* \note: This has undefined behavior if the key is not valid or not
* present in the map.
*/
StringList &operator[](const String &key);
/*!
* If a PropertyMap is read from a File object using File::properties(),
* the StringList returned from this function will represent metadata
* that could not be parsed into the PropertyMap representation. This could
* be e.g. binary data, unknown ID3 frames, etc.
* You can remove items from the returned list, which tells TagLib to remove
* those unsupported elements if you call File::setProperties() with the
* same PropertyMap as argument.
*/
StringList &unsupportedData();
private:
/*!
* Converts \a proposed into another String suitable to be used as
* a key, or returns String::null if this is not possible.
*/
String prepareKey(const String &proposed) const;
StringList unsupported;
};
}