std::find to find template

std::find in C++20 can use ranges, which is equivalent here. Less error
prone.

Namespace is properly to avoid any conflicts with std::find or others

Signed-off-by: Rosen Penev <rosenp@gmail.com>
main
Rosen Penev 2 years ago
parent c9f7a9f34e
commit 7fd7ee62a3

@ -41,12 +41,19 @@ constexpr auto emptyYodAdjust_ = std::array{
}; };
//! List of all command identifiers and corresponding strings //! List of all command identifiers and corresponding strings
constexpr auto cmdIdAndString = std::array{ constexpr struct CmdIdAndString {
std::pair(CmdId::add, "add"), CmdId cmdId_;
std::pair(CmdId::set, "set"), const char* string_;
std::pair(CmdId::del, "del"), //! Comparison operator for \em string
std::pair(CmdId::reg, "reg"), bool operator==(const std::string& string) const {
std::pair(CmdId::invalid, "invalidCmd"), // End of list marker return string == string_;
}
} cmdIdAndString[] = {
{CmdId::add, "add"},
{CmdId::set, "set"},
{CmdId::del, "del"},
{CmdId::reg, "reg"},
{CmdId::invalid, "invalidCmd"}, // End of list marker
}; };
// Return a command Id for a command string // Return a command Id for a command string
@ -1433,8 +1440,8 @@ bool parseLine(ModifyCmd& modifyCmd, const std::string& line, int num) {
} // parseLine } // parseLine
CmdId commandId(const std::string& cmdString) { CmdId commandId(const std::string& cmdString) {
auto it = std::find_if(cmdIdAndString.begin(), cmdIdAndString.end(), [&](auto cs) { return cs.second == cmdString; }); auto it = Exiv2::find(cmdIdAndString, cmdString);
return it != cmdIdAndString.end() ? it->first : CmdId::invalid; return it ? it->cmdId_ : CmdId::invalid;
} }
std::string parseEscapes(const std::string& input) { std::string parseEscapes(const std::string& input) {

@ -265,7 +265,6 @@ void AsfVideo::readMetadata() {
void AsfVideo::decodeBlock() { void AsfVideo::decodeBlock() {
DataBuf buf(BUFF_MIN_SIZE + 1); DataBuf buf(BUFF_MIN_SIZE + 1);
uint64_t size = 0; uint64_t size = 0;
const Internal::TagVocabulary* tv;
uint64_t cur_pos = io_->tell(); uint64_t cur_pos = io_->tell();
byte guidBuf[GUI_SIZE]; byte guidBuf[GUI_SIZE];
@ -278,12 +277,11 @@ void AsfVideo::decodeBlock() {
char GUID[GUID_SIZE] = ""; // the getGUID function write the GUID[36], char GUID[GUID_SIZE] = ""; // the getGUID function write the GUID[36],
getGUID(guidBuf, GUID);
tv = find(GUIDReferenceTags, GUID);
io_->read(buf.data(), BUFF_MIN_SIZE); io_->read(buf.data(), BUFF_MIN_SIZE);
size = Util::getUint64_t(buf); size = Util::getUint64_t(buf);
getGUID(guidBuf, GUID);
auto tv = Exiv2::find(GUIDReferenceTags, GUID);
if (tv) { if (tv) {
auto tagDecoder = [&](const Internal::TagVocabulary* tv, uint64_t size) { auto tagDecoder = [&](const Internal::TagVocabulary* tv, uint64_t size) {
uint64_t cur_pos = io_->tell(); uint64_t cur_pos = io_->tell();
@ -392,7 +390,7 @@ void AsfVideo::contentDescription(uint64_t size) {
io_->read(buf.data(), length[i]); io_->read(buf.data(), length[i]);
if (io_->error() || io_->eof()) if (io_->error() || io_->eof())
throw Error(ErrorCode::kerFailedToReadImageData); throw Error(ErrorCode::kerFailedToReadImageData);
const TagDetails* td = find(contentDescriptionTags, i); auto td = Exiv2::find(contentDescriptionTags, i);
assert(td); assert(td);
std::string str(reinterpret_cast<const char*>(buf.data()), length[i]); std::string str(reinterpret_cast<const char*>(buf.data()), length[i]);
if (convertStringCharset(str, "UCS-2LE", "UTF-8")) { if (convertStringCharset(str, "UCS-2LE", "UTF-8")) {
@ -414,8 +412,7 @@ void AsfVideo::streamProperties() {
char streamType[GUID_SIZE] = ""; char streamType[GUID_SIZE] = "";
getGUID(guidBuf, streamType); getGUID(guidBuf, streamType);
const TagVocabulary* tv; auto tv = Exiv2::find(GUIDReferenceTags, streamType);
tv = find(GUIDReferenceTags, streamType);
io_->read(guidBuf, GUI_SIZE); io_->read(guidBuf, GUI_SIZE);
if (compareTag(exvGettext(tv->label_), "Audio_Media")) if (compareTag(exvGettext(tv->label_), "Audio_Media"))
@ -632,7 +629,7 @@ void AsfVideo::fileProperties() {
const TagDetails* td; const TagDetails* td;
while (count--) { while (count--) {
td = find(filePropertiesTags, (count + 1)); td = Exiv2::find(filePropertiesTags, (count + 1));
io_->read(buf.data(), BUFF_MIN_SIZE); io_->read(buf.data(), BUFF_MIN_SIZE);
if (count == 0) { if (count == 0) {

@ -1553,8 +1553,8 @@ const ConvFctList convFctList[] = {
[[maybe_unused]] bool convertStringCharsetWindows(std::string& str, const char* from, const char* to) { [[maybe_unused]] bool convertStringCharsetWindows(std::string& str, const char* from, const char* to) {
bool ret = false; bool ret = false;
const ConvFctList* p = find(convFctList, std::pair(from, to));
std::string tmpstr = str; std::string tmpstr = str;
auto p = Exiv2::find(convFctList, std::pair(from, to));
if (p) if (p)
ret = p->convFct_(tmpstr); ret = p->convFct_(tmpstr);
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS

@ -241,7 +241,7 @@ std::ostream& printFujiDriveSetting(std::ostream& os, const Value& value, const
auto byte3 = (value.toInt64() >> 16) & 0xff; auto byte3 = (value.toInt64() >> 16) & 0xff;
auto fps = value.toInt64() >> 24; auto fps = value.toInt64() >> 24;
auto setting = find(fujiDriveSettingByte1, byte1); auto setting = Exiv2::find(fujiDriveSettingByte1, byte1);
if (setting) { if (setting) {
os << exvGettext(setting->label_); os << exvGettext(setting->label_);
} else { } else {
@ -347,7 +347,7 @@ std::ostream& printFujiFaceElementTypes(std::ostream& os, const Value& value, co
longValue -= '0'; longValue -= '0';
} }
auto td = find(fujiFaceElementType, longValue); auto td = Exiv2::find(fujiFaceElementType, longValue);
if (n != 0) { if (n != 0) {
os << " "; os << " ";
} }

@ -137,16 +137,16 @@ bool TiffMnRegistry::operator==(IfdId key) const {
TiffComponent* TiffMnCreator::create(uint16_t tag, IfdId group, const std::string& make, const byte* pData, size_t size, TiffComponent* TiffMnCreator::create(uint16_t tag, IfdId group, const std::string& make, const byte* pData, size_t size,
ByteOrder byteOrder) { ByteOrder byteOrder) {
auto tmr = std::find(std::begin(registry_), std::end(registry_), make); auto tmr = Exiv2::find(registry_, make);
if (tmr != std::end(registry_)) { if (!tmr) {
return tmr->newMnFct_(tag, group, tmr->mnGroup_, pData, size, byteOrder); return nullptr;
} }
return nullptr; return tmr->newMnFct_(tag, group, tmr->mnGroup_, pData, size, byteOrder);
} // TiffMnCreator::create } // TiffMnCreator::create
TiffComponent* TiffMnCreator::create(uint16_t tag, IfdId group, IfdId mnGroup) { TiffComponent* TiffMnCreator::create(uint16_t tag, IfdId group, IfdId mnGroup) {
auto tmr = std::find(std::begin(registry_), std::end(registry_), mnGroup); auto tmr = Exiv2::find(registry_, mnGroup);
if (tmr != std::end(registry_)) { if (tmr) {
if (tmr->newMnFct2_) { if (tmr->newMnFct2_) {
return tmr->newMnFct2_(tag, group, mnGroup); return tmr->newMnFct2_(tag, group, mnGroup);
} }

@ -1483,7 +1483,7 @@ static bool inRange(long value, long min, long max) {
} }
static std::ostream& resolvedLens(std::ostream& os, long lensID, long index) { static std::ostream& resolvedLens(std::ostream& os, long lensID, long index) {
const TagDetails* td = find(minoltaSonyLensID, lensID); auto td = Exiv2::find(minoltaSonyLensID, lensID);
std::vector<std::string> tokens = split(td[0].label_, "|"); std::vector<std::string> tokens = split(td[0].label_, "|");
return os << exvGettext(trim(tokens.at(index - 1)).c_str()); return os << exvGettext(trim(tokens.at(index - 1)).c_str());
} }

@ -3791,7 +3791,7 @@ std::ostream& Nikon3MakerNote::print0x009e(std::ostream& os, const Value& value,
if (l != 0) if (l != 0)
trim = false; trim = false;
std::string d = s.empty() ? "" : "; "; std::string d = s.empty() ? "" : "; ";
const TagDetails* td = find(nikonRetouchHistory, l); auto td = Exiv2::find(nikonRetouchHistory, l);
if (td) { if (td) {
s = std::string(exvGettext(td->label_)).append(d).append(s); s = std::string(exvGettext(td->label_)).append(d).append(s);
} else { } else {

@ -1096,7 +1096,7 @@ std::ostream& resolveLens0x32c(std::ostream& os, const Value& value, const ExifD
if (index > 0) { if (index > 0) {
const unsigned long lensID = 0x32c; const unsigned long lensID = 0x32c;
const TagDetails* td = find(pentaxLensType, lensID); auto td = Exiv2::find(pentaxLensType, lensID);
os << exvGettext(td[index].label_); os << exvGettext(td[index].label_);
return os; return os;
} }
@ -1160,7 +1160,7 @@ std::ostream& resolveLens0x3ff(std::ostream& os, const Value& value, const ExifD
if (index > 0) { if (index > 0) {
const unsigned long lensID = 0x3ff; const unsigned long lensID = 0x3ff;
const TagDetails* td = find(pentaxLensType, lensID); auto td = Exiv2::find(pentaxLensType, lensID);
os << exvGettext(td[index].label_); os << exvGettext(td[index].label_);
return os; return os;
} }
@ -1187,7 +1187,7 @@ std::ostream& resolveLens0x8ff(std::ostream& os, const Value& value, const ExifD
if (index > 0) { if (index > 0) {
const unsigned long lensID = 0x8ff; const unsigned long lensID = 0x8ff;
const TagDetails* td = find(pentaxLensType, lensID); auto td = Exiv2::find(pentaxLensType, lensID);
os << exvGettext(td[index].label_); os << exvGettext(td[index].label_);
return os; return os;
} }
@ -1221,7 +1221,7 @@ std::ostream& resolveLens0x319(std::ostream& os, const Value& value, const ExifD
if (index > 0) { if (index > 0) {
const unsigned long lensID = 0x319; const unsigned long lensID = 0x319;
const TagDetails* td = find(pentaxLensType, lensID); auto td = Exiv2::find(pentaxLensType, lensID);
os << exvGettext(td[index].label_); os << exvGettext(td[index].label_);
return os; return os;
} }

@ -70,7 +70,7 @@ std::ostream& printCombiTag(std::ostream& os, const Value& value, const ExifData
} }
l += (value.toUint32(c) << ((count - c - 1) * 8)); l += (value.toUint32(c) << ((count - c - 1) * 8));
} }
const TagDetails* td = find(array, l); auto td = Exiv2::find(array, l);
if (td) { if (td) {
os << exvGettext(td->label_); os << exvGettext(td->label_);
} else { } else {

@ -5003,7 +5003,7 @@ std::string XmpProperties::prefix(const std::string& ns) {
if (i != nsRegistry_.end()) { if (i != nsRegistry_.end()) {
p = i->second.prefix_; p = i->second.prefix_;
} else { } else {
const XmpNsInfo* xn = find(xmpNsInfo, XmpNsInfo::Ns(ns2)); auto xn = Exiv2::find(xmpNsInfo, XmpNsInfo::Ns(ns2));
if (xn) if (xn)
p = std::string(xn->prefix_); p = std::string(xn->prefix_);
} }
@ -5082,7 +5082,7 @@ const XmpNsInfo* XmpProperties::nsInfoUnsafe(const std::string& prefix) {
const XmpNsInfo::Prefix pf(prefix); const XmpNsInfo::Prefix pf(prefix);
const XmpNsInfo* xn = lookupNsRegistryUnsafe(pf); const XmpNsInfo* xn = lookupNsRegistryUnsafe(pf);
if (!xn) if (!xn)
xn = find(xmpNsInfo, pf); xn = Exiv2::find(xmpNsInfo, pf);
if (!xn) if (!xn)
throw Error(ErrorCode::kerNoNamespaceInfoForXmpPrefix, prefix); throw Error(ErrorCode::kerNoNamespaceInfoForXmpPrefix, prefix);
return xn; return xn;
@ -5108,7 +5108,7 @@ void XmpProperties::printProperties(std::ostream& os, const std::string& prefix)
std::ostream& XmpProperties::printProperty(std::ostream& os, const std::string& key, const Value& value) { std::ostream& XmpProperties::printProperty(std::ostream& os, const std::string& key, const Value& value) {
PrintFct fct = printValue; PrintFct fct = printValue;
if (value.count() != 0) { if (value.count() != 0) {
const XmpPrintInfo* info = find(xmpPrintInfo, key); auto info = Exiv2::find(xmpPrintInfo, key);
if (info) if (info)
fct = info->printFct_; fct = info->printFct_;
} }

@ -775,7 +775,7 @@ void QuickTimeVideo::CameraTagsDecoder(size_t size_external) {
buf.read_uint32(0, littleEndian) / static_cast<double>(buf2.read_uint32(0, littleEndian)); buf.read_uint32(0, littleEndian) / static_cast<double>(buf2.read_uint32(0, littleEndian));
io_->readOrThrow(buf.data(), 10); io_->readOrThrow(buf.data(), 10);
io_->readOrThrow(buf.data(), 4); io_->readOrThrow(buf.data(), 4);
td = find(whiteBalance, buf.read_uint32(0, littleEndian)); td = Exiv2::find(whiteBalance, buf.read_uint32(0, littleEndian));
if (td) if (td)
xmpData_["Xmp.video.WhiteBalance"] = exvGettext(td->label_); xmpData_["Xmp.video.WhiteBalance"] = exvGettext(td->label_);
io_->readOrThrow(buf.data(), 4); io_->readOrThrow(buf.data(), 4);
@ -814,9 +814,9 @@ void QuickTimeVideo::userDataDecoder(size_t size_external) {
if (buf.data()[0] == 169) if (buf.data()[0] == 169)
buf.data()[0] = ' '; buf.data()[0] = ' ';
td = find(userDatatags, Exiv2::toString(buf.data())); td = Exiv2::find(userDatatags, Exiv2::toString(buf.data()));
tv = find(userDataReferencetags, Exiv2::toString(buf.data())); tv = Exiv2::find(userDataReferencetags, Exiv2::toString(buf.data()));
if (size <= 12) if (size <= 12)
break; break;
@ -840,7 +840,7 @@ void QuickTimeVideo::userDataDecoder(size_t size_external) {
enforce(tv, Exiv2::ErrorCode::kerCorruptedMetadata); enforce(tv, Exiv2::ErrorCode::kerCorruptedMetadata);
io_->readOrThrow(buf.data(), 2); io_->readOrThrow(buf.data(), 2);
buf.data()[2] = '\0'; buf.data()[2] = '\0';
tv_internal = find(cameraByteOrderTags, Exiv2::toString(buf.data())); tv_internal = Exiv2::find(cameraByteOrderTags, Exiv2::toString(buf.data()));
if (tv_internal) if (tv_internal)
xmpData_[exvGettext(tv->label_)] = exvGettext(tv_internal->label_); xmpData_[exvGettext(tv->label_)] = exvGettext(tv_internal->label_);
@ -870,7 +870,7 @@ void QuickTimeVideo::NikonTagsDecoder(size_t size_external) {
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
io_->readOrThrow(buf.data(), 4); io_->readOrThrow(buf.data(), 4);
TagID = buf.read_uint32(0, bigEndian); TagID = buf.read_uint32(0, bigEndian);
td = find(NikonNCTGTags, TagID); td = Exiv2::find(NikonNCTGTags, TagID);
io_->readOrThrow(buf.data(), 2); io_->readOrThrow(buf.data(), 2);
dataType = buf.read_uint16(0, bigEndian); dataType = buf.read_uint16(0, bigEndian);
@ -893,40 +893,40 @@ void QuickTimeVideo::NikonTagsDecoder(size_t size_external) {
std::memset(buf.data(), 0x0, buf.size()); std::memset(buf.data(), 0x0, buf.size());
io_->readOrThrow(buf.data(), 1); io_->readOrThrow(buf.data(), 1);
td2 = find(PictureControlAdjust, static_cast<int>(buf.data()[0]) & 7); td2 = Exiv2::find(PictureControlAdjust, static_cast<int>(buf.data()[0]) & 7);
if (td2) if (td2)
xmpData_["Xmp.video.PictureControlAdjust"] = exvGettext(td2->label_); xmpData_["Xmp.video.PictureControlAdjust"] = exvGettext(td2->label_);
else else
xmpData_["Xmp.video.PictureControlAdjust"] = static_cast<int>(buf.data()[0]) & 7; xmpData_["Xmp.video.PictureControlAdjust"] = static_cast<int>(buf.data()[0]) & 7;
io_->readOrThrow(buf.data(), 1); io_->readOrThrow(buf.data(), 1);
td2 = find(NormalSoftHard, static_cast<int>(buf.data()[0]) & 7); td2 = Exiv2::find(NormalSoftHard, static_cast<int>(buf.data()[0]) & 7);
if (td2) if (td2)
xmpData_["Xmp.video.PictureControlQuickAdjust"] = exvGettext(td2->label_); xmpData_["Xmp.video.PictureControlQuickAdjust"] = exvGettext(td2->label_);
io_->readOrThrow(buf.data(), 1); io_->readOrThrow(buf.data(), 1);
td2 = find(NormalSoftHard, static_cast<int>(buf.data()[0]) & 7); td2 = Exiv2::find(NormalSoftHard, static_cast<int>(buf.data()[0]) & 7);
if (td2) if (td2)
xmpData_["Xmp.video.Sharpness"] = exvGettext(td2->label_); xmpData_["Xmp.video.Sharpness"] = exvGettext(td2->label_);
else else
xmpData_["Xmp.video.Sharpness"] = static_cast<int>(buf.data()[0]) & 7; xmpData_["Xmp.video.Sharpness"] = static_cast<int>(buf.data()[0]) & 7;
io_->readOrThrow(buf.data(), 1); io_->readOrThrow(buf.data(), 1);
td2 = find(NormalSoftHard, static_cast<int>(buf.data()[0]) & 7); td2 = Exiv2::find(NormalSoftHard, static_cast<int>(buf.data()[0]) & 7);
if (td2) if (td2)
xmpData_["Xmp.video.Contrast"] = exvGettext(td2->label_); xmpData_["Xmp.video.Contrast"] = exvGettext(td2->label_);
else else
xmpData_["Xmp.video.Contrast"] = static_cast<int>(buf.data()[0]) & 7; xmpData_["Xmp.video.Contrast"] = static_cast<int>(buf.data()[0]) & 7;
io_->readOrThrow(buf.data(), 1); io_->readOrThrow(buf.data(), 1);
td2 = find(NormalSoftHard, static_cast<int>(buf.data()[0]) & 7); td2 = Exiv2::find(NormalSoftHard, static_cast<int>(buf.data()[0]) & 7);
if (td2) if (td2)
xmpData_["Xmp.video.Brightness"] = exvGettext(td2->label_); xmpData_["Xmp.video.Brightness"] = exvGettext(td2->label_);
else else
xmpData_["Xmp.video.Brightness"] = static_cast<int>(buf.data()[0]) & 7; xmpData_["Xmp.video.Brightness"] = static_cast<int>(buf.data()[0]) & 7;
io_->readOrThrow(buf.data(), 1); io_->readOrThrow(buf.data(), 1);
td2 = find(Saturation, static_cast<int>(buf.data()[0]) & 7); td2 = Exiv2::find(Saturation, static_cast<int>(buf.data()[0]) & 7);
if (td2) if (td2)
xmpData_["Xmp.video.Saturation"] = exvGettext(td2->label_); xmpData_["Xmp.video.Saturation"] = exvGettext(td2->label_);
else else
@ -936,14 +936,14 @@ void QuickTimeVideo::NikonTagsDecoder(size_t size_external) {
xmpData_["Xmp.video.HueAdjustment"] = static_cast<int>(buf.data()[0]) & 7; xmpData_["Xmp.video.HueAdjustment"] = static_cast<int>(buf.data()[0]) & 7;
io_->readOrThrow(buf.data(), 1); io_->readOrThrow(buf.data(), 1);
td2 = find(FilterEffect, static_cast<int>(buf.data()[0])); td2 = Exiv2::find(FilterEffect, static_cast<int>(buf.data()[0]));
if (td2) if (td2)
xmpData_["Xmp.video.FilterEffect"] = exvGettext(td2->label_); xmpData_["Xmp.video.FilterEffect"] = exvGettext(td2->label_);
else else
xmpData_["Xmp.video.FilterEffect"] = static_cast<int>(buf.data()[0]); xmpData_["Xmp.video.FilterEffect"] = static_cast<int>(buf.data()[0]);
io_->readOrThrow(buf.data(), 1); io_->readOrThrow(buf.data(), 1);
td2 = find(ToningEffect, static_cast<int>(buf.data()[0])); td2 = Exiv2::find(ToningEffect, static_cast<int>(buf.data()[0]));
if (td2) if (td2)
xmpData_["Xmp.video.ToningEffect"] = exvGettext(td2->label_); xmpData_["Xmp.video.ToningEffect"] = exvGettext(td2->label_);
else else
@ -963,12 +963,12 @@ void QuickTimeVideo::NikonTagsDecoder(size_t size_external) {
io_->readOrThrow(buf.data(), 2); io_->readOrThrow(buf.data(), 2);
xmpData_["Xmp.video.TimeZone"] = Exiv2::getShort(buf.data(), bigEndian); xmpData_["Xmp.video.TimeZone"] = Exiv2::getShort(buf.data(), bigEndian);
io_->readOrThrow(buf.data(), 1); io_->readOrThrow(buf.data(), 1);
td2 = find(YesNo, static_cast<int>(buf.data()[0])); td2 = Exiv2::find(YesNo, static_cast<int>(buf.data()[0]));
if (td2) if (td2)
xmpData_["Xmp.video.DayLightSavings"] = exvGettext(td2->label_); xmpData_["Xmp.video.DayLightSavings"] = exvGettext(td2->label_);
io_->readOrThrow(buf.data(), 1); io_->readOrThrow(buf.data(), 1);
td2 = find(DateDisplayFormat, static_cast<int>(buf.data()[0])); td2 = Exiv2::find(DateDisplayFormat, static_cast<int>(buf.data()[0]));
if (td2) if (td2)
xmpData_["Xmp.video.DateDisplayFormat"] = exvGettext(td2->label_); xmpData_["Xmp.video.DateDisplayFormat"] = exvGettext(td2->label_);
@ -1143,14 +1143,14 @@ void QuickTimeVideo::audioDescDecoder() {
io_->readOrThrow(buf.data(), 4); io_->readOrThrow(buf.data(), 4);
switch (i) { switch (i) {
case AudioFormat: case AudioFormat:
td = find(qTimeFileType, Exiv2::toString(buf.data())); td = Exiv2::find(qTimeFileType, Exiv2::toString(buf.data()));
if (td) if (td)
xmpData_["Xmp.audio.Compressor"] = exvGettext(td->label_); xmpData_["Xmp.audio.Compressor"] = exvGettext(td->label_);
else else
xmpData_["Xmp.audio.Compressor"] = Exiv2::toString(buf.data()); xmpData_["Xmp.audio.Compressor"] = Exiv2::toString(buf.data());
break; break;
case AudioVendorID: case AudioVendorID:
td = find(vendorIDTags, Exiv2::toString(buf.data())); td = Exiv2::find(vendorIDTags, Exiv2::toString(buf.data()));
if (td) if (td)
xmpData_["Xmp.audio.VendorID"] = exvGettext(td->label_); xmpData_["Xmp.audio.VendorID"] = exvGettext(td->label_);
break; break;
@ -1183,14 +1183,14 @@ void QuickTimeVideo::imageDescDecoder() {
switch (i) { switch (i) {
case codec: case codec:
td = find(qTimeFileType, Exiv2::toString(buf.data())); td = Exiv2::find(qTimeFileType, Exiv2::toString(buf.data()));
if (td) if (td)
xmpData_["Xmp.video.Codec"] = exvGettext(td->label_); xmpData_["Xmp.video.Codec"] = exvGettext(td->label_);
else else
xmpData_["Xmp.video.Codec"] = Exiv2::toString(buf.data()); xmpData_["Xmp.video.Codec"] = Exiv2::toString(buf.data());
break; break;
case VendorID: case VendorID:
td = find(vendorIDTags, Exiv2::toString(buf.data())); td = Exiv2::find(vendorIDTags, Exiv2::toString(buf.data()));
if (td) if (td)
xmpData_["Xmp.video.VendorID"] = exvGettext(td->label_); xmpData_["Xmp.video.VendorID"] = exvGettext(td->label_);
break; break;
@ -1247,7 +1247,7 @@ void QuickTimeVideo::videoHeaderDecoder(size_t size) {
switch (i) { switch (i) {
case GraphicsMode: case GraphicsMode:
td = find(graphicsModetags, buf.read_uint16(0, bigEndian)); td = Exiv2::find(graphicsModetags, buf.read_uint16(0, bigEndian));
if (td) if (td)
xmpData_["Xmp.video.GraphicsMode"] = exvGettext(td->label_); xmpData_["Xmp.video.GraphicsMode"] = exvGettext(td->label_);
break; break;
@ -1274,7 +1274,7 @@ void QuickTimeVideo::handlerDecoder(size_t size) {
switch (i) { switch (i) {
case HandlerClass: case HandlerClass:
tv = find(handlerClassTags, Exiv2::toString(buf.data())); tv = Exiv2::find(handlerClassTags, Exiv2::toString(buf.data()));
if (tv) { if (tv) {
if (currentStream_ == Video) if (currentStream_ == Video)
xmpData_["Xmp.video.HandlerClass"] = exvGettext(tv->label_); xmpData_["Xmp.video.HandlerClass"] = exvGettext(tv->label_);
@ -1283,7 +1283,7 @@ void QuickTimeVideo::handlerDecoder(size_t size) {
} }
break; break;
case HandlerType: case HandlerType:
tv = find(handlerTypeTags, Exiv2::toString(buf.data())); tv = Exiv2::find(handlerTypeTags, Exiv2::toString(buf.data()));
if (tv) { if (tv) {
if (currentStream_ == Video) if (currentStream_ == Video)
xmpData_["Xmp.video.HandlerType"] = exvGettext(tv->label_); xmpData_["Xmp.video.HandlerType"] = exvGettext(tv->label_);
@ -1292,7 +1292,7 @@ void QuickTimeVideo::handlerDecoder(size_t size) {
} }
break; break;
case HandlerVendorID: case HandlerVendorID:
tv = find(vendorIDTags, Exiv2::toString(buf.data())); tv = Exiv2::find(vendorIDTags, Exiv2::toString(buf.data()));
if (tv) { if (tv) {
if (currentStream_ == Video) if (currentStream_ == Video)
xmpData_["Xmp.video.HandlerVendorID"] = exvGettext(tv->label_); xmpData_["Xmp.video.HandlerVendorID"] = exvGettext(tv->label_);
@ -1314,7 +1314,7 @@ void QuickTimeVideo::fileTypeDecoder(size_t size) {
for (int i = 0; size / 4 != 0; size -= 4, i++) { for (int i = 0; size / 4 != 0; size -= 4, i++) {
io_->readOrThrow(buf.data(), 4); io_->readOrThrow(buf.data(), 4);
td = find(qTimeFileType, Exiv2::toString(buf.data())); td = Exiv2::find(qTimeFileType, Exiv2::toString(buf.data()));
switch (i) { switch (i) {
case 0: case 0:
@ -1598,7 +1598,7 @@ bool isQTimeType(BasicIo& iIo, bool advance) {
// we only match if we actually know the video type. This is done // we only match if we actually know the video type. This is done
// to avoid matching just on ftyp because bmffimage also has that // to avoid matching just on ftyp because bmffimage also has that
// header. // header.
auto td = find(qTimeFileType, std::string{buf.c_str(8), 4}); auto td = Exiv2::find(qTimeFileType, std::string{buf.c_str(8), 4});
if (td) { if (td) {
matched = true; matched = true;
} }

@ -772,7 +772,7 @@ void RiffVideo::nikonTagsHandler() {
io_->read(buf.data(), 2); io_->read(buf.data(), 2);
dataSize = Exiv2::getULong(buf.data(), littleEndian); dataSize = Exiv2::getULong(buf.data(), littleEndian);
temp -= (RIFF_TAG_SIZE + dataSize); temp -= (RIFF_TAG_SIZE + dataSize);
td = find(nikonAVITags, tagID); td = Exiv2::find(nikonAVITags, tagID);
if (dataSize <= 0) { if (dataSize <= 0) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
@ -861,7 +861,7 @@ void RiffVideo::infoTagsHandler() {
size -= RIFF_TAG_SIZE; size -= RIFF_TAG_SIZE;
if (!Exiv2::getULong(buf.data(), littleEndian)) if (!Exiv2::getULong(buf.data(), littleEndian))
break; break;
tv = find(infoTags, Exiv2::toString(buf.data())); tv = Exiv2::find(infoTags, Exiv2::toString(buf.data()));
io_->read(buf.data(), RIFF_TAG_SIZE); io_->read(buf.data(), RIFF_TAG_SIZE);
size -= RIFF_TAG_SIZE; size -= RIFF_TAG_SIZE;
infoSize = Exiv2::getULong(buf.data(), littleEndian); infoSize = Exiv2::getULong(buf.data(), littleEndian);
@ -1132,7 +1132,7 @@ void RiffVideo::streamFormatHandler(size_t size) {
switch (tag) { switch (tag) {
case encoding: case encoding:
td = find(audioEncodingValues, Exiv2::getUShort(buf.data(), littleEndian)); td = Exiv2::find(audioEncodingValues, Exiv2::getUShort(buf.data(), littleEndian));
if (td) { if (td) {
xmpData_["Xmp.audio.Compressor"] = exvGettext(td->label_); xmpData_["Xmp.audio.Compressor"] = exvGettext(td->label_);
} else { } else {
@ -1175,8 +1175,7 @@ double RiffVideo::returnSampleRate(Exiv2::DataBuf& buf, size_t divisor) {
} // RiffVideo::returnSampleRate } // RiffVideo::returnSampleRate
const char* RiffVideo::printAudioEncoding(uint64_t i) { const char* RiffVideo::printAudioEncoding(uint64_t i) {
const TagDetails* td; auto td = Exiv2::find(audioEncodingValues, i);
td = find(audioEncodingValues, i);
if (td) if (td)
return exvGettext(td->label_); return exvGettext(td->label_);

@ -2320,7 +2320,7 @@ const TagInfo* mnTagList() {
bool isMakerIfd(IfdId ifdId) { bool isMakerIfd(IfdId ifdId) {
bool rc = false; bool rc = false;
const GroupInfo* ii = find(groupInfo, ifdId); auto ii = Exiv2::find(groupInfo, ifdId);
if (ii && 0 == strcmp(ii->ifdName_, "Makernote")) { if (ii && 0 == strcmp(ii->ifdName_, "Makernote")) {
rc = true; rc = true;
} }
@ -2364,7 +2364,7 @@ void taglist(std::ostream& os, IfdId ifdId) {
} // taglist } // taglist
const TagInfo* tagList(IfdId ifdId) { const TagInfo* tagList(IfdId ifdId) {
const GroupInfo* ii = find(groupInfo, ifdId); auto ii = Exiv2::find(groupInfo, ifdId);
if (!ii || !ii->tagList_) if (!ii || !ii->tagList_)
return nullptr; return nullptr;
return ii->tagList_(); return ii->tagList_();
@ -2399,21 +2399,21 @@ const TagInfo* tagInfo(const std::string& tagName, IfdId ifdId) {
IfdId groupId(const std::string& groupName) { IfdId groupId(const std::string& groupName) {
IfdId ifdId = IfdId::ifdIdNotSet; IfdId ifdId = IfdId::ifdIdNotSet;
const GroupInfo* ii = find(groupInfo, GroupInfo::GroupName(groupName)); auto ii = Exiv2::find(groupInfo, GroupInfo::GroupName(groupName));
if (ii) if (ii)
ifdId = static_cast<IfdId>(ii->ifdId_); ifdId = static_cast<IfdId>(ii->ifdId_);
return ifdId; return ifdId;
} }
const char* ifdName(IfdId ifdId) { const char* ifdName(IfdId ifdId) {
const GroupInfo* ii = find(groupInfo, ifdId); auto ii = Exiv2::find(groupInfo, ifdId);
if (!ii) if (!ii)
return groupInfo[0].ifdName_; return groupInfo[0].ifdName_;
return ii->ifdName_; return ii->ifdName_;
} }
const char* groupName(IfdId ifdId) { const char* groupName(IfdId ifdId) {
const GroupInfo* ii = find(groupInfo, ifdId); auto ii = Exiv2::find(groupInfo, ifdId);
if (!ii) if (!ii)
return groupInfo[0].groupName_; return groupInfo[0].groupName_;
return ii->groupName_; return ii->groupName_;
@ -3047,7 +3047,7 @@ const GroupInfo* groupList() {
} }
const TagInfo* tagList(const std::string& groupName) { const TagInfo* tagList(const std::string& groupName) {
const GroupInfo* ii = find(groupInfo, GroupInfo::GroupName(groupName)); auto ii = Exiv2::find(groupInfo, GroupInfo::GroupName(groupName));
if (!ii || !ii->tagList_) { if (!ii || !ii->tagList_) {
return nullptr; return nullptr;
} }

@ -95,7 +95,7 @@ struct TagVocabulary {
*/ */
template <size_t N, const StringTagDetails (&array)[N]> template <size_t N, const StringTagDetails (&array)[N]>
std::ostream& printTagString(std::ostream& os, const std::string value, const ExifData*) { std::ostream& printTagString(std::ostream& os, const std::string value, const ExifData*) {
const StringTagDetails* td = find(array, value); auto td = Exiv2::find(array, value);
if (td) { if (td) {
os << exvGettext(td->label_); os << exvGettext(td->label_);
} else { } else {
@ -152,7 +152,7 @@ std::ostream& printTagString4(std::ostream& os, const Value& value, const ExifDa
*/ */
template <size_t N, const TagDetails (&array)[N]> template <size_t N, const TagDetails (&array)[N]>
std::ostream& printTagNoError(std::ostream& os, const int64_t value, const ExifData*) { std::ostream& printTagNoError(std::ostream& os, const int64_t value, const ExifData*) {
const TagDetails* td = find(array, value); auto td = Exiv2::find(array, value);
if (td) { if (td) {
os << exvGettext(td->label_); os << exvGettext(td->label_);
} else { } else {
@ -179,7 +179,7 @@ std::ostream& printTagNoError(std::ostream& os, const Value& value, const ExifDa
*/ */
template <size_t N, const TagDetails (&array)[N]> template <size_t N, const TagDetails (&array)[N]>
std::ostream& printTag(std::ostream& os, const int64_t value, const ExifData*) { std::ostream& printTag(std::ostream& os, const int64_t value, const ExifData*) {
const TagDetails* td = find(array, value); auto td = Exiv2::find(array, value);
if (td) { if (td) {
os << exvGettext(td->label_); os << exvGettext(td->label_);
} else { } else {
@ -300,7 +300,7 @@ std::ostream& printTagBitlistAllLE(std::ostream& os, const Value& value, const E
*/ */
template <size_t N, const TagVocabulary (&array)[N]> template <size_t N, const TagVocabulary (&array)[N]>
std::ostream& printTagVocabulary(std::ostream& os, const Value& value, const ExifData*) { std::ostream& printTagVocabulary(std::ostream& os, const Value& value, const ExifData*) {
const TagVocabulary* td = find(array, value.toString()); auto td = Exiv2::find(array, value.toString());
if (td) { if (td) {
os << exvGettext(td->label_); os << exvGettext(td->label_);
} else { } else {
@ -322,7 +322,7 @@ std::ostream& printTagVocabularyMulti(std::ostream& os, const Value& value, cons
for (size_t i = 0; i < value.count(); i++) { for (size_t i = 0; i < value.count(); i++) {
if (i != 0) if (i != 0)
os << ", "; os << ", ";
const TagVocabulary* td = find(array, value.toString(i)); auto td = Exiv2::find(array, value.toString(i));
if (td) { if (td) {
os << exvGettext(td->label_); os << exvGettext(td->label_);
} else { } else {

@ -1967,7 +1967,7 @@ const TiffMappingInfo TiffMapping::tiffMappingInfo_[] = {
DecoderFct TiffMapping::findDecoder(const std::string& make, uint32_t extendedTag, IfdId group) { DecoderFct TiffMapping::findDecoder(const std::string& make, uint32_t extendedTag, IfdId group) {
DecoderFct decoderFct = &TiffDecoder::decodeStdTiffEntry; DecoderFct decoderFct = &TiffDecoder::decodeStdTiffEntry;
const TiffMappingInfo* td = find(tiffMappingInfo_, TiffMappingInfo::Key(make, extendedTag, group)); auto td = Exiv2::find(tiffMappingInfo_, TiffMappingInfo::Key(make, extendedTag, group));
if (td) { if (td) {
// This may set decoderFct to 0, meaning that the tag should not be decoded // This may set decoderFct to 0, meaning that the tag should not be decoded
decoderFct = td->decoderFct_; decoderFct = td->decoderFct_;
@ -1977,7 +1977,7 @@ DecoderFct TiffMapping::findDecoder(const std::string& make, uint32_t extendedTa
EncoderFct TiffMapping::findEncoder(const std::string& make, uint32_t extendedTag, IfdId group) { EncoderFct TiffMapping::findEncoder(const std::string& make, uint32_t extendedTag, IfdId group) {
EncoderFct encoderFct = nullptr; EncoderFct encoderFct = nullptr;
const TiffMappingInfo* td = find(tiffMappingInfo_, TiffMappingInfo::Key(make, extendedTag, group)); auto td = Exiv2::find(tiffMappingInfo_, TiffMappingInfo::Key(make, extendedTag, group));
if (td) { if (td) {
// Returns 0 if no special encoder function is found // Returns 0 if no special encoder function is found
encoderFct = td->encoderFct_; encoderFct = td->encoderFct_;

@ -22,7 +22,7 @@
// ***************************************************************************** // *****************************************************************************
namespace { namespace {
//! Information pertaining to the defined %Exiv2 value type identifiers. //! Information pertaining to the defined %Exiv2 value type identifiers.
struct TypeInfoTable { constexpr struct TypeInfoTable {
Exiv2::TypeId typeId_; //!< Type id Exiv2::TypeId typeId_; //!< Type id
const char* name_; //!< Name of the type const char* name_; //!< Name of the type
size_t size_; //!< Bytes per data entry size_t size_; //!< Bytes per data entry
@ -34,34 +34,32 @@ struct TypeInfoTable {
bool operator==(const std::string& name) const { bool operator==(const std::string& name) const {
return name == name_; return name == name_;
} }
}; // struct TypeInfoTable } typeInfoTable[] = {
//! Lookup list with information of Exiv2 types
//! Lookup list with information of Exiv2 types {Exiv2::invalidTypeId, "Invalid", 0},
constexpr auto typeInfoTable = std::array{ {Exiv2::unsignedByte, "Byte", 1},
TypeInfoTable{Exiv2::invalidTypeId, "Invalid", 0}, {Exiv2::asciiString, "Ascii", 1},
TypeInfoTable{Exiv2::unsignedByte, "Byte", 1}, {Exiv2::unsignedShort, "Short", 2},
TypeInfoTable{Exiv2::asciiString, "Ascii", 1}, {Exiv2::unsignedLong, "Long", 4},
TypeInfoTable{Exiv2::unsignedShort, "Short", 2}, {Exiv2::unsignedRational, "Rational", 8},
TypeInfoTable{Exiv2::unsignedLong, "Long", 4}, {Exiv2::signedByte, "SByte", 1},
TypeInfoTable{Exiv2::unsignedRational, "Rational", 8}, {Exiv2::undefined, "Undefined", 1},
TypeInfoTable{Exiv2::signedByte, "SByte", 1}, {Exiv2::signedShort, "SShort", 2},
TypeInfoTable{Exiv2::undefined, "Undefined", 1}, {Exiv2::signedLong, "SLong", 4},
TypeInfoTable{Exiv2::signedShort, "SShort", 2}, {Exiv2::signedRational, "SRational", 8},
TypeInfoTable{Exiv2::signedLong, "SLong", 4}, {Exiv2::tiffFloat, "Float", 4},
TypeInfoTable{Exiv2::signedRational, "SRational", 8}, {Exiv2::tiffDouble, "Double", 8},
TypeInfoTable{Exiv2::tiffFloat, "Float", 4}, {Exiv2::tiffIfd, "Ifd", 4},
TypeInfoTable{Exiv2::tiffDouble, "Double", 8}, {Exiv2::string, "String", 1},
TypeInfoTable{Exiv2::tiffIfd, "Ifd", 4}, {Exiv2::date, "Date", 8},
TypeInfoTable{Exiv2::string, "String", 1}, {Exiv2::time, "Time", 11},
TypeInfoTable{Exiv2::date, "Date", 8}, {Exiv2::comment, "Comment", 1},
TypeInfoTable{Exiv2::time, "Time", 11}, {Exiv2::directory, "Directory", 1},
TypeInfoTable{Exiv2::comment, "Comment", 1}, {Exiv2::xmpText, "XmpText", 1},
TypeInfoTable{Exiv2::directory, "Directory", 1}, {Exiv2::xmpAlt, "XmpAlt", 1},
TypeInfoTable{Exiv2::xmpText, "XmpText", 1}, {Exiv2::xmpBag, "XmpBag", 1},
TypeInfoTable{Exiv2::xmpAlt, "XmpAlt", 1}, {Exiv2::xmpSeq, "XmpSeq", 1},
TypeInfoTable{Exiv2::xmpBag, "XmpBag", 1}, {Exiv2::langAlt, "LangAlt", 1},
TypeInfoTable{Exiv2::xmpSeq, "XmpSeq", 1},
TypeInfoTable{Exiv2::langAlt, "LangAlt", 1},
}; };
} // namespace } // namespace
@ -70,22 +68,22 @@ constexpr auto typeInfoTable = std::array{
// class member definitions // class member definitions
namespace Exiv2 { namespace Exiv2 {
const char* TypeInfo::typeName(TypeId typeId) { const char* TypeInfo::typeName(TypeId typeId) {
auto tit = std::find(typeInfoTable.begin(), typeInfoTable.end(), typeId); auto tit = Exiv2::find(typeInfoTable, typeId);
if (tit == typeInfoTable.end()) if (!tit)
return nullptr; return nullptr;
return tit->name_; return tit->name_;
} }
TypeId TypeInfo::typeId(const std::string& typeName) { TypeId TypeInfo::typeId(const std::string& typeName) {
auto tit = std::find(typeInfoTable.begin(), typeInfoTable.end(), typeName); auto tit = Exiv2::find(typeInfoTable, typeName);
if (tit == typeInfoTable.end()) if (!tit)
return invalidTypeId; return invalidTypeId;
return tit->typeId_; return tit->typeId_;
} }
size_t TypeInfo::typeSize(TypeId typeId) { size_t TypeInfo::typeSize(TypeId typeId) {
auto tit = std::find(typeInfoTable.begin(), typeInfoTable.end(), typeId); auto tit = Exiv2::find(typeInfoTable, typeId);
if (tit == typeInfoTable.end()) if (!tit)
return 0; return 0;
return tit->size_; return tit->size_;
} }

Loading…
Cancel
Save