]> granicus.if.org Git - taglib/commitdiff
Add unsupportedData() to PropertyMap, simplified [] behavior.
authorMichael Helmling <helmling@mathematik.uni-kl.de>
Tue, 17 Jan 2012 17:09:30 +0000 (18:09 +0100)
committerMichael Helmling <helmling@mathematik.uni-kl.de>
Tue, 17 Jan 2012 17:09:30 +0000 (18:09 +0100)
taglib/toolkit/tpropertymap.cpp
taglib/toolkit/tpropertymap.h

index 08b94ba799907b44923e321488ecaae64b779763..00aeca884c243b6939889666d6a288c91fa055e9 100644 (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;
index f82a7dfbcc79df3d8e78b163afc90e063fdc24e9..2025873d4d105d2c779982c4eb840319878187ca 100644 (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;
   };
 
 }