Skip to content

Commit fdfcde5

Browse files
nehebpiponazo
authored andcommitted
structured binding conversions
Signed-off-by: Rosen Penev <[email protected]>
1 parent bd0eefd commit fdfcde5

File tree

12 files changed

+70
-79
lines changed

12 files changed

+70
-79
lines changed

include/exiv2/value.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,9 +1259,7 @@ class ValueType : public Value {
12591259
//! Utility for toInt64, toUint32, etc.
12601260
template <typename I>
12611261
inline I rational_to_integer_helper(size_t n) const {
1262-
const auto& t = value_.at(n);
1263-
const auto a = t.first;
1264-
const auto b = t.second;
1262+
auto&& [a, b] = value_.at(n);
12651263

12661264
// Protect against divide-by-zero.
12671265
if (b <= 0) {

src/canonmn_int.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2763,10 +2763,10 @@ std::ostream& CanonMakerNote::printSi0x0016(std::ostream& os, const Value& value
27632763
if (value.typeId() != unsignedShort || value.count() == 0)
27642764
return os << value;
27652765

2766-
URational ur = exposureTime(canonEv(value.toInt64()));
2767-
os << ur.first;
2768-
if (ur.second > 1) {
2769-
os << "/" << ur.second;
2766+
auto [u, r] = exposureTime(canonEv(value.toInt64()));
2767+
os << u;
2768+
if (r > 1) {
2769+
os << "/" << r;
27702770
}
27712771
os.flags(f);
27722772
return os << " s";

src/convert.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -662,8 +662,8 @@ void Converter::cnvExifDate(const char* from, const char* to) {
662662
double dhour = pos->toFloat(0);
663663
double dmin = pos->toFloat(1);
664664
// Hack: Need Value::toDouble
665-
Rational r = pos->toRational(2);
666-
double dsec = static_cast<double>(r.first) / r.second;
665+
auto [r, s] = pos->toRational(2);
666+
double dsec = static_cast<double>(r) / s;
667667

668668
if (!pos->value().ok()) {
669669
#ifndef SUPPRESS_WARNINGS
@@ -821,8 +821,7 @@ void Converter::cnvExifGPSCoord(const char* from, const char* to) {
821821
}
822822
double deg[3];
823823
for (int i = 0; i < 3; ++i) {
824-
const int32_t z = pos->toRational(i).first;
825-
const int32_t d = pos->toRational(i).second;
824+
const auto [z, d] = pos->toRational(i);
826825
if (d == 0) {
827826
#ifndef SUPPRESS_WARNINGS
828827
EXV_WARNING << "Failed to convert " << from << " to " << to << "\n";

src/epsimage.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -625,13 +625,11 @@ void readWriteEpsMetadata(BasicIo& io, std::string& xmpPacket, NativePreviewList
625625
}
626626
removableEmbeddings.emplace_back(posXmpTrailer, posXmpTrailerEnd);
627627
#ifdef DEBUG
628-
EXV_DEBUG << "readWriteEpsMetadata: Recognized unmarked trailer of removable XMP embedding at "
629-
"["
630-
<< removableEmbeddings.back().first << "," << removableEmbeddings.back().second
631-
<< ")"
632-
"\n";
628+
auto [r, s] = removableEmbeddings.back();
629+
EXV_DEBUG << "readWriteEpsMetadata: Recognized unmarked trailer of removable XMP embedding at [" << r << "," << s
630+
<< ")\n"
633631
#endif
634-
posXmpTrailerEnd = posXmpTrailer;
632+
posXmpTrailerEnd = posXmpTrailer;
635633
}
636634

637635
// interpret comment "%ADO_ContainsXMP:"
@@ -707,8 +705,8 @@ void readWriteEpsMetadata(BasicIo& io, std::string& xmpPacket, NativePreviewList
707705
if (posOtherXmp >= posEndPageSetup)
708706
break;
709707
bool isRemovableEmbedding = false;
710-
for (auto&& removableEmbedding : removableEmbeddings) {
711-
if (removableEmbedding.first <= posOtherXmp && posOtherXmp < removableEmbedding.second) {
708+
for (auto&& [r, s] : removableEmbeddings) {
709+
if (r <= posOtherXmp && posOtherXmp < s) {
712710
isRemovableEmbedding = true;
713711
break;
714712
}
@@ -837,8 +835,8 @@ void readWriteEpsMetadata(BasicIo& io, std::string& xmpPacket, NativePreviewList
837835
if (useFlexibleEmbedding) {
838836
positions.push_back(xmpPos);
839837
}
840-
for (auto&& removableEmbedding : removableEmbeddings) {
841-
positions.push_back(removableEmbedding.first);
838+
for (auto&& [r, s] : removableEmbeddings) {
839+
positions.push_back(r);
842840
}
843841
std::sort(positions.begin(), positions.end());
844842

@@ -955,9 +953,9 @@ void readWriteEpsMetadata(BasicIo& io, std::string& xmpPacket, NativePreviewList
955953
}
956954
if (!useFlexibleEmbedding) {
957955
// remove preceding embedding(s)
958-
for (auto&& removableEmbedding : removableEmbeddings) {
959-
if (pos == removableEmbedding.first) {
960-
skipPos = removableEmbedding.second;
956+
for (auto&& [p, s] : removableEmbeddings) {
957+
if (pos == p) {
958+
skipPos = s;
961959
#ifdef DEBUG
962960
EXV_DEBUG << "readWriteEpsMetadata: Skipping to " << skipPos << " at " << __FILE__ << ":" << __LINE__
963961
<< "\n";

src/nikonmn_int.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,13 @@ std::ostream& Nikon1MakerNote::print0x0007(std::ostream& os, const Value& value,
192192

193193
std::ostream& Nikon1MakerNote::print0x0085(std::ostream& os, const Value& value, const ExifData*) {
194194
std::ios::fmtflags f(os.flags());
195-
Rational distance = value.toRational();
196-
if (distance.first == 0) {
195+
auto [r, s] = value.toRational();
196+
if (r == 0) {
197197
os << _("Unknown");
198-
} else if (distance.second != 0) {
198+
} else if (s != 0) {
199199
std::ostringstream oss;
200200
oss.copyfmt(os);
201-
os << std::fixed << std::setprecision(2) << static_cast<float>(distance.first) / distance.second << " m";
201+
os << std::fixed << std::setprecision(2) << static_cast<float>(r) / s << " m";
202202
os.copyfmt(oss);
203203
} else {
204204
os << "(" << value << ")";
@@ -209,13 +209,13 @@ std::ostream& Nikon1MakerNote::print0x0085(std::ostream& os, const Value& value,
209209

210210
std::ostream& Nikon1MakerNote::print0x0086(std::ostream& os, const Value& value, const ExifData*) {
211211
std::ios::fmtflags f(os.flags());
212-
Rational zoom = value.toRational();
213-
if (zoom.first == 0) {
212+
auto [r, s] = value.toRational();
213+
if (r == 0) {
214214
os << _("Not used");
215-
} else if (zoom.second != 0) {
215+
} else if (s != 0) {
216216
std::ostringstream oss;
217217
oss.copyfmt(os);
218-
os << std::fixed << std::setprecision(1) << static_cast<float>(zoom.first) / zoom.second << "x";
218+
os << std::fixed << std::setprecision(1) << static_cast<float>(r) / s << "x";
219219
os.copyfmt(oss);
220220
} else {
221221
os << "(" << value << ")";
@@ -342,13 +342,13 @@ const TagInfo* Nikon2MakerNote::tagList() {
342342

343343
std::ostream& Nikon2MakerNote::print0x000a(std::ostream& os, const Value& value, const ExifData*) {
344344
std::ios::fmtflags f(os.flags());
345-
Rational zoom = value.toRational();
346-
if (zoom.first == 0) {
345+
auto [r, s] = value.toRational();
346+
if (r == 0) {
347347
os << _("Not used");
348-
} else if (zoom.second != 0) {
348+
} else if (s != 0) {
349349
std::ostringstream oss;
350350
oss.copyfmt(os);
351-
os << std::fixed << std::setprecision(1) << static_cast<float>(zoom.first) / zoom.second << "x";
351+
os << std::fixed << std::setprecision(1) << static_cast<float>(r) / s << "x";
352352
os.copyfmt(oss);
353353
} else {
354354
os << "(" << value << ")";
@@ -1355,18 +1355,18 @@ std::ostream& Nikon3MakerNote::print0x0084(std::ostream& os, const Value& value,
13551355
const int64_t len1 = value.toInt64(0);
13561356
const int64_t len2 = value.toInt64(1);
13571357

1358-
Rational fno1 = value.toRational(2);
1359-
Rational fno2 = value.toRational(3);
1358+
auto [r1, s1] = value.toRational(2);
1359+
auto [r2, s2] = value.toRational(3);
13601360
os << len1;
13611361
if (len2 != len1) {
13621362
os << "-" << len2;
13631363
}
13641364
os << "mm ";
13651365
std::ostringstream oss;
13661366
oss.copyfmt(os);
1367-
os << "F" << std::setprecision(2) << static_cast<float>(fno1.first) / fno1.second;
1368-
if (fno2 != fno1) {
1369-
os << "-" << std::setprecision(2) << static_cast<float>(fno2.first) / fno2.second;
1367+
os << "F" << std::setprecision(2) << static_cast<float>(r1) / s1;
1368+
if (r2 != r1) {
1369+
os << "-" << std::setprecision(2) << static_cast<float>(r2) / s2;
13701370
}
13711371
os.copyfmt(oss);
13721372
os.flags(f);
@@ -1375,13 +1375,13 @@ std::ostream& Nikon3MakerNote::print0x0084(std::ostream& os, const Value& value,
13751375

13761376
std::ostream& Nikon3MakerNote::print0x0085(std::ostream& os, const Value& value, const ExifData*) {
13771377
std::ios::fmtflags f(os.flags());
1378-
Rational distance = value.toRational();
1379-
if (distance.first == 0) {
1378+
auto [r, s] = value.toRational();
1379+
if (r == 0) {
13801380
os << _("Unknown");
1381-
} else if (distance.second != 0) {
1381+
} else if (s != 0) {
13821382
std::ostringstream oss;
13831383
oss.copyfmt(os);
1384-
os << std::fixed << std::setprecision(2) << static_cast<float>(distance.first) / distance.second << " m";
1384+
os << std::fixed << std::setprecision(2) << static_cast<float>(r) / s << " m";
13851385
os.copyfmt(oss);
13861386
} else {
13871387
os << "(" << value << ")";
@@ -1392,13 +1392,13 @@ std::ostream& Nikon3MakerNote::print0x0085(std::ostream& os, const Value& value,
13921392

13931393
std::ostream& Nikon3MakerNote::print0x0086(std::ostream& os, const Value& value, const ExifData*) {
13941394
std::ios::fmtflags f(os.flags());
1395-
Rational zoom = value.toRational();
1396-
if (zoom.first == 0) {
1395+
auto [r, s] = value.toRational();
1396+
if (r == 0) {
13971397
os << _("Not used");
1398-
} else if (zoom.second != 0) {
1398+
} else if (s != 0) {
13991399
std::ostringstream oss;
14001400
oss.copyfmt(os);
1401-
os << std::fixed << std::setprecision(1) << static_cast<float>(zoom.first) / zoom.second << "x";
1401+
os << std::fixed << std::setprecision(1) << static_cast<float>(r) / s << "x";
14021402
os.copyfmt(oss);
14031403
} else {
14041404
os << "(" << value << ")";

src/olympusmn_int.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,14 +1483,14 @@ std::ostream& OlympusMakerNote::print0x0305(std::ostream& os, const Value& value
14831483
return os << value;
14841484
}
14851485

1486-
Rational distance = value.toRational();
1487-
if (static_cast<uint32_t>(distance.first) == 0xffffffff) {
1486+
auto [r, s] = value.toRational();
1487+
if (static_cast<uint32_t>(r) == 0xffffffff) {
14881488
os << _("Infinity");
14891489
} else {
14901490
std::ostringstream oss;
14911491
oss.copyfmt(os);
14921492
os << std::fixed << std::setprecision(2);
1493-
os << static_cast<float>(distance.first) / 1000 << " m";
1493+
os << static_cast<float>(r) / 1000 << " m";
14941494
os.copyfmt(oss);
14951495
}
14961496
os.flags(f);

src/tiffcomposite_int.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,10 +1282,10 @@ uint32_t TiffImageEntry::doWriteImage(IoWrapper& ioWrapper, ByteOrder /*byteOrde
12821282
<< std::hex << tag() << std::dec << ": Writing " << strips_.size() << " strips";
12831283
#endif
12841284
len = 0;
1285-
for (auto&& strip : strips_) {
1286-
ioWrapper.write(strip.first, strip.second);
1287-
len += strip.second;
1288-
uint32_t align = strip.second & 1; // Align strip data to word boundary
1285+
for (auto&& [f, s] : strips_) {
1286+
ioWrapper.write(f, s);
1287+
len += s;
1288+
uint32_t align = s & 1; // Align strip data to word boundary
12891289
if (align)
12901290
ioWrapper.putb(0x0);
12911291
len += align;

src/types.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -561,13 +561,13 @@ int64_t parseInt64(const std::string& s, bool& ok) {
561561
if (ok)
562562
return static_cast<int64_t>(f);
563563

564-
auto r = stringTo<Rational>(s, ok);
564+
auto [r, st] = stringTo<Rational>(s, ok);
565565
if (ok) {
566-
if (r.second <= 0) {
566+
if (st <= 0) {
567567
ok = false;
568568
return 0;
569569
}
570-
return static_cast<int64_t>(static_cast<float>(r.first) / r.second);
570+
return static_cast<int64_t>(static_cast<float>(r) / st);
571571
}
572572

573573
bool b = stringTo<bool>(s, ok);
@@ -591,13 +591,13 @@ float parseFloat(const std::string& s, bool& ok) {
591591
if (ok)
592592
return ret;
593593

594-
auto r = stringTo<Rational>(s, ok);
594+
auto [r, st] = stringTo<Rational>(s, ok);
595595
if (ok) {
596-
if (r.second == 0) {
596+
if (st == 0) {
597597
ok = false;
598598
return 0.0;
599599
}
600-
return static_cast<float>(r.first) / r.second;
600+
return static_cast<float>(r) / st;
601601
}
602602

603603
bool b = stringTo<bool>(s, ok);

src/value.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -733,11 +733,11 @@ std::ostream& LangAltValue::write(std::ostream& os) const {
733733
}
734734

735735
// Write the others
736-
for (auto&& v : value_) {
737-
if (v.first != x_default) {
736+
for (auto&& [lang, s] : value_) {
737+
if (lang != x_default) {
738738
if (!first)
739739
os << ", ";
740-
os << "lang=\"" << v.first << "\" " << v.second;
740+
os << "lang=\"" << lang << "\" " << s;
741741
first = false;
742742
}
743743
}

src/version.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,9 +503,7 @@ void Exiv2::dumpLibraryInfo(std::ostream& os, const std::vector<std::regex>& key
503503

504504
Exiv2::Dictionary ns;
505505
Exiv2::XmpProperties::registeredNamespaces(ns);
506-
for (auto&& n : ns) {
507-
std::string xmlns = n.first;
508-
std::string uri = n.second;
506+
for (auto&& [xmlns, uri] : ns) {
509507
output(os, keys, name, xmlns + ":" + uri);
510508
}
511509
#endif

0 commit comments

Comments
 (0)