diff --git a/include/exiv2/value.hpp b/include/exiv2/value.hpp index 8acf845e9d..d7081a0cc1 100644 --- a/include/exiv2/value.hpp +++ b/include/exiv2/value.hpp @@ -1259,9 +1259,7 @@ class ValueType : public Value { //! Utility for toInt64, toUint32, etc. template inline I rational_to_integer_helper(size_t n) const { - const auto& t = value_.at(n); - const auto a = t.first; - const auto b = t.second; + auto&& [a, b] = value_.at(n); // Protect against divide-by-zero. if (b <= 0) { diff --git a/src/canonmn_int.cpp b/src/canonmn_int.cpp index 241712b0ef..0f6cc203aa 100644 --- a/src/canonmn_int.cpp +++ b/src/canonmn_int.cpp @@ -2763,10 +2763,10 @@ std::ostream& CanonMakerNote::printSi0x0016(std::ostream& os, const Value& value if (value.typeId() != unsignedShort || value.count() == 0) return os << value; - URational ur = exposureTime(canonEv(value.toInt64())); - os << ur.first; - if (ur.second > 1) { - os << "/" << ur.second; + auto [u, r] = exposureTime(canonEv(value.toInt64())); + os << u; + if (r > 1) { + os << "/" << r; } os.flags(f); return os << " s"; diff --git a/src/convert.cpp b/src/convert.cpp index 8bbdfd386c..739eb3432c 100644 --- a/src/convert.cpp +++ b/src/convert.cpp @@ -662,8 +662,8 @@ void Converter::cnvExifDate(const char* from, const char* to) { double dhour = pos->toFloat(0); double dmin = pos->toFloat(1); // Hack: Need Value::toDouble - Rational r = pos->toRational(2); - double dsec = static_cast(r.first) / r.second; + auto [r, s] = pos->toRational(2); + double dsec = static_cast(r) / s; if (!pos->value().ok()) { #ifndef SUPPRESS_WARNINGS @@ -821,8 +821,7 @@ void Converter::cnvExifGPSCoord(const char* from, const char* to) { } double deg[3]; for (int i = 0; i < 3; ++i) { - const int32_t z = pos->toRational(i).first; - const int32_t d = pos->toRational(i).second; + const auto [z, d] = pos->toRational(i); if (d == 0) { #ifndef SUPPRESS_WARNINGS EXV_WARNING << "Failed to convert " << from << " to " << to << "\n"; diff --git a/src/epsimage.cpp b/src/epsimage.cpp index b1421a07bf..9db942f7ac 100644 --- a/src/epsimage.cpp +++ b/src/epsimage.cpp @@ -625,13 +625,11 @@ void readWriteEpsMetadata(BasicIo& io, std::string& xmpPacket, NativePreviewList } removableEmbeddings.emplace_back(posXmpTrailer, posXmpTrailerEnd); #ifdef DEBUG - EXV_DEBUG << "readWriteEpsMetadata: Recognized unmarked trailer of removable XMP embedding at " - "[" - << removableEmbeddings.back().first << "," << removableEmbeddings.back().second - << ")" - "\n"; + auto [r, s] = removableEmbeddings.back(); + EXV_DEBUG << "readWriteEpsMetadata: Recognized unmarked trailer of removable XMP embedding at [" << r << "," << s + << ")\n" #endif - posXmpTrailerEnd = posXmpTrailer; + posXmpTrailerEnd = posXmpTrailer; } // interpret comment "%ADO_ContainsXMP:" @@ -707,8 +705,8 @@ void readWriteEpsMetadata(BasicIo& io, std::string& xmpPacket, NativePreviewList if (posOtherXmp >= posEndPageSetup) break; bool isRemovableEmbedding = false; - for (auto&& removableEmbedding : removableEmbeddings) { - if (removableEmbedding.first <= posOtherXmp && posOtherXmp < removableEmbedding.second) { + for (auto&& [r, s] : removableEmbeddings) { + if (r <= posOtherXmp && posOtherXmp < s) { isRemovableEmbedding = true; break; } @@ -837,8 +835,8 @@ void readWriteEpsMetadata(BasicIo& io, std::string& xmpPacket, NativePreviewList if (useFlexibleEmbedding) { positions.push_back(xmpPos); } - for (auto&& removableEmbedding : removableEmbeddings) { - positions.push_back(removableEmbedding.first); + for (auto&& [r, s] : removableEmbeddings) { + positions.push_back(r); } std::sort(positions.begin(), positions.end()); @@ -955,9 +953,9 @@ void readWriteEpsMetadata(BasicIo& io, std::string& xmpPacket, NativePreviewList } if (!useFlexibleEmbedding) { // remove preceding embedding(s) - for (auto&& removableEmbedding : removableEmbeddings) { - if (pos == removableEmbedding.first) { - skipPos = removableEmbedding.second; + for (auto&& [p, s] : removableEmbeddings) { + if (pos == p) { + skipPos = s; #ifdef DEBUG EXV_DEBUG << "readWriteEpsMetadata: Skipping to " << skipPos << " at " << __FILE__ << ":" << __LINE__ << "\n"; diff --git a/src/nikonmn_int.cpp b/src/nikonmn_int.cpp index b6ee44cff0..2d872021ba 100644 --- a/src/nikonmn_int.cpp +++ b/src/nikonmn_int.cpp @@ -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::ios::fmtflags f(os.flags()); - Rational distance = value.toRational(); - if (distance.first == 0) { + auto [r, s] = value.toRational(); + if (r == 0) { os << _("Unknown"); - } else if (distance.second != 0) { + } else if (s != 0) { std::ostringstream oss; oss.copyfmt(os); - os << std::fixed << std::setprecision(2) << static_cast(distance.first) / distance.second << " m"; + os << std::fixed << std::setprecision(2) << static_cast(r) / s << " m"; os.copyfmt(oss); } else { 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::ios::fmtflags f(os.flags()); - Rational zoom = value.toRational(); - if (zoom.first == 0) { + auto [r, s] = value.toRational(); + if (r == 0) { os << _("Not used"); - } else if (zoom.second != 0) { + } else if (s != 0) { std::ostringstream oss; oss.copyfmt(os); - os << std::fixed << std::setprecision(1) << static_cast(zoom.first) / zoom.second << "x"; + os << std::fixed << std::setprecision(1) << static_cast(r) / s << "x"; os.copyfmt(oss); } else { os << "(" << value << ")"; @@ -342,13 +342,13 @@ const TagInfo* Nikon2MakerNote::tagList() { std::ostream& Nikon2MakerNote::print0x000a(std::ostream& os, const Value& value, const ExifData*) { std::ios::fmtflags f(os.flags()); - Rational zoom = value.toRational(); - if (zoom.first == 0) { + auto [r, s] = value.toRational(); + if (r == 0) { os << _("Not used"); - } else if (zoom.second != 0) { + } else if (s != 0) { std::ostringstream oss; oss.copyfmt(os); - os << std::fixed << std::setprecision(1) << static_cast(zoom.first) / zoom.second << "x"; + os << std::fixed << std::setprecision(1) << static_cast(r) / s << "x"; os.copyfmt(oss); } else { 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 len2 = value.toInt64(1); - Rational fno1 = value.toRational(2); - Rational fno2 = value.toRational(3); + auto [r1, s1] = value.toRational(2); + auto [r2, s2] = value.toRational(3); os << len1; if (len2 != len1) { os << "-" << len2; @@ -1364,9 +1364,9 @@ std::ostream& Nikon3MakerNote::print0x0084(std::ostream& os, const Value& value, os << "mm "; std::ostringstream oss; oss.copyfmt(os); - os << "F" << std::setprecision(2) << static_cast(fno1.first) / fno1.second; - if (fno2 != fno1) { - os << "-" << std::setprecision(2) << static_cast(fno2.first) / fno2.second; + os << "F" << std::setprecision(2) << static_cast(r1) / s1; + if (r2 != r1) { + os << "-" << std::setprecision(2) << static_cast(r2) / s2; } os.copyfmt(oss); 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::ios::fmtflags f(os.flags()); - Rational distance = value.toRational(); - if (distance.first == 0) { + auto [r, s] = value.toRational(); + if (r == 0) { os << _("Unknown"); - } else if (distance.second != 0) { + } else if (s != 0) { std::ostringstream oss; oss.copyfmt(os); - os << std::fixed << std::setprecision(2) << static_cast(distance.first) / distance.second << " m"; + os << std::fixed << std::setprecision(2) << static_cast(r) / s << " m"; os.copyfmt(oss); } else { 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::ios::fmtflags f(os.flags()); - Rational zoom = value.toRational(); - if (zoom.first == 0) { + auto [r, s] = value.toRational(); + if (r == 0) { os << _("Not used"); - } else if (zoom.second != 0) { + } else if (s != 0) { std::ostringstream oss; oss.copyfmt(os); - os << std::fixed << std::setprecision(1) << static_cast(zoom.first) / zoom.second << "x"; + os << std::fixed << std::setprecision(1) << static_cast(r) / s << "x"; os.copyfmt(oss); } else { os << "(" << value << ")"; diff --git a/src/olympusmn_int.cpp b/src/olympusmn_int.cpp index f39a2bb544..aa6c393d0d 100644 --- a/src/olympusmn_int.cpp +++ b/src/olympusmn_int.cpp @@ -1483,14 +1483,14 @@ std::ostream& OlympusMakerNote::print0x0305(std::ostream& os, const Value& value return os << value; } - Rational distance = value.toRational(); - if (static_cast(distance.first) == 0xffffffff) { + auto [r, s] = value.toRational(); + if (static_cast(r) == 0xffffffff) { os << _("Infinity"); } else { std::ostringstream oss; oss.copyfmt(os); os << std::fixed << std::setprecision(2); - os << static_cast(distance.first) / 1000 << " m"; + os << static_cast(r) / 1000 << " m"; os.copyfmt(oss); } os.flags(f); diff --git a/src/tiffcomposite_int.cpp b/src/tiffcomposite_int.cpp index 66e913adb9..841e97e24f 100644 --- a/src/tiffcomposite_int.cpp +++ b/src/tiffcomposite_int.cpp @@ -1282,10 +1282,10 @@ uint32_t TiffImageEntry::doWriteImage(IoWrapper& ioWrapper, ByteOrder /*byteOrde << std::hex << tag() << std::dec << ": Writing " << strips_.size() << " strips"; #endif len = 0; - for (auto&& strip : strips_) { - ioWrapper.write(strip.first, strip.second); - len += strip.second; - uint32_t align = strip.second & 1; // Align strip data to word boundary + for (auto&& [f, s] : strips_) { + ioWrapper.write(f, s); + len += s; + uint32_t align = s & 1; // Align strip data to word boundary if (align) ioWrapper.putb(0x0); len += align; diff --git a/src/types.cpp b/src/types.cpp index 718716883c..a53f3c27b4 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -561,13 +561,13 @@ int64_t parseInt64(const std::string& s, bool& ok) { if (ok) return static_cast(f); - auto r = stringTo(s, ok); + auto [r, st] = stringTo(s, ok); if (ok) { - if (r.second <= 0) { + if (st <= 0) { ok = false; return 0; } - return static_cast(static_cast(r.first) / r.second); + return static_cast(static_cast(r) / st); } bool b = stringTo(s, ok); @@ -591,13 +591,13 @@ float parseFloat(const std::string& s, bool& ok) { if (ok) return ret; - auto r = stringTo(s, ok); + auto [r, st] = stringTo(s, ok); if (ok) { - if (r.second == 0) { + if (st == 0) { ok = false; return 0.0; } - return static_cast(r.first) / r.second; + return static_cast(r) / st; } bool b = stringTo(s, ok); diff --git a/src/value.cpp b/src/value.cpp index 5ef99ebb84..686b4fc983 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -733,11 +733,11 @@ std::ostream& LangAltValue::write(std::ostream& os) const { } // Write the others - for (auto&& v : value_) { - if (v.first != x_default) { + for (auto&& [lang, s] : value_) { + if (lang != x_default) { if (!first) os << ", "; - os << "lang=\"" << v.first << "\" " << v.second; + os << "lang=\"" << lang << "\" " << s; first = false; } } diff --git a/src/version.cpp b/src/version.cpp index e068304b52..a9548cabab 100644 --- a/src/version.cpp +++ b/src/version.cpp @@ -503,9 +503,7 @@ void Exiv2::dumpLibraryInfo(std::ostream& os, const std::vector& key Exiv2::Dictionary ns; Exiv2::XmpProperties::registeredNamespaces(ns); - for (auto&& n : ns) { - std::string xmlns = n.first; - std::string uri = n.second; + for (auto&& [xmlns, uri] : ns) { output(os, keys, name, xmlns + ":" + uri); } #endif diff --git a/src/xmp.cpp b/src/xmp.cpp index fd1f9cd8fe..5355f578e6 100644 --- a/src/xmp.cpp +++ b/src/xmp.cpp @@ -822,11 +822,11 @@ int XmpParser::encode(std::string& xmpPacket, const XmpData& xmpData, uint16_t f return 2; } // Register custom namespaces with XMP-SDK - for (auto&& i : XmpProperties::nsRegistry_) { + for (auto&& [xmp, uri] : XmpProperties::nsRegistry_) { #ifdef EXIV2_DEBUG_MESSAGES - std::cerr << "Registering " << i.second.prefix_ << " : " << i.first << "\n"; + std::cerr << "Registering " << uri.prefix_ << " : " << xmp << "\n"; #endif - registerNs(i.first, i.second.prefix_); + registerNs(xmp, uri.prefix_); } SXMPMeta meta; 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()); int idx = 1; - for (auto&& k : la->value_) { - if (!k.second.empty()) { // remove lang specs with no value - printNode(ns, i.tagName(), k.second, 0); - meta.AppendArrayItem(ns.c_str(), i.tagName().c_str(), kXMP_PropArrayIsAlternate, k.second.c_str()); + for (auto&& [lang, specs] : la->value_) { + if (!specs.empty()) { // remove lang specs with no value + printNode(ns, i.tagName(), specs, 0); + meta.AppendArrayItem(ns.c_str(), i.tagName().c_str(), kXMP_PropArrayIsAlternate, specs.c_str()); 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; diff --git a/src/xmpsidecar.cpp b/src/xmpsidecar.cpp index 9e727609d9..388217195e 100644 --- a/src/xmpsidecar.cpp +++ b/src/xmpsidecar.cpp @@ -114,11 +114,9 @@ void XmpSidecar::writeMetadata() { copyIptcToXmp(iptcData_, xmpData_); // #1112 - restore dates if they lost their TZ info - for (auto&& date : dates_) { - std::string sKey = date.first; + for (auto&& [sKey, value_orig] : dates_) { Exiv2::XmpKey key(sKey); if (xmpData_.findKey(key) != xmpData_.end()) { - std::string value_orig(date.second); std::string value_now(xmpData_[sKey].value().toString()); // std::cout << key << " -> " << value_now << " => " << value_orig << std::endl; if (value_orig.find(value_now.substr(0, 10)) != std::string::npos) {