From edb2fe584d84c691e8c57e5842d624c6ebaadb78 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Tue, 13 Aug 2024 18:50:56 -0700 Subject: [PATCH] clang-tidy: for loop conversion Found with modernize-loop-convert Signed-off-by: Rosen Penev --- samples/exifdata-test.cpp | 14 ++++++-------- samples/exifdata.cpp | 1 - samples/exifprint.cpp | 19 +++++++++---------- samples/iptcprint.cpp | 11 +++++------ samples/prevtest.cpp | 3 +-- samples/remotetest.cpp | 14 ++++++-------- samples/tiff-test.cpp | 11 +++++------ samples/write-test.cpp | 11 +++++------ samples/write2-test.cpp | 14 ++++++-------- 9 files changed, 43 insertions(+), 55 deletions(-) diff --git a/samples/exifdata-test.cpp b/samples/exifdata-test.cpp index 3de607af53..264faa1fba 100644 --- a/samples/exifdata-test.cpp +++ b/samples/exifdata-test.cpp @@ -98,13 +98,11 @@ void print(const std::string& file) { auto image = Exiv2::ImageFactory::open(file); image->readMetadata(); - Exiv2::ExifData& ed = image->exifData(); - auto end = ed.end(); - for (auto i = ed.begin(); i != end; ++i) { - std::cout << std::setw(45) << std::setfill(' ') << std::left << i->key() << " " - << "0x" << std::setw(4) << std::setfill('0') << std::right << std::hex << i->tag() << " " << std::setw(12) - << std::setfill(' ') << std::left << i->ifdName() << " " << std::setw(9) << std::setfill(' ') << std::left - << i->typeName() << " " << std::dec << std::setw(3) << std::setfill(' ') << std::right << i->count() - << " " << std::dec << i->toString() << "\n"; + for (const auto& i : image->exifData()) { + std::cout << std::setw(45) << std::setfill(' ') << std::left << i.key() << " " + << "0x" << std::setw(4) << std::setfill('0') << std::right << std::hex << i.tag() << " " << std::setw(12) + << std::setfill(' ') << std::left << i.ifdName() << " " << std::setw(9) << std::setfill(' ') << std::left + << i.typeName() << " " << std::dec << std::setw(3) << std::setfill(' ') << std::right << i.count() << " " + << std::dec << i.toString() << "\n"; } } diff --git a/samples/exifdata.cpp b/samples/exifdata.cpp index 4171105d18..abe3d4ca82 100644 --- a/samples/exifdata.cpp +++ b/samples/exifdata.cpp @@ -7,7 +7,6 @@ #include using format_t = std::map; -using format_i = format_t::const_iterator; enum format_e { wolf, csv, json, xml }; void syntax(const char* argv[], format_t& formats) { diff --git a/samples/exifprint.cpp b/samples/exifprint.cpp index ee59c85002..f528fafa61 100644 --- a/samples/exifprint.cpp +++ b/samples/exifprint.cpp @@ -77,25 +77,24 @@ int main(int argc, char* const argv[]) { shortLong.insert("Exif.Photo.StripOffsets"); shortLong.insert("Exif.Photo.StripByteCounts"); - auto end = exifData.end(); - for (auto i = exifData.begin(); i != end; ++i) { + for (const auto& i : exifData) { if (!bLint) { - const char* tn = i->typeName(); - std::cout << std::setw(44) << std::setfill(' ') << std::left << i->key() << " " - << "0x" << std::setw(4) << std::setfill('0') << std::right << std::hex << i->tag() << " " + const char* tn = i.typeName(); + std::cout << std::setw(44) << std::setfill(' ') << std::left << i.key() << " " + << "0x" << std::setw(4) << std::setfill('0') << std::right << std::hex << i.tag() << " " << std::setw(9) << std::setfill(' ') << std::left << (tn ? tn : "Unknown") << " " << std::dec - << std::setw(3) << std::setfill(' ') << std::right << i->count() << " " << std::dec << i->toString() + << std::setw(3) << std::setfill(' ') << std::right << i.count() << " " << std::dec << i.toString() << "\n"; } else { - const Exiv2::TagInfo* tagInfo = findTag(Exiv2::ExifTags::tagList(i->groupName()), i->tag()); + const Exiv2::TagInfo* tagInfo = findTag(Exiv2::ExifTags::tagList(i.groupName()), i.tag()); if (tagInfo) { - Exiv2::TypeId type = i->typeId(); + Exiv2::TypeId type = i.typeId(); if (type != tagInfo->typeId_ && (tagInfo->typeId_ != Exiv2::comment || type != Exiv2::undefined) // comment is stored as undefined - && (shortLong.find(i->key()) == shortLong.end() || + && (shortLong.find(i.key()) == shortLong.end() || (type != Exiv2::unsignedShort && type != Exiv2::unsignedLong)) // can be short or long! ) { - std::cerr << i->key() << " type " << i->typeName() << " (" << type << ")" + std::cerr << i.key() << " type " << i.typeName() << " (" << type << ")" << " expected " << Exiv2::TypeInfo::typeName(tagInfo->typeId_) << " (" << tagInfo->typeId_ << ")" << '\n'; rc = 2; diff --git a/samples/iptcprint.cpp b/samples/iptcprint.cpp index 0f87fa66f7..56b6ed399c 100644 --- a/samples/iptcprint.cpp +++ b/samples/iptcprint.cpp @@ -24,12 +24,11 @@ int main(int argc, char* const argv[]) try { throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, error); } - auto end = iptcData.end(); - for (auto md = iptcData.begin(); md != end; ++md) { - std::cout << std::setw(44) << std::setfill(' ') << std::left << md->key() << " " - << "0x" << std::setw(4) << std::setfill('0') << std::right << std::hex << md->tag() << " " << std::setw(9) - << std::setfill(' ') << std::left << md->typeName() << " " << std::dec << std::setw(3) - << std::setfill(' ') << std::right << md->count() << " " << std::dec << md->value() << '\n'; + for (const auto& md : iptcData) { + std::cout << std::setw(44) << std::setfill(' ') << std::left << md.key() << " " + << "0x" << std::setw(4) << std::setfill('0') << std::right << std::hex << md.tag() << " " << std::setw(9) + << std::setfill(' ') << std::left << md.typeName() << " " << std::dec << std::setw(3) << std::setfill(' ') + << std::right << md.count() << " " << std::dec << md.value() << '\n'; } return EXIT_SUCCESS; diff --git a/samples/prevtest.cpp b/samples/prevtest.cpp index 89d983ff60..d902d79563 100644 --- a/samples/prevtest.cpp +++ b/samples/prevtest.cpp @@ -19,8 +19,7 @@ int main(int argc, char* const argv[]) try { image->readMetadata(); Exiv2::PreviewManager loader(*image); - Exiv2::PreviewPropertiesList list = loader.getPreviewProperties(); - for (auto&& pos : list) { + for (const auto& pos : loader.getPreviewProperties()) { std::cout << pos.mimeType_ << " preview, type " << pos.id_ << ", " << pos.size_ << " bytes, " << pos.width_ << 'x' << pos.height_ << " pixels" << "\n"; diff --git a/samples/remotetest.cpp b/samples/remotetest.cpp index 291f4f7405..130fd22554 100644 --- a/samples/remotetest.cpp +++ b/samples/remotetest.cpp @@ -56,14 +56,12 @@ int main(int argc, char* const argv[]) { error += ": No Exif data found in the file"; throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, error); } - auto end = exifReadData.end(); - for (auto i = exifReadData.begin(); i != end; ++i) { - const char* tn = i->typeName(); - std::cout << std::setw(44) << std::setfill(' ') << std::left << i->key() << " " - << "0x" << std::setw(4) << std::setfill('0') << std::right << std::hex << i->tag() << " " - << std::setw(9) << std::setfill(' ') << std::left << (tn ? tn : "Unknown") << " " << std::dec - << std::setw(3) << std::setfill(' ') << std::right << i->count() << " " << std::dec << i->value() - << "\n"; + for (const auto& i : exifReadData) { + const char* tn = i.typeName(); + std::cout << std::setw(44) << std::setfill(' ') << std::left << i.key() << " " + << "0x" << std::setw(4) << std::setfill('0') << std::right << std::hex << i.tag() << " " << std::setw(9) + << std::setfill(' ') << std::left << (tn ? tn : "Unknown") << " " << std::dec << std::setw(3) + << std::setfill(' ') << std::right << i.count() << " " << std::dec << i.value() << "\n"; } // del, reset the metadata diff --git a/samples/tiff-test.cpp b/samples/tiff-test.cpp index 6fec8fcbd6..23d86db8ae 100644 --- a/samples/tiff-test.cpp +++ b/samples/tiff-test.cpp @@ -87,11 +87,10 @@ void print(const ExifData& exifData) { std::string error("No Exif data found in the file"); throw Exiv2::Error(ErrorCode::kerErrorMessage, error); } - auto end = exifData.end(); - for (auto i = exifData.begin(); i != end; ++i) { - std::cout << std::setw(44) << std::setfill(' ') << std::left << i->key() << " " - << "0x" << std::setw(4) << std::setfill('0') << std::right << std::hex << i->tag() << " " << std::setw(9) - << std::setfill(' ') << std::left << i->typeName() << " " << std::dec << std::setw(3) << std::setfill(' ') - << std::right << i->count() << " " << std::dec << i->value() << "\n"; + for (const auto& i : exifData) { + std::cout << std::setw(44) << std::setfill(' ') << std::left << i.key() << " " + << "0x" << std::setw(4) << std::setfill('0') << std::right << std::hex << i.tag() << " " << std::setw(9) + << std::setfill(' ') << std::left << i.typeName() << " " << std::dec << std::setw(3) << std::setfill(' ') + << std::right << i.count() << " " << std::dec << i.value() << "\n"; } } diff --git a/samples/write-test.cpp b/samples/write-test.cpp index 2b38a05810..433774fc95 100644 --- a/samples/write-test.cpp +++ b/samples/write-test.cpp @@ -153,11 +153,10 @@ void testCase(const std::string& file1, const std::string& file2, const std::str // ***************************************************************************** void exifPrint(const ExifData& exifData) { - auto i = exifData.begin(); - for (; i != exifData.end(); ++i) { - std::cout << std::setw(44) << std::setfill(' ') << std::left << i->key() << " " - << "0x" << std::setw(4) << std::setfill('0') << std::right << std::hex << i->tag() << " " << std::setw(9) - << std::setfill(' ') << std::left << i->typeName() << " " << std::dec << std::setw(3) << std::setfill(' ') - << std::right << i->count() << " " << std::dec << i->value() << "\n"; + for (const auto& i : exifData) { + std::cout << std::setw(44) << std::setfill(' ') << std::left << i.key() << " " + << "0x" << std::setw(4) << std::setfill('0') << std::right << std::hex << i.tag() << " " << std::setw(9) + << std::setfill(' ') << std::left << i.typeName() << " " << std::dec << std::setw(3) << std::setfill(' ') + << std::right << i.count() << " " << std::dec << i.value() << "\n"; } } diff --git a/samples/write2-test.cpp b/samples/write2-test.cpp index 707aff188a..8f71d0728c 100644 --- a/samples/write2-test.cpp +++ b/samples/write2-test.cpp @@ -201,13 +201,11 @@ void print(const std::string& file) { auto image = Exiv2::ImageFactory::open(file); image->readMetadata(); - Exiv2::ExifData& ed = image->exifData(); - auto end = ed.end(); - for (auto i = ed.begin(); i != end; ++i) { - std::cout << std::setw(45) << std::setfill(' ') << std::left << i->key() << " " - << "0x" << std::setw(4) << std::setfill('0') << std::right << std::hex << i->tag() << " " << std::setw(12) - << std::setfill(' ') << std::left << i->ifdName() << " " << std::setw(9) << std::setfill(' ') << std::left - << i->typeName() << " " << std::dec << std::setw(3) << std::setfill(' ') << std::right << i->count() - << " " << std::dec << i->value() << "\n"; + for (const auto& i : image->exifData()) { + std::cout << std::setw(45) << std::setfill(' ') << std::left << i.key() << " " + << "0x" << std::setw(4) << std::setfill('0') << std::right << std::hex << i.tag() << " " << std::setw(12) + << std::setfill(' ') << std::left << i.ifdName() << " " << std::setw(9) << std::setfill(' ') << std::left + << i.typeName() << " " << std::dec << std::setw(3) << std::setfill(' ') << std::right << i.count() << " " + << std::dec << i.value() << "\n"; } }