Skip to content

Commit

Permalink
manual for range loop conversions
Browse files Browse the repository at this point in the history
Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb authored and piponazo committed May 17, 2021
1 parent 8e52032 commit 20dfab8
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 150 deletions.
75 changes: 37 additions & 38 deletions src/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 ;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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;
Expand Down
101 changes: 40 additions & 61 deletions src/crwimage_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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_[]

/*
Expand Down Expand Up @@ -169,8 +165,6 @@ namespace Exiv2 {
{ 0x2804, 0x300a },
{ 0x300a, 0x0000 },
{ 0x0000, 0xffff },
// End of list marker
{ 0xffff, 0xffff }
};

const char CiffHeader::signature_[] = "HEAPCCDR";
Expand All @@ -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;
}
}

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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;

Expand All @@ -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;
}

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<uint16_t>(i->size());
for (auto&& exif : exifData) {
if (exif.ifdId() != ifdId)
continue;
const uint16_t s = exif.tag() * 2 + static_cast<uint16_t>(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;
Expand Down
Loading

0 comments on commit 20dfab8

Please sign in to comment.