From 20dfab80369d2531e63821c7e22ec532c6d6314d Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Tue, 11 May 2021 17:54:52 -0700 Subject: [PATCH] manual for range loop conversions Signed-off-by: Rosen Penev --- src/actions.cpp | 75 ++++++++++++++-------------- src/crwimage_int.cpp | 101 +++++++++++++++----------------------- src/olympusmn_int.cpp | 44 ++++++----------- src/tiffcomposite_int.cpp | 21 ++++---- src/tiffvisitor_int.cpp | 24 +++++---- src/value.cpp | 6 +-- 6 files changed, 121 insertions(+), 150 deletions(-) diff --git a/src/actions.cpp b/src/actions.cpp index 2dfcc49f6f..17e87bc3cf 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -489,14 +489,15 @@ namespace Action { bool Print::grepTag(const std::string& key) { bool result=Params::instance().greps_.empty(); - for (auto g = Params::instance().greps_.begin(); !result && g != Params::instance().greps_.end(); ++g) - { + for (auto&& g : Params::instance().greps_) { + if (result) + break; #if defined(EXV_HAVE_REGEX_H) - result = regexec( &(*g), key.c_str(), 0, NULL, 0) == 0 ; + result = regexec(&g, key.c_str(), 0, NULL, 0) == 0; #else - std::string Pattern(g->pattern_); + std::string Pattern(g.pattern_); std::string Key(key); - if ( g->bIgnoreCase_ ) { + if (g.bIgnoreCase_) { // https://notfaq.wordpress.com/2007/08/04/cc-convert-string-to-upperlower-case/ std::transform(Pattern.begin(), Pattern.end(),Pattern.begin(), ::tolower); std::transform(Key.begin() , Key.end() ,Key.begin() , ::tolower); @@ -510,9 +511,10 @@ namespace Action { bool Print::keyTag(const std::string& key) { bool result=Params::instance().keys_.empty(); - for (auto k = Params::instance().keys_.begin(); !result && k != Params::instance().keys_.end(); ++k) - { - result = key == *k; + for (auto&& k : Params::instance().keys_) { + if (result) + break; + result = key == k; } return result ; } @@ -1309,29 +1311,29 @@ namespace Action { // loop through command table and apply each command ModifyCmds& modifyCmds = Params::instance().modifyCmds_; - auto i = modifyCmds.cbegin(); - auto end = modifyCmds.cend(); int rc = 0; int ret = 0; - for (; i != end; ++i) { - switch (i->cmdId_) { - case add: - ret = addMetadatum(pImage, *i); - if (rc == 0) rc = ret; - break; - case set: - ret = setMetadatum(pImage, *i); - if (rc == 0) rc = ret; - break; - case del: - delMetadatum(pImage, *i); - break; - case reg: - regNamespace(*i); - break; - case invalidCmdId: - assert(invalidCmdId == i->cmdId_); - break; + for (auto&& cmd : modifyCmds) { + switch (cmd.cmdId_) { + case add: + ret = addMetadatum(pImage, cmd); + if (rc == 0) + rc = ret; + break; + case set: + ret = setMetadatum(pImage, cmd); + if (rc == 0) + rc = ret; + break; + case del: + delMetadatum(pImage, cmd); + break; + case reg: + regNamespace(cmd); + break; + case invalidCmdId: + assert(invalidCmdId == cmd.cmdId_); + break; } } return rc; @@ -1958,9 +1960,8 @@ namespace { << " " << _("to") << " " << target << std::endl; } if ( preserve ) { - auto end = sourceImage->exifData().end(); - for (auto i = sourceImage->exifData().begin(); i != end; ++i) { - targetImage->exifData()[i->key()] = i->value(); + for (auto&& exif : sourceImage->exifData()) { + targetImage->exifData()[exif.key()] = exif.value(); } } else { targetImage->setExifData(sourceImage->exifData()); @@ -1973,9 +1974,8 @@ namespace { << " " << _("to") << " " << target << std::endl; } if ( preserve ) { - Exiv2::IptcData::const_iterator end = sourceImage->iptcData().end(); - for (Exiv2::IptcData::const_iterator i = sourceImage->iptcData().begin(); i != end; ++i) { - targetImage->iptcData()[i->key()] = i->value(); + for (auto&& iptc : sourceImage->iptcData()) { + targetImage->iptcData()[iptc.key()] = iptc.value(); } } else { targetImage->setIptcData(sourceImage->iptcData()); @@ -2000,9 +2000,8 @@ namespace { os.close(); rc = 0; } else if (preserve) { - Exiv2::XmpData::const_iterator end = sourceImage->xmpData().end(); - for (Exiv2::XmpData::const_iterator i = sourceImage->xmpData().begin(); i != end; ++i) { - targetImage->xmpData()[i->key()] = i->value(); + for (auto&& xmp : sourceImage->xmpData()) { + targetImage->xmpData()[xmp.key()] = xmp.value(); } } else { // std::cout << "long cut" << std::endl; diff --git a/src/crwimage_int.cpp b/src/crwimage_int.cpp index 8ac31406a1..3326be7299 100644 --- a/src/crwimage_int.cpp +++ b/src/crwimage_int.cpp @@ -62,16 +62,14 @@ namespace { { 6, -270 }, { 8, 270 }, { 8, -90 }, - // last entry - { 0, 0 } }; uint16_t RotationMap::orientation(int32_t degrees) { uint16_t o = 1; - for (int i = 0; omList_[i].orientation != 0; ++i) { - if (omList_[i].degrees == degrees) { - o = omList_[i].orientation; + for (auto&& om : omList_) { + if (om.degrees == degrees) { + o = om.orientation; break; } } @@ -81,9 +79,9 @@ namespace { int32_t RotationMap::degrees(uint16_t orientation) { int32_t d = 0; - for (int i = 0; omList_[i].orientation != 0; ++i) { - if (omList_[i].orientation == orientation) { - d = omList_[i].degrees; + for (auto&& om : omList_) { + if (om.orientation == orientation) { + d = om.degrees; break; } } @@ -139,8 +137,6 @@ namespace Exiv2 { //CrwMapping(0x1818, 0x3002, 0, 0x9204, exifId, decodeBasic, encodeBasic), CrwMapping(0x183b, 0x300b, 0, 0x0015, canonId, decodeBasic, encodeBasic), CrwMapping(0x2008, 0x0000, 0, 0, ifd1Id, decode0x2008, encode0x2008), - // End of list marker - CrwMapping(0x0000, 0x0000, 0, 0x0000, ifdIdNotSet, 0, 0) }; // CrwMap::crwMapping_[] /* @@ -169,8 +165,6 @@ namespace Exiv2 { { 0x2804, 0x300a }, { 0x300a, 0x0000 }, { 0x0000, 0xffff }, - // End of list marker - { 0xffff, 0xffff } }; const char CiffHeader::signature_[] = "HEAPCCDR"; @@ -188,10 +182,8 @@ namespace Exiv2 { CiffDirectory::~CiffDirectory() { - Components::iterator b = components_.begin(); - Components::iterator e = components_.end(); - for (Components::iterator i = b; i != e; ++i) { - delete *i; + for (auto&& component : components_) { + delete component; } } @@ -359,10 +351,8 @@ namespace Exiv2 { void CiffDirectory::doDecode(Image& image, ByteOrder byteOrder) const { - Components::const_iterator b = components_.begin(); - Components::const_iterator e = components_.end(); - for (Components::const_iterator i = b; i != e; ++i) { - (*i)->decode(image, byteOrder); + for (auto&& component : components_) { + component->decode(image, byteOrder); } } // CiffDirectory::doDecode @@ -445,10 +435,8 @@ namespace Exiv2 { uint32_t dirOffset = 0; // Value data - const Components::iterator b = components_.begin(); - const Components::iterator e = components_.end(); - for (Components::iterator i = b; i != e; ++i) { - dirOffset = (*i)->write(blob, byteOrder, dirOffset); + for (auto&& component : components_) { + dirOffset = component->write(blob, byteOrder, dirOffset); } const uint32_t dirStart = dirOffset; @@ -459,8 +447,8 @@ namespace Exiv2 { dirOffset += 2; // Directory entries - for (Components::iterator i = b; i != e; ++i) { - (*i)->writeDirEntry(blob, byteOrder); + for (auto&& component : components_) { + component->writeDirEntry(blob, byteOrder); dirOffset += 10; } @@ -565,10 +553,8 @@ namespace Exiv2 { const std::string& prefix) const { CiffComponent::doPrint(os, byteOrder, prefix); - Components::const_iterator b = components_.begin(); - Components::const_iterator e = components_.end(); - for (Components::const_iterator i = b; i != e; ++i) { - (*i)->print(os, byteOrder, prefix + " "); + for (auto&& component : components_) { + component->print(os, byteOrder, prefix + " "); } } // CiffDirectory::doPrint @@ -642,11 +628,9 @@ namespace Exiv2 { CiffComponent* CiffDirectory::doFindComponent(uint16_t crwTagId, uint16_t crwDir) const { - CiffComponent* cc = NULL; - const Components::const_iterator b = components_.begin(); - const Components::const_iterator e = components_.end(); - for (Components::const_iterator i = b; i != e; ++i) { - cc = (*i)->findComponent(crwTagId, crwDir); + CiffComponent* cc; + for (auto&& component : components_) { + cc = component->findComponent(crwTagId, crwDir); if (cc) return cc; } return 0; @@ -691,16 +675,13 @@ namespace Exiv2 { if not found, create it set value */ - const Components::iterator b = components_.begin(); - const Components::iterator e = components_.end(); - if (!crwDirs.empty()) { CrwSubDir csd = crwDirs.top(); crwDirs.pop(); // Find the directory - for (Components::iterator i = b; i != e; ++i) { - if ((*i)->tag() == csd.crwDir_) { - cc_ = *i; + for (auto&& component : components_) { + if (component->tag() == csd.crwDir_) { + cc_ = component; break; } } @@ -715,9 +696,9 @@ namespace Exiv2 { } else { // Find the tag - for (Components::iterator i = b; i != e; ++i) { - if ((*i)->tagId() == crwTagId) { - cc_ = *i; + for (auto&& component : components_) { + if (component->tagId() == crwTagId) { + cc_ = component; break; } } @@ -814,10 +795,9 @@ namespace Exiv2 { const CrwMapping* CrwMap::crwMapping(uint16_t crwDir, uint16_t crwTagId) { - for (int i = 0; crwMapping_[i].ifdId_ != ifdIdNotSet; ++i) { - if ( crwMapping_[i].crwDir_ == crwDir - && crwMapping_[i].crwTagId_ == crwTagId) { - return &(crwMapping_[i]); + for (auto&& crw : crwMapping_) { + if (crw.crwDir_ == crwDir && crw.crwTagId_ == crwTagId) { + return &crw; } } return 0; @@ -1010,19 +990,19 @@ namespace Exiv2 { void CrwMap::loadStack(CrwDirs& crwDirs, uint16_t crwDir) { - for (int i = 0; crwSubDir_[i].crwDir_ != 0xffff; ++i) { - if (crwSubDir_[i].crwDir_ == crwDir) { - crwDirs.push(crwSubDir_[i]); - crwDir = crwSubDir_[i].parent_; + for (auto&& crw : crwSubDir_) { + if (crw.crwDir_ == crwDir) { + crwDirs.push(crw); + crwDir = crw.parent_; } } } // CrwMap::loadStack void CrwMap::encode(CiffHeader* pHead, const Image& image) { - for (const CrwMapping* cmi = crwMapping_; cmi->ifdId_ != ifdIdNotSet; ++cmi) { - if (cmi->fromExif_ != 0) { - cmi->fromExif_(image, cmi, pHead); + for (auto&& crw : crwMapping_) { + if (crw.fromExif_ != 0) { + crw.fromExif_(image, &crw, pHead); } } } // CrwMap::encode @@ -1237,14 +1217,13 @@ namespace Exiv2 { std::memset(buf.pData_, 0x0, buf.size_); uint16_t len = 0; - const auto b = exifData.begin(); - const auto e = exifData.end(); - for (auto i = b; i != e; ++i) { - if (i->ifdId() != ifdId) continue; - const uint16_t s = i->tag()*2 + static_cast(i->size()); + for (auto&& exif : exifData) { + if (exif.ifdId() != ifdId) + continue; + const uint16_t s = exif.tag() * 2 + static_cast(exif.size()); assert(s <= size); if (len < s) len = s; - i->copy(buf.pData_ + i->tag()*2, byteOrder); + exif.copy(buf.pData_ + exif.tag() * 2, byteOrder); } // Round the size to make it even. buf.size_ = len + len%2; diff --git a/src/olympusmn_int.cpp b/src/olympusmn_int.cpp index 406712039b..437a523a3f 100644 --- a/src/olympusmn_int.cpp +++ b/src/olympusmn_int.cpp @@ -1373,8 +1373,6 @@ namespace Exiv2 { { { 3, 1, 0 }, "Leica D Vario Elmarit 14-50mm F2.8-3.5 Asph." }, { { 3, 2, 0 }, "Leica D Summilux 25mm F1.4 Asph." }, { { 5, 1, 16 }, "Tamron 14-150mm F3.5-5.8 Di III" }, - // End of list marker - { { 0xff, 0, 0 }, "" } }; if (value.count() != 6 || value.typeId() != unsignedByte) { @@ -1385,11 +1383,9 @@ namespace Exiv2 { byte v2 = (byte)value.toLong(2); byte v3 = (byte)value.toLong(3); - for (int i = 0; lensTypes[i].val[0] != 0xff; i++) { - if (lensTypes[i].val[0] == v0 && - lensTypes[i].val[1] == v2 && - lensTypes[i].val[2] == v3) { - return os << lensTypes[i].label; + for (auto&& type : lensTypes) { + if (type.val[0] == v0 && type.val[1] == v2 && type.val[2] == v3) { + return os << type.label; } } return os << value; @@ -1423,8 +1419,6 @@ namespace Exiv2 { { { 0, 4 }, "Olympus Zuiko Digital EC-14 1.4x Teleconverter" }, { { 0, 8 }, "Olympus EX-25 Extension Tube" }, { { 0, 16 },"Olympus Zuiko Digital EC-20 2.0x Teleconverter" }, - // End of list marker - { { 0xff, 0 }, "" } }; if (value.count() != 6 || value.typeId() != unsignedByte) { @@ -1434,10 +1428,9 @@ namespace Exiv2 { byte v0 = (byte)value.toLong(0); byte v2 = (byte)value.toLong(2); - for (int i = 0; extenderModels[i].val[0] != 0xff; i++) { - if (extenderModels[i].val[0] == v0 && - extenderModels[i].val[1] == v2) { - return os << extenderModels[i].label; + for (auto&& model : extenderModels) { + if (model.val[0] == v0 && model.val[1] == v2) { + return os << model.label; } } return os << value; @@ -1547,8 +1540,6 @@ namespace Exiv2 { { { 39, 1280}, N_("Partial Color") }, { { 40, 1280}, N_("Partial Color II") }, { { 41, 1280}, N_("Partial Color III") }, - // End of list marker - { { 0xffff, 0 }, "" } }; if (value.count() != 4 || value.typeId() != unsignedShort) { @@ -1558,10 +1549,9 @@ namespace Exiv2 { uint16_t v0 = (uint16_t)value.toLong(0); uint16_t v1 = (uint16_t)value.toLong(1); - for (int i = 0; artFilters[i].val[0] != 0xffff; i++) { - if (artFilters[i].val[0] == v0 && - artFilters[i].val[1] == v1) { - return os << artFilters[i].label; + for (auto&& filter : artFilters) { + if (filter.val[0] == v0 && filter.val[1] == v1) { + return os << filter.label; } } return os << ""; @@ -1621,8 +1611,6 @@ value, const ExifData* metadata) { 2, N_("Right") }, { 3, N_("Center (vertical)") }, { 255, N_("None") }, - // End of list marker - { 0xffff, "" } }; static struct { @@ -1652,8 +1640,6 @@ value, const ExifData* metadata) { 0x14, N_("Bottom-left (vertical)") }, { 0x15, N_("Bottom-center (vertical)") }, { 0x16, N_("Bottom-right (vertical)") }, - // End of list marker - { 0xff, "" } }; if (value.count() != 1 || value.typeId() != unsignedShort) { @@ -1676,17 +1662,17 @@ value, const ExifData* metadata) uint16_t v = (uint16_t) value.toLong(0); if (!E3_E30model) { - for (int i = 0; afPoints[i].val != 0xffff; i++) { - if (afPoints[i].val == v) { - return os << afPoints[i].label; + for (auto&& point : afPoints) { + if (point.val == v) { + return os << point.label; } } } else { // E-3 and E-30 - for (int i = 0; afPointsE3[i].val != 0xff; i++) { - if (afPointsE3[i].val == (v & 0x1f)) { - os << afPointsE3[i].label; + for (auto&& point : afPointsE3) { + if (point.val == (v & 0x1f)) { + os << point.label; os << ", "; if ((v & 0xe0) == 0) return os << N_("Single Target"); if (v & 0x40) return os << N_("All Target"); diff --git a/src/tiffcomposite_int.cpp b/src/tiffcomposite_int.cpp index bf111edd38..81c59fbe17 100644 --- a/src/tiffcomposite_int.cpp +++ b/src/tiffcomposite_int.cpp @@ -880,9 +880,10 @@ namespace Exiv2 { void TiffDirectory::doAccept(TiffVisitor& visitor) { visitor.visitDirectory(this); - for (Components::const_iterator i = components_.begin(); - visitor.go(TiffVisitor::geTraverse) && i != components_.end(); ++i) { - (*i)->accept(visitor); + for (auto&& component : components_) { + if (!visitor.go(TiffVisitor::geTraverse)) + break; + component->accept(visitor); } if (visitor.go(TiffVisitor::geTraverse)) visitor.visitDirectoryNext(this); if (pNext_) pNext_->accept(visitor); @@ -892,9 +893,10 @@ namespace Exiv2 { void TiffSubIfd::doAccept(TiffVisitor& visitor) { visitor.visitSubIfd(this); - for (Ifds::iterator i = ifds_.begin(); - visitor.go(TiffVisitor::geTraverse) && i != ifds_.end(); ++i) { - (*i)->accept(visitor); + for (auto&& ifd : ifds_) { + if (!visitor.go(TiffVisitor::geTraverse)) + break; + ifd->accept(visitor); } } // TiffSubIfd::doAccept @@ -920,9 +922,10 @@ namespace Exiv2 { void TiffBinaryArray::doAccept(TiffVisitor& visitor) { visitor.visitBinaryArray(this); - for (Components::const_iterator i = elements_.begin(); - visitor.go(TiffVisitor::geTraverse) && i != elements_.end(); ++i) { - (*i)->accept(visitor); + for (auto&& element : elements_) { + if (!visitor.go(TiffVisitor::geTraverse)) + break; + element->accept(visitor); } if (visitor.go(TiffVisitor::geTraverse)) visitor.visitBinaryArrayEnd(this); } // TiffBinaryArray::doAccept diff --git a/src/tiffvisitor_int.cpp b/src/tiffvisitor_int.cpp index 4013beef4d..bdb140691b 100644 --- a/src/tiffvisitor_int.cpp +++ b/src/tiffvisitor_int.cpp @@ -489,23 +489,27 @@ namespace Exiv2 { { 0x260c , nMasks , false }, // AFPointsInFocus { 0x260d , nMasks , false }, // AFPointsSelected { 0x260e , nMasks , false }, // AFPointsUnusable - { 0xffff , 0 , true } // end marker }; // check we have enough data! uint16_t count = 0; - for ( uint16_t i = 0; records[i].tag != 0xffff ; i++) count += records[i].size ; - if ( count > ints.size() ) return ; + for (auto&& record : records) { + count += record.size; + if (count > ints.size()) + return; + } - for ( uint16_t i = 0; records[i].tag != 0xffff ; i++) { + for (auto&& record : records) { const TagInfo* pTags = ExifTags::tagList("Canon") ; - const TagInfo* pTag = findTag(pTags,records[i].tag); + const TagInfo* pTag = findTag(pTags, record.tag); if ( pTag ) { - Exiv2::Value::UniquePtr v = Exiv2::Value::create(records[i].bSigned?Exiv2::signedShort:Exiv2::unsignedShort); - std::ostringstream s; - if ( records[i].bSigned ) { - for ( int16_t k = 0 ; k < records[i].size ; k++ ) s << " " << ints.at(nStart++); + auto v = Exiv2::Value::create(record.bSigned ? Exiv2::signedShort : Exiv2::unsignedShort); + std::ostringstream s; + if (record.bSigned) { + for (int16_t k = 0; k < record.size; k++) + s << " " << ints.at(nStart++); } else { - for ( int16_t k = 0 ; k < records[i].size ; k++ ) s << " " << uint.at(nStart++); + for (int16_t k = 0; k < record.size; k++) + s << " " << uint.at(nStart++); } v->read(s.str()); diff --git a/src/value.cpp b/src/value.cpp index 4c26009846..633879d464 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -868,10 +868,10 @@ namespace Exiv2 { } // Write the others - for (i = value_.begin(); i != value_.end(); ++i) { - if (i->first != x_default ) { + for (auto&& v : value_) { + if (v.first != x_default) { if (!first) os << ", "; - os << "lang=\"" << i->first << "\" " << i->second; + os << "lang=\"" << v.first << "\" " << v.second; first = false; } }