Skip to content

Commit 5d5354e

Browse files
nehebpiponazo
authored andcommitted
clang-tidy: C array to std::array conversions
Signed-off-by: Rosen Penev <[email protected]>
1 parent 8a37d6a commit 5d5354e

File tree

5 files changed

+112
-118
lines changed

5 files changed

+112
-118
lines changed

src/datasets.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "i18n.h" // NLS support.
1212
#include "types.hpp"
1313

14+
#include <array>
1415
#include <iomanip>
1516
#include <regex>
1617
#include <sstream>
@@ -19,11 +20,11 @@
1920
// class member definitions
2021

2122
namespace Exiv2 {
22-
constexpr const char* familyName_{"Iptc"};
23-
constexpr RecordInfo recordInfo_[] = {
24-
{IptcDataSets::invalidRecord, "(invalid)", N_("(invalid)")},
25-
{IptcDataSets::envelope, "Envelope", N_("IIM envelope record")},
26-
{IptcDataSets::application2, "Application2", N_("IIM application record 2")},
23+
constexpr auto familyName_ = "Iptc";
24+
constexpr auto recordInfo_ = std::array{
25+
RecordInfo{IptcDataSets::invalidRecord, "(invalid)", N_("(invalid)")},
26+
RecordInfo{IptcDataSets::envelope, "Envelope", N_("IIM envelope record")},
27+
RecordInfo{IptcDataSets::application2, "Application2", N_("IIM application record 2")},
2728
};
2829

2930
constexpr DataSet envelopeRecord[] = {

src/epsimage.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,17 @@ constexpr std::string_view xmpHeaders[] = {
6666
};
6767

6868
// list of all valid XMP trailers
69-
struct XmpTrailer {
70-
std::string_view trailer;
71-
bool readOnly;
72-
};
69+
using XmpTrailer = std::pair<std::string_view, bool>;
7370

74-
constexpr XmpTrailer xmpTrailers[] = {
71+
constexpr auto xmpTrailers = std::array{
7572

7673
// We do not enforce the trailing "?>" here, because the XMP specification
7774
// permits additional attributes after end="...".
7875

79-
{"<?xpacket end=\"r\"", true},
80-
{"<?xpacket end='r'", true},
81-
{"<?xpacket end=\"w\"", false},
82-
{"<?xpacket end='w'", false},
76+
XmpTrailer("<?xpacket end=\"r\"", true),
77+
XmpTrailer("<?xpacket end='r'", true),
78+
XmpTrailer("<?xpacket end=\"w\"", false),
79+
XmpTrailer("<?xpacket end='w'", false),
8380
};
8481

8582
// closing part of all valid XMP trailers
@@ -190,8 +187,7 @@ void findXmp(size_t& xmpPos, size_t& xmpSize, const byte* data, size_t startPos,
190187
if (data[xmpPos] != '\x00' && data[xmpPos] != '<')
191188
continue;
192189
for (auto&& xmpTrailer : xmpTrailers) {
193-
auto trailer = xmpTrailer.trailer;
194-
const bool readOnly = xmpTrailer.readOnly;
190+
auto [trailer, readOnly] = xmpTrailer;
195191

196192
if (trailerPos + trailer.size() > size)
197193
continue;

src/exif.cpp

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -496,10 +496,7 @@ ByteOrder ExifParser::decode(ExifData& exifData, const byte* pData, size_t size)
496496

497497
//! @cond IGNORE
498498
enum Ptt { pttLen, pttTag, pttIfd };
499-
struct PreviewTags {
500-
Ptt ptt_;
501-
const char* key_;
502-
};
499+
using PreviewTags = std::pair<Ptt, const char*>;
503500
//! @endcond
504501

505502
WriteMethod ExifParser::encode(Blob& blob, const byte* pData, size_t size, ByteOrder byteOrder,
@@ -545,12 +542,13 @@ WriteMethod ExifParser::encode(Blob& blob, const byte* pData, size_t size, ByteO
545542
}
546543

547544
// Delete IFDs which do not occur in JPEGs
548-
static const IfdId filteredIfds[] = {subImage1Id, subImage2Id, subImage3Id, subImage4Id, subImage5Id,
549-
subImage6Id, subImage7Id, subImage8Id, subImage9Id, subThumb1Id,
550-
panaRawId, ifd2Id, ifd3Id};
545+
static constexpr auto filteredIfds = std::array{
546+
subImage1Id, subImage2Id, subImage3Id, subImage4Id, subImage5Id, subImage6Id, subImage7Id,
547+
subImage8Id, subImage9Id, subThumb1Id, panaRawId, ifd2Id, ifd3Id,
548+
};
551549
for (auto&& filteredIfd : filteredIfds) {
552550
#ifdef EXIV2_DEBUG_MESSAGES
553-
std::cerr << "Warning: Exif IFD " << filteredIfds << " not encoded\n";
551+
std::cerr << "Warning: Exif IFD " << filteredIfd << " not encoded\n";
554552
#endif
555553
eraseIfd(ed, filteredIfd);
556554
}
@@ -575,41 +573,41 @@ WriteMethod ExifParser::encode(Blob& blob, const byte* pData, size_t size, ByteO
575573
// Todo: Enhance preview classes to be able to write and delete previews and use that instead.
576574
// Table must be sorted by preview, the first tag in each group is the size
577575
static constexpr auto filteredPvTags = std::array{
578-
PreviewTags{pttLen, "Exif.Minolta.ThumbnailLength"},
579-
PreviewTags{pttTag, "Exif.Minolta.ThumbnailOffset"},
580-
PreviewTags{pttLen, "Exif.Minolta.Thumbnail"},
581-
PreviewTags{pttLen, "Exif.NikonPreview.JPEGInterchangeFormatLength"},
582-
PreviewTags{pttIfd, "NikonPreview"},
583-
PreviewTags{pttLen, "Exif.Olympus.ThumbnailLength"},
584-
PreviewTags{pttTag, "Exif.Olympus.ThumbnailOffset"},
585-
PreviewTags{pttLen, "Exif.Olympus.ThumbnailImage"},
586-
PreviewTags{pttLen, "Exif.Olympus.Thumbnail"},
587-
PreviewTags{pttLen, "Exif.Olympus2.ThumbnailLength"},
588-
PreviewTags{pttTag, "Exif.Olympus2.ThumbnailOffset"},
589-
PreviewTags{pttLen, "Exif.Olympus2.ThumbnailImage"},
590-
PreviewTags{pttLen, "Exif.Olympus2.Thumbnail"},
591-
PreviewTags{pttLen, "Exif.OlympusCs.PreviewImageLength"},
592-
PreviewTags{pttTag, "Exif.OlympusCs.PreviewImageStart"},
593-
PreviewTags{pttTag, "Exif.OlympusCs.PreviewImageValid"},
594-
PreviewTags{pttLen, "Exif.Pentax.PreviewLength"},
595-
PreviewTags{pttTag, "Exif.Pentax.PreviewOffset"},
596-
PreviewTags{pttTag, "Exif.Pentax.PreviewResolution"},
597-
PreviewTags{pttLen, "Exif.PentaxDng.PreviewLength"},
598-
PreviewTags{pttTag, "Exif.PentaxDng.PreviewOffset"},
599-
PreviewTags{pttTag, "Exif.PentaxDng.PreviewResolution"},
600-
PreviewTags{pttLen, "Exif.SamsungPreview.JPEGInterchangeFormatLength"},
601-
PreviewTags{pttIfd, "SamsungPreview"},
602-
PreviewTags{pttLen, "Exif.Thumbnail.StripByteCounts"},
603-
PreviewTags{pttIfd, "Thumbnail"},
604-
PreviewTags{pttLen, "Exif.Thumbnail.JPEGInterchangeFormatLength"},
605-
PreviewTags{pttIfd, "Thumbnail"},
576+
PreviewTags(pttLen, "Exif.Minolta.ThumbnailLength"),
577+
PreviewTags(pttTag, "Exif.Minolta.ThumbnailOffset"),
578+
PreviewTags(pttLen, "Exif.Minolta.Thumbnail"),
579+
PreviewTags(pttLen, "Exif.NikonPreview.JPEGInterchangeFormatLength"),
580+
PreviewTags(pttIfd, "NikonPreview"),
581+
PreviewTags(pttLen, "Exif.Olympus.ThumbnailLength"),
582+
PreviewTags(pttTag, "Exif.Olympus.ThumbnailOffset"),
583+
PreviewTags(pttLen, "Exif.Olympus.ThumbnailImage"),
584+
PreviewTags(pttLen, "Exif.Olympus.Thumbnail"),
585+
PreviewTags(pttLen, "Exif.Olympus2.ThumbnailLength"),
586+
PreviewTags(pttTag, "Exif.Olympus2.ThumbnailOffset"),
587+
PreviewTags(pttLen, "Exif.Olympus2.ThumbnailImage"),
588+
PreviewTags(pttLen, "Exif.Olympus2.Thumbnail"),
589+
PreviewTags(pttLen, "Exif.OlympusCs.PreviewImageLength"),
590+
PreviewTags(pttTag, "Exif.OlympusCs.PreviewImageStart"),
591+
PreviewTags(pttTag, "Exif.OlympusCs.PreviewImageValid"),
592+
PreviewTags(pttLen, "Exif.Pentax.PreviewLength"),
593+
PreviewTags(pttTag, "Exif.Pentax.PreviewOffset"),
594+
PreviewTags(pttTag, "Exif.Pentax.PreviewResolution"),
595+
PreviewTags(pttLen, "Exif.PentaxDng.PreviewLength"),
596+
PreviewTags(pttTag, "Exif.PentaxDng.PreviewOffset"),
597+
PreviewTags(pttTag, "Exif.PentaxDng.PreviewResolution"),
598+
PreviewTags(pttLen, "Exif.SamsungPreview.JPEGInterchangeFormatLength"),
599+
PreviewTags(pttIfd, "SamsungPreview"),
600+
PreviewTags(pttLen, "Exif.Thumbnail.StripByteCounts"),
601+
PreviewTags(pttIfd, "Thumbnail"),
602+
PreviewTags(pttLen, "Exif.Thumbnail.JPEGInterchangeFormatLength"),
603+
PreviewTags(pttIfd, "Thumbnail"),
606604
};
607605
bool delTags = false;
608-
for (auto&& filteredPvTag : filteredPvTags) {
609-
switch (filteredPvTag.ptt_) {
606+
for (auto&& [ptt, key] : filteredPvTags) {
607+
switch (ptt) {
610608
case pttLen: {
611609
delTags = false;
612-
auto pos = ed.findKey(ExifKey(filteredPvTag.key_));
610+
auto pos = ed.findKey(ExifKey(key));
613611
if (pos != ed.end() && sumToLong(*pos) > 32768) {
614612
delTags = true;
615613
#ifndef SUPPRESS_WARNINGS
@@ -621,7 +619,7 @@ WriteMethod ExifParser::encode(Blob& blob, const byte* pData, size_t size, ByteO
621619
}
622620
case pttTag: {
623621
if (delTags) {
624-
auto pos = ed.findKey(ExifKey(filteredPvTag.key_));
622+
auto pos = ed.findKey(ExifKey(key));
625623
if (pos != ed.end()) {
626624
#ifndef SUPPRESS_WARNINGS
627625
EXV_WARNING << "Exif tag " << pos->key() << " not encoded\n";
@@ -634,9 +632,9 @@ WriteMethod ExifParser::encode(Blob& blob, const byte* pData, size_t size, ByteO
634632
case pttIfd:
635633
if (delTags) {
636634
#ifndef SUPPRESS_WARNINGS
637-
EXV_WARNING << "Exif IFD " << filteredPvTag.key_ << " not encoded\n";
635+
EXV_WARNING << "Exif IFD " << key << " not encoded\n";
638636
#endif
639-
eraseIfd(ed, Internal::groupId(filteredPvTag.key_));
637+
eraseIfd(ed, Internal::groupId(key));
640638
}
641639
break;
642640
}

src/olympusmn_int.cpp

Lines changed: 54 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "tags_int.hpp"
1111
#include "value.hpp"
1212

13+
#include <array>
14+
1315
// *****************************************************************************
1416
// class member definitions
1517
namespace Exiv2::Internal {
@@ -1344,20 +1346,17 @@ std::ostream& OlympusMakerNote::printEq0x0301(std::ostream& os, const Value& val
13441346
//! OlympusCs FocusMode, tag 0x0301
13451347
// (1 or 2 values)
13461348
std::ostream& OlympusMakerNote::printCs0x0301(std::ostream& os, const Value& value, const ExifData*) {
1347-
static struct {
1348-
uint16_t val;
1349-
const char* label;
1350-
} focusModes0[] = {
1351-
{0, N_("Single AF")}, {1, N_("Sequential shooting AF")},
1352-
{2, N_("Continuous AF")}, {3, N_("Multi AF")},
1353-
{4, N_("Face detect")}, {10, N_("MF")},
1349+
using mode0 = std::pair<uint16_t, const char*>;
1350+
static constexpr auto focusModes0 = std::array{
1351+
mode0(0, N_("Single AF")), mode0(1, N_("Sequential shooting AF")),
1352+
mode0(2, N_("Continuous AF")), mode0(3, N_("Multi AF")),
1353+
mode0(4, N_("Face detect")), mode0(10, N_("MF")),
13541354
};
1355-
static struct {
1356-
uint16_t val;
1357-
const char* label;
1358-
} focusModes1[] = {
1359-
{0x0001, N_("S-AF")}, {0x0004, N_("C-AF")}, {0x0010, N_("MF")},
1360-
{0x0020, N_("Face detect")}, {0x0040, N_("Imager AF")}, {0x0100, N_("AF sensor")},
1355+
1356+
using mode1 = std::pair<uint16_t, const char*>;
1357+
static constexpr auto focusModes1 = std::array{
1358+
mode1(0x0001, N_("S-AF")), mode1(0x0004, N_("C-AF")), mode1(0x0010, N_("MF")),
1359+
mode1(0x0020, N_("Face detect")), mode1(0x0040, N_("Imager AF")), mode1(0x0100, N_("AF sensor")),
13611360
};
13621361

13631362
if (value.count() < 1 || value.typeId() != unsignedShort) {
@@ -1370,19 +1369,19 @@ std::ostream& OlympusMakerNote::printCs0x0301(std::ostream& os, const Value& val
13701369
std::string p; // Used to enable ',' separation
13711370

13721371
v = static_cast<uint16_t>(value.toInt64(1));
1373-
for (auto&& mode : focusModes1) {
1374-
if ((v & mode.val) != 0) {
1372+
for (auto&& [val, label] : focusModes1) {
1373+
if ((v & val) != 0) {
13751374
if (!p.empty()) {
13761375
os << ", ";
13771376
}
1378-
p = mode.label;
1377+
p = label;
13791378
os << p;
13801379
}
13811380
}
13821381
} else {
1383-
for (auto&& mode : focusModes0) {
1384-
if (mode.val == v) {
1385-
os << mode.label;
1382+
for (auto&& [val, label] : focusModes0) {
1383+
if (val == v) {
1384+
os << label;
13861385
break;
13871386
}
13881387
}
@@ -1500,41 +1499,38 @@ std::ostream& OlympusMakerNote::print0x0305(std::ostream& os, const Value& value
15001499

15011500
// Olympus FocusInfo tag 0x0308 AFPoint
15021501
std::ostream& OlympusMakerNote::print0x0308(std::ostream& os, const Value& value, const ExifData* metadata) {
1503-
static struct {
1504-
uint16_t val;
1505-
const char* label;
1506-
} afPoints[] = {
1507-
{0, N_("Left (or n/a)")}, {1, N_("Center (horizontal)")}, {2, N_("Right")}, {3, N_("Center (vertical)")},
1508-
{255, N_("None")},
1502+
using point = std::pair<uint16_t, const char*>;
1503+
static constexpr auto afPoints = std::array{
1504+
point(0, N_("Left (or n/a)")), point(1, N_("Center (horizontal)")),
1505+
point(2, N_("Right")), point(3, N_("Center (vertical)")),
1506+
point(255, N_("None")),
15091507
};
15101508

1511-
static struct {
1512-
byte val;
1513-
const char* label;
1514-
} afPointsE3[] = {
1515-
{0x00, N_("None")},
1516-
{0x01, N_("Top-left (horizontal)")},
1517-
{0x02, N_("Top-center (horizontal)")},
1518-
{0x03, N_("Top-right (horizontal)")},
1519-
{0x04, N_("Left (horizontal)")},
1520-
{0x05, N_("Mid-left (horizontal)")},
1521-
{0x06, N_("Center (horizontal)")},
1522-
{0x07, N_("Mid-right (horizontal)")},
1523-
{0x08, N_("Right (horizontal)")},
1524-
{0x09, N_("Bottom-left (horizontal)")},
1525-
{0x0a, N_("Bottom-center (horizontal)")},
1526-
{0x0b, N_("Bottom-right (horizontal)")},
1527-
{0x0c, N_("Top-left (vertical)")},
1528-
{0x0d, N_("Top-center (vertical)")},
1529-
{0x0e, N_("Top-right (vertical)")},
1530-
{0x0f, N_("Left (vertical)")},
1531-
{0x10, N_("Mid-left (vertical)")},
1532-
{0x11, N_("Center (vertical)")},
1533-
{0x12, N_("Mid-right (vertical)")},
1534-
{0x13, N_("Right (vertical)")},
1535-
{0x14, N_("Bottom-left (vertical)")},
1536-
{0x15, N_("Bottom-center (vertical)")},
1537-
{0x16, N_("Bottom-right (vertical)")},
1509+
using pointE3 = std::pair<byte, const char*>;
1510+
static constexpr auto afPointsE3 = std::array{
1511+
pointE3(0x00, N_("None")),
1512+
pointE3(0x01, N_("Top-left (horizontal)")),
1513+
pointE3(0x02, N_("Top-center (horizontal)")),
1514+
pointE3(0x03, N_("Top-right (horizontal)")),
1515+
pointE3(0x04, N_("Left (horizontal)")),
1516+
pointE3(0x05, N_("Mid-left (horizontal)")),
1517+
pointE3(0x06, N_("Center (horizontal)")),
1518+
pointE3(0x07, N_("Mid-right (horizontal)")),
1519+
pointE3(0x08, N_("Right (horizontal)")),
1520+
pointE3(0x09, N_("Bottom-left (horizontal)")),
1521+
pointE3(0x0a, N_("Bottom-center (horizontal)")),
1522+
pointE3(0x0b, N_("Bottom-right (horizontal)")),
1523+
pointE3(0x0c, N_("Top-left (vertical)")),
1524+
pointE3(0x0d, N_("Top-center (vertical)")),
1525+
pointE3(0x0e, N_("Top-right (vertical)")),
1526+
pointE3(0x0f, N_("Left (vertical)")),
1527+
pointE3(0x10, N_("Mid-left (vertical)")),
1528+
pointE3(0x11, N_("Center (vertical)")),
1529+
pointE3(0x12, N_("Mid-right (vertical)")),
1530+
pointE3(0x13, N_("Right (vertical)")),
1531+
pointE3(0x14, N_("Bottom-left (vertical)")),
1532+
pointE3(0x15, N_("Bottom-center (vertical)")),
1533+
pointE3(0x16, N_("Bottom-right (vertical)")),
15381534
};
15391535

15401536
if (value.count() != 1 || value.typeId() != unsignedShort) {
@@ -1556,16 +1552,16 @@ std::ostream& OlympusMakerNote::print0x0308(std::ostream& os, const Value& value
15561552
auto v = static_cast<uint16_t>(value.toInt64(0));
15571553

15581554
if (!E3_E30model) {
1559-
for (auto&& point : afPoints) {
1560-
if (point.val == v) {
1561-
return os << point.label;
1555+
for (auto&& [val, label] : afPoints) {
1556+
if (val == v) {
1557+
return os << label;
15621558
}
15631559
}
15641560
} else {
15651561
// E-3 and E-30
1566-
for (auto&& point : afPointsE3) {
1567-
if (point.val == (v & 0x1f)) {
1568-
os << point.label;
1562+
for (auto&& [val, label] : afPointsE3) {
1563+
if (val == (v & 0x1f)) {
1564+
os << label;
15691565
os << ", ";
15701566
if ((v & 0xe0) == 0)
15711567
return os << N_("Single Target");

src/orfimage.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "tiffimage.hpp"
1414
#include "tiffimage_int.hpp"
1515

16+
#include <array>
1617
#include <iostream>
1718

1819
// *****************************************************************************
@@ -124,10 +125,12 @@ WriteMethod OrfParser::encode(BasicIo& io, const byte* pData, size_t size, ByteO
124125
ExifData ed = exifData;
125126

126127
// Delete IFDs which do not occur in TIFF images
127-
static const IfdId filteredIfds[] = {panaRawId};
128+
static constexpr auto filteredIfds = {
129+
panaRawId,
130+
};
128131
for (auto&& filteredIfd : filteredIfds) {
129132
#ifdef EXIV2_DEBUG_MESSAGES
130-
std::cerr << "Warning: Exif IFD " << filteredIfds << " not encoded\n";
133+
std::cerr << "Warning: Exif IFD " << filteredIfd << " not encoded\n";
131134
#endif
132135
ed.erase(std::remove_if(ed.begin(), ed.end(), FindExifdatum(filteredIfd)), ed.end());
133136
}

0 commit comments

Comments
 (0)