structured binding conversions

Signed-off-by: Rosen Penev <rosenp@gmail.com>
main
Rosen Penev 3 years ago committed by Luis Díaz Más
parent bd0eefdab7
commit fdfcde5e4b

@ -1259,9 +1259,7 @@ class ValueType : public Value {
//! Utility for toInt64, toUint32, etc. //! Utility for toInt64, toUint32, etc.
template <typename I> template <typename I>
inline I rational_to_integer_helper(size_t n) const { inline I rational_to_integer_helper(size_t n) const {
const auto& t = value_.at(n); auto&& [a, b] = value_.at(n);
const auto a = t.first;
const auto b = t.second;
// Protect against divide-by-zero. // Protect against divide-by-zero.
if (b <= 0) { if (b <= 0) {

@ -2763,10 +2763,10 @@ std::ostream& CanonMakerNote::printSi0x0016(std::ostream& os, const Value& value
if (value.typeId() != unsignedShort || value.count() == 0) if (value.typeId() != unsignedShort || value.count() == 0)
return os << value; return os << value;
URational ur = exposureTime(canonEv(value.toInt64())); auto [u, r] = exposureTime(canonEv(value.toInt64()));
os << ur.first; os << u;
if (ur.second > 1) { if (r > 1) {
os << "/" << ur.second; os << "/" << r;
} }
os.flags(f); os.flags(f);
return os << " s"; return os << " s";

@ -662,8 +662,8 @@ void Converter::cnvExifDate(const char* from, const char* to) {
double dhour = pos->toFloat(0); double dhour = pos->toFloat(0);
double dmin = pos->toFloat(1); double dmin = pos->toFloat(1);
// Hack: Need Value::toDouble // Hack: Need Value::toDouble
Rational r = pos->toRational(2); auto [r, s] = pos->toRational(2);
double dsec = static_cast<double>(r.first) / r.second; double dsec = static_cast<double>(r) / s;
if (!pos->value().ok()) { if (!pos->value().ok()) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
@ -821,8 +821,7 @@ void Converter::cnvExifGPSCoord(const char* from, const char* to) {
} }
double deg[3]; double deg[3];
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
const int32_t z = pos->toRational(i).first; const auto [z, d] = pos->toRational(i);
const int32_t d = pos->toRational(i).second;
if (d == 0) { if (d == 0) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Failed to convert " << from << " to " << to << "\n"; EXV_WARNING << "Failed to convert " << from << " to " << to << "\n";

@ -625,13 +625,11 @@ void readWriteEpsMetadata(BasicIo& io, std::string& xmpPacket, NativePreviewList
} }
removableEmbeddings.emplace_back(posXmpTrailer, posXmpTrailerEnd); removableEmbeddings.emplace_back(posXmpTrailer, posXmpTrailerEnd);
#ifdef DEBUG #ifdef DEBUG
EXV_DEBUG << "readWriteEpsMetadata: Recognized unmarked trailer of removable XMP embedding at " auto [r, s] = removableEmbeddings.back();
"[" EXV_DEBUG << "readWriteEpsMetadata: Recognized unmarked trailer of removable XMP embedding at [" << r << "," << s
<< removableEmbeddings.back().first << "," << removableEmbeddings.back().second << ")\n"
<< ")"
"\n";
#endif #endif
posXmpTrailerEnd = posXmpTrailer; posXmpTrailerEnd = posXmpTrailer;
} }
// interpret comment "%ADO_ContainsXMP:" // interpret comment "%ADO_ContainsXMP:"
@ -707,8 +705,8 @@ void readWriteEpsMetadata(BasicIo& io, std::string& xmpPacket, NativePreviewList
if (posOtherXmp >= posEndPageSetup) if (posOtherXmp >= posEndPageSetup)
break; break;
bool isRemovableEmbedding = false; bool isRemovableEmbedding = false;
for (auto&& removableEmbedding : removableEmbeddings) { for (auto&& [r, s] : removableEmbeddings) {
if (removableEmbedding.first <= posOtherXmp && posOtherXmp < removableEmbedding.second) { if (r <= posOtherXmp && posOtherXmp < s) {
isRemovableEmbedding = true; isRemovableEmbedding = true;
break; break;
} }
@ -837,8 +835,8 @@ void readWriteEpsMetadata(BasicIo& io, std::string& xmpPacket, NativePreviewList
if (useFlexibleEmbedding) { if (useFlexibleEmbedding) {
positions.push_back(xmpPos); positions.push_back(xmpPos);
} }
for (auto&& removableEmbedding : removableEmbeddings) { for (auto&& [r, s] : removableEmbeddings) {
positions.push_back(removableEmbedding.first); positions.push_back(r);
} }
std::sort(positions.begin(), positions.end()); std::sort(positions.begin(), positions.end());
@ -955,9 +953,9 @@ void readWriteEpsMetadata(BasicIo& io, std::string& xmpPacket, NativePreviewList
} }
if (!useFlexibleEmbedding) { if (!useFlexibleEmbedding) {
// remove preceding embedding(s) // remove preceding embedding(s)
for (auto&& removableEmbedding : removableEmbeddings) { for (auto&& [p, s] : removableEmbeddings) {
if (pos == removableEmbedding.first) { if (pos == p) {
skipPos = removableEmbedding.second; skipPos = s;
#ifdef DEBUG #ifdef DEBUG
EXV_DEBUG << "readWriteEpsMetadata: Skipping to " << skipPos << " at " << __FILE__ << ":" << __LINE__ EXV_DEBUG << "readWriteEpsMetadata: Skipping to " << skipPos << " at " << __FILE__ << ":" << __LINE__
<< "\n"; << "\n";

@ -192,13 +192,13 @@ std::ostream& Nikon1MakerNote::print0x0007(std::ostream& os, const Value& value,
std::ostream& Nikon1MakerNote::print0x0085(std::ostream& os, const Value& value, const ExifData*) { std::ostream& Nikon1MakerNote::print0x0085(std::ostream& os, const Value& value, const ExifData*) {
std::ios::fmtflags f(os.flags()); std::ios::fmtflags f(os.flags());
Rational distance = value.toRational(); auto [r, s] = value.toRational();
if (distance.first == 0) { if (r == 0) {
os << _("Unknown"); os << _("Unknown");
} else if (distance.second != 0) { } else if (s != 0) {
std::ostringstream oss; std::ostringstream oss;
oss.copyfmt(os); oss.copyfmt(os);
os << std::fixed << std::setprecision(2) << static_cast<float>(distance.first) / distance.second << " m"; os << std::fixed << std::setprecision(2) << static_cast<float>(r) / s << " m";
os.copyfmt(oss); os.copyfmt(oss);
} else { } else {
os << "(" << value << ")"; os << "(" << value << ")";
@ -209,13 +209,13 @@ std::ostream& Nikon1MakerNote::print0x0085(std::ostream& os, const Value& value,
std::ostream& Nikon1MakerNote::print0x0086(std::ostream& os, const Value& value, const ExifData*) { std::ostream& Nikon1MakerNote::print0x0086(std::ostream& os, const Value& value, const ExifData*) {
std::ios::fmtflags f(os.flags()); std::ios::fmtflags f(os.flags());
Rational zoom = value.toRational(); auto [r, s] = value.toRational();
if (zoom.first == 0) { if (r == 0) {
os << _("Not used"); os << _("Not used");
} else if (zoom.second != 0) { } else if (s != 0) {
std::ostringstream oss; std::ostringstream oss;
oss.copyfmt(os); oss.copyfmt(os);
os << std::fixed << std::setprecision(1) << static_cast<float>(zoom.first) / zoom.second << "x"; os << std::fixed << std::setprecision(1) << static_cast<float>(r) / s << "x";
os.copyfmt(oss); os.copyfmt(oss);
} else { } else {
os << "(" << value << ")"; os << "(" << value << ")";
@ -342,13 +342,13 @@ const TagInfo* Nikon2MakerNote::tagList() {
std::ostream& Nikon2MakerNote::print0x000a(std::ostream& os, const Value& value, const ExifData*) { std::ostream& Nikon2MakerNote::print0x000a(std::ostream& os, const Value& value, const ExifData*) {
std::ios::fmtflags f(os.flags()); std::ios::fmtflags f(os.flags());
Rational zoom = value.toRational(); auto [r, s] = value.toRational();
if (zoom.first == 0) { if (r == 0) {
os << _("Not used"); os << _("Not used");
} else if (zoom.second != 0) { } else if (s != 0) {
std::ostringstream oss; std::ostringstream oss;
oss.copyfmt(os); oss.copyfmt(os);
os << std::fixed << std::setprecision(1) << static_cast<float>(zoom.first) / zoom.second << "x"; os << std::fixed << std::setprecision(1) << static_cast<float>(r) / s << "x";
os.copyfmt(oss); os.copyfmt(oss);
} else { } else {
os << "(" << value << ")"; os << "(" << value << ")";
@ -1355,8 +1355,8 @@ std::ostream& Nikon3MakerNote::print0x0084(std::ostream& os, const Value& value,
const int64_t len1 = value.toInt64(0); const int64_t len1 = value.toInt64(0);
const int64_t len2 = value.toInt64(1); const int64_t len2 = value.toInt64(1);
Rational fno1 = value.toRational(2); auto [r1, s1] = value.toRational(2);
Rational fno2 = value.toRational(3); auto [r2, s2] = value.toRational(3);
os << len1; os << len1;
if (len2 != len1) { if (len2 != len1) {
os << "-" << len2; os << "-" << len2;
@ -1364,9 +1364,9 @@ std::ostream& Nikon3MakerNote::print0x0084(std::ostream& os, const Value& value,
os << "mm "; os << "mm ";
std::ostringstream oss; std::ostringstream oss;
oss.copyfmt(os); oss.copyfmt(os);
os << "F" << std::setprecision(2) << static_cast<float>(fno1.first) / fno1.second; os << "F" << std::setprecision(2) << static_cast<float>(r1) / s1;
if (fno2 != fno1) { if (r2 != r1) {
os << "-" << std::setprecision(2) << static_cast<float>(fno2.first) / fno2.second; os << "-" << std::setprecision(2) << static_cast<float>(r2) / s2;
} }
os.copyfmt(oss); os.copyfmt(oss);
os.flags(f); os.flags(f);
@ -1375,13 +1375,13 @@ std::ostream& Nikon3MakerNote::print0x0084(std::ostream& os, const Value& value,
std::ostream& Nikon3MakerNote::print0x0085(std::ostream& os, const Value& value, const ExifData*) { std::ostream& Nikon3MakerNote::print0x0085(std::ostream& os, const Value& value, const ExifData*) {
std::ios::fmtflags f(os.flags()); std::ios::fmtflags f(os.flags());
Rational distance = value.toRational(); auto [r, s] = value.toRational();
if (distance.first == 0) { if (r == 0) {
os << _("Unknown"); os << _("Unknown");
} else if (distance.second != 0) { } else if (s != 0) {
std::ostringstream oss; std::ostringstream oss;
oss.copyfmt(os); oss.copyfmt(os);
os << std::fixed << std::setprecision(2) << static_cast<float>(distance.first) / distance.second << " m"; os << std::fixed << std::setprecision(2) << static_cast<float>(r) / s << " m";
os.copyfmt(oss); os.copyfmt(oss);
} else { } else {
os << "(" << value << ")"; os << "(" << value << ")";
@ -1392,13 +1392,13 @@ std::ostream& Nikon3MakerNote::print0x0085(std::ostream& os, const Value& value,
std::ostream& Nikon3MakerNote::print0x0086(std::ostream& os, const Value& value, const ExifData*) { std::ostream& Nikon3MakerNote::print0x0086(std::ostream& os, const Value& value, const ExifData*) {
std::ios::fmtflags f(os.flags()); std::ios::fmtflags f(os.flags());
Rational zoom = value.toRational(); auto [r, s] = value.toRational();
if (zoom.first == 0) { if (r == 0) {
os << _("Not used"); os << _("Not used");
} else if (zoom.second != 0) { } else if (s != 0) {
std::ostringstream oss; std::ostringstream oss;
oss.copyfmt(os); oss.copyfmt(os);
os << std::fixed << std::setprecision(1) << static_cast<float>(zoom.first) / zoom.second << "x"; os << std::fixed << std::setprecision(1) << static_cast<float>(r) / s << "x";
os.copyfmt(oss); os.copyfmt(oss);
} else { } else {
os << "(" << value << ")"; os << "(" << value << ")";

@ -1483,14 +1483,14 @@ std::ostream& OlympusMakerNote::print0x0305(std::ostream& os, const Value& value
return os << value; return os << value;
} }
Rational distance = value.toRational(); auto [r, s] = value.toRational();
if (static_cast<uint32_t>(distance.first) == 0xffffffff) { if (static_cast<uint32_t>(r) == 0xffffffff) {
os << _("Infinity"); os << _("Infinity");
} else { } else {
std::ostringstream oss; std::ostringstream oss;
oss.copyfmt(os); oss.copyfmt(os);
os << std::fixed << std::setprecision(2); os << std::fixed << std::setprecision(2);
os << static_cast<float>(distance.first) / 1000 << " m"; os << static_cast<float>(r) / 1000 << " m";
os.copyfmt(oss); os.copyfmt(oss);
} }
os.flags(f); os.flags(f);

@ -1282,10 +1282,10 @@ uint32_t TiffImageEntry::doWriteImage(IoWrapper& ioWrapper, ByteOrder /*byteOrde
<< std::hex << tag() << std::dec << ": Writing " << strips_.size() << " strips"; << std::hex << tag() << std::dec << ": Writing " << strips_.size() << " strips";
#endif #endif
len = 0; len = 0;
for (auto&& strip : strips_) { for (auto&& [f, s] : strips_) {
ioWrapper.write(strip.first, strip.second); ioWrapper.write(f, s);
len += strip.second; len += s;
uint32_t align = strip.second & 1; // Align strip data to word boundary uint32_t align = s & 1; // Align strip data to word boundary
if (align) if (align)
ioWrapper.putb(0x0); ioWrapper.putb(0x0);
len += align; len += align;

@ -561,13 +561,13 @@ int64_t parseInt64(const std::string& s, bool& ok) {
if (ok) if (ok)
return static_cast<int64_t>(f); return static_cast<int64_t>(f);
auto r = stringTo<Rational>(s, ok); auto [r, st] = stringTo<Rational>(s, ok);
if (ok) { if (ok) {
if (r.second <= 0) { if (st <= 0) {
ok = false; ok = false;
return 0; return 0;
} }
return static_cast<int64_t>(static_cast<float>(r.first) / r.second); return static_cast<int64_t>(static_cast<float>(r) / st);
} }
bool b = stringTo<bool>(s, ok); bool b = stringTo<bool>(s, ok);
@ -591,13 +591,13 @@ float parseFloat(const std::string& s, bool& ok) {
if (ok) if (ok)
return ret; return ret;
auto r = stringTo<Rational>(s, ok); auto [r, st] = stringTo<Rational>(s, ok);
if (ok) { if (ok) {
if (r.second == 0) { if (st == 0) {
ok = false; ok = false;
return 0.0; return 0.0;
} }
return static_cast<float>(r.first) / r.second; return static_cast<float>(r) / st;
} }
bool b = stringTo<bool>(s, ok); bool b = stringTo<bool>(s, ok);

@ -733,11 +733,11 @@ std::ostream& LangAltValue::write(std::ostream& os) const {
} }
// Write the others // Write the others
for (auto&& v : value_) { for (auto&& [lang, s] : value_) {
if (v.first != x_default) { if (lang != x_default) {
if (!first) if (!first)
os << ", "; os << ", ";
os << "lang=\"" << v.first << "\" " << v.second; os << "lang=\"" << lang << "\" " << s;
first = false; first = false;
} }
} }

@ -503,9 +503,7 @@ void Exiv2::dumpLibraryInfo(std::ostream& os, const std::vector<std::regex>& key
Exiv2::Dictionary ns; Exiv2::Dictionary ns;
Exiv2::XmpProperties::registeredNamespaces(ns); Exiv2::XmpProperties::registeredNamespaces(ns);
for (auto&& n : ns) { for (auto&& [xmlns, uri] : ns) {
std::string xmlns = n.first;
std::string uri = n.second;
output(os, keys, name, xmlns + ":" + uri); output(os, keys, name, xmlns + ":" + uri);
} }
#endif #endif

@ -822,11 +822,11 @@ int XmpParser::encode(std::string& xmpPacket, const XmpData& xmpData, uint16_t f
return 2; return 2;
} }
// Register custom namespaces with XMP-SDK // Register custom namespaces with XMP-SDK
for (auto&& i : XmpProperties::nsRegistry_) { for (auto&& [xmp, uri] : XmpProperties::nsRegistry_) {
#ifdef EXIV2_DEBUG_MESSAGES #ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Registering " << i.second.prefix_ << " : " << i.first << "\n"; std::cerr << "Registering " << uri.prefix_ << " : " << xmp << "\n";
#endif #endif
registerNs(i.first, i.second.prefix_); registerNs(xmp, uri.prefix_);
} }
SXMPMeta meta; SXMPMeta meta;
for (auto&& i : xmpData) { for (auto&& i : xmpData) {
@ -840,12 +840,12 @@ int XmpParser::encode(std::string& xmpPacket, const XmpData& xmpData, uint16_t f
throw Error(ErrorCode::kerEncodeLangAltPropertyFailed, i.key()); throw Error(ErrorCode::kerEncodeLangAltPropertyFailed, i.key());
int idx = 1; int idx = 1;
for (auto&& k : la->value_) { for (auto&& [lang, specs] : la->value_) {
if (!k.second.empty()) { // remove lang specs with no value if (!specs.empty()) { // remove lang specs with no value
printNode(ns, i.tagName(), k.second, 0); printNode(ns, i.tagName(), specs, 0);
meta.AppendArrayItem(ns.c_str(), i.tagName().c_str(), kXMP_PropArrayIsAlternate, k.second.c_str()); meta.AppendArrayItem(ns.c_str(), i.tagName().c_str(), kXMP_PropArrayIsAlternate, specs.c_str());
const std::string item = i.tagName() + "[" + toString(idx++) + "]"; const std::string item = i.tagName() + "[" + toString(idx++) + "]";
meta.SetQualifier(ns.c_str(), item.c_str(), kXMP_NS_XML, "lang", k.first.c_str()); meta.SetQualifier(ns.c_str(), item.c_str(), kXMP_NS_XML, "lang", lang.c_str());
} }
} }
continue; continue;

@ -114,11 +114,9 @@ void XmpSidecar::writeMetadata() {
copyIptcToXmp(iptcData_, xmpData_); copyIptcToXmp(iptcData_, xmpData_);
// #1112 - restore dates if they lost their TZ info // #1112 - restore dates if they lost their TZ info
for (auto&& date : dates_) { for (auto&& [sKey, value_orig] : dates_) {
std::string sKey = date.first;
Exiv2::XmpKey key(sKey); Exiv2::XmpKey key(sKey);
if (xmpData_.findKey(key) != xmpData_.end()) { if (xmpData_.findKey(key) != xmpData_.end()) {
std::string value_orig(date.second);
std::string value_now(xmpData_[sKey].value().toString()); std::string value_now(xmpData_[sKey].value().toString());
// std::cout << key << " -> " << value_now << " => " << value_orig << std::endl; // std::cout << key << " -> " << value_now << " => " << value_orig << std::endl;
if (value_orig.find(value_now.substr(0, 10)) != std::string::npos) { if (value_orig.find(value_now.substr(0, 10)) != std::string::npos) {

Loading…
Cancel
Save