]> granicus.if.org Git - taglib/commitdiff
Add an (internal) TagUnion class. I'll pull out the reimplementation
authorScott Wheeler <wheeler@kde.org>
Thu, 31 Jan 2008 00:34:43 +0000 (00:34 +0000)
committerScott Wheeler <wheeler@kde.org>
Thu, 31 Jan 2008 00:34:43 +0000 (00:34 +0000)
of this in the next commits.

git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@768954 283d02a7-25f6-0310-bc7c-ecb5cbfe19da

taglib/CMakeLists.txt
taglib/Makefile.am
taglib/tagunion.cpp [new file with mode: 0644]
taglib/tagunion.h [new file with mode: 0644]

index b036185820df0b300fa5a18144de9fd4beb91ef9..1e16dd182f80f188d18d94be69900e94f56736e1 100644 (file)
@@ -132,6 +132,7 @@ SET(tag_LIB_SRCS ${mpeg_SRCS} ${id3v1_SRCS} ${id3v2_SRCS} ${frames_SRCS} ${ogg_S
                 ${vorbis_SRCS} ${oggflacs_SRCS} ${mpc_SRCS} ${ape_SRCS} ${toolkit_SRCS} ${flacs_SRCS}
                 ${wavpack_SRCS} ${speex_SRCS} ${trueaudio_SRCS}
                 tag.cpp
+                tagunion.cpp
                 fileref.cpp
                 audioproperties.cpp
 )
index e1e8e02f29aae90da2d7658e0cbd3cfa3e4f43de..f05ccebf1e72ba1a20c559f1c8842bfdb1d8e9ce 100644 (file)
@@ -16,7 +16,7 @@ INCLUDES = \
 
 lib_LTLIBRARIES = libtag.la
 
-libtag_la_SOURCES = tag.cpp fileref.cpp audioproperties.cpp
+libtag_la_SOURCES = tag.cpp tagunion.cpp fileref.cpp audioproperties.cpp
 taglib_include_HEADERS = tag.h fileref.h audioproperties.h taglib_export.h
 taglib_includedir = $(includedir)/taglib
 
diff --git a/taglib/tagunion.cpp b/taglib/tagunion.cpp
new file mode 100644 (file)
index 0000000..e5a651f
--- /dev/null
@@ -0,0 +1,180 @@
+/***************************************************************************
+    copyright            : (C) 2007 by Scott Wheeler
+    email                : wheeler@kde.org
+ ***************************************************************************/
+
+/***************************************************************************
+ *   This library is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU Lesser General Public License version   *
+ *   2.1 as published by the Free Software Foundation.                     *
+ *                                                                         *
+ *   This library is distributed in the hope that it will be useful, but   *
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
+ *   Lesser General Public License for more details.                       *
+ *                                                                         *
+ *   You should have received a copy of the GNU Lesser General Public      *
+ *   License along with this library; if not, write to the Free Software   *
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
+ *   USA                                                                   *
+ *                                                                         *
+ *   Alternatively, this file is available under the Mozilla Public        *
+ *   License Version 1.1.  You may obtain a copy of the License at         *
+ *   http://www.mozilla.org/MPL/                                           *
+ ***************************************************************************/
+
+#include "tagunion.h"
+
+using namespace TagLib;
+
+#define stringUnion(method)                                      \
+  if(d->tags[0] && !d->tags[0]->method().isEmpty())              \
+    return d->tags[0]->method();                                 \
+  if(d->tags[1] && !d->tags[1]->method().isEmpty())              \
+    return d->tags[0]->method();                                 \
+  if(d->tags[2] && !d->tags[2]->method().isEmpty())              \
+    return d->tags[0]->method();                                 \
+  return String::null                                            \
+
+#define numberUnion(method)                                      \
+  if(d->tags[0] && d->tags[0]->method() > 0)                     \
+    return d->tags[0]->method();                                 \
+  if(d->tags[0] && d->tags[0]->method() > 0)                     \
+    return d->tags[0]->method();                                 \
+  if(d->tags[0] && d->tags[0]->method() > 0)                     \
+    return d->tags[0]->method();                                 \
+  return 0
+
+#define setUnion(method, value)                                  \
+  if(d->tags[0])                                                 \
+    d->tags[0]->set##method(value);                              \
+  if(d->tags[1])                                                 \
+    d->tags[1]->set##method(value);                              \
+  if(d->tags[2])                                                 \
+    d->tags[2]->set##method(value);                              \
+
+class TagUnion::TagUnionPrivate
+{
+public:
+  TagUnionPrivate() : tags(3, static_cast<Tag *>(0))
+  {
+
+  }
+
+  ~TagUnionPrivate()
+  {
+    delete tags[0];
+    delete tags[1];
+    delete tags[2];
+  }
+
+  std::vector<Tag *> tags;
+};
+
+TagUnion::TagUnion(Tag *first, Tag *second, Tag *third)
+{
+  d = new TagUnionPrivate;
+
+  d->tags[0] = first;
+  d->tags[1] = second;
+  d->tags[2] = third;
+}
+
+TagUnion::~TagUnion()
+{
+  delete d;
+}
+
+Tag *TagUnion::tag(int index) const
+{
+  return d->tags[index];
+}
+
+void TagUnion::setTag(int index, Tag *tag)
+{
+  delete d->tags[index];
+  d->tags[index] = tag;
+}
+
+String TagUnion::title() const
+{
+  stringUnion(title);
+}
+
+String TagUnion::artist() const
+{
+  stringUnion(artist);
+}
+
+String TagUnion::album() const
+{
+  stringUnion(album);
+}
+
+String TagUnion::comment() const
+{
+  stringUnion(comment);
+}
+
+String TagUnion::genre() const
+{
+  stringUnion(genre);
+}
+
+TagLib::uint TagUnion::year() const
+{
+  numberUnion(year);
+}
+
+TagLib::uint TagUnion::track() const
+{
+  numberUnion(track);
+}
+
+void TagUnion::setTitle(const String &s)
+{
+  setUnion(Title, s);
+}
+
+void TagUnion::setArtist(const String &s)
+{
+  setUnion(Artist, s);
+}
+
+void TagUnion::setAlbum(const String &s)
+{
+  setUnion(Album, s);
+}
+
+void TagUnion::setComment(const String &s)
+{
+  setUnion(Comment, s);
+}
+
+void TagUnion::setGenre(const String &s)
+{
+  setUnion(Genre, s);
+}
+
+void TagUnion::setYear(uint i)
+{
+  setUnion(Year, i);
+}
+
+void TagUnion::setTrack(uint i)
+{
+  setUnion(Track, i);
+}
+
+bool TagUnion::isEmpty() const
+{
+  if(d->tags[0] && !d->tags[0]->isEmpty())
+    return false;
+  if(d->tags[1] && !d->tags[1]->isEmpty())
+    return false;
+  if(d->tags[2] && !d->tags[2]->isEmpty())
+    return false;
+
+  return true;
+}
+
diff --git a/taglib/tagunion.h b/taglib/tagunion.h
new file mode 100644 (file)
index 0000000..d944aef
--- /dev/null
@@ -0,0 +1,73 @@
+/***************************************************************************
+    copyright            : (C) 2007 by Scott Wheeler
+    email                : wheeler@kde.org
+ ***************************************************************************/
+
+/***************************************************************************
+ *   This library is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU Lesser General Public License version   *
+ *   2.1 as published by the Free Software Foundation.                     *
+ *                                                                         *
+ *   This library is distributed in the hope that it will be useful, but   *
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
+ *   Lesser General Public License for more details.                       *
+ *                                                                         *
+ *   You should have received a copy of the GNU Lesser General Public      *
+ *   License along with this library; if not, write to the Free Software   *
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
+ *   USA                                                                   *
+ *                                                                         *
+ *   Alternatively, this file is available under the Mozilla Public        *
+ *   License Version 1.1.  You may obtain a copy of the License at         *
+ *   http://www.mozilla.org/MPL/                                           *
+ ***************************************************************************/
+
+#ifndef TAGLIB_TAGUNION_H
+#define TAGLIB_TAGUNION_H
+
+#include "tag.h"
+
+namespace TagLib {
+
+  /*!
+   * \internal
+   */
+
+  class TagUnion : public Tag
+  {
+  public:
+
+    TagUnion(Tag *first = 0, Tag *second = 0, Tag *third = 0);
+    virtual ~TagUnion();
+
+    Tag *tag(int index) const;
+    void setTag(int index, Tag *tag);
+
+    virtual String title() const;
+    virtual String artist() const;
+    virtual String album() const;
+    virtual String comment() const;
+    virtual String genre() const;
+    virtual uint year() const;
+    virtual uint track() const;
+
+    virtual void setTitle(const String &s);
+    virtual void setArtist(const String &s);
+    virtual void setAlbum(const String &s);
+    virtual void setComment(const String &s);
+    virtual void setGenre(const String &s);
+    virtual void setYear(uint i);
+    virtual void setTrack(uint i);
+    virtual bool isEmpty() const;
+
+  private:
+    TagUnion(const Tag &);
+    TagUnion &operator=(const Tag &);
+
+    class TagUnionPrivate;
+    TagUnionPrivate *d;
+  };
+}
+
+#endif