Skip to content

Commit

Permalink
clang-tidy: for loop conversion
Browse files Browse the repository at this point in the history
Found with modernize-loop-convert

Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb committed Aug 14, 2024
1 parent 169b636 commit 5605379
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 55 deletions.
14 changes: 6 additions & 8 deletions samples/exifdata-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
1 change: 0 additions & 1 deletion samples/exifdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <string>

using format_t = std::map<std::string, int>;
using format_i = format_t::const_iterator;
enum format_e { wolf, csv, json, xml };

void syntax(const char* argv[], format_t& formats) {
Expand Down
19 changes: 9 additions & 10 deletions samples/exifprint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 5 additions & 6 deletions samples/iptcprint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions samples/prevtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
14 changes: 6 additions & 8 deletions samples/remotetest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions samples/tiff-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
11 changes: 5 additions & 6 deletions samples/write-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
14 changes: 6 additions & 8 deletions samples/write2-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}

0 comments on commit 5605379

Please sign in to comment.