]> granicus.if.org Git - taglib/commitdiff
Made im/export functions nonvirtual. Added similar functions to File and
authorMichael Helmling <helmling@mathematik.uni-kl.de>
Sun, 28 Aug 2011 20:58:40 +0000 (22:58 +0200)
committerMichael Helmling <helmling@mathematik.uni-kl.de>
Sun, 28 Aug 2011 20:58:40 +0000 (22:58 +0200)
its subclasses. TagLib::File contains a bunch of dynamic_casts to call
the correct specializations.

20 files changed:
taglib/ape/apefile.cpp
taglib/ape/apefile.h
taglib/ape/apetag.h
taglib/flac/flacfile.cpp
taglib/flac/flacfile.h
taglib/mpc/mpcfile.cpp
taglib/mpc/mpcfile.h
taglib/mpeg/id3v2/id3v2tag.h
taglib/mpeg/mpegfile.cpp
taglib/mpeg/mpegfile.h
taglib/ogg/flac/oggflacfile.cpp
taglib/ogg/flac/oggflacfile.h
taglib/ogg/speex/speexfile.cpp
taglib/ogg/speex/speexfile.h
taglib/ogg/vorbis/vorbisfile.cpp
taglib/ogg/vorbis/vorbisfile.h
taglib/ogg/xiphcomment.h
taglib/tag.h
taglib/toolkit/tfile.cpp
taglib/toolkit/tfile.h

index 2973a47685d3032aeb07c12ea17e60e2b2240a59..7c63412ebb9a479057c7a69bd4b18a1b3a3c784b 100644 (file)
@@ -109,6 +109,25 @@ TagLib::Tag *APE::File::tag() const
   return &d->tag;
 }
 
+TagLib::TagDict APE::File::toDict(void) const
+{
+  if (d->hasAPE)
+    return d->tag.access<APE::Tag>(APEIndex, false)->toDict();
+  if (d->hasID3v1)
+    return d->tag.access<ID3v1::Tag>(ID3v1Index, false)->toDict();
+  return TagLib::TagDict();
+}
+
+void APE::File::fromDict(const TagDict &dict)
+{
+  if (d->hasAPE)
+    d->tag.access<APE::Tag>(APEIndex, false)->fromDict(dict);
+  else if (d->hasID3v1)
+    d->tag.access<ID3v1::Tag>(ID3v1Index, false)->fromDict(dict);
+  else
+    d->tag.access<APE::Tag>(APE, true)->fromDict(dict);
+}
+
 APE::Properties *APE::File::audioProperties() const
 {
   return d->properties;
index 2f22fddec9319179b6cfabadd396d1891195c318..ab290b8372090d8727b7203a6b958f7ed56b1f17 100644 (file)
@@ -110,6 +110,19 @@ namespace TagLib {
        */
       virtual TagLib::Tag *tag() const;
 
+      /*!
+       * Implements the unified tag dictionary interface -- export function.
+       * If the file contains both an APE and an ID3v1 tag, only APE
+       * will be converted to the TagDict.
+       */
+      TagDict toDict() const;
+
+      /*!
+       * Implements the unified tag dictionary interface -- import function.
+       * As for the export, only one tag is taken into account. If the file
+       * has no tag at all, APE will be created.
+       */
+      void fromDict(const TagDict &);
       /*!
        * Returns the APE::Properties for this file.  If no audio properties
        * were read then this will return a null pointer.
index b48d9291aeead0e761f0e00e98849245c2d4b9fb..089420eaf41c400acb2910df3997326a2dbf608b 100644 (file)
@@ -114,13 +114,13 @@ namespace TagLib {
        * TRACK to TRACKNUMBER and YEAR to DATE, respectively, in order to be compliant
        * with the names used in other formats.
        */
-      virtual TagDict toDict() const;
+      TagDict toDict() const;
 
       /*!
        * Implements the unified tag dictionary interface -- import function. The same
        * comments as for the export function apply.
        */
-      virtual void fromDict(const TagDict &);
+      void fromDict(const TagDict &);
 
       /*!
        * Returns a pointer to the tag's footer.
index 5065cd29770c2205e5fb75c1f52ff8b49c4b923e..ec925d0fa1fc9eab80c993a0b82f3bbd5887f267 100644 (file)
@@ -138,6 +138,31 @@ TagLib::Tag *FLAC::File::tag() const
   return &d->tag;
 }
 
+TagLib::TagDict FLAC::File::toDict(void) const
+{
+  // once Tag::toDict() is virtual, this case distinction could actually be done
+  // within TagUnion.
+  if (d->hasXiphComment)
+    return d->tag.access<Ogg::XiphComment>(XiphIndex, false)->toDict();
+  if (d->hasID3v2)
+    return d->tag.access<ID3v2::Tag>(ID3v2Index, false)->toDict();
+  if (d->hasID3v1)
+    return d->tag.access<ID3v1::Tag>(ID3v1Index, false)->toDict();
+  return TagLib::TagDict();
+}
+
+void FLAC::File::fromDict(const TagDict &dict)
+{
+  if (d->hasXiphComment)
+    d->tag.access<Ogg::XiphComment>(XiphIndex, false)->fromDict(dict);
+  else if (d->hasID3v2)
+    d->tag.access<ID3v2::Tag>(ID3v2Index, false)->fromDict(dict);
+  else if (d->hasID3v1)
+    d->tag.access<ID3v1::Tag>(ID3v1Index, false)->fromDict(dict);
+  else
+    d->tag.access<Ogg::XiphComment>(XiphIndex, true)->fromDict(dict);
+}
+
 FLAC::Properties *FLAC::File::audioProperties() const
 {
   return d->properties;
index 01466a2ddbd6cdafaa405e2a759775df34c9b34c..9fdc1c2ebce34947a339f47a9d184d066c10e51f 100644 (file)
@@ -29,6 +29,7 @@
 #include "taglib_export.h"
 #include "tfile.h"
 #include "tlist.h"
+#include "tag.h"
 
 #include "flacpicture.h"
 #include "flacproperties.h"
@@ -36,7 +37,6 @@
 namespace TagLib {
 
   class Tag;
-
   namespace ID3v2 { class FrameFactory; class Tag; }
   namespace ID3v1 { class Tag; }
   namespace Ogg { class XiphComment; }
@@ -118,6 +118,21 @@ namespace TagLib {
        */
       virtual TagLib::Tag *tag() const;
 
+      /*!
+       * Implements the unified tag dictionary interface -- export function.
+       * If the file contains more than one tag (e.g. XiphComment and ID3v1),
+       * only the first one (in the order XiphComment, ID3v2, ID3v1) will be
+       * converted to the TagDict.
+       */
+      TagDict toDict() const;
+
+      /*!
+       * Implements the unified tag dictionary interface -- import function.
+       * As with the export, only one tag is taken into account. If the file
+       * has no tag at all, a XiphComment will be created.
+       */
+      void fromDict(const TagDict &);
+
       /*!
        * Returns the FLAC::Properties for this file.  If no audio properties
        * were read then this will return a null pointer.
index 216c1b3bcac10e38109c9184961ec021d14d8ffd..2482a90c7ad45bdfff4b39ece845063c4388c59b 100644 (file)
@@ -113,6 +113,27 @@ TagLib::Tag *MPC::File::tag() const
   return &d->tag;
 }
 
+TagLib::TagDict MPC::File::toDict(void) const
+{
+  // once Tag::toDict() is virtual, this case distinction could actually be done
+  // within TagUnion.
+  if (d->hasAPE)
+    return d->tag.access<APE::Tag>(APEIndex, false)->toDict();
+  if (d->hasID3v1)
+    return d->tag.access<ID3v1::Tag>(ID3v1Index, false)->toDict();
+  return TagLib::TagDict();
+}
+
+void MPC::File::fromDict(const TagDict &dict)
+{
+  if (d->hasAPE)
+    d->tag.access<APE::Tag>(APEIndex, false)->fromDict(dict);
+  else if (d->hasID3v1)
+    d->tag.access<ID3v1::Tag>(ID3v1Index, false)->fromDict(dict);
+  else
+    d->tag.access<APE::Tag>(APEIndex, true)->fromDict(dict);
+}
+
 MPC::Properties *MPC::File::audioProperties() const
 {
   return d->properties;
index 93471cf1256ba4fa88cd8ef1f8f5a879fd30b83c..6ff91e719ba3adb4ac3dd10b169a65f2a666b073 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "taglib_export.h"
 #include "tfile.h"
+#include "tag.h"
 
 #include "mpcproperties.h"
 
@@ -107,6 +108,20 @@ namespace TagLib {
        */
       virtual TagLib::Tag *tag() const;
 
+      /*!
+       * Implements the unified tag dictionary interface -- export function.
+       * If the file contains both an APE and an ID3v1 tag, only the APE
+       * tag  will be converted to the TagDict.
+       */
+      TagDict toDict() const;
+
+      /*!
+       * Implements the unified tag dictionary interface -- import function.
+       * As with the export, only one tag is taken into account. If the file
+       * has no tag at all, APE will be created.
+       */
+      void fromDict(const TagDict &);
+
       /*!
        * Returns the MPC::Properties for this file.  If no audio properties
        * were read then this will return a null pointer.
index f67a71e7e34cad6f81bd0dab4c6274cf8bcd3cd9..3f731282a7a6a0ee83ee8df13d159ddc138258ef 100644 (file)
@@ -265,13 +265,13 @@ namespace TagLib {
        * This function does some work to translate the hard-specified ID3v2
        * frame types into a free-form string-to-stringlist dictionary.
        */
-      virtual TagDict toDict() const;
+      TagDict toDict() const;
 
       /*!
        * Implements the unified tag dictionary interface -- import function.
        * See the comments in toDict().
        */
-      virtual void fromDict(const TagDict &);
+      void fromDict(const TagDict &);
 
       /*!
        * Render the tag back to binary data, suitable to be written to disk.
index a3bad823bd48a75cad8f8ac810241916df2fa465..645409fa9b0019777d8f1dc6e4c050ea1898e1a6 100644 (file)
@@ -133,6 +133,31 @@ TagLib::Tag *MPEG::File::tag() const
   return &d->tag;
 }
 
+TagLib::TagDict MPEG::File::toDict(void) const
+{
+  // once Tag::toDict() is virtual, this case distinction could actually be done
+  // within TagUnion.
+  if (d->hasID3v2)
+    return d->tag.access<ID3v2::Tag>(ID3v2Index, false)->toDict();
+  if (d->hasAPE)
+    return d->tag.access<APE::Tag>(APEIndex, false)->toDict();
+  if (d->hasID3v1)
+    return d->tag.access<ID3v1::Tag>(ID3v1Index, false)->toDict();
+  return TagLib::TagDict();
+}
+
+void MPEG::File::fromDict(const TagDict &dict)
+{
+  if (d->hasID3v2)
+    d->tag.access<ID3v2::Tag>(ID3v2Index, false)->fromDict(dict);
+  else if (d->hasAPE)
+    d->tag.access<APE::Tag>(APEIndex, false)->fromDict(dict);
+  else if (d->hasID3v1)
+    d->tag.access<ID3v1::Tag>(ID3v1Index, false)->fromDict(dict);
+  else
+    d->tag.access<ID3v2::Tag>(ID3v2Index, true)->fromDict(dict);
+}
+
 MPEG::Properties *MPEG::File::audioProperties() const
 {
   return d->properties;
index cff5469dab60aea7760759a7a2a25faed7badea3..75da7b0a6a545548388ec41abcf26a2e5296506b 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "taglib_export.h"
 #include "tfile.h"
+#include "tag.h"
 
 #include "mpegproperties.h"
 
@@ -128,6 +129,21 @@ namespace TagLib {
        */
       virtual Tag *tag() const;
 
+      /*!
+       * Implements the unified tag dictionary interface -- export function.
+       * If the file contains more than one tag (e.g. ID3v2 and v1), only the
+       * first one (in the order ID3v2, APE, ID3v1) will be converted to the
+       * TagDict.
+       */
+      TagDict toDict() const;
+
+      /*!
+       * Implements the unified tag dictionary interface -- import function.
+       * As with the export, only one tag is taken into account. If the file
+       * has no tag at all, ID3v2 will be created.
+       */
+      void fromDict(const TagDict &);
+
       /*!
        * Returns the MPEG::Properties for this file.  If no audio properties
        * were read then this will return a null pointer.
index 3addbffaa9b19760f7cd9a2df6c7954a8db0306b..437dabf09690dca09bee881a803e7c632dece89b 100644 (file)
@@ -92,6 +92,16 @@ Ogg::XiphComment *Ogg::FLAC::File::tag() const
   return d->comment;
 }
 
+TagLib::TagDict Ogg::FLAC::File::toDict(void) const
+{
+  return d->comment->toDict();
+}
+
+void Ogg::FLAC::File::fromDict(const TagDict &dict)
+{
+  d->comment->fromDict(dict);
+}
+
 Properties *Ogg::FLAC::File::audioProperties() const
 {
   return d->properties;
index d4373795f1d2e398240cc619db020b9309c61178..e39ac2cc4ed9ed133d7fda89611a42fbc0dfa31f 100644 (file)
@@ -89,6 +89,18 @@ namespace TagLib {
        */
       virtual XiphComment *tag() const;
 
+      /*!
+       * Implements the unified tag dictionary interface -- export function.
+       * Returns the contents of the Ogg::XiphComment as TagDict.
+       */
+      TagDict toDict() const;
+
+      /*!
+       * Implements the unified tag dictionary interface -- import function.
+       * Matches the TagDict's contents to the XiphComment of the file.
+       */
+      void fromDict(const TagDict &);
+
       /*!
        * Returns the FLAC::Properties for this file.  If no audio properties
        * were read then this will return a null pointer.
index 3a4940a26a3e40c3dd92a0960d1eda67164a1edc..d602bcc827f186df085ca52df5424be25e3a74fb 100644 (file)
@@ -82,6 +82,16 @@ Ogg::XiphComment *Speex::File::tag() const
   return d->comment;
 }
 
+TagLib::TagDict Ogg::Speex::File::toDict(void) const
+{
+  return d->comment->toDict();
+}
+
+void Ogg::Speex::File::fromDict(const TagDict &dict)
+{
+  d->comment->fromDict(dict);
+}
+
 Speex::Properties *Speex::File::audioProperties() const
 {
   return d->properties;
index c14cf2aa60d61d87d915716c175630a41f35e079..2af6cd828202aa6ced26a183911d0aad61e78e6b 100644 (file)
@@ -82,6 +82,17 @@ namespace TagLib {
          * TagLib::File::tag().
          */
         virtual Ogg::XiphComment *tag() const;
+        /*!
+         * Implements the unified tag dictionary interface -- export function.
+         * Returns the contents of the Ogg::XiphComment as TagDict.
+         */
+        TagDict toDict() const;
+
+        /*!
+         * Implements the unified tag dictionary interface -- import function.
+         * Matches the TagDict's contents to the XiphComment of the file.
+         */
+        void fromDict(const TagDict &);
 
         /*!
          * Returns the Speex::Properties for this file.  If no audio properties
index 60056f83388467570f4d528f1937586cddbb808d..fe50d6d09c4c9e7be63d9ec481b7b9ff226d758c 100644 (file)
@@ -85,6 +85,16 @@ Ogg::XiphComment *Vorbis::File::tag() const
   return d->comment;
 }
 
+TagLib::TagDict Ogg::Vorbis::File::toDict(void) const
+{
+  return d->comment->toDict();
+}
+
+void Ogg::Vorbis::File::fromDict(const TagDict &dict)
+{
+  d->comment->fromDict(dict);
+}
+
 Vorbis::Properties *Vorbis::File::audioProperties() const
 {
   return d->properties;
index 299d9c2d3c7f56e268e2a809424a9775f716ca03..989eac3dc370ec2943cfb6d71dedf806d1a86f62 100644 (file)
@@ -90,6 +90,17 @@ namespace TagLib {
        */
       virtual Ogg::XiphComment *tag() const;
 
+      /*!
+       * Implements the unified tag dictionary interface -- export function.
+       * Returns the contents of the Ogg::XiphComment as TagDict.
+       */
+      TagDict toDict() const;
+
+      /*!
+       * Implements the unified tag dictionary interface -- import function.
+       * Matches the TagDict's contents to the XiphComment of the file.
+       */
+      void fromDict(const TagDict &);
       /*!
        * Returns the Vorbis::Properties for this file.  If no audio properties
        * were read then this will return a null pointer.
index 6ad23c6ac02702812fc6d9844a50ac20ab06974e..f9f23d54019ca2b712934ddaa204b39568b76836 100644 (file)
@@ -147,13 +147,13 @@ namespace TagLib {
        * comment is nothing more than a map from tag names to list of values,
        * as is the dict interface).
        */
-      virtual TagDict toDict() const;
+      TagDict toDict() const;
 
       /*!
        * Implements the unified tag dictionary interface -- import function.
        * The tags from the given dict will be stored one-to-one in the file.
        */
-      virtual void fromDict(const TagDict &);
+      void fromDict(const TagDict &);
 
       /*!
        * Returns the vendor ID of the Ogg Vorbis encoder.  libvorbis 1.0 as the
index 45caf08337aa08a7f4d050a97766ee630290ba33..728c3980867dad6235eef9c111ea122741537b1e 100644 (file)
@@ -63,7 +63,7 @@ namespace TagLib {
      * of the specific metadata format into a "human-readable" map of strings
      * to lists of strings, being as precise as possible.
      */
-    virtual TagDict toDict() const;
+    TagDict toDict() const;
 
     /*!
      * Unified tag dictionary interface -- import function. Converts a map
@@ -72,7 +72,7 @@ namespace TagLib {
      * be lost by this operation. Especially the default implementation handles
      * only single values of the default tags specified in this class.
      */
-    virtual void fromDict(const TagDict &);
+    void fromDict(const TagDict &);
 
     /*!
      * Returns the track name; if no track name is present in the tag
index ae3eec1d959d15c3566aa31c6c1f415a56906794..9ac5f9bb9b637fb213c693cefa58c417d9e4ecd5 100644 (file)
 # define W_OK 2
 #endif
 
+#include "asffile.h"
+#include "mpegfile.h"
+#include "vorbisfile.h"
+#include "flacfile.h"
+#include "oggflacfile.h"
+#include "mpcfile.h"
+#include "mp4file.h"
+#include "wavpackfile.h"
+#include "speexfile.h"
+#include "trueaudiofile.h"
+#include "aifffile.h"
+#include "wavfile.h"
+#include "apefile.h"
+#include "modfile.h"
+#include "s3mfile.h"
+#include "itfile.h"
+#include "xmfile.h"                                   \
+
 using namespace TagLib;
 
 class File::FilePrivate
@@ -95,6 +113,48 @@ FileName File::name() const
   return d->stream->name();
 }
 
+TagDict File::toDict() const
+{
+  // ugly workaround until this method is virtual
+  if (dynamic_cast<const APE::File* >(this))
+      return dynamic_cast<const APE::File* >(this)->toDict();
+  if (dynamic_cast<const FLAC::File* >(this))
+        return dynamic_cast<const FLAC::File* >(this)->toDict();
+  if (dynamic_cast<const MPC::File* >(this))
+        return dynamic_cast<const MPC::File* >(this)->toDict();
+  if (dynamic_cast<const MPEG::File* >(this))
+        return dynamic_cast<const MPEG::File* >(this)->toDict();
+  if (dynamic_cast<const Ogg::FLAC::File* >(this))
+    return dynamic_cast<const Ogg::FLAC::File* >(this)->toDict();
+  if (dynamic_cast<const Ogg::Speex::File* >(this))
+      return dynamic_cast<const Ogg::Speex::File* >(this)->toDict();
+  if (dynamic_cast<const Ogg::Vorbis::File* >(this))
+      return dynamic_cast<const Ogg::Vorbis::File* >(this)->toDict();
+  // no specialized implementation available -> use generic one
+  return tag()->toDict();
+}
+
+void File::fromDict(const TagDict &dict)
+{
+  if (dynamic_cast<const APE::File* >(this))
+    dynamic_cast< APE::File* >(this)->fromDict(dict);
+  else if (dynamic_cast<const FLAC::File* >(this))
+    dynamic_cast< FLAC::File* >(this)->fromDict(dict);
+  else if (dynamic_cast<const MPC::File* >(this))
+      dynamic_cast< MPC::File* >(this)->fromDict(dict);
+  else if (dynamic_cast<const MPEG::File* >(this))
+      dynamic_cast< MPEG::File* >(this)->fromDict(dict);
+  else if (dynamic_cast<const Ogg::FLAC::File* >(this))
+      dynamic_cast< Ogg::FLAC::File* >(this)->fromDict(dict);
+  else if (dynamic_cast<const Ogg::Speex::File* >(this))
+        dynamic_cast< Ogg::Speex::File* >(this)->fromDict(dict);
+  else if (dynamic_cast<const Ogg::Vorbis::File* >(this))
+        dynamic_cast< Ogg::Vorbis::File* >(this)->fromDict(dict);
+  else
+    tag()->fromDict(dict);
+
+}
+
 ByteVector File::readBlock(ulong length)
 {
   return d->stream->readBlock(length);
index ee6f0488e1b4cb1df95f5504390cfb6b9228522a..75faf8a88029b2b316d12638d1d745ac1663b1f2 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "taglib_export.h"
 #include "taglib.h"
+#include "tag.h"
 #include "tbytevector.h"
 #include "tiostream.h"
 
@@ -76,6 +77,20 @@ namespace TagLib {
      */
     virtual Tag *tag() const = 0;
 
+    /*!
+     * Exports the tags of the file as dictionary mapping (human readable) tag
+     * names (Strings) to StringLists of tag values. Calls the according specialization
+     * in the File subclasses.
+     * Will be made virtual in future releases.
+     */
+    TagDict toDict() const;
+
+    /*!
+     * Sets the tags of this File to those specified by the given TagDict. Calls the
+     * according specialization method in the subclasses of File to do the translation
+     * into the format-specific details.
+     */
+    void fromDict(const TagDict &);
     /*!
      * Returns a pointer to this file's audio properties.  This should be
      * reimplemented in the concrete subclasses.  If no audio properties were