diff --git a/taglib/asf/asftag.cpp b/taglib/asf/asftag.cpp index 13d92b5f..1389c122 100644 --- a/taglib/asf/asftag.cpp +++ b/taglib/asf/asftag.cpp @@ -160,6 +160,16 @@ ASF::AttributeListMap& ASF::Tag::attributeListMap() return d->attributeListMap; } +const ASF::AttributeListMap &ASF::Tag::attributeListMap() const +{ + return d->attributeListMap; +} + +bool ASF::Tag::contains(const String &key) const +{ + return d->attributeListMap.contains(key); +} + void ASF::Tag::removeItem(const String &key) { AttributeListMap::Iterator it = d->attributeListMap.find(key); @@ -167,6 +177,11 @@ void ASF::Tag::removeItem(const String &key) d->attributeListMap.erase(it); } +ASF::AttributeList ASF::Tag::attribute(const String &name) const +{ + return d->attributeListMap[name]; +} + void ASF::Tag::setAttribute(const String &name, const Attribute &attribute) { AttributeList value; @@ -174,6 +189,11 @@ void ASF::Tag::setAttribute(const String &name, const Attribute &attribute) d->attributeListMap.insert(name, value); } +void ASF::Tag::setAttribute(const String &name, const AttributeList &values) +{ + d->attributeListMap.insert(name, values); +} + void ASF::Tag::addAttribute(const String &name, const Attribute &attribute) { if(d->attributeListMap.contains(name)) { diff --git a/taglib/asf/asftag.h b/taglib/asf/asftag.h index f68579d8..8f322b18 100644 --- a/taglib/asf/asftag.h +++ b/taglib/asf/asftag.h @@ -152,24 +152,43 @@ namespace TagLib { virtual bool isEmpty() const; /*! - * Returns a reference to the item list map. This is an AttributeListMap of - * all of the items in the tag. - * - * This is the most powerfull structure for accessing the items of the tag. + * \deprecated */ AttributeListMap &attributeListMap(); + /*! + * Returns a reference to the item list map. This is an AttributeListMap of + * all of the items in the tag. + */ + const AttributeListMap &attributeListMap() const; + + /*! + * \return True if a value for \a attribute is currently set. + */ + bool contains(const String &name) const; + /*! * Removes the \a key attribute from the tag */ void removeItem(const String &name); + /*! + * \return The list of values for the key \a name, or an empty list if no + * values have been set. + */ + AttributeList attribute(const String &name) const; + /*! * Sets the \a key attribute to the value of \a attribute. If an attribute * with the \a key is already present, it will be replaced. */ void setAttribute(const String &name, const Attribute &attribute); + /*! + * Sets multiple \a values to the key \a name. + */ + void setAttribute(const String &name, const AttributeList &values); + /*! * Sets the \a key attribute to the value of \a attribute. If an attribute * with the \a key is already present, it will be added to the list. diff --git a/tests/test_asf.cpp b/tests/test_asf.cpp index 8610c24b..21c35324 100644 --- a/tests/test_asf.cpp +++ b/tests/test_asf.cpp @@ -52,7 +52,7 @@ public: ASF::AttributeList values; values.append("Foo"); values.append("Bar"); - f->tag()->attributeListMap()["WM/AlbumTitle"] = values; + f->tag()->setAttribute("WM/AlbumTitle", values); f->save(); delete f; @@ -67,22 +67,24 @@ public: string newname = copy.fileName(); ASF::File *f = new ASF::File(newname.c_str()); - CPPUNIT_ASSERT(!f->tag()->attributeListMap().contains("WM/TrackNumber")); + CPPUNIT_ASSERT(!f->tag()->contains("WM/TrackNumber")); f->tag()->setAttribute("WM/TrackNumber", (unsigned int)(123)); f->save(); delete f; f = new ASF::File(newname.c_str()); - CPPUNIT_ASSERT(f->tag()->attributeListMap().contains("WM/TrackNumber")); - CPPUNIT_ASSERT_EQUAL(ASF::Attribute::DWordType, f->tag()->attributeListMap()["WM/TrackNumber"].front().type()); + CPPUNIT_ASSERT(f->tag()->contains("WM/TrackNumber")); + CPPUNIT_ASSERT_EQUAL(ASF::Attribute::DWordType, + f->tag()->attribute("WM/TrackNumber").front().type()); CPPUNIT_ASSERT_EQUAL(TagLib::uint(123), f->tag()->track()); f->tag()->setTrack(234); f->save(); delete f; f = new ASF::File(newname.c_str()); - CPPUNIT_ASSERT(f->tag()->attributeListMap().contains("WM/TrackNumber")); - CPPUNIT_ASSERT_EQUAL(ASF::Attribute::UnicodeType, f->tag()->attributeListMap()["WM/TrackNumber"].front().type()); + CPPUNIT_ASSERT(f->tag()->contains("WM/TrackNumber")); + CPPUNIT_ASSERT_EQUAL(ASF::Attribute::UnicodeType, + f->tag()->attribute("WM/TrackNumber").front().type()); CPPUNIT_ASSERT_EQUAL(TagLib::uint(234), f->tag()->track()); delete f; } @@ -93,16 +95,14 @@ public: string newname = copy.fileName(); ASF::File *f = new ASF::File(newname.c_str()); - ASF::AttributeList values; ASF::Attribute attr("Foo"); attr.setStream(43); - values.append(attr); - f->tag()->attributeListMap()["WM/AlbumTitle"] = values; + f->tag()->setAttribute("WM/AlbumTitle", attr); f->save(); delete f; f = new ASF::File(newname.c_str()); - CPPUNIT_ASSERT_EQUAL(43, f->tag()->attributeListMap()["WM/AlbumTitle"][0].stream()); + CPPUNIT_ASSERT_EQUAL(43, f->tag()->attribute("WM/AlbumTitle").front().stream()); delete f; } @@ -112,18 +112,16 @@ public: string newname = copy.fileName(); ASF::File *f = new ASF::File(newname.c_str()); - ASF::AttributeList values; ASF::Attribute attr("Foo"); attr.setStream(32); attr.setLanguage(56); - values.append(attr); - f->tag()->attributeListMap()["WM/AlbumTitle"] = values; + f->tag()->setAttribute("WM/AlbumTitle", attr); f->save(); delete f; f = new ASF::File(newname.c_str()); - CPPUNIT_ASSERT_EQUAL(32, f->tag()->attributeListMap()["WM/AlbumTitle"][0].stream()); - CPPUNIT_ASSERT_EQUAL(56, f->tag()->attributeListMap()["WM/AlbumTitle"][0].language()); + CPPUNIT_ASSERT_EQUAL(32, f->tag()->attribute("WM/AlbumTitle").front().stream()); + CPPUNIT_ASSERT_EQUAL(56, f->tag()->attribute("WM/AlbumTitle").front().language()); delete f; } @@ -133,15 +131,14 @@ public: string newname = copy.fileName(); ASF::File *f = new ASF::File(newname.c_str()); - ASF::AttributeList values; ASF::Attribute attr(ByteVector(70000, 'x')); - values.append(attr); - f->tag()->attributeListMap()["WM/Blob"] = values; + f->tag()->setAttribute("WM/Blob", attr); f->save(); delete f; f = new ASF::File(newname.c_str()); - CPPUNIT_ASSERT_EQUAL(ByteVector(70000, 'x'), f->tag()->attributeListMap()["WM/Blob"][0].toByteVector()); + CPPUNIT_ASSERT_EQUAL(ByteVector(70000, 'x'), + f->tag()->attribute("WM/Blob").front().toByteVector()); delete f; } @@ -151,20 +148,17 @@ public: string newname = copy.fileName(); ASF::File *f = new ASF::File(newname.c_str()); - ASF::AttributeList values; ASF::Picture picture; picture.setMimeType("image/jpeg"); picture.setType(ASF::Picture::FrontCover); picture.setDescription("description"); picture.setPicture("data"); - ASF::Attribute attr(picture); - values.append(attr); - f->tag()->attributeListMap()["WM/Picture"] = values; + f->tag()->setAttribute("WM/Picture", picture); f->save(); delete f; f = new ASF::File(newname.c_str()); - ASF::AttributeList values2 = f->tag()->attributeListMap()["WM/Picture"]; + ASF::AttributeList values2 = f->tag()->attribute("WM/Picture"); CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), values2.size()); ASF::Attribute attr2 = values2.front(); ASF::Picture picture2 = attr2.toPicture(); @@ -195,12 +189,12 @@ public: picture2.setDescription("back cover"); picture2.setPicture("PNG data"); values.append(ASF::Attribute(picture2)); - f->tag()->attributeListMap()["WM/Picture"] = values; + f->tag()->setAttribute("WM/Picture", values); f->save(); delete f; f = new ASF::File(newname.c_str()); - ASF::AttributeList values2 = f->tag()->attributeListMap()["WM/Picture"]; + ASF::AttributeList values2 = f->tag()->attribute("WM/Picture"); CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), values2.size()); ASF::Picture picture3 = values2[1].toPicture(); CPPUNIT_ASSERT(picture3.isValid()); @@ -220,7 +214,7 @@ public: void testProperties() { ASF::File f(TEST_FILE_PATH_C("silence-1.wma")); - + PropertyMap tags = f.properties(); tags["TRACKNUMBER"] = StringList("2"); @@ -234,19 +228,19 @@ public: CPPUNIT_ASSERT_EQUAL(String("Foo Bar"), f.tag()->artist()); CPPUNIT_ASSERT_EQUAL(StringList("Foo Bar"), tags["ARTIST"]); - CPPUNIT_ASSERT(f.tag()->attributeListMap().contains("WM/BeatsPerMinute")); + CPPUNIT_ASSERT(f.tag()->contains("WM/BeatsPerMinute")); CPPUNIT_ASSERT_EQUAL(1u, f.tag()->attributeListMap()["WM/BeatsPerMinute"].size()); - CPPUNIT_ASSERT_EQUAL(String("123"), f.tag()->attributeListMap()["WM/BeatsPerMinute"].front().toString()); + CPPUNIT_ASSERT_EQUAL(String("123"), f.tag()->attribute("WM/BeatsPerMinute").front().toString()); CPPUNIT_ASSERT_EQUAL(StringList("123"), tags["BPM"]); - CPPUNIT_ASSERT(f.tag()->attributeListMap().contains("WM/TrackNumber")); + CPPUNIT_ASSERT(f.tag()->contains("WM/TrackNumber")); CPPUNIT_ASSERT_EQUAL(1u, f.tag()->attributeListMap()["WM/TrackNumber"].size()); - CPPUNIT_ASSERT_EQUAL(String("2"), f.tag()->attributeListMap()["WM/TrackNumber"].front().toString()); + CPPUNIT_ASSERT_EQUAL(String("2"), f.tag()->attribute("WM/TrackNumber").front().toString()); CPPUNIT_ASSERT_EQUAL(StringList("2"), tags["TRACKNUMBER"]); - CPPUNIT_ASSERT(f.tag()->attributeListMap().contains("WM/PartOfSet")); + CPPUNIT_ASSERT(f.tag()->contains("WM/PartOfSet")); CPPUNIT_ASSERT_EQUAL(1u, f.tag()->attributeListMap()["WM/PartOfSet"].size()); - CPPUNIT_ASSERT_EQUAL(String("3"), f.tag()->attributeListMap()["WM/PartOfSet"].front().toString()); + CPPUNIT_ASSERT_EQUAL(String("3"), f.tag()->attribute("WM/PartOfSet").front().toString()); CPPUNIT_ASSERT_EQUAL(StringList("3"), tags["DISCNUMBER"]); }