From 8826ae2484d10a6ec7818dd685d1024593fbad79 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Tue, 7 May 2013 12:01:51 +0900 Subject: [PATCH] Changed TagUnion to take the count of tags --- taglib/ape/apefile.cpp | 1 + taglib/flac/flacfile.cpp | 1 + taglib/mpc/mpcfile.cpp | 1 + taglib/mpeg/mpegfile.cpp | 1 + taglib/riff/wav/wavfile.cpp | 3 +- taglib/tagunion.cpp | 106 +++++++++++++---------------- taglib/tagunion.h | 16 ++--- taglib/trueaudio/trueaudiofile.cpp | 1 + taglib/wavpack/wavpackfile.cpp | 1 + 9 files changed, 62 insertions(+), 69 deletions(-) diff --git a/taglib/ape/apefile.cpp b/taglib/ape/apefile.cpp index 9abee2ad..4e4e0cb8 100644 --- a/taglib/ape/apefile.cpp +++ b/taglib/ape/apefile.cpp @@ -57,6 +57,7 @@ public: APELocation(-1), APESize(0), ID3v1Location(-1), + tag(2), properties(0), hasAPE(false), hasID3v1(false) {} diff --git a/taglib/flac/flacfile.cpp b/taglib/flac/flacfile.cpp index dda41f21..9e46bcfa 100644 --- a/taglib/flac/flacfile.cpp +++ b/taglib/flac/flacfile.cpp @@ -57,6 +57,7 @@ public: ID3v2Location(-1), ID3v2OriginalSize(0), ID3v1Location(-1), + tag(3), properties(0), flacStart(0), streamStart(0), diff --git a/taglib/mpc/mpcfile.cpp b/taglib/mpc/mpcfile.cpp index 4569fb5b..1b2908d1 100644 --- a/taglib/mpc/mpcfile.cpp +++ b/taglib/mpc/mpcfile.cpp @@ -52,6 +52,7 @@ public: ID3v2Header(0), ID3v2Location(-1), ID3v2Size(0), + tag(2), properties(0), scanned(false), hasAPE(false), diff --git a/taglib/mpeg/mpegfile.cpp b/taglib/mpeg/mpegfile.cpp index 295275fd..749a7749 100644 --- a/taglib/mpeg/mpegfile.cpp +++ b/taglib/mpeg/mpegfile.cpp @@ -55,6 +55,7 @@ public: APEFooterLocation(-1), APEOriginalSize(0), ID3v1Location(-1), + tag(3), hasID3v2(false), hasID3v1(false), hasAPE(false), diff --git a/taglib/riff/wav/wavfile.cpp b/taglib/riff/wav/wavfile.cpp index 3bea4823..6a391431 100644 --- a/taglib/riff/wav/wavfile.cpp +++ b/taglib/riff/wav/wavfile.cpp @@ -45,7 +45,8 @@ class RIFF::WAV::File::FilePrivate public: FilePrivate() : properties(0), - tagChunkID("ID3 ") + tagChunkID("ID3 "), + tag(2) { } diff --git a/taglib/tagunion.cpp b/taglib/tagunion.cpp index 6815a38f..cb45d692 100644 --- a/taglib/tagunion.cpp +++ b/taglib/tagunion.cpp @@ -29,95 +29,85 @@ using namespace TagLib; -#define stringUnion(method) \ - if(tag(0) && !tag(0)->method().isEmpty()) \ - return tag(0)->method(); \ - if(tag(1) && !tag(1)->method().isEmpty()) \ - return tag(1)->method(); \ - if(tag(2) && !tag(2)->method().isEmpty()) \ - return tag(2)->method(); \ - return String::null \ +namespace +{ + typedef std::vector > TagVector; + typedef TagVector::iterator TagIterator; + typedef TagVector::const_iterator TagConstIterator; +} -#define numberUnion(method) \ - if(tag(0) && tag(0)->method() > 0) \ - return tag(0)->method(); \ - if(tag(1) && tag(1)->method() > 0) \ - return tag(1)->method(); \ - if(tag(2) && tag(2)->method() > 0) \ - return tag(2)->method(); \ - return 0 +#define stringUnion(method) \ + for(TagConstIterator it = d->tags.begin(); it != d->tags.end(); ++it) { \ + String val = (*it) ? (*it)->method() : String::null; \ + if(!val.isEmpty()) \ + return val; \ + } \ + return String::null; -#define setUnion(method, value) \ - if(tag(0)) \ - tag(0)->set##method(value); \ - if(tag(1)) \ - tag(1)->set##method(value); \ - if(tag(2)) \ - tag(2)->set##method(value); \ +#define numberUnion(method) \ + for(TagConstIterator it = d->tags.begin(); it != d->tags.end(); ++it) { \ + uint val = (*it) ? (*it)->method() : 0; \ + if(val > 0) \ + return val; \ + } \ + return 0; + +#define setUnion(method, value) \ + for(TagIterator it = d->tags.begin(); it != d->tags.end(); ++it) { \ + if(*it) \ + (*it)->set##method(value); \ + } class TagUnion::TagUnionPrivate { public: - TagUnionPrivate() : tags(3, static_cast(0)) + TagUnionPrivate(size_t count) + : tags(count) { - } - ~TagUnionPrivate() - { - delete tags[0]; - delete tags[1]; - delete tags[2]; - } - - std::vector tags; + std::vector > tags; }; -TagUnion::TagUnion(Tag *first, Tag *second, Tag *third) +TagUnion::TagUnion(size_t count) + : d(new TagUnionPrivate(count)) { - d = new TagUnionPrivate; - - d->tags[0] = first; - d->tags[1] = second; - d->tags[2] = third; } TagUnion::~TagUnion() { - delete d; } -Tag *TagUnion::operator[](int index) const +Tag *TagUnion::operator[](size_t index) const { return tag(index); } -Tag *TagUnion::tag(int index) const +Tag *TagUnion::tag(size_t index) const { - return d->tags[index]; + return d->tags[index].get(); } -void TagUnion::set(int index, Tag *tag) +void TagUnion::set(size_t index, Tag *tag) { - delete d->tags[index]; - d->tags[index] = tag; + d->tags[index].reset(tag); } PropertyMap TagUnion::properties() const { - for(uint i = 0; i < 3; ++i) { - if(tag(i)) { - return tag(i)->properties(); - } + for(TagConstIterator it = d->tags.begin(); it != d->tags.end(); ++it) { + if(*it) + return (*it)->properties(); } + return PropertyMap(); } void TagUnion::removeUnsupportedProperties(const StringList &unsupported) { - for(uint i = 0; i < 3; ++i) { - if(tag(i)) - tag(i)->removeUnsupportedProperties(unsupported); + for(TagIterator it = d->tags.begin(); it != d->tags.end(); ++it) { + if(*it) + (*it)->removeUnsupportedProperties(unsupported); } } @@ -194,12 +184,10 @@ void TagUnion::setTrack(uint 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; + for(TagIterator it = d->tags.begin(); it != d->tags.end(); ++it) { + if(*it && !(*it)->isEmpty()) + return false; + } return true; } diff --git a/taglib/tagunion.h b/taglib/tagunion.h index f8399648..39c3e2af 100644 --- a/taglib/tagunion.h +++ b/taglib/tagunion.h @@ -43,18 +43,16 @@ namespace TagLib { enum AccessType { Read, Write }; /*! - * Creates a TagLib::Tag that is the union of \a first, \a second, and - * \a third. The TagUnion takes ownership of these tags and will handle - * their deletion. + * Creates a TagLib::Tag that is the union of \a count tags. */ - TagUnion(Tag *first = 0, Tag *second = 0, Tag *third = 0); + TagUnion(size_t count); virtual ~TagUnion(); - Tag *operator[](int index) const; - Tag *tag(int index) const; + Tag *operator[](size_t index) const; + Tag *tag(size_t index) const; - void set(int index, Tag *tag); + void set(size_t index, Tag *tag); virtual PropertyMap properties() const; @@ -77,7 +75,7 @@ namespace TagLib { virtual void setTrack(uint i); virtual bool isEmpty() const; - template T *access(int index, bool create) + template T *access(size_t index, bool create) { if(!create || tag(index)) return static_cast(tag(index)); @@ -91,7 +89,7 @@ namespace TagLib { TagUnion &operator=(const Tag &); class TagUnionPrivate; - TagUnionPrivate *d; + TAGLIB_SHARED_PTR d; }; } diff --git a/taglib/trueaudio/trueaudiofile.cpp b/taglib/trueaudio/trueaudiofile.cpp index e3902870..b21455a3 100644 --- a/taglib/trueaudio/trueaudiofile.cpp +++ b/taglib/trueaudio/trueaudiofile.cpp @@ -54,6 +54,7 @@ public: ID3v2Location(-1), ID3v2OriginalSize(0), ID3v1Location(-1), + tag(2), properties(0), hasID3v1(false), hasID3v2(false) {} diff --git a/taglib/wavpack/wavpackfile.cpp b/taglib/wavpack/wavpackfile.cpp index 94a1e7cd..b9d5f055 100644 --- a/taglib/wavpack/wavpackfile.cpp +++ b/taglib/wavpack/wavpackfile.cpp @@ -53,6 +53,7 @@ public: APELocation(-1), APESize(0), ID3v1Location(-1), + tag(2), properties(0), hasAPE(false), hasID3v1(false) {}