Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc cleanups #2132

Merged
merged 6 commits into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions include/exiv2/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,12 +461,6 @@ namespace Exiv2 {
return rc == src + N ? nullptr : rc;
}

//! Template used in the COUNTOF macro to determine the size of an array
template <typename T, int N>
char (&sizer(T (&)[N]))[N];
//! Macro to determine the size of an array
#define EXV_COUNTOF(a) (sizeof(Exiv2::sizer(a)))

//! Utility function to convert the argument of any type to a string
template <typename T>
std::string toString(const T& arg) {
Expand Down
3 changes: 2 additions & 1 deletion samples/exifprint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ try {
std::vector<std::regex> keys;
Exiv2::dumpLibraryInfo(std::cout,keys);
return rc;
} else if ( strcmp(file,"--version-test") == 0 ) {
}
if (strcmp(file, "--version-test") == 0) {
// verifies/test macro EXIV2_TEST_VERSION
// described in include/exiv2/version.hpp
std::cout << "EXV_PACKAGE_VERSION " << EXV_PACKAGE_VERSION << std::endl
Expand Down
2 changes: 1 addition & 1 deletion src/basicio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace {
pos += subject.find(search, pos + replace.length());
}
}
}
} // namespace

namespace Exiv2 {
void BasicIo::readOrThrow(byte* buf, size_t rcount, ErrorCode err) {
Expand Down
76 changes: 37 additions & 39 deletions src/easyaccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ namespace {
@param keys Array of keys to look for
@param count Number of elements in the array
*/
ExifData::const_iterator findMetadatum(const ExifData& ed,
const char* keys[],
int count)
ExifData::const_iterator findMetadatum(const ExifData& ed, const char* keys[], size_t count)
{
for (int i = 0; i < count; ++i) {
for (size_t i = 0; i < count; ++i) {
auto pos = ed.findKey(ExifKey(keys[i]));
if (pos != ed.end()) return pos;
}
Expand Down Expand Up @@ -48,7 +46,7 @@ namespace Exiv2 {
"Exif.Sony2Cs2.Rotation",
"Exif.Sony1MltCsA100.Rotation"
};
return findMetadatum(ed, keys, EXV_COUNTOF(keys));
return findMetadatum(ed, keys, std::size(keys));
}

ExifData::const_iterator isoSpeed(const ExifData& ed)
Expand Down Expand Up @@ -104,10 +102,10 @@ namespace Exiv2 {
};

// Find the first ISO value which is not "0"
const int cnt = EXV_COUNTOF(keys);
const size_t cnt = std::size(keys);
auto md = ed.end();
int64_t iso_val = -1;
for (int idx = 0; idx < cnt; ) {
for (size_t idx = 0; idx < cnt;) {
md = findMetadatum(ed, keys + idx, cnt - idx);
if (md == ed.end()) break;
std::ostringstream os;
Expand Down Expand Up @@ -168,7 +166,7 @@ namespace Exiv2 {
"Exif.Photo.DateTimeOriginal",
"Exif.Image.DateTimeOriginal"
};
return findMetadatum(ed, keys, EXV_COUNTOF(keys));
return findMetadatum(ed, keys, std::size(keys));
}

ExifData::const_iterator flashBias(const ExifData& ed)
Expand All @@ -183,7 +181,7 @@ namespace Exiv2 {
"Exif.Sony1.FlashExposureComp",
"Exif.Sony2.FlashExposureComp"
};
return findMetadatum(ed, keys, EXV_COUNTOF(keys));
return findMetadatum(ed, keys, std::size(keys));
}

ExifData::const_iterator exposureMode(const ExifData& ed)
Expand All @@ -201,7 +199,7 @@ namespace Exiv2 {
"Exif.Sony2Cs.ExposureProgram",
"Exif.Sigma.ExposureMode"
};
return findMetadatum(ed, keys, EXV_COUNTOF(keys));
return findMetadatum(ed, keys, std::size(keys));
}

ExifData::const_iterator sceneMode(const ExifData& ed)
Expand All @@ -222,7 +220,7 @@ namespace Exiv2 {
"Exif.PentaxDng.PictureMode",
"Exif.Photo.SceneCaptureType"
};
return findMetadatum(ed, keys, EXV_COUNTOF(keys));
return findMetadatum(ed, keys, std::size(keys));
}

ExifData::const_iterator macroMode(const ExifData& ed)
Expand All @@ -238,7 +236,7 @@ namespace Exiv2 {
"Exif.Sony1.Macro",
"Exif.Sony2.Macro"
};
return findMetadatum(ed, keys, EXV_COUNTOF(keys));
return findMetadatum(ed, keys, std::size(keys));
}

ExifData::const_iterator imageQuality(const ExifData& ed)
Expand Down Expand Up @@ -269,7 +267,7 @@ namespace Exiv2 {
"Exif.Casio2.QualityMode",
"Exif.Casio2.Quality"
};
return findMetadatum(ed, keys, EXV_COUNTOF(keys));
return findMetadatum(ed, keys, std::size(keys));
}

ExifData::const_iterator whiteBalance(const ExifData& ed)
Expand Down Expand Up @@ -300,7 +298,7 @@ namespace Exiv2 {
"Exif.Casio2.WhiteBalance2",
"Exif.Photo.WhiteBalance"
};
return findMetadatum(ed, keys, EXV_COUNTOF(keys));
return findMetadatum(ed, keys, std::size(keys));
}

ExifData::const_iterator lensName(const ExifData& ed)
Expand All @@ -323,7 +321,7 @@ namespace Exiv2 {
"Exif.Panasonic.LensType",
"Exif.Samsung2.LensType"
};
return findMetadatum(ed, keys, EXV_COUNTOF(keys));
return findMetadatum(ed, keys, std::size(keys));
}

ExifData::const_iterator saturation(const ExifData& ed)
Expand All @@ -345,7 +343,7 @@ namespace Exiv2 {
"Exif.Casio2.Saturation",
"Exif.Casio2.Saturation2"
};
return findMetadatum(ed, keys, EXV_COUNTOF(keys));
return findMetadatum(ed, keys, std::size(keys));
}

ExifData::const_iterator sharpness(const ExifData& ed)
Expand All @@ -367,7 +365,7 @@ namespace Exiv2 {
"Exif.Casio2.Sharpness",
"Exif.Casio2.Sharpness2"
};
return findMetadatum(ed, keys, EXV_COUNTOF(keys));
return findMetadatum(ed, keys, std::size(keys));
}

ExifData::const_iterator contrast(const ExifData& ed)
Expand All @@ -390,7 +388,7 @@ namespace Exiv2 {
"Exif.Casio2.Contrast2"

};
return findMetadatum(ed, keys, EXV_COUNTOF(keys));
return findMetadatum(ed, keys, std::size(keys));
}

ExifData::const_iterator sceneCaptureType(const ExifData& ed)
Expand All @@ -399,7 +397,7 @@ namespace Exiv2 {
"Exif.Photo.SceneCaptureType",
"Exif.Olympus.SpecialMode"
};
return findMetadatum(ed, keys, EXV_COUNTOF(keys));
return findMetadatum(ed, keys, std::size(keys));
}

ExifData::const_iterator meteringMode(const ExifData& ed)
Expand All @@ -410,23 +408,23 @@ namespace Exiv2 {
"Exif.CanonCs.MeteringMode",
"Exif.Sony1MltCsA100.MeteringMode"
};
return findMetadatum(ed, keys, EXV_COUNTOF(keys));
return findMetadatum(ed, keys, std::size(keys));
}

ExifData::const_iterator make(const ExifData& ed)
{
static const char* keys[] = {
"Exif.Image.Make"
};
return findMetadatum(ed, keys, EXV_COUNTOF(keys));
return findMetadatum(ed, keys, std::size(keys));
}

ExifData::const_iterator model(const ExifData& ed)
{
static const char* keys[] = {
"Exif.Image.Model"
};
return findMetadatum(ed, keys, EXV_COUNTOF(keys));
return findMetadatum(ed, keys, std::size(keys));
}

ExifData::const_iterator exposureTime(const ExifData& ed)
Expand All @@ -436,7 +434,7 @@ namespace Exiv2 {
"Exif.Image.ExposureTime",
"Exif.Samsung2.ExposureTime"
};
return findMetadatum(ed, keys, EXV_COUNTOF(keys));
return findMetadatum(ed, keys, std::size(keys));
}

ExifData::const_iterator fNumber(const ExifData& ed)
Expand All @@ -446,7 +444,7 @@ namespace Exiv2 {
"Exif.Image.FNumber",
"Exif.Samsung2.FNumber"
};
return findMetadatum(ed, keys, EXV_COUNTOF(keys));
return findMetadatum(ed, keys, std::size(keys));
}

ExifData::const_iterator shutterSpeedValue(const ExifData& ed)
Expand All @@ -455,7 +453,7 @@ namespace Exiv2 {
"Exif.Photo.ShutterSpeedValue",
"Exif.Image.ShutterSpeedValue"
};
return findMetadatum(ed, keys, EXV_COUNTOF(keys));
return findMetadatum(ed, keys, std::size(keys));
}

ExifData::const_iterator apertureValue(const ExifData& ed)
Expand All @@ -464,7 +462,7 @@ namespace Exiv2 {
"Exif.Photo.ApertureValue",
"Exif.Image.ApertureValue"
};
return findMetadatum(ed, keys, EXV_COUNTOF(keys));
return findMetadatum(ed, keys, std::size(keys));
}

ExifData::const_iterator brightnessValue(const ExifData& ed)
Expand All @@ -473,7 +471,7 @@ namespace Exiv2 {
"Exif.Photo.BrightnessValue",
"Exif.Image.BrightnessValue"
};
return findMetadatum(ed, keys, EXV_COUNTOF(keys));
return findMetadatum(ed, keys, std::size(keys));
}

ExifData::const_iterator exposureBiasValue(const ExifData& ed)
Expand All @@ -482,7 +480,7 @@ namespace Exiv2 {
"Exif.Photo.ExposureBiasValue",
"Exif.Image.ExposureBiasValue"
};
return findMetadatum(ed, keys, EXV_COUNTOF(keys));
return findMetadatum(ed, keys, std::size(keys));
}

ExifData::const_iterator maxApertureValue(const ExifData& ed)
Expand All @@ -491,7 +489,7 @@ namespace Exiv2 {
"Exif.Photo.MaxApertureValue",
"Exif.Image.MaxApertureValue"
};
return findMetadatum(ed, keys, EXV_COUNTOF(keys));
return findMetadatum(ed, keys, std::size(keys));
}

ExifData::const_iterator subjectDistance(const ExifData& ed)
Expand All @@ -512,7 +510,7 @@ namespace Exiv2 {
"Exif.Casio.ObjectDistance",
"Exif.Casio2.ObjectDistance"
};
return findMetadatum(ed, keys, EXV_COUNTOF(keys));
return findMetadatum(ed, keys, std::size(keys));
}

ExifData::const_iterator lightSource(const ExifData& ed)
Expand All @@ -521,7 +519,7 @@ namespace Exiv2 {
"Exif.Photo.LightSource",
"Exif.Image.LightSource"
};
return findMetadatum(ed, keys, EXV_COUNTOF(keys));
return findMetadatum(ed, keys, std::size(keys));
}

ExifData::const_iterator flash(const ExifData& ed)
Expand All @@ -530,7 +528,7 @@ namespace Exiv2 {
"Exif.Photo.Flash",
"Exif.Image.Flash"
};
return findMetadatum(ed, keys, EXV_COUNTOF(keys));
return findMetadatum(ed, keys, std::size(keys));
}

ExifData::const_iterator serialNumber(const ExifData& ed)
Expand All @@ -544,7 +542,7 @@ namespace Exiv2 {
"Exif.Olympus.SerialNumber2",
"Exif.Sigma.SerialNumber"
};
return findMetadatum(ed, keys, EXV_COUNTOF(keys));
return findMetadatum(ed, keys, std::size(keys));
}

ExifData::const_iterator focalLength(const ExifData& ed)
Expand All @@ -560,7 +558,7 @@ namespace Exiv2 {
"Exif.PentaxDng.FocalLength",
"Exif.Casio2.FocalLength"
};
return findMetadatum(ed, keys, EXV_COUNTOF(keys));
return findMetadatum(ed, keys, std::size(keys));
}

ExifData::const_iterator subjectArea(const ExifData& ed)
Expand All @@ -569,7 +567,7 @@ namespace Exiv2 {
"Exif.Photo.SubjectArea",
"Exif.Image.SubjectLocation"
};
return findMetadatum(ed, keys, EXV_COUNTOF(keys));
return findMetadatum(ed, keys, std::size(keys));
}

ExifData::const_iterator flashEnergy(const ExifData& ed)
Expand All @@ -578,7 +576,7 @@ namespace Exiv2 {
"Exif.Photo.FlashEnergy",
"Exif.Image.FlashEnergy"
};
return findMetadatum(ed, keys, EXV_COUNTOF(keys));
return findMetadatum(ed, keys, std::size(keys));
}

ExifData::const_iterator exposureIndex(const ExifData& ed)
Expand All @@ -587,7 +585,7 @@ namespace Exiv2 {
"Exif.Photo.ExposureIndex",
"Exif.Image.ExposureIndex"
};
return findMetadatum(ed, keys, EXV_COUNTOF(keys));
return findMetadatum(ed, keys, std::size(keys));
}

ExifData::const_iterator sensingMethod(const ExifData& ed)
Expand All @@ -596,7 +594,7 @@ namespace Exiv2 {
"Exif.Photo.SensingMethod",
"Exif.Image.SensingMethod"
};
return findMetadatum(ed, keys, EXV_COUNTOF(keys));
return findMetadatum(ed, keys, std::size(keys));
}

ExifData::const_iterator afPoint(const ExifData& ed)
Expand Down Expand Up @@ -625,7 +623,7 @@ namespace Exiv2 {
"Exif.Casio.AFPoint",
"Exif.Casio2.AFPointPosition"
};
return findMetadatum(ed, keys, EXV_COUNTOF(keys));
return findMetadatum(ed, keys, std::size(keys));
}

} // namespace Exiv2
6 changes: 3 additions & 3 deletions src/nikonmn_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ namespace Exiv2::Internal {
{
if (value.count() >= 1) {
const uint32_t focusArea = value.toUint32(0);
if (focusArea >= EXV_COUNTOF(nikonFocusarea)) {
if (focusArea >= std::size(nikonFocusarea)) {
os << "Invalid value";
} else {
os << nikonFocusarea[focusArea];
Expand Down Expand Up @@ -2963,9 +2963,9 @@ fmountlens[] = {
oss.copyfmt(os);
const auto temp = value.toInt64();

printTag<EXV_COUNTOF(nikonFlashControlMode), nikonFlashControlMode>(os, (temp >> 4), data);
printTag<std::size(nikonFlashControlMode), nikonFlashControlMode>(os, (temp >> 4), data);
os << ", ";
printTag<EXV_COUNTOF(nikonFlashControlMode), nikonFlashControlMode>(os, (temp & 0x0f), data);
printTag<std::size(nikonFlashControlMode), nikonFlashControlMode>(os, (temp & 0x0f), data);

os.copyfmt(oss);
os.flags(f);
Expand Down
6 changes: 4 additions & 2 deletions src/pentaxmn_int.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@ namespace Exiv2::Internal {
}

//! Shortcut for the printCombiTag template which requires typing the array name only once.
#define EXV_PRINT_COMBITAG(array, count, ignoredcount) printCombiTag<EXV_COUNTOF(array), array, count, ignoredcount, ignoredcount>
#define EXV_PRINT_COMBITAG(array, count, ignoredcount) \
printCombiTag<std::size(array), array, count, ignoredcount, ignoredcount>
//! Shortcut for the printCombiTag template which requires typing the array name only once.
#define EXV_PRINT_COMBITAG_MULTI(array, count, ignoredcount, ignoredcountmax) printCombiTag<EXV_COUNTOF(array), array, count, ignoredcount, ignoredcountmax>
#define EXV_PRINT_COMBITAG_MULTI(array, count, ignoredcount, ignoredcountmax) \
printCombiTag<std::size(array), array, count, ignoredcount, ignoredcountmax>

} // namespace Exiv2::Internal

Expand Down
Loading