diff --git a/taglib/tagunion.cpp b/taglib/tagunion.cpp index 6480dcba..d38520ae 100644 --- a/taglib/tagunion.cpp +++ b/taglib/tagunion.cpp @@ -118,6 +118,46 @@ namespace TagLib } } + template + PropertyMap TagUnion::setProperties(const PropertyMap &properties) + { + //Record unassigned properties for each tag in the union + std::vector returnCandidates; + for (size_t i = 0; i < COUNT; ++i) { + if (d->tags[i]) + returnCandidates.insert(returnCandidates.end(), + d->tags[i]->setProperties(properties)); + } + + if (!returnCandidates.empty()) { + //Only one tag present, return its unassigned properties + if (returnCandidates.size() == 1) { + return returnCandidates.front(); + } + + //Multiple tags in union: + //if a property has been assigned in any member tag + //remove it from ignored properties to return + PropertyMap propertiesCopy(properties); + for (std::vector::iterator i = returnCandidates.begin(); + i != returnCandidates.end(); i++) { + for (PropertyMap::Iterator j = propertiesCopy.begin(); + j != propertiesCopy.end();) { + if (!i->contains(j->first)) { + j = propertiesCopy.erase(j->first).begin(); + } + else { + j++; + } + } + } + } + + //No assignments made by union member tags. + //Return input (this should not happen) + return properties; + } + template String TagUnion::title() const { diff --git a/taglib/tagunion.h b/taglib/tagunion.h index 6c608210..dc36806b 100644 --- a/taglib/tagunion.h +++ b/taglib/tagunion.h @@ -58,8 +58,8 @@ namespace TagLib { void set(size_t index, Tag *tag); virtual PropertyMap properties() const; - virtual void removeUnsupportedProperties(const StringList& properties); + virtual PropertyMap setProperties(const PropertyMap& properties); virtual String title() const; virtual String artist() const;