From 63922f2676c0a19a82ed99a3641851a29645eafa Mon Sep 17 00:00:00 2001 From: Urs Fleisch Date: Sat, 15 Jul 2023 20:53:49 +0200 Subject: [PATCH] Avoid unnecessary detaching of containers If only a constant iterator is needed, make the container const if possible, otherwise use cbegin() and cend() to get a constant iterator without detaching the container. These fixes are needed so that `auto` can deduce the correct iterator type. --- bindings/c/tag_c.cpp | 2 +- examples/tagreader.cpp | 4 +-- examples/tagwriter.cpp | 4 +-- taglib/ape/apeitem.cpp | 8 ++--- taglib/ape/apetag.cpp | 8 ++--- taglib/asf/asffile.cpp | 4 +-- taglib/asf/asftag.cpp | 6 ++-- taglib/fileref.cpp | 8 ++--- taglib/flac/flacfile.cpp | 6 ++-- taglib/mod/modtag.cpp | 2 +- taglib/mp4/mp4atom.cpp | 10 +++--- taglib/mp4/mp4tag.cpp | 34 +++++++++---------- taglib/mpeg/id3v2/frames/chapterframe.cpp | 12 +++---- taglib/mpeg/id3v2/frames/commentsframe.cpp | 2 +- .../id3v2/frames/eventtimingcodesframe.cpp | 4 +-- .../mpeg/id3v2/frames/relativevolumeframe.cpp | 8 ++--- .../id3v2/frames/synchronizedlyricsframe.cpp | 8 ++--- .../id3v2/frames/tableofcontentsframe.cpp | 16 ++++----- .../id3v2/frames/textidentificationframe.cpp | 14 ++++---- .../frames/uniquefileidentifierframe.cpp | 2 +- .../frames/unsynchronizedlyricsframe.cpp | 2 +- taglib/mpeg/id3v2/frames/urllinkframe.cpp | 2 +- taglib/mpeg/id3v2/id3v2framefactory.cpp | 4 +-- taglib/mpeg/id3v2/id3v2header.cpp | 2 +- taglib/mpeg/id3v2/id3v2tag.cpp | 14 ++++---- taglib/ogg/oggfile.cpp | 6 ++-- taglib/ogg/oggpage.cpp | 6 ++-- taglib/ogg/oggpageheader.cpp | 4 +-- taglib/ogg/xiphcomment.cpp | 18 +++++----- taglib/riff/riffutils.h | 2 ++ taglib/riff/wav/infotag.cpp | 4 +-- taglib/tag.cpp | 2 +- taglib/toolkit/tbytevector.cpp | 10 ++++++ taglib/toolkit/tbytevector.h | 10 ++++++ taglib/toolkit/tlist.h | 17 ++++++++++ taglib/toolkit/tlist.tcc | 18 ++++++++++ taglib/toolkit/tmap.h | 12 +++++++ taglib/toolkit/tmap.tcc | 12 +++++++ taglib/toolkit/tpropertymap.cpp | 2 +- taglib/toolkit/tstring.cpp | 10 ++++++ taglib/toolkit/tstring.h | 11 ++++++ taglib/xm/xmfile.cpp | 4 +-- 42 files changed, 218 insertions(+), 116 deletions(-) diff --git a/bindings/c/tag_c.cpp b/bindings/c/tag_c.cpp index 21875520..7ffb378f 100644 --- a/bindings/c/tag_c.cpp +++ b/bindings/c/tag_c.cpp @@ -259,7 +259,7 @@ void taglib_tag_free_strings() if(!stringManagementEnabled) return; - for(List::ConstIterator it = strings.begin(); it != strings.end(); ++it) + for(List::ConstIterator it = strings.cbegin(); it != strings.cend(); ++it) free(*it); strings.clear(); } diff --git a/examples/tagreader.cpp b/examples/tagreader.cpp index 62524d3e..1c67f097 100644 --- a/examples/tagreader.cpp +++ b/examples/tagreader.cpp @@ -56,14 +56,14 @@ int main(int argc, char *argv[]) TagLib::PropertyMap tags = f.file()->properties(); unsigned int longest = 0; - for(TagLib::PropertyMap::ConstIterator i = tags.begin(); i != tags.end(); ++i) { + for(TagLib::PropertyMap::ConstIterator i = tags.cbegin(); i != tags.cend(); ++i) { if (i->first.size() > longest) { longest = i->first.size(); } } cout << "-- TAG (properties) --" << endl; - for(TagLib::PropertyMap::ConstIterator i = tags.begin(); i != tags.end(); ++i) { + for(TagLib::PropertyMap::ConstIterator i = tags.cbegin(); i != tags.cend(); ++i) { for(TagLib::StringList::ConstIterator j = i->second.begin(); j != i->second.end(); ++j) { cout << left << std::setw(longest) << i->first << " - " << '"' << *j << '"' << endl; } diff --git a/examples/tagwriter.cpp b/examples/tagwriter.cpp index ed8b0d7a..d935f36b 100644 --- a/examples/tagwriter.cpp +++ b/examples/tagwriter.cpp @@ -118,7 +118,7 @@ int main(int argc, char *argv[]) TagLib::String value = argv[i + 1]; TagLib::List::ConstIterator it; - for(it = fileList.begin(); it != fileList.end(); ++it) { + for(it = fileList.cbegin(); it != fileList.cend(); ++it) { TagLib::Tag *t = (*it).tag(); @@ -178,7 +178,7 @@ int main(int argc, char *argv[]) } TagLib::List::ConstIterator it; - for(it = fileList.begin(); it != fileList.end(); ++it) + for(it = fileList.cbegin(); it != fileList.cend(); ++it) (*it).file()->save(); return 0; diff --git a/taglib/ape/apeitem.cpp b/taglib/ape/apeitem.cpp index 40b2db37..7e4a91e3 100644 --- a/taglib/ape/apeitem.cpp +++ b/taglib/ape/apeitem.cpp @@ -181,11 +181,11 @@ int APE::Item::size() const switch(d->type) { case Text: if(!d->text.isEmpty()) { - StringList::ConstIterator it = d->text.begin(); + StringList::ConstIterator it = d->text.cbegin(); result += it->data(String::UTF8).size(); it++; - for(; it != d->text.end(); ++it) + for(; it != d->text.cend(); ++it) result += 1 + it->data(String::UTF8).size(); } break; @@ -268,11 +268,11 @@ ByteVector APE::Item::render() const return data; if(d->type == Text) { - StringList::ConstIterator it = d->text.begin(); + StringList::ConstIterator it = d->text.cbegin(); value.append(it->data(String::UTF8)); it++; - for(; it != d->text.end(); ++it) { + for(; it != d->text.cend(); ++it) { value.append('\0'); value.append(it->data(String::UTF8)); } diff --git a/taglib/ape/apetag.cpp b/taglib/ape/apetag.cpp index 51201015..ae74e021 100644 --- a/taglib/ape/apetag.cpp +++ b/taglib/ape/apetag.cpp @@ -265,13 +265,13 @@ PropertyMap APE::Tag::setProperties(const PropertyMap &origProps) toRemove.append(remIt->first); } - for(StringList::ConstIterator removeIt = toRemove.begin(); removeIt != toRemove.end(); removeIt++) + for(StringList::ConstIterator removeIt = toRemove.cbegin(); removeIt != toRemove.cend(); removeIt++) removeItem(*removeIt); // now sync in the "forward direction" - PropertyMap::ConstIterator it = properties.begin(); + PropertyMap::ConstIterator it = properties.cbegin(); PropertyMap invalid; - for(; it != properties.end(); ++it) { + for(; it != properties.cend(); ++it) { const String &tagName = it->first; if(!checkKey(tagName)) invalid.insert(it->first, it->second); @@ -382,7 +382,7 @@ ByteVector APE::Tag::render() const ByteVector data; unsigned int itemCount = 0; - for(ItemListMap::ConstIterator it = d->itemListMap.begin(); it != d->itemListMap.end(); ++it) { + for(ItemListMap::ConstIterator it = d->itemListMap.cbegin(); it != d->itemListMap.cend(); ++it) { data.append(it->second.render()); itemCount++; } diff --git a/taglib/asf/asffile.cpp b/taglib/asf/asffile.cpp index ef11041a..967faae2 100644 --- a/taglib/asf/asffile.cpp +++ b/taglib/asf/asffile.cpp @@ -409,7 +409,7 @@ void ASF::File::FilePrivate::HeaderExtensionObject::parse(ASF::File *file, unsig ByteVector ASF::File::FilePrivate::HeaderExtensionObject::render(ASF::File *file) { data.clear(); - for(List::ConstIterator it = objects.begin(); it != objects.end(); ++it) { + for(List::ConstIterator it = objects.cbegin(); it != objects.cend(); ++it) { data.append((*it)->render(file)); } data = ByteVector("\x11\xD2\xD3\xAB\xBA\xA9\xcf\x11\x8E\xE6\x00\xC0\x0C\x20\x53\x65\x06\x00", 18) + ByteVector::fromUInt(data.size(), false) + data; @@ -601,7 +601,7 @@ bool ASF::File::save() } ByteVector data; - for(List::ConstIterator it = d->objects.begin(); it != d->objects.end(); ++it) { + for(List::ConstIterator it = d->objects.cbegin(); it != d->objects.cend(); ++it) { data.append((*it)->render(this)); } diff --git a/taglib/asf/asftag.cpp b/taglib/asf/asftag.cpp index e2a9ed80..22148f7e 100644 --- a/taglib/asf/asftag.cpp +++ b/taglib/asf/asftag.cpp @@ -287,8 +287,8 @@ PropertyMap ASF::Tag::properties() const props["COMMENT"] = d->comment; } - ASF::AttributeListMap::ConstIterator it = d->attributeListMap.begin(); - for(; it != d->attributeListMap.end(); ++it) { + ASF::AttributeListMap::ConstIterator it = d->attributeListMap.cbegin(); + for(; it != d->attributeListMap.cend(); ++it) { const String key = translateKey(it->first); if(!key.isEmpty()) { AttributeList::ConstIterator it2 = it->second.begin(); @@ -327,7 +327,7 @@ PropertyMap ASF::Tag::setProperties(const PropertyMap &props) } } - PropertyMap origProps = properties(); + const PropertyMap origProps = properties(); PropertyMap::ConstIterator it = origProps.begin(); for(; it != origProps.end(); ++it) { if(!props.contains(it->first) || props[it->first].isEmpty()) { diff --git a/taglib/fileref.cpp b/taglib/fileref.cpp index 6e8f9e31..35e03eeb 100644 --- a/taglib/fileref.cpp +++ b/taglib/fileref.cpp @@ -74,8 +74,8 @@ namespace if(::strlen(fileName) == 0) return nullptr; #endif - ResolverList::ConstIterator it = fileTypeResolvers.begin(); - for(; it != fileTypeResolvers.end(); ++it) { + ResolverList::ConstIterator it = fileTypeResolvers.cbegin(); + for(; it != fileTypeResolvers.cend(); ++it) { File *file = (*it)->createFile(fileName, readAudioProperties, audioPropertiesStyle); if(file) return file; @@ -87,8 +87,8 @@ namespace File *detectByResolvers(IOStream* stream, bool readAudioProperties, AudioProperties::ReadStyle audioPropertiesStyle) { - for(ResolverList::ConstIterator it = fileTypeResolvers.begin(); - it != fileTypeResolvers.end(); ++it) { + for(ResolverList::ConstIterator it = fileTypeResolvers.cbegin(); + it != fileTypeResolvers.cend(); ++it) { if(const FileRef::StreamTypeResolver *streamResolver = dynamic_cast(*it)) { if(File *file = streamResolver->createFileFromStream( diff --git a/taglib/flac/flacfile.cpp b/taglib/flac/flacfile.cpp index bde1cd1b..efd1159a 100644 --- a/taglib/flac/flacfile.cpp +++ b/taglib/flac/flacfile.cpp @@ -47,7 +47,7 @@ namespace { typedef List BlockList; typedef BlockList::Iterator BlockIterator; - typedef BlockList::Iterator BlockConstIterator; + typedef BlockList::ConstIterator BlockConstIterator; enum { FlacXiphIndex = 0, FlacID3v2Index = 1, FlacID3v1Index = 2 }; @@ -209,7 +209,7 @@ bool FLAC::File::save() // Render data for the metadata blocks ByteVector data; - for(BlockConstIterator it = d->blocks.begin(); it != d->blocks.end(); ++it) { + for(BlockConstIterator it = d->blocks.cbegin(); it != d->blocks.cend(); ++it) { ByteVector blockData = (*it)->render(); ByteVector blockHeader = ByteVector::fromUInt(blockData.size()); blockHeader[0] = (*it)->code(); @@ -333,7 +333,7 @@ Ogg::XiphComment *FLAC::File::xiphComment(bool create) List FLAC::File::pictureList() { List pictures; - for(BlockConstIterator it = d->blocks.begin(); it != d->blocks.end(); ++it) { + for(BlockConstIterator it = d->blocks.cbegin(); it != d->blocks.cend(); ++it) { Picture *picture = dynamic_cast(*it); if(picture) { pictures.append(picture); diff --git a/taglib/mod/modtag.cpp b/taglib/mod/modtag.cpp index 0495045b..1c8bff2c 100644 --- a/taglib/mod/modtag.cpp +++ b/taglib/mod/modtag.cpp @@ -163,7 +163,7 @@ PropertyMap Mod::Tag::setProperties(const PropertyMap &origProps) // for each tag that has been set above, remove the first entry in the corresponding // value list. The others will be returned as unsupported by this format. - for(StringList::ConstIterator it = oneValueSet.begin(); it != oneValueSet.end(); ++it) { + for(StringList::ConstIterator it = oneValueSet.cbegin(); it != oneValueSet.cend(); ++it) { if(properties[*it].size() == 1) properties.erase(*it); else diff --git a/taglib/mp4/mp4atom.cpp b/taglib/mp4/mp4atom.cpp index 2d57deb6..ec9250e6 100644 --- a/taglib/mp4/mp4atom.cpp +++ b/taglib/mp4/mp4atom.cpp @@ -139,7 +139,7 @@ MP4::Atom::find(const char *name1, const char *name2, const char *name3, const c if(name1 == nullptr) { return this; } - for(AtomList::ConstIterator it = children.begin(); it != children.end(); ++it) { + for(AtomList::ConstIterator it = children.cbegin(); it != children.cend(); ++it) { if((*it)->name == name1) { return (*it)->find(name2, name3, name4); } @@ -151,7 +151,7 @@ MP4::AtomList MP4::Atom::findall(const char *name, bool recursive) { MP4::AtomList result; - for(AtomList::ConstIterator it = children.begin(); it != children.end(); ++it) { + for(AtomList::ConstIterator it = children.cbegin(); it != children.cend(); ++it) { if((*it)->name == name) { result.append(*it); } @@ -169,7 +169,7 @@ MP4::Atom::path(MP4::AtomList &path, const char *name1, const char *name2, const if(name1 == nullptr) { return true; } - for(AtomList::ConstIterator it = children.begin(); it != children.end(); ++it) { + for(AtomList::ConstIterator it = children.cbegin(); it != children.cend(); ++it) { if((*it)->name == name1) { return (*it)->path(path, name2, name3); } @@ -199,7 +199,7 @@ MP4::Atoms::~Atoms() MP4::Atom * MP4::Atoms::find(const char *name1, const char *name2, const char *name3, const char *name4) { - for(AtomList::ConstIterator it = atoms.begin(); it != atoms.end(); ++it) { + for(AtomList::ConstIterator it = atoms.cbegin(); it != atoms.cend(); ++it) { if((*it)->name == name1) { return (*it)->find(name2, name3, name4); } @@ -211,7 +211,7 @@ MP4::AtomList MP4::Atoms::path(const char *name1, const char *name2, const char *name3, const char *name4) { MP4::AtomList path; - for(AtomList::ConstIterator it = atoms.begin(); it != atoms.end(); ++it) { + for(AtomList::ConstIterator it = atoms.cbegin(); it != atoms.cend(); ++it) { if((*it)->name == name1) { if(!(*it)->path(path, name2, name3, name4)) { path.clear(); diff --git a/taglib/mp4/mp4tag.cpp b/taglib/mp4/mp4tag.cpp index 590ace97..08564fdc 100644 --- a/taglib/mp4/mp4tag.cpp +++ b/taglib/mp4/mp4tag.cpp @@ -61,7 +61,7 @@ MP4::Tag::Tag(TagLib::File *file, MP4::Atoms *atoms) : return; } - for(AtomList::ConstIterator it = ilst->children.begin(); it != ilst->children.end(); ++it) { + for(AtomList::ConstIterator it = ilst->children.cbegin(); it != ilst->children.cend(); ++it) { MP4::Atom *atom = *it; file->seek(atom->offset + 8); if(atom->name == "----") { @@ -164,7 +164,7 @@ MP4::Tag::parseData2(const MP4::Atom *atom, int expectedFlags, bool freeForm) ByteVectorList MP4::Tag::parseData(const MP4::Atom *atom, int expectedFlags, bool freeForm) { - AtomDataList data = parseData2(atom, expectedFlags, freeForm); + const AtomDataList data = parseData2(atom, expectedFlags, freeForm); ByteVectorList result; for(AtomDataList::ConstIterator it = data.begin(); it != data.end(); ++it) { result.append(it->data); @@ -244,7 +244,7 @@ MP4::Tag::parseBool(const MP4::Atom *atom) void MP4::Tag::parseText(const MP4::Atom *atom, int expectedFlags) { - ByteVectorList data = parseData(atom, expectedFlags); + const ByteVectorList data = parseData(atom, expectedFlags); if(!data.isEmpty()) { StringList value; for(ByteVectorList::ConstIterator it = data.begin(); it != data.end(); ++it) { @@ -257,7 +257,7 @@ MP4::Tag::parseText(const MP4::Atom *atom, int expectedFlags) void MP4::Tag::parseFreeForm(const MP4::Atom *atom) { - AtomDataList data = parseData2(atom, -1, true); + const AtomDataList data = parseData2(atom, -1, true); if(data.size() > 2) { AtomDataList::ConstIterator itBegin = data.begin(); @@ -418,7 +418,7 @@ ByteVector MP4::Tag::renderText(const ByteVector &name, const MP4::Item &item, int flags) const { ByteVectorList data; - StringList value = item.toStringList(); + const StringList value = item.toStringList(); for(StringList::ConstIterator it = value.begin(); it != value.end(); ++it) { data.append(it->data(String::UTF8)); } @@ -429,7 +429,7 @@ ByteVector MP4::Tag::renderCovr(const ByteVector &name, const MP4::Item &item) const { ByteVector data; - MP4::CoverArtList value = item.toCoverArtList(); + const MP4::CoverArtList value = item.toCoverArtList(); for(MP4::CoverArtList::ConstIterator it = value.begin(); it != value.end(); ++it) { data.append(renderAtom("data", ByteVector::fromUInt(it->format()) + ByteVector(4, '\0') + it->data())); @@ -458,13 +458,13 @@ MP4::Tag::renderFreeForm(const String &name, const MP4::Item &item) const } } if(type == TypeUTF8) { - StringList value = item.toStringList(); + const StringList value = item.toStringList(); for(StringList::ConstIterator it = value.begin(); it != value.end(); ++it) { data.append(renderAtom("data", ByteVector::fromUInt(type) + ByteVector(4, '\0') + it->data(String::UTF8))); } } else { - ByteVectorList value = item.toByteVectorList(); + const ByteVectorList value = item.toByteVectorList(); for(ByteVectorList::ConstIterator it = value.begin(); it != value.end(); ++it) { data.append(renderAtom("data", ByteVector::fromUInt(type) + ByteVector(4, '\0') + *it)); } @@ -476,7 +476,7 @@ bool MP4::Tag::save() { ByteVector data; - for(MP4::ItemMap::ConstIterator it = d->items.begin(); it != d->items.end(); ++it) { + for(MP4::ItemMap::ConstIterator it = d->items.cbegin(); it != d->items.cend(); ++it) { const String name = it->first; if(name.startsWith("----")) { data.append(renderFreeForm(name, it->second)); @@ -587,7 +587,7 @@ MP4::Tag::updateOffsets(offset_t delta, offset_t offset) { MP4::Atom *moov = d->atoms->find("moov"); if(moov) { - MP4::AtomList stco = moov->findall("stco", true); + const MP4::AtomList stco = moov->findall("stco", true); for(MP4::AtomList::ConstIterator it = stco.begin(); it != stco.end(); ++it) { MP4::Atom *atom = *it; if(atom->offset > offset) { @@ -608,7 +608,7 @@ MP4::Tag::updateOffsets(offset_t delta, offset_t offset) } } - MP4::AtomList co64 = moov->findall("co64", true); + const MP4::AtomList co64 = moov->findall("co64", true); for(MP4::AtomList::ConstIterator it = co64.begin(); it != co64.end(); ++it) { MP4::Atom *atom = *it; if(atom->offset > offset) { @@ -632,7 +632,7 @@ MP4::Tag::updateOffsets(offset_t delta, offset_t offset) MP4::Atom *moof = d->atoms->find("moof"); if(moof) { - MP4::AtomList tfhd = moof->findall("tfhd", true); + const MP4::AtomList tfhd = moof->findall("tfhd", true); for(MP4::AtomList::ConstIterator it = tfhd.begin(); it != tfhd.end(); ++it) { MP4::Atom *atom = *it; if(atom->offset > offset) { @@ -689,10 +689,10 @@ MP4::Tag::saveExisting(ByteVector data, const AtomList &path) offset_t length = ilst->length; MP4::Atom *meta = *(--it); - AtomList::ConstIterator index = meta->children.find(ilst); + AtomList::ConstIterator index = meta->children.cfind(ilst); // check if there is an atom before 'ilst', and possibly use it as padding - if(index != meta->children.begin()) { + if(index != meta->children.cbegin()) { AtomList::ConstIterator prevIndex = index; prevIndex--; MP4::Atom *prev = *prevIndex; @@ -704,7 +704,7 @@ MP4::Tag::saveExisting(ByteVector data, const AtomList &path) // check if there is an atom after 'ilst', and possibly use it as padding AtomList::ConstIterator nextIndex = index; nextIndex++; - if(nextIndex != meta->children.end()) { + if(nextIndex != meta->children.cend()) { MP4::Atom *next = *nextIndex; if(next->name == "free") { length += next->length; @@ -986,7 +986,7 @@ namespace PropertyMap MP4::Tag::properties() const { PropertyMap props; - for(MP4::ItemMap::ConstIterator it = d->items.begin(); it != d->items.end(); ++it) { + for(MP4::ItemMap::ConstIterator it = d->items.cbegin(); it != d->items.cend(); ++it) { const String key = translateKey(it->first); if(!key.isEmpty()) { if(key == "TRACKNUMBER" || key == "DISCNUMBER") { @@ -1031,7 +1031,7 @@ PropertyMap MP4::Tag::setProperties(const PropertyMap &props) } } - PropertyMap origProps = properties(); + const PropertyMap origProps = properties(); for(PropertyMap::ConstIterator it = origProps.begin(); it != origProps.end(); ++it) { if(!props.contains(it->first) || props[it->first].isEmpty()) { d->items.erase(reverseKeyMap[it->first]); diff --git a/taglib/mpeg/id3v2/frames/chapterframe.cpp b/taglib/mpeg/id3v2/frames/chapterframe.cpp index 0794cdf9..e8477684 100644 --- a/taglib/mpeg/id3v2/frames/chapterframe.cpp +++ b/taglib/mpeg/id3v2/frames/chapterframe.cpp @@ -186,7 +186,7 @@ void ChapterFrame::removeEmbeddedFrame(Frame *frame, bool del) void ChapterFrame::removeEmbeddedFrames(const ByteVector &id) { - FrameList l = d->embeddedFrameListMap[id]; + const FrameList l = d->embeddedFrameListMap[id]; for(FrameList::ConstIterator it = l.begin(); it != l.end(); ++it) removeEmbeddedFrame(*it, true); } @@ -205,8 +205,8 @@ String ChapterFrame::toString() const if(!d->embeddedFrameList.isEmpty()) { StringList frameIDs; - for(FrameList::ConstIterator it = d->embeddedFrameList.begin(); - it != d->embeddedFrameList.end(); ++it) + for(FrameList::ConstIterator it = d->embeddedFrameList.cbegin(); + it != d->embeddedFrameList.cend(); ++it) frameIDs.append((*it)->frameID()); s += ", sub-frames: [ " + frameIDs.toString(", ") + " ]"; } @@ -227,8 +227,8 @@ ChapterFrame *ChapterFrame::findByElementID(const ID3v2::Tag *tag, const ByteVec { ID3v2::FrameList comments = tag->frameList("CHAP"); - for(ID3v2::FrameList::ConstIterator it = comments.begin(); - it != comments.end(); + for(ID3v2::FrameList::ConstIterator it = comments.cbegin(); + it != comments.cend(); ++it) { ChapterFrame *frame = dynamic_cast(*it); @@ -293,7 +293,7 @@ ByteVector ChapterFrame::renderFields() const data.append(ByteVector::fromUInt(d->endTime, true)); data.append(ByteVector::fromUInt(d->startOffset, true)); data.append(ByteVector::fromUInt(d->endOffset, true)); - FrameList l = d->embeddedFrameList; + const FrameList l = d->embeddedFrameList; for(FrameList::ConstIterator it = l.begin(); it != l.end(); ++it) { (*it)->header()->setVersion(header()->version()); data.append((*it)->render()); diff --git a/taglib/mpeg/id3v2/frames/commentsframe.cpp b/taglib/mpeg/id3v2/frames/commentsframe.cpp index 07fa1502..1e3af40f 100644 --- a/taglib/mpeg/id3v2/frames/commentsframe.cpp +++ b/taglib/mpeg/id3v2/frames/commentsframe.cpp @@ -125,7 +125,7 @@ PropertyMap CommentsFrame::asProperties() const CommentsFrame *CommentsFrame::findByDescription(const ID3v2::Tag *tag, const String &d) // static { - ID3v2::FrameList comments = tag->frameList("COMM"); + const ID3v2::FrameList comments = tag->frameList("COMM"); for(ID3v2::FrameList::ConstIterator it = comments.begin(); it != comments.end(); diff --git a/taglib/mpeg/id3v2/frames/eventtimingcodesframe.cpp b/taglib/mpeg/id3v2/frames/eventtimingcodesframe.cpp index 4d1a5d8c..062ea46c 100644 --- a/taglib/mpeg/id3v2/frames/eventtimingcodesframe.cpp +++ b/taglib/mpeg/id3v2/frames/eventtimingcodesframe.cpp @@ -121,8 +121,8 @@ ByteVector EventTimingCodesFrame::renderFields() const ByteVector v; v.append(static_cast(d->timestampFormat)); - for(SynchedEventList::ConstIterator it = d->synchedEvents.begin(); - it != d->synchedEvents.end(); + for(SynchedEventList::ConstIterator it = d->synchedEvents.cbegin(); + it != d->synchedEvents.cend(); ++it) { const SynchedEvent &entry = *it; v.append(static_cast(entry.type)); diff --git a/taglib/mpeg/id3v2/frames/relativevolumeframe.cpp b/taglib/mpeg/id3v2/frames/relativevolumeframe.cpp index f9b54cdf..3fed352f 100644 --- a/taglib/mpeg/id3v2/frames/relativevolumeframe.cpp +++ b/taglib/mpeg/id3v2/frames/relativevolumeframe.cpp @@ -78,8 +78,8 @@ List RelativeVolumeFrame::channels() const { List l; - Map::ConstIterator it = d->channels.begin(); - for(; it != d->channels.end(); ++it) + Map::ConstIterator it = d->channels.cbegin(); + for(; it != d->channels.cend(); ++it) l.append((*it).first); return l; @@ -162,9 +162,9 @@ ByteVector RelativeVolumeFrame::renderFields() const data.append(d->identification.data(String::Latin1)); data.append(textDelimiter(String::Latin1)); - Map::ConstIterator it = d->channels.begin(); + Map::ConstIterator it = d->channels.cbegin(); - for(; it != d->channels.end(); ++it) { + for(; it != d->channels.cend(); ++it) { ChannelType type = (*it).first; const ChannelData &channel = (*it).second; diff --git a/taglib/mpeg/id3v2/frames/synchronizedlyricsframe.cpp b/taglib/mpeg/id3v2/frames/synchronizedlyricsframe.cpp index fbc8809d..0c80f1fa 100644 --- a/taglib/mpeg/id3v2/frames/synchronizedlyricsframe.cpp +++ b/taglib/mpeg/id3v2/frames/synchronizedlyricsframe.cpp @@ -206,8 +206,8 @@ ByteVector SynchronizedLyricsFrame::renderFields() const String::Type encoding = d->textEncoding; encoding = checkTextEncoding(d->description, encoding); - for(SynchedTextList::ConstIterator it = d->synchedText.begin(); - it != d->synchedText.end(); + for(SynchedTextList::ConstIterator it = d->synchedText.cbegin(); + it != d->synchedText.cend(); ++it) { encoding = checkTextEncoding(it->text, encoding); } @@ -218,8 +218,8 @@ ByteVector SynchronizedLyricsFrame::renderFields() const v.append(static_cast(d->type)); v.append(d->description.data(encoding)); v.append(textDelimiter(encoding)); - for(SynchedTextList::ConstIterator it = d->synchedText.begin(); - it != d->synchedText.end(); + for(SynchedTextList::ConstIterator it = d->synchedText.cbegin(); + it != d->synchedText.cend(); ++it) { const SynchedText &entry = *it; v.append(entry.text.data(encoding)); diff --git a/taglib/mpeg/id3v2/frames/tableofcontentsframe.cpp b/taglib/mpeg/id3v2/frames/tableofcontentsframe.cpp index 3f16acbe..e1a46419 100644 --- a/taglib/mpeg/id3v2/frames/tableofcontentsframe.cpp +++ b/taglib/mpeg/id3v2/frames/tableofcontentsframe.cpp @@ -213,7 +213,7 @@ void TableOfContentsFrame::removeEmbeddedFrame(Frame *frame, bool del) void TableOfContentsFrame::removeEmbeddedFrames(const ByteVector &id) { - FrameList l = d->embeddedFrameListMap[id]; + const FrameList l = d->embeddedFrameListMap[id]; for(FrameList::ConstIterator it = l.begin(); it != l.end(); ++it) removeEmbeddedFrame(*it, true); } @@ -230,8 +230,8 @@ String TableOfContentsFrame::toString() const if(!d->embeddedFrameList.isEmpty()) { StringList frameIDs; - for(FrameList::ConstIterator it = d->embeddedFrameList.begin(); - it != d->embeddedFrameList.end(); ++it) + for(FrameList::ConstIterator it = d->embeddedFrameList.cbegin(); + it != d->embeddedFrameList.cend(); ++it) frameIDs.append((*it)->frameID()); s += ", sub-frames: [ " + frameIDs.toString(", ") + " ]"; } @@ -251,7 +251,7 @@ PropertyMap TableOfContentsFrame::asProperties() const TableOfContentsFrame *TableOfContentsFrame::findByElementID(const ID3v2::Tag *tag, const ByteVector &eID) // static { - ID3v2::FrameList tablesOfContents = tag->frameList("CTOC"); + const ID3v2::FrameList tablesOfContents = tag->frameList("CTOC"); for(ID3v2::FrameList::ConstIterator it = tablesOfContents.begin(); it != tablesOfContents.end(); @@ -267,7 +267,7 @@ TableOfContentsFrame *TableOfContentsFrame::findByElementID(const ID3v2::Tag *ta TableOfContentsFrame *TableOfContentsFrame::findTopLevel(const ID3v2::Tag *tag) // static { - ID3v2::FrameList tablesOfContents = tag->frameList("CTOC"); + const ID3v2::FrameList tablesOfContents = tag->frameList("CTOC"); for(ID3v2::FrameList::ConstIterator it = tablesOfContents.begin(); it != tablesOfContents.end(); @@ -337,13 +337,13 @@ ByteVector TableOfContentsFrame::renderFields() const flags += 1; data.append(flags); data.append(static_cast(entryCount())); - ByteVectorList::ConstIterator it = d->childElements.begin(); - while(it != d->childElements.end()) { + ByteVectorList::ConstIterator it = d->childElements.cbegin(); + while(it != d->childElements.cend()) { data.append(*it); data.append('\0'); it++; } - FrameList l = d->embeddedFrameList; + const FrameList l = d->embeddedFrameList; for(FrameList::ConstIterator it = l.begin(); it != l.end(); ++it) { (*it)->header()->setVersion(header()->version()); data.append((*it)->render()); diff --git a/taglib/mpeg/id3v2/frames/textidentificationframe.cpp b/taglib/mpeg/id3v2/frames/textidentificationframe.cpp index 35b10703..7757b2f8 100644 --- a/taglib/mpeg/id3v2/frames/textidentificationframe.cpp +++ b/taglib/mpeg/id3v2/frames/textidentificationframe.cpp @@ -211,7 +211,7 @@ void TextIdentificationFrame::parseFields(const ByteVector &data) while(dataLength % byteAlign != 0) dataLength++; - ByteVectorList l = ByteVectorList::split(data.mid(1, dataLength), textDelimiter(d->textEncoding), byteAlign); + const ByteVectorList l = ByteVectorList::split(data.mid(1, dataLength), textDelimiter(d->textEncoding), byteAlign); d->fieldList.clear(); @@ -256,13 +256,13 @@ ByteVector TextIdentificationFrame::renderFields() const v.append(static_cast(encoding)); - for(StringList::ConstIterator it = d->fieldList.begin(); it != d->fieldList.end(); it++) { + for(StringList::ConstIterator it = d->fieldList.cbegin(); it != d->fieldList.cend(); it++) { // Since the field list is null delimited, if this is not the first // element in the list, append the appropriate delimiter for this // encoding. - if(it != d->fieldList.begin()) + if(it != d->fieldList.cbegin()) v.append(textDelimiter(encoding)); v.append((*it).data(encoding)); @@ -290,7 +290,7 @@ PropertyMap TextIdentificationFrame::makeTIPLProperties() const map.unsupportedData().append(frameID()); return map; } - StringList l = fieldList(); + const StringList l = fieldList(); for(StringList::ConstIterator it = l.begin(); it != l.end(); ++it) { bool found = false; for(size_t i = 0; i < involvedPeopleSize; ++i) @@ -317,7 +317,7 @@ PropertyMap TextIdentificationFrame::makeTMCLProperties() const map.unsupportedData().append(frameID()); return map; } - StringList l = fieldList(); + const StringList l = fieldList(); for(StringList::ConstIterator it = l.begin(); it != l.end(); ++it) { String instrument = it->upper(); if(instrument.isEmpty()) { @@ -417,7 +417,7 @@ PropertyMap UserTextIdentificationFrame::asProperties() const { PropertyMap map; String tagName = txxxToKey(description()); - StringList v = fieldList(); + const StringList v = fieldList(); for(StringList::ConstIterator it = v.begin(); it != v.end(); ++it) if(it != v.begin()) map.insert(tagName, *it); @@ -427,7 +427,7 @@ PropertyMap UserTextIdentificationFrame::asProperties() const UserTextIdentificationFrame *UserTextIdentificationFrame::find( ID3v2::Tag *tag, const String &description) // static { - FrameList l = tag->frameList("TXXX"); + const FrameList l = tag->frameList("TXXX"); for(FrameList::ConstIterator it = l.begin(); it != l.end(); ++it) { UserTextIdentificationFrame *f = dynamic_cast(*it); if(f && f->description() == description) diff --git a/taglib/mpeg/id3v2/frames/uniquefileidentifierframe.cpp b/taglib/mpeg/id3v2/frames/uniquefileidentifierframe.cpp index 98fa7546..69526991 100644 --- a/taglib/mpeg/id3v2/frames/uniquefileidentifierframe.cpp +++ b/taglib/mpeg/id3v2/frames/uniquefileidentifierframe.cpp @@ -103,7 +103,7 @@ PropertyMap UniqueFileIdentifierFrame::asProperties() const UniqueFileIdentifierFrame *UniqueFileIdentifierFrame::findByOwner(const ID3v2::Tag *tag, const String &o) // static { - ID3v2::FrameList comments = tag->frameList("UFID"); + const ID3v2::FrameList comments = tag->frameList("UFID"); for(ID3v2::FrameList::ConstIterator it = comments.begin(); it != comments.end(); diff --git a/taglib/mpeg/id3v2/frames/unsynchronizedlyricsframe.cpp b/taglib/mpeg/id3v2/frames/unsynchronizedlyricsframe.cpp index e6afbc40..fc002528 100644 --- a/taglib/mpeg/id3v2/frames/unsynchronizedlyricsframe.cpp +++ b/taglib/mpeg/id3v2/frames/unsynchronizedlyricsframe.cpp @@ -127,7 +127,7 @@ PropertyMap UnsynchronizedLyricsFrame::asProperties() const UnsynchronizedLyricsFrame *UnsynchronizedLyricsFrame::findByDescription(const ID3v2::Tag *tag, const String &d) // static { - ID3v2::FrameList lyrics = tag->frameList("USLT"); + const ID3v2::FrameList lyrics = tag->frameList("USLT"); for(ID3v2::FrameList::ConstIterator it = lyrics.begin(); it != lyrics.end(); ++it){ UnsynchronizedLyricsFrame *frame = dynamic_cast(*it); diff --git a/taglib/mpeg/id3v2/frames/urllinkframe.cpp b/taglib/mpeg/id3v2/frames/urllinkframe.cpp index 2f32e5c8..5fa3c743 100644 --- a/taglib/mpeg/id3v2/frames/urllinkframe.cpp +++ b/taglib/mpeg/id3v2/frames/urllinkframe.cpp @@ -179,7 +179,7 @@ PropertyMap UserUrlLinkFrame::asProperties() const UserUrlLinkFrame *UserUrlLinkFrame::find(ID3v2::Tag *tag, const String &description) // static { - FrameList l = tag->frameList("WXXX"); + const FrameList l = tag->frameList("WXXX"); for(FrameList::ConstIterator it = l.begin(); it != l.end(); ++it) { UserUrlLinkFrame *f = dynamic_cast(*it); if(f && f->description() == description) diff --git a/taglib/mpeg/id3v2/id3v2framefactory.cpp b/taglib/mpeg/id3v2/id3v2framefactory.cpp index 4377dad4..75baf4cd 100644 --- a/taglib/mpeg/id3v2/id3v2framefactory.cpp +++ b/taglib/mpeg/id3v2/id3v2framefactory.cpp @@ -58,7 +58,7 @@ namespace StringList fields = frame->fieldList(); StringList newfields; - for(StringList::ConstIterator it = fields.begin(); it != fields.end(); ++it) { + for(StringList::ConstIterator it = fields.cbegin(); it != fields.cend(); ++it) { String s = *it; int offset = 0; int end = 0; @@ -144,7 +144,7 @@ Frame *FrameFactory::createFrame(const ByteVector &origData, const Header *tagHe } #endif - for(ByteVector::ConstIterator it = frameID.begin(); it != frameID.end(); it++) { + for(ByteVector::ConstIterator it = frameID.cbegin(); it != frameID.cend(); it++) { if( (*it < 'A' || *it > 'Z') && (*it < '0' || *it > '9') ) { delete header; return nullptr; diff --git a/taglib/mpeg/id3v2/id3v2header.cpp b/taglib/mpeg/id3v2/id3v2header.cpp index 6a6e3b2b..6b8684fc 100644 --- a/taglib/mpeg/id3v2/id3v2header.cpp +++ b/taglib/mpeg/id3v2/id3v2header.cpp @@ -202,7 +202,7 @@ void Header::parse(const ByteVector &data) // note that we're doing things a little out of order here -- the size is // later in the bytestream than the version - ByteVector sizeData = data.mid(6, 4); + const ByteVector sizeData = data.mid(6, 4); if(sizeData.size() != 4) { d->tagSize = 0; diff --git a/taglib/mpeg/id3v2/id3v2tag.cpp b/taglib/mpeg/id3v2/id3v2tag.cpp index bc6c56f4..87b48e0a 100644 --- a/taglib/mpeg/id3v2/id3v2tag.cpp +++ b/taglib/mpeg/id3v2/id3v2tag.cpp @@ -378,7 +378,7 @@ void ID3v2::Tag::removeFrame(Frame *frame, bool del) void ID3v2::Tag::removeFrames(const ByteVector &id) { - FrameList l = d->frameListMap[id]; + const FrameList l = d->frameListMap[id]; for(FrameList::ConstIterator it = l.begin(); it != l.end(); ++it) removeFrame(*it, true); } @@ -402,7 +402,7 @@ void ID3v2::Tag::removeUnsupportedProperties(const StringList &properties) continue; // invalid specification ByteVector id = frameID.data(String::Latin1); // delete all unknown frames of given type - FrameList l = frameList(id); + const FrameList l = frameList(id); for(FrameList::ConstIterator fit = l.begin(); fit != l.end(); fit++) if (dynamic_cast(*fit) != nullptr) removeFrame(*fit); @@ -461,7 +461,7 @@ PropertyMap ID3v2::Tag::setProperties(const PropertyMap &origProps) properties.erase(frameProperties); } } - for(FrameList::ConstIterator it = framesToDelete.begin(); it != framesToDelete.end(); ++it) + for(FrameList::ConstIterator it = framesToDelete.cbegin(); it != framesToDelete.cend(); ++it) removeFrame(*it); // now create remaining frames: @@ -472,7 +472,7 @@ PropertyMap ID3v2::Tag::setProperties(const PropertyMap &origProps) if(!tmclProperties.isEmpty()) addFrame(TextIdentificationFrame::createTMCLFrame(tmclProperties)); // now create the "one key per frame" frames - for(PropertyMap::ConstIterator it = properties.begin(); it != properties.end(); ++it) + for(PropertyMap::ConstIterator it = properties.cbegin(); it != properties.cend(); ++it) addFrame(Frame::createTextualFrame(it->first, it->second)); return PropertyMap(); // ID3 implements the complete PropertyMap interface, so an empty map is returned } @@ -502,7 +502,7 @@ void ID3v2::Tag::downgradeFrames(FrameList *frames, FrameList *newFrames) const ID3v2::TextIdentificationFrame *frameTMCL = nullptr; ID3v2::TextIdentificationFrame *frameTCON = nullptr; - for(FrameList::ConstIterator it = d->frameList.begin(); it != d->frameList.end(); it++) { + for(FrameList::ConstIterator it = d->frameList.cbegin(); it != d->frameList.cend(); it++) { ID3v2::Frame *frame = *it; ByteVector frameID = frame->header()->frameID(); @@ -591,7 +591,7 @@ void ID3v2::Tag::downgradeFrames(FrameList *frames, FrameList *newFrames) const } if(frameTCON) { - StringList genres = frameTCON->fieldList(); + const StringList genres = frameTCON->fieldList(); String combined; String genreText; const bool hasMultipleGenres = genres.size() > 1; @@ -647,7 +647,7 @@ ByteVector ID3v2::Tag::render(Version version) const // Loop through the frames rendering them and adding them to the tagData. - for(FrameList::ConstIterator it = frameList.begin(); it != frameList.end(); it++) { + for(FrameList::ConstIterator it = frameList.cbegin(); it != frameList.cend(); it++) { (*it)->header()->setVersion(version == v3 ? 3 : 4); if((*it)->header()->frameID().size() != 4) { debug("An ID3v2 frame of unsupported or unknown type \'" diff --git a/taglib/ogg/oggfile.cpp b/taglib/ogg/oggfile.cpp index 9ffed806..7cd69504 100644 --- a/taglib/ogg/oggfile.cpp +++ b/taglib/ogg/oggfile.cpp @@ -95,7 +95,7 @@ ByteVector Ogg::File::packet(unsigned int i) // Look for the first page in which the requested packet starts. - List::ConstIterator it = d->pages.begin(); + List::ConstIterator it = d->pages.cbegin(); while((*it)->containsPacket(i) == Page::DoesNotContainPacket) ++it; @@ -160,7 +160,7 @@ bool Ogg::File::save() } Map::ConstIterator it; - for(it = d->dirtyPackets.begin(); it != d->dirtyPackets.end(); ++it) + for(it = d->dirtyPackets.cbegin(); it != d->dirtyPackets.cend(); ++it) writePacket(it->first, it->second); d->dirtyPackets.clear(); @@ -236,7 +236,7 @@ void Ogg::File::writePacket(unsigned int i, const ByteVector &packet) // Look for the pages where the requested packet should belong to. - List::ConstIterator it = d->pages.begin(); + List::ConstIterator it = d->pages.cbegin(); while((*it)->containsPacket(i) == Page::DoesNotContainPacket) ++it; diff --git a/taglib/ogg/oggpage.cpp b/taglib/ogg/oggpage.cpp index 7fcaf4ad..8b05cd46 100644 --- a/taglib/ogg/oggpage.cpp +++ b/taglib/ogg/oggpage.cpp @@ -211,7 +211,7 @@ ByteVectorList Ogg::Page::packets() const d->file->seek(d->fileOffset + d->header.size()); - List packetSizes = d->header.packetSizes(); + const List packetSizes = d->header.packetSizes(); List::ConstIterator it = packetSizes.begin(); for(; it != packetSizes.end(); ++it) @@ -243,8 +243,8 @@ ByteVector Ogg::Page::render() const debug("Ogg::Page::render() -- this page is empty!"); } else { - ByteVectorList::ConstIterator it = d->packets.begin(); - for(; it != d->packets.end(); ++it) + ByteVectorList::ConstIterator it = d->packets.cbegin(); + for(; it != d->packets.cend(); ++it) data.append(*it); } diff --git a/taglib/ogg/oggpageheader.cpp b/taglib/ogg/oggpageheader.cpp index 10a1efc2..76753e81 100644 --- a/taglib/ogg/oggpageheader.cpp +++ b/taglib/ogg/oggpageheader.cpp @@ -295,7 +295,7 @@ ByteVector Ogg::PageHeader::lacingValues() const { ByteVector data; - for(List::ConstIterator it = d->packetSizes.begin(); it != d->packetSizes.end(); ++it) { + for(List::ConstIterator it = d->packetSizes.cbegin(); it != d->packetSizes.cend(); ++it) { // The size of a packet in an Ogg page is indicated by a series of "lacing // values" where the sum of the values is the packet size in bytes. Each of @@ -304,7 +304,7 @@ ByteVector Ogg::PageHeader::lacingValues() const data.resize(data.size() + (*it / 255), '\xff'); - if(it != --d->packetSizes.end() || d->lastPacketCompleted) + if(it != --d->packetSizes.cend() || d->lastPacketCompleted) data.append(static_cast(*it % 255)); } diff --git a/taglib/ogg/xiphcomment.cpp b/taglib/ogg/xiphcomment.cpp index 8187c383..e03d1ed3 100644 --- a/taglib/ogg/xiphcomment.cpp +++ b/taglib/ogg/xiphcomment.cpp @@ -39,7 +39,7 @@ namespace typedef List PictureList; typedef PictureList::Iterator PictureIterator; - typedef PictureList::Iterator PictureConstIterator; + typedef PictureList::ConstIterator PictureConstIterator; } // namespace class Ogg::XiphComment::XiphCommentPrivate @@ -191,7 +191,7 @@ void Ogg::XiphComment::setTrack(unsigned int i) bool Ogg::XiphComment::isEmpty() const { - for(FieldConstIterator it = d->fieldListMap.begin(); it != d->fieldListMap.end(); ++it) { + for(FieldConstIterator it = d->fieldListMap.cbegin(); it != d->fieldListMap.cend(); ++it) { if(!(*it).second.isEmpty()) return false; } @@ -203,7 +203,7 @@ unsigned int Ogg::XiphComment::fieldCount() const { unsigned int count = 0; - for(FieldConstIterator it = d->fieldListMap.begin(); it != d->fieldListMap.end(); ++it) + for(FieldConstIterator it = d->fieldListMap.cbegin(); it != d->fieldListMap.cend(); ++it) count += (*it).second.size(); count += d->pictureList.size(); @@ -225,11 +225,11 @@ PropertyMap Ogg::XiphComment::setProperties(const PropertyMap &properties) { // check which keys are to be deleted StringList toRemove; - for(FieldConstIterator it = d->fieldListMap.begin(); it != d->fieldListMap.end(); ++it) + for(FieldConstIterator it = d->fieldListMap.cbegin(); it != d->fieldListMap.cend(); ++it) if (!properties.contains(it->first)) toRemove.append(it->first); - for(StringList::ConstIterator it = toRemove.begin(); it != toRemove.end(); ++it) + for(StringList::ConstIterator it = toRemove.cbegin(); it != toRemove.cend(); ++it) removeFields(*it); // now go through keys in \a properties and check that the values match those in the xiph comment @@ -366,13 +366,13 @@ ByteVector Ogg::XiphComment::render(bool addFramingBit) const // std::pair where the first String is the field name and // the StringList is the values associated with that field. - FieldListMap::ConstIterator it = d->fieldListMap.begin(); - for(; it != d->fieldListMap.end(); ++it) { + FieldListMap::ConstIterator it = d->fieldListMap.cbegin(); + for(; it != d->fieldListMap.cend(); ++it) { // And now iterate over the values of the current list. String fieldName = (*it).first; - StringList values = (*it).second; + const StringList values = (*it).second; StringList::ConstIterator valuesIt = values.begin(); for(; valuesIt != values.end(); ++valuesIt) { @@ -385,7 +385,7 @@ ByteVector Ogg::XiphComment::render(bool addFramingBit) const } } - for(PictureConstIterator it = d->pictureList.begin(); it != d->pictureList.end(); ++it) { + for(PictureConstIterator it = d->pictureList.cbegin(); it != d->pictureList.cend(); ++it) { ByteVector picture = (*it)->render().toBase64(); data.append(ByteVector::fromUInt(picture.size() + 23, false)); data.append("METADATA_BLOCK_PICTURE="); diff --git a/taglib/riff/riffutils.h b/taglib/riff/riffutils.h index c913e019..1c3817da 100644 --- a/taglib/riff/riffutils.h +++ b/taglib/riff/riffutils.h @@ -26,6 +26,8 @@ #ifndef TAGLIB_RIFFUTILS_H #define TAGLIB_RIFFUTILS_H +#include "tbytevector.h" + // THIS FILE IS NOT A PART OF THE TAGLIB API #ifndef DO_NOT_DOCUMENT // tell Doxygen not to document this header diff --git a/taglib/riff/wav/infotag.cpp b/taglib/riff/wav/infotag.cpp index 94944626..121e870e 100644 --- a/taglib/riff/wav/infotag.cpp +++ b/taglib/riff/wav/infotag.cpp @@ -201,8 +201,8 @@ ByteVector RIFF::Info::Tag::render() const { ByteVector data("INFO"); - FieldListMap::ConstIterator it = d->fieldListMap.begin(); - for(; it != d->fieldListMap.end(); ++it) { + FieldListMap::ConstIterator it = d->fieldListMap.cbegin(); + for(; it != d->fieldListMap.cend(); ++it) { ByteVector text = stringHandler->render(it->second); if(text.isEmpty()) continue; diff --git a/taglib/tag.cpp b/taglib/tag.cpp index 3526226f..1d3832b1 100644 --- a/taglib/tag.cpp +++ b/taglib/tag.cpp @@ -141,7 +141,7 @@ PropertyMap Tag::setProperties(const PropertyMap &origProps) // for each tag that has been set above, remove the first entry in the corresponding // value list. The others will be returned as unsupported by this format. - for(StringList::ConstIterator it = oneValueSet.begin(); it != oneValueSet.end(); ++it) { + for(StringList::ConstIterator it = oneValueSet.cbegin(); it != oneValueSet.cend(); ++it) { if(properties[*it].size() == 1) properties.erase(*it); else diff --git a/taglib/toolkit/tbytevector.cpp b/taglib/toolkit/tbytevector.cpp index 529773c0..f409f5e2 100644 --- a/taglib/toolkit/tbytevector.cpp +++ b/taglib/toolkit/tbytevector.cpp @@ -616,6 +616,11 @@ ByteVector::ConstIterator ByteVector::begin() const return d->data->begin() + d->offset; } +ByteVector::ConstIterator ByteVector::cbegin() const +{ + return d->data->cbegin() + d->offset; +} + ByteVector::Iterator ByteVector::end() { detach(); @@ -627,6 +632,11 @@ ByteVector::ConstIterator ByteVector::end() const return d->data->begin() + d->offset + d->length; } +ByteVector::ConstIterator ByteVector::cend() const +{ + return d->data->cbegin() + d->offset + d->length; +} + ByteVector::ReverseIterator ByteVector::rbegin() { detach(); diff --git a/taglib/toolkit/tbytevector.h b/taglib/toolkit/tbytevector.h index 734a3be5..dce39725 100644 --- a/taglib/toolkit/tbytevector.h +++ b/taglib/toolkit/tbytevector.h @@ -240,6 +240,11 @@ namespace TagLib { */ ConstIterator begin() const; + /*! + * Returns a ConstIterator that points to the front of the vector. + */ + ConstIterator cbegin() const; + /*! * Returns an Iterator that points to the back of the vector. */ @@ -250,6 +255,11 @@ namespace TagLib { */ ConstIterator end() const; + /*! + * Returns a ConstIterator that points to the back of the vector. + */ + ConstIterator cend() const; + /*! * Returns a ReverseIterator that points to the front of the vector. */ diff --git a/taglib/toolkit/tlist.h b/taglib/toolkit/tlist.h index b4bd0fe7..a943c844 100644 --- a/taglib/toolkit/tlist.h +++ b/taglib/toolkit/tlist.h @@ -88,6 +88,12 @@ namespace TagLib { */ ConstIterator begin() const; + /*! + * Returns an STL style constant iterator to the beginning of the list. See + * std::list::iterator for the semantics. + */ + ConstIterator cbegin() const; + /*! * Returns an STL style iterator to the end of the list. See * std::list::iterator for the semantics. @@ -100,6 +106,12 @@ namespace TagLib { */ ConstIterator end() const; + /*! + * Returns an STL style constant iterator to the end of the list. See + * std::list::const_iterator for the semantics. + */ + ConstIterator cend() const; + /*! * Inserts a copy of \a value before \a it. */ @@ -168,6 +180,11 @@ namespace TagLib { */ ConstIterator find(const T &value) const; + /*! + * Find the first occurrence of \a value. + */ + ConstIterator cfind(const T &value) const; + /*! * Returns true if the list contains \a value. */ diff --git a/taglib/toolkit/tlist.tcc b/taglib/toolkit/tlist.tcc index c204c2de..c9a5c558 100644 --- a/taglib/toolkit/tlist.tcc +++ b/taglib/toolkit/tlist.tcc @@ -119,6 +119,12 @@ typename List::ConstIterator List::begin() const return d->list.begin(); } +template +typename List::ConstIterator List::cbegin() const +{ + return d->list.cbegin(); +} + template typename List::Iterator List::end() { @@ -132,6 +138,12 @@ typename List::ConstIterator List::end() const return d->list.end(); } +template +typename List::ConstIterator List::cend() const +{ + return d->list.cend(); +} + template typename List::Iterator List::insert(Iterator it, const T &item) { @@ -217,6 +229,12 @@ typename List::ConstIterator List::find(const T &value) const return std::find(d->list.begin(), d->list.end(), value); } +template +typename List::ConstIterator List::cfind(const T &value) const +{ + return std::find(d->list.cbegin(), d->list.cend(), value); +} + template bool List::contains(const T &value) const { diff --git a/taglib/toolkit/tmap.h b/taglib/toolkit/tmap.h index 520a2672..ed0a0256 100644 --- a/taglib/toolkit/tmap.h +++ b/taglib/toolkit/tmap.h @@ -90,6 +90,12 @@ namespace TagLib { */ ConstIterator begin() const; + /*! + * Returns an STL style iterator to the beginning of the map. See + * std::map::const_iterator for the semantics. + */ + ConstIterator cbegin() const; + /*! * Returns an STL style iterator to the end of the map. See * std::map::iterator for the semantics. @@ -102,6 +108,12 @@ namespace TagLib { */ ConstIterator end() const; + /*! + * Returns an STL style iterator to the end of the map. See + * std::map::const_iterator for the semantics. + */ + ConstIterator cend() const; + /*! * Inserts \a value under \a key in the map. If a value for \a key already * exists it will be overwritten. diff --git a/taglib/toolkit/tmap.tcc b/taglib/toolkit/tmap.tcc index 5367a185..0ca27c5d 100644 --- a/taglib/toolkit/tmap.tcc +++ b/taglib/toolkit/tmap.tcc @@ -78,6 +78,12 @@ typename Map::ConstIterator Map::begin() const return d->map.begin(); } +template +typename Map::ConstIterator Map::cbegin() const +{ + return d->map.cbegin(); +} + template typename Map::Iterator Map::end() { @@ -91,6 +97,12 @@ typename Map::ConstIterator Map::end() const return d->map.end(); } +template +typename Map::ConstIterator Map::cend() const +{ + return d->map.cend(); +} + template Map &Map::insert(const Key &key, const T &value) { diff --git a/taglib/toolkit/tpropertymap.cpp b/taglib/toolkit/tpropertymap.cpp index 2e21ceb2..072e6498 100644 --- a/taglib/toolkit/tpropertymap.cpp +++ b/taglib/toolkit/tpropertymap.cpp @@ -167,7 +167,7 @@ String PropertyMap::toString() const void PropertyMap::removeEmpty() { PropertyMap m; - for(ConstIterator it = begin(); it != end(); ++it) { + for(ConstIterator it = cbegin(); it != cend(); ++it) { if(!it->second.isEmpty()) m.insert(it->first, it->second); } diff --git a/taglib/toolkit/tstring.cpp b/taglib/toolkit/tstring.cpp index 4b313ee2..f064a000 100644 --- a/taglib/toolkit/tstring.cpp +++ b/taglib/toolkit/tstring.cpp @@ -309,6 +309,11 @@ String::ConstIterator String::begin() const return d->data.begin(); } +String::ConstIterator String::cbegin() const +{ + return d->data.cbegin(); +} + String::Iterator String::end() { detach(); @@ -320,6 +325,11 @@ String::ConstIterator String::end() const return d->data.end(); } +String::ConstIterator String::cend() const +{ + return d->data.cend(); +} + int String::find(const String &s, int offset) const { return static_cast(d->data.find(s.d->data, offset)); diff --git a/taglib/toolkit/tstring.h b/taglib/toolkit/tstring.h index f9146466..f83770de 100644 --- a/taglib/toolkit/tstring.h +++ b/taglib/toolkit/tstring.h @@ -252,6 +252,11 @@ namespace TagLib { */ ConstIterator begin() const; + /*! + * Returns a const iterator pointing to the beginning of the string. + */ + ConstIterator cbegin() const; + /*! * Returns an iterator pointing to the end of the string (the position * after the last character). @@ -264,6 +269,12 @@ namespace TagLib { */ ConstIterator end() const; + /*! + * Returns a const iterator pointing to the end of the string (the position + * after the last character). + */ + ConstIterator cend() const; + /*! * Finds the first occurrence of pattern \a s in this string starting from * \a offset. If the pattern is not found, -1 is returned. diff --git a/taglib/xm/xmfile.cpp b/taglib/xm/xmfile.cpp index 961aaa23..7a8ec0d8 100644 --- a/taglib/xm/xmfile.cpp +++ b/taglib/xm/xmfile.cpp @@ -333,8 +333,8 @@ public: unsigned int read(TagLib::File &file, unsigned int limit) override { unsigned int sumcount = 0; - for(List::ConstIterator i = m_readers.begin(); - limit > 0 && i != m_readers.end(); ++ i) { + for(List::ConstIterator i = m_readers.cbegin(); + limit > 0 && i != m_readers.cend(); ++ i) { unsigned int count = (*i)->read(file, limit); limit -= count; sumcount += count;