structured binding conversions
Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
committed by
Luis Díaz Más
parent
bd0eefdab7
commit
fdfcde5e4b
@@ -1259,9 +1259,7 @@ class ValueType : public Value {
|
||||
//! Utility for toInt64, toUint32, etc.
|
||||
template <typename I>
|
||||
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) {
|
||||
|
||||
+4
-4
@@ -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";
|
||||
|
||||
+3
-4
@@ -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<double>(r.first) / r.second;
|
||||
auto [r, s] = pos->toRational(2);
|
||||
double dsec = static_cast<double>(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";
|
||||
|
||||
+11
-13
@@ -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";
|
||||
|
||||
+25
-25
@@ -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<float>(distance.first) / distance.second << " m";
|
||||
os << std::fixed << std::setprecision(2) << static_cast<float>(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<float>(zoom.first) / zoom.second << "x";
|
||||
os << std::fixed << std::setprecision(1) << static_cast<float>(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<float>(zoom.first) / zoom.second << "x";
|
||||
os << std::fixed << std::setprecision(1) << static_cast<float>(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<float>(fno1.first) / fno1.second;
|
||||
if (fno2 != fno1) {
|
||||
os << "-" << std::setprecision(2) << static_cast<float>(fno2.first) / fno2.second;
|
||||
os << "F" << std::setprecision(2) << static_cast<float>(r1) / s1;
|
||||
if (r2 != r1) {
|
||||
os << "-" << std::setprecision(2) << static_cast<float>(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<float>(distance.first) / distance.second << " m";
|
||||
os << std::fixed << std::setprecision(2) << static_cast<float>(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<float>(zoom.first) / zoom.second << "x";
|
||||
os << std::fixed << std::setprecision(1) << static_cast<float>(r) / s << "x";
|
||||
os.copyfmt(oss);
|
||||
} else {
|
||||
os << "(" << value << ")";
|
||||
|
||||
@@ -1483,14 +1483,14 @@ std::ostream& OlympusMakerNote::print0x0305(std::ostream& os, const Value& value
|
||||
return os << value;
|
||||
}
|
||||
|
||||
Rational distance = value.toRational();
|
||||
if (static_cast<uint32_t>(distance.first) == 0xffffffff) {
|
||||
auto [r, s] = value.toRational();
|
||||
if (static_cast<uint32_t>(r) == 0xffffffff) {
|
||||
os << _("Infinity");
|
||||
} else {
|
||||
std::ostringstream oss;
|
||||
oss.copyfmt(os);
|
||||
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.flags(f);
|
||||
|
||||
@@ -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;
|
||||
|
||||
+6
-6
@@ -561,13 +561,13 @@ int64_t parseInt64(const std::string& s, bool& ok) {
|
||||
if (ok)
|
||||
return static_cast<int64_t>(f);
|
||||
|
||||
auto r = stringTo<Rational>(s, ok);
|
||||
auto [r, st] = stringTo<Rational>(s, ok);
|
||||
if (ok) {
|
||||
if (r.second <= 0) {
|
||||
if (st <= 0) {
|
||||
ok = false;
|
||||
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);
|
||||
@@ -591,13 +591,13 @@ float parseFloat(const std::string& s, bool& ok) {
|
||||
if (ok)
|
||||
return ret;
|
||||
|
||||
auto r = stringTo<Rational>(s, ok);
|
||||
auto [r, st] = stringTo<Rational>(s, ok);
|
||||
if (ok) {
|
||||
if (r.second == 0) {
|
||||
if (st == 0) {
|
||||
ok = false;
|
||||
return 0.0;
|
||||
}
|
||||
return static_cast<float>(r.first) / r.second;
|
||||
return static_cast<float>(r) / st;
|
||||
}
|
||||
|
||||
bool b = stringTo<bool>(s, ok);
|
||||
|
||||
+3
-3
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-3
@@ -503,9 +503,7 @@ void Exiv2::dumpLibraryInfo(std::ostream& os, const std::vector<std::regex>& 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
|
||||
|
||||
+8
-8
@@ -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;
|
||||
|
||||
+1
-3
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user