Skip to content

Commit

Permalink
find_if conversion
Browse files Browse the repository at this point in the history
Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb committed Jul 11, 2022
1 parent 9bc4e51 commit 8d9553f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 34 deletions.
52 changes: 22 additions & 30 deletions src/crwimage_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,31 +550,27 @@ CiffComponent* CiffDirectory::doAdd(CrwDirs& crwDirs, uint16_t crwTagId) {
set value
*/
if (!crwDirs.empty()) {
auto [dir, parent] = crwDirs.top();
auto dir = crwDirs.top();
crwDirs.pop();
// Find the directory
for (auto&& component : components_) {
if (component->tag() == dir) {
cc_ = component;
break;
}
}
auto it =
std::find_if(components_.begin(), components_.end(), [=](const auto& c) { return c->tag() == dir.first; });
if (it != components_.end())
cc_ = *it;
if (!cc_) {
// Directory doesn't exist yet, add it
m_ = std::make_unique<CiffDirectory>(dir, parent);
m_ = std::make_unique<CiffDirectory>(dir.first, dir.second);
cc_ = m_.get();
add(std::move(m_));
}
// Recursive call to next lower level directory
cc_ = cc_->add(crwDirs, crwTagId);
} else {
// Find the tag
for (auto&& component : components_) {
if (component->tagId() == crwTagId) {
cc_ = component;
break;
}
}
auto it =
std::find_if(components_.begin(), components_.end(), [=](const auto& c) { return c->tagId() == crwTagId; });
if (it != components_.end())
cc_ = *it;
if (!cc_) {
// Tag doesn't exist yet, add it
m_ = std::make_unique<CiffEntry>(crwTagId, tag());
Expand Down Expand Up @@ -604,27 +600,23 @@ void CiffComponent::doRemove(CrwDirs& /*crwDirs*/, uint16_t /*crwTagId*/) {

void CiffDirectory::doRemove(CrwDirs& crwDirs, uint16_t crwTagId) {
if (!crwDirs.empty()) {
auto [dir, _] = crwDirs.top();
auto dir = crwDirs.top();
crwDirs.pop();
// Find the directory
for (auto i = components_.begin(); i != components_.end(); ++i) {
if ((*i)->tag() == dir) {
// Recursive call to next lower level directory
(*i)->remove(crwDirs, crwTagId);
if ((*i)->empty())
components_.erase(i);
break;
}
auto it =
std::find_if(components_.begin(), components_.end(), [=](const auto& c) { return c->tag() == dir.first; });
if (it != components_.end()) {
// Recursive call to next lower level directory
(*it)->remove(crwDirs, crwTagId);
if ((*it)->empty())
components_.erase(it);
}
} else {
// Find the tag
for (auto i = components_.begin(); i != components_.end(); ++i) {
if ((*i)->tagId() == crwTagId) {
// Remove the entry and abort the loop
delete *i;
components_.erase(i);
break;
}
auto it = std::find_if(components_.begin(), components_.end(), [=](const auto& c) { return c->tag() == crwTagId; });
if (it != components_.end()) {
delete *it;
components_.erase(it);
}
}
} // CiffDirectory::doRemove
Expand Down
2 changes: 1 addition & 1 deletion src/makernote_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ int nikonSelector(uint16_t tag, const byte* pData, size_t size, TiffComponent* /
return -1;

auto ix = NikonArrayIdx::Key(tag, reinterpret_cast<const char*>(pData), size);
auto it = std::find_if(nikonArrayIdx.begin(), nikonArrayIdx.end(), [ix](auto&& aix) { return aix == ix; });
auto it = std::find(nikonArrayIdx.begin(), nikonArrayIdx.end(), ix);
if (it == nikonArrayIdx.end())
return -1;

Expand Down
6 changes: 3 additions & 3 deletions src/sonymn_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ std::ostream& SonyMakerNote::printSonyMisc3cShotNumberSincePowerUp(std::ostream&
"DSC-RX100M4", "DSC-RX100M5", "DSC-WX220", "DSC-WX350", "DSC-WX500",
};

bool f = std::any_of(models.begin(), models.end(), [model = pos->toString()](auto&& m) { return m == model; });
bool f = std::find(models.begin(), models.end(), pos->toString()) != models.end();
if (f)
return os << value.toInt64();
return os << N_("n/a");
Expand Down Expand Up @@ -922,7 +922,7 @@ std::ostream& SonyMakerNote::printSonyMisc3cSonyImageHeight(std::ostream& os, co

// Models that do not support this tag
const auto models = std::array{"ILCE-1", "ILCE-7SM3", "ILME-FX3"};
bool f = std::any_of(models.begin(), models.end(), [model = pos->toString()](auto&& m) { return m == model; });
bool f = std::find(models.begin(), models.end(), pos->toString()) != models.end();
if (f)
return os << N_("n/a");

Expand All @@ -941,7 +941,7 @@ std::ostream& SonyMakerNote::printSonyMisc3cModelReleaseYear(std::ostream& os, c

// Models that do not support this tag
const auto models = std::array{"ILCE-1", "ILCE-7SM3", "ILME-FX3"};
bool f = std::any_of(models.begin(), models.end(), [model = pos->toString()](auto&& m) { return m == model; });
bool f = std::find(models.begin(), models.end(), pos->toString()) != models.end();
if (f)
return os << N_("n/a");

Expand Down

0 comments on commit 8d9553f

Please sign in to comment.