clang-tidy: C array to std::array conversions

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

@ -11,6 +11,7 @@
#include "i18n.h" // NLS support. #include "i18n.h" // NLS support.
#include "types.hpp" #include "types.hpp"
#include <array>
#include <iomanip> #include <iomanip>
#include <regex> #include <regex>
#include <sstream> #include <sstream>
@ -19,11 +20,11 @@
// class member definitions // class member definitions
namespace Exiv2 { namespace Exiv2 {
constexpr const char* familyName_{"Iptc"}; constexpr auto familyName_ = "Iptc";
constexpr RecordInfo recordInfo_[] = { constexpr auto recordInfo_ = std::array{
{IptcDataSets::invalidRecord, "(invalid)", N_("(invalid)")}, RecordInfo{IptcDataSets::invalidRecord, "(invalid)", N_("(invalid)")},
{IptcDataSets::envelope, "Envelope", N_("IIM envelope record")}, RecordInfo{IptcDataSets::envelope, "Envelope", N_("IIM envelope record")},
{IptcDataSets::application2, "Application2", N_("IIM application record 2")}, RecordInfo{IptcDataSets::application2, "Application2", N_("IIM application record 2")},
}; };
constexpr DataSet envelopeRecord[] = { constexpr DataSet envelopeRecord[] = {

@ -66,20 +66,17 @@ constexpr std::string_view xmpHeaders[] = {
}; };
// list of all valid XMP trailers // list of all valid XMP trailers
struct XmpTrailer { using XmpTrailer = std::pair<std::string_view, bool>;
std::string_view trailer;
bool readOnly;
};
constexpr XmpTrailer xmpTrailers[] = { constexpr auto xmpTrailers = std::array{
// We do not enforce the trailing "?>" here, because the XMP specification // We do not enforce the trailing "?>" here, because the XMP specification
// permits additional attributes after end="...". // permits additional attributes after end="...".
{"<?xpacket end=\"r\"", true}, XmpTrailer("<?xpacket end=\"r\"", true),
{"<?xpacket end='r'", true}, XmpTrailer("<?xpacket end='r'", true),
{"<?xpacket end=\"w\"", false}, XmpTrailer("<?xpacket end=\"w\"", false),
{"<?xpacket end='w'", false}, XmpTrailer("<?xpacket end='w'", false),
}; };
// closing part of all valid XMP trailers // 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,
if (data[xmpPos] != '\x00' && data[xmpPos] != '<') if (data[xmpPos] != '\x00' && data[xmpPos] != '<')
continue; continue;
for (auto&& xmpTrailer : xmpTrailers) { for (auto&& xmpTrailer : xmpTrailers) {
auto trailer = xmpTrailer.trailer; auto [trailer, readOnly] = xmpTrailer;
const bool readOnly = xmpTrailer.readOnly;
if (trailerPos + trailer.size() > size) if (trailerPos + trailer.size() > size)
continue; continue;

@ -496,10 +496,7 @@ ByteOrder ExifParser::decode(ExifData& exifData, const byte* pData, size_t size)
//! @cond IGNORE //! @cond IGNORE
enum Ptt { pttLen, pttTag, pttIfd }; enum Ptt { pttLen, pttTag, pttIfd };
struct PreviewTags { using PreviewTags = std::pair<Ptt, const char*>;
Ptt ptt_;
const char* key_;
};
//! @endcond //! @endcond
WriteMethod ExifParser::encode(Blob& blob, const byte* pData, size_t size, ByteOrder byteOrder, 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
} }
// Delete IFDs which do not occur in JPEGs // Delete IFDs which do not occur in JPEGs
static const IfdId filteredIfds[] = {subImage1Id, subImage2Id, subImage3Id, subImage4Id, subImage5Id, static constexpr auto filteredIfds = std::array{
subImage6Id, subImage7Id, subImage8Id, subImage9Id, subThumb1Id, subImage1Id, subImage2Id, subImage3Id, subImage4Id, subImage5Id, subImage6Id, subImage7Id,
panaRawId, ifd2Id, ifd3Id}; subImage8Id, subImage9Id, subThumb1Id, panaRawId, ifd2Id, ifd3Id,
};
for (auto&& filteredIfd : filteredIfds) { for (auto&& filteredIfd : filteredIfds) {
#ifdef EXIV2_DEBUG_MESSAGES #ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Warning: Exif IFD " << filteredIfds << " not encoded\n"; std::cerr << "Warning: Exif IFD " << filteredIfd << " not encoded\n";
#endif #endif
eraseIfd(ed, filteredIfd); eraseIfd(ed, filteredIfd);
} }
@ -575,41 +573,41 @@ WriteMethod ExifParser::encode(Blob& blob, const byte* pData, size_t size, ByteO
// Todo: Enhance preview classes to be able to write and delete previews and use that instead. // Todo: Enhance preview classes to be able to write and delete previews and use that instead.
// Table must be sorted by preview, the first tag in each group is the size // Table must be sorted by preview, the first tag in each group is the size
static constexpr auto filteredPvTags = std::array{ static constexpr auto filteredPvTags = std::array{
PreviewTags{pttLen, "Exif.Minolta.ThumbnailLength"}, PreviewTags(pttLen, "Exif.Minolta.ThumbnailLength"),
PreviewTags{pttTag, "Exif.Minolta.ThumbnailOffset"}, PreviewTags(pttTag, "Exif.Minolta.ThumbnailOffset"),
PreviewTags{pttLen, "Exif.Minolta.Thumbnail"}, PreviewTags(pttLen, "Exif.Minolta.Thumbnail"),
PreviewTags{pttLen, "Exif.NikonPreview.JPEGInterchangeFormatLength"}, PreviewTags(pttLen, "Exif.NikonPreview.JPEGInterchangeFormatLength"),
PreviewTags{pttIfd, "NikonPreview"}, PreviewTags(pttIfd, "NikonPreview"),
PreviewTags{pttLen, "Exif.Olympus.ThumbnailLength"}, PreviewTags(pttLen, "Exif.Olympus.ThumbnailLength"),
PreviewTags{pttTag, "Exif.Olympus.ThumbnailOffset"}, PreviewTags(pttTag, "Exif.Olympus.ThumbnailOffset"),
PreviewTags{pttLen, "Exif.Olympus.ThumbnailImage"}, PreviewTags(pttLen, "Exif.Olympus.ThumbnailImage"),
PreviewTags{pttLen, "Exif.Olympus.Thumbnail"}, PreviewTags(pttLen, "Exif.Olympus.Thumbnail"),
PreviewTags{pttLen, "Exif.Olympus2.ThumbnailLength"}, PreviewTags(pttLen, "Exif.Olympus2.ThumbnailLength"),
PreviewTags{pttTag, "Exif.Olympus2.ThumbnailOffset"}, PreviewTags(pttTag, "Exif.Olympus2.ThumbnailOffset"),
PreviewTags{pttLen, "Exif.Olympus2.ThumbnailImage"}, PreviewTags(pttLen, "Exif.Olympus2.ThumbnailImage"),
PreviewTags{pttLen, "Exif.Olympus2.Thumbnail"}, PreviewTags(pttLen, "Exif.Olympus2.Thumbnail"),
PreviewTags{pttLen, "Exif.OlympusCs.PreviewImageLength"}, PreviewTags(pttLen, "Exif.OlympusCs.PreviewImageLength"),
PreviewTags{pttTag, "Exif.OlympusCs.PreviewImageStart"}, PreviewTags(pttTag, "Exif.OlympusCs.PreviewImageStart"),
PreviewTags{pttTag, "Exif.OlympusCs.PreviewImageValid"}, PreviewTags(pttTag, "Exif.OlympusCs.PreviewImageValid"),
PreviewTags{pttLen, "Exif.Pentax.PreviewLength"}, PreviewTags(pttLen, "Exif.Pentax.PreviewLength"),
PreviewTags{pttTag, "Exif.Pentax.PreviewOffset"}, PreviewTags(pttTag, "Exif.Pentax.PreviewOffset"),
PreviewTags{pttTag, "Exif.Pentax.PreviewResolution"}, PreviewTags(pttTag, "Exif.Pentax.PreviewResolution"),
PreviewTags{pttLen, "Exif.PentaxDng.PreviewLength"}, PreviewTags(pttLen, "Exif.PentaxDng.PreviewLength"),
PreviewTags{pttTag, "Exif.PentaxDng.PreviewOffset"}, PreviewTags(pttTag, "Exif.PentaxDng.PreviewOffset"),
PreviewTags{pttTag, "Exif.PentaxDng.PreviewResolution"}, PreviewTags(pttTag, "Exif.PentaxDng.PreviewResolution"),
PreviewTags{pttLen, "Exif.SamsungPreview.JPEGInterchangeFormatLength"}, PreviewTags(pttLen, "Exif.SamsungPreview.JPEGInterchangeFormatLength"),
PreviewTags{pttIfd, "SamsungPreview"}, PreviewTags(pttIfd, "SamsungPreview"),
PreviewTags{pttLen, "Exif.Thumbnail.StripByteCounts"}, PreviewTags(pttLen, "Exif.Thumbnail.StripByteCounts"),
PreviewTags{pttIfd, "Thumbnail"}, PreviewTags(pttIfd, "Thumbnail"),
PreviewTags{pttLen, "Exif.Thumbnail.JPEGInterchangeFormatLength"}, PreviewTags(pttLen, "Exif.Thumbnail.JPEGInterchangeFormatLength"),
PreviewTags{pttIfd, "Thumbnail"}, PreviewTags(pttIfd, "Thumbnail"),
}; };
bool delTags = false; bool delTags = false;
for (auto&& filteredPvTag : filteredPvTags) { for (auto&& [ptt, key] : filteredPvTags) {
switch (filteredPvTag.ptt_) { switch (ptt) {
case pttLen: { case pttLen: {
delTags = false; delTags = false;
auto pos = ed.findKey(ExifKey(filteredPvTag.key_)); auto pos = ed.findKey(ExifKey(key));
if (pos != ed.end() && sumToLong(*pos) > 32768) { if (pos != ed.end() && sumToLong(*pos) > 32768) {
delTags = true; delTags = true;
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
@ -621,7 +619,7 @@ WriteMethod ExifParser::encode(Blob& blob, const byte* pData, size_t size, ByteO
} }
case pttTag: { case pttTag: {
if (delTags) { if (delTags) {
auto pos = ed.findKey(ExifKey(filteredPvTag.key_)); auto pos = ed.findKey(ExifKey(key));
if (pos != ed.end()) { if (pos != ed.end()) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Exif tag " << pos->key() << " not encoded\n"; 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
case pttIfd: case pttIfd:
if (delTags) { if (delTags) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Exif IFD " << filteredPvTag.key_ << " not encoded\n"; EXV_WARNING << "Exif IFD " << key << " not encoded\n";
#endif #endif
eraseIfd(ed, Internal::groupId(filteredPvTag.key_)); eraseIfd(ed, Internal::groupId(key));
} }
break; break;
} }

@ -10,6 +10,8 @@
#include "tags_int.hpp" #include "tags_int.hpp"
#include "value.hpp" #include "value.hpp"
#include <array>
// ***************************************************************************** // *****************************************************************************
// class member definitions // class member definitions
namespace Exiv2::Internal { namespace Exiv2::Internal {
@ -1344,20 +1346,17 @@ std::ostream& OlympusMakerNote::printEq0x0301(std::ostream& os, const Value& val
//! OlympusCs FocusMode, tag 0x0301 //! OlympusCs FocusMode, tag 0x0301
// (1 or 2 values) // (1 or 2 values)
std::ostream& OlympusMakerNote::printCs0x0301(std::ostream& os, const Value& value, const ExifData*) { std::ostream& OlympusMakerNote::printCs0x0301(std::ostream& os, const Value& value, const ExifData*) {
static struct { using mode0 = std::pair<uint16_t, const char*>;
uint16_t val; static constexpr auto focusModes0 = std::array{
const char* label; mode0(0, N_("Single AF")), mode0(1, N_("Sequential shooting AF")),
} focusModes0[] = { mode0(2, N_("Continuous AF")), mode0(3, N_("Multi AF")),
{0, N_("Single AF")}, {1, N_("Sequential shooting AF")}, mode0(4, N_("Face detect")), mode0(10, N_("MF")),
{2, N_("Continuous AF")}, {3, N_("Multi AF")},
{4, N_("Face detect")}, {10, N_("MF")},
}; };
static struct {
uint16_t val; using mode1 = std::pair<uint16_t, const char*>;
const char* label; static constexpr auto focusModes1 = std::array{
} focusModes1[] = { mode1(0x0001, N_("S-AF")), mode1(0x0004, N_("C-AF")), mode1(0x0010, N_("MF")),
{0x0001, N_("S-AF")}, {0x0004, N_("C-AF")}, {0x0010, N_("MF")}, mode1(0x0020, N_("Face detect")), mode1(0x0040, N_("Imager AF")), mode1(0x0100, N_("AF sensor")),
{0x0020, N_("Face detect")}, {0x0040, N_("Imager AF")}, {0x0100, N_("AF sensor")},
}; };
if (value.count() < 1 || value.typeId() != unsignedShort) { if (value.count() < 1 || value.typeId() != unsignedShort) {
@ -1370,19 +1369,19 @@ std::ostream& OlympusMakerNote::printCs0x0301(std::ostream& os, const Value& val
std::string p; // Used to enable ',' separation std::string p; // Used to enable ',' separation
v = static_cast<uint16_t>(value.toInt64(1)); v = static_cast<uint16_t>(value.toInt64(1));
for (auto&& mode : focusModes1) { for (auto&& [val, label] : focusModes1) {
if ((v & mode.val) != 0) { if ((v & val) != 0) {
if (!p.empty()) { if (!p.empty()) {
os << ", "; os << ", ";
} }
p = mode.label; p = label;
os << p; os << p;
} }
} }
} else { } else {
for (auto&& mode : focusModes0) { for (auto&& [val, label] : focusModes0) {
if (mode.val == v) { if (val == v) {
os << mode.label; os << label;
break; break;
} }
} }
@ -1500,41 +1499,38 @@ std::ostream& OlympusMakerNote::print0x0305(std::ostream& os, const Value& value
// Olympus FocusInfo tag 0x0308 AFPoint // Olympus FocusInfo tag 0x0308 AFPoint
std::ostream& OlympusMakerNote::print0x0308(std::ostream& os, const Value& value, const ExifData* metadata) { std::ostream& OlympusMakerNote::print0x0308(std::ostream& os, const Value& value, const ExifData* metadata) {
static struct { using point = std::pair<uint16_t, const char*>;
uint16_t val; static constexpr auto afPoints = std::array{
const char* label; point(0, N_("Left (or n/a)")), point(1, N_("Center (horizontal)")),
} afPoints[] = { point(2, N_("Right")), point(3, N_("Center (vertical)")),
{0, N_("Left (or n/a)")}, {1, N_("Center (horizontal)")}, {2, N_("Right")}, {3, N_("Center (vertical)")}, point(255, N_("None")),
{255, N_("None")},
}; };
static struct { using pointE3 = std::pair<byte, const char*>;
byte val; static constexpr auto afPointsE3 = std::array{
const char* label; pointE3(0x00, N_("None")),
} afPointsE3[] = { pointE3(0x01, N_("Top-left (horizontal)")),
{0x00, N_("None")}, pointE3(0x02, N_("Top-center (horizontal)")),
{0x01, N_("Top-left (horizontal)")}, pointE3(0x03, N_("Top-right (horizontal)")),
{0x02, N_("Top-center (horizontal)")}, pointE3(0x04, N_("Left (horizontal)")),
{0x03, N_("Top-right (horizontal)")}, pointE3(0x05, N_("Mid-left (horizontal)")),
{0x04, N_("Left (horizontal)")}, pointE3(0x06, N_("Center (horizontal)")),
{0x05, N_("Mid-left (horizontal)")}, pointE3(0x07, N_("Mid-right (horizontal)")),
{0x06, N_("Center (horizontal)")}, pointE3(0x08, N_("Right (horizontal)")),
{0x07, N_("Mid-right (horizontal)")}, pointE3(0x09, N_("Bottom-left (horizontal)")),
{0x08, N_("Right (horizontal)")}, pointE3(0x0a, N_("Bottom-center (horizontal)")),
{0x09, N_("Bottom-left (horizontal)")}, pointE3(0x0b, N_("Bottom-right (horizontal)")),
{0x0a, N_("Bottom-center (horizontal)")}, pointE3(0x0c, N_("Top-left (vertical)")),
{0x0b, N_("Bottom-right (horizontal)")}, pointE3(0x0d, N_("Top-center (vertical)")),
{0x0c, N_("Top-left (vertical)")}, pointE3(0x0e, N_("Top-right (vertical)")),
{0x0d, N_("Top-center (vertical)")}, pointE3(0x0f, N_("Left (vertical)")),
{0x0e, N_("Top-right (vertical)")}, pointE3(0x10, N_("Mid-left (vertical)")),
{0x0f, N_("Left (vertical)")}, pointE3(0x11, N_("Center (vertical)")),
{0x10, N_("Mid-left (vertical)")}, pointE3(0x12, N_("Mid-right (vertical)")),
{0x11, N_("Center (vertical)")}, pointE3(0x13, N_("Right (vertical)")),
{0x12, N_("Mid-right (vertical)")}, pointE3(0x14, N_("Bottom-left (vertical)")),
{0x13, N_("Right (vertical)")}, pointE3(0x15, N_("Bottom-center (vertical)")),
{0x14, N_("Bottom-left (vertical)")}, pointE3(0x16, N_("Bottom-right (vertical)")),
{0x15, N_("Bottom-center (vertical)")},
{0x16, N_("Bottom-right (vertical)")},
}; };
if (value.count() != 1 || value.typeId() != unsignedShort) { if (value.count() != 1 || value.typeId() != unsignedShort) {
@ -1556,16 +1552,16 @@ std::ostream& OlympusMakerNote::print0x0308(std::ostream& os, const Value& value
auto v = static_cast<uint16_t>(value.toInt64(0)); auto v = static_cast<uint16_t>(value.toInt64(0));
if (!E3_E30model) { if (!E3_E30model) {
for (auto&& point : afPoints) { for (auto&& [val, label] : afPoints) {
if (point.val == v) { if (val == v) {
return os << point.label; return os << label;
} }
} }
} else { } else {
// E-3 and E-30 // E-3 and E-30
for (auto&& point : afPointsE3) { for (auto&& [val, label] : afPointsE3) {
if (point.val == (v & 0x1f)) { if (val == (v & 0x1f)) {
os << point.label; os << label;
os << ", "; os << ", ";
if ((v & 0xe0) == 0) if ((v & 0xe0) == 0)
return os << N_("Single Target"); return os << N_("Single Target");

@ -13,6 +13,7 @@
#include "tiffimage.hpp" #include "tiffimage.hpp"
#include "tiffimage_int.hpp" #include "tiffimage_int.hpp"
#include <array>
#include <iostream> #include <iostream>
// ***************************************************************************** // *****************************************************************************
@ -124,10 +125,12 @@ WriteMethod OrfParser::encode(BasicIo& io, const byte* pData, size_t size, ByteO
ExifData ed = exifData; ExifData ed = exifData;
// Delete IFDs which do not occur in TIFF images // Delete IFDs which do not occur in TIFF images
static const IfdId filteredIfds[] = {panaRawId}; static constexpr auto filteredIfds = {
panaRawId,
};
for (auto&& filteredIfd : filteredIfds) { for (auto&& filteredIfd : filteredIfds) {
#ifdef EXIV2_DEBUG_MESSAGES #ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Warning: Exif IFD " << filteredIfds << " not encoded\n"; std::cerr << "Warning: Exif IFD " << filteredIfd << " not encoded\n";
#endif #endif
ed.erase(std::remove_if(ed.begin(), ed.end(), FindExifdatum(filteredIfd)), ed.end()); ed.erase(std::remove_if(ed.begin(), ed.end(), FindExifdatum(filteredIfd)), ed.end());
} }

Loading…
Cancel
Save