From 34d07836144e0ec9a77aceaf977eae26e82beb7f Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Thu, 13 May 2021 17:56:43 -0700 Subject: [PATCH] clang-tidy: use auto Found with modernize-use-auto Signed-off-by: Rosen Penev --- samples/Jzon.cpp | 2 +- samples/addmoddel.cpp | 2 +- samples/exiv2json.cpp | 4 +-- samples/geotag.cpp | 6 ++--- samples/iptctest.cpp | 4 +-- src/actions.cpp | 2 +- src/basicio.cpp | 22 ++++++++-------- src/bmffimage.cpp | 4 +-- src/canonmn_int.cpp | 2 +- src/convert.cpp | 4 +-- src/crwimage_int.cpp | 2 +- src/easyaccess.cpp | 6 ++--- src/exif.cpp | 2 +- src/exiv2.cpp | 8 +++--- src/futils.cpp | 12 ++++----- src/image.cpp | 14 +++++----- src/image_int.cpp | 4 +-- src/ini.cpp | 2 +- src/iptc.cpp | 10 +++---- src/jp2image.cpp | 8 +++--- src/jpgimage.cpp | 8 +++--- src/makernote_int.cpp | 8 +++--- src/nikonmn_int.cpp | 55 +++++++++++++++++++++------------------ src/olympusmn_int.cpp | 12 ++++----- src/pgfimage.cpp | 2 +- src/pngchunk_int.cpp | 4 +-- src/pngimage.cpp | 11 ++++---- src/preview.cpp | 10 +++---- src/properties.cpp | 8 +++--- src/tags.cpp | 2 +- src/tags_int.cpp | 2 +- src/tiffcomposite_int.cpp | 20 +++++++------- src/tiffimage_int.cpp | 8 +++--- src/tiffvisitor_int.cpp | 24 ++++++++--------- src/types.cpp | 8 +++--- src/value.cpp | 7 +++-- src/version.cpp | 4 +-- src/webpimage.cpp | 2 +- src/xmp.cpp | 8 +++--- unitTests/test_futils.cpp | 6 ++--- unitTests/test_slice.cpp | 8 +++--- 41 files changed, 167 insertions(+), 170 deletions(-) diff --git a/samples/Jzon.cpp b/samples/Jzon.cpp index 016bd6e78c..0c15096953 100644 --- a/samples/Jzon.cpp +++ b/samples/Jzon.cpp @@ -577,7 +577,7 @@ namespace Jzon void Array::Remove(size_t index) { if (index < children.size()) { - ChildList::iterator it = children.begin() + index; + auto it = children.begin() + index; delete (*it); children.erase(it); } diff --git a/samples/addmoddel.cpp b/samples/addmoddel.cpp index dc06b562e3..d3a3e7b417 100644 --- a/samples/addmoddel.cpp +++ b/samples/addmoddel.cpp @@ -96,7 +96,7 @@ try { // Get a pointer to a copy of the value v = pos->getValue(); // Downcast the Value pointer to its actual type - Exiv2::URationalValue* prv = dynamic_cast(v.release()); + auto prv = dynamic_cast(v.release()); if (prv == 0) throw Exiv2::Error(Exiv2::kerErrorMessage, "Downcast failed"); rv = Exiv2::URationalValue::UniquePtr(prv); // Modify the value directly through the interface of URationalValue diff --git a/samples/exiv2json.cpp b/samples/exiv2json.cpp index bc1d50fc63..968038fff1 100644 --- a/samples/exiv2json.cpp +++ b/samples/exiv2json.cpp @@ -210,7 +210,7 @@ void push(Jzon::Node& node,const std::string& key,T i) case Exiv2::langAlt: { ABORT_IF_I_EMTPY Jzon::Object l ; - const Exiv2::LangAltValue& langs = dynamic_cast(i->value()); + const auto& langs = dynamic_cast(i->value()); for (auto&& lang : langs.value_) { l.Add(lang.first, lang.second); } @@ -246,7 +246,7 @@ void push(Jzon::Node& node,const std::string& key,T i) void fileSystemPush(const char* path,Jzon::Node& nfs) { - Jzon::Object& fs = (Jzon::Object&) nfs; + auto& fs = (Jzon::Object&)nfs; fs.Add("path",path); char resolved_path[2000]; // PATH_MAX]; fs.Add("realpath",realpath(path,resolved_path)); diff --git a/samples/geotag.cpp b/samples/geotag.cpp index feae2a6243..5fa5a72683 100644 --- a/samples/geotag.cpp +++ b/samples/geotag.cpp @@ -335,7 +335,7 @@ class UserData // XML Parser Callbacks static void startElement(void* userData, const char* name, const char** atts ) { - UserData* me = (UserData*) userData; + auto me = (UserData*)userData; //for ( int i = 0 ; i < me->indent ; i++ ) printf(" "); //printf("begin %s\n",name); me->bTime = strcmp(name,"time")==0; @@ -357,7 +357,7 @@ static void startElement(void* userData, const char* name, const char** atts ) static void endElement(void* userData, const char* name) { - UserData* me = (UserData*) userData; + auto me = (UserData*)userData; me->indent-- ; if ( strcmp(name,"trkpt")==0 ) { @@ -379,7 +379,7 @@ static void endElement(void* userData, const char* name) void charHandler(void* userData,const char* s,int len) { - UserData* me = (UserData*) userData; + auto me = (UserData*)userData; if ( me->nTrkpt == 1 ) { char buffer[100]; diff --git a/samples/iptctest.cpp b/samples/iptctest.cpp index 5e38980945..50a61f4dee 100644 --- a/samples/iptctest.cpp +++ b/samples/iptctest.cpp @@ -142,7 +142,7 @@ void processRemove(const std::string& line, int num, IptcData &iptcData) const std::string key( line.substr(keyStart) ); IptcKey iptcKey(key); - IptcData::iterator iter = iptcData.findKey(iptcKey); + auto iter = iptcData.findKey(iptcKey); if (iter != iptcData.end()) { iptcData.erase(iter); } @@ -174,7 +174,7 @@ void processModify(const std::string& line, int num, IptcData &iptcData) Value::UniquePtr value = Value::create(type); value->read(data); - IptcData::iterator iter = iptcData.findKey(iptcKey); + auto iter = iptcData.findKey(iptcKey); if (iter != iptcData.end()) { iter->setValue(value.get()); } diff --git a/src/actions.cpp b/src/actions.cpp index 17e87bc3cf..b886a12c71 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -1718,7 +1718,7 @@ namespace Action { return 0; } Exiv2::Value::UniquePtr v = pos->getValue(); - const Exiv2::CommentValue* pcv = dynamic_cast(v.get()); + const auto pcv = dynamic_cast(v.get()); if (!pcv) { if (Params::instance().verbose_) { std::cout << _("Found Exif user comment with unexpected value type") << "\n"; diff --git a/src/basicio.cpp b/src/basicio.cpp index 3437c7ea96..74ea45d323 100644 --- a/src/basicio.cpp +++ b/src/basicio.cpp @@ -600,7 +600,7 @@ namespace Exiv2 { const bool wasOpen = (p_->fp_ != 0); const std::string lastMode(p_->openMode_); - FileIo *fileIo = dynamic_cast(&src); + auto fileIo = dynamic_cast(&src); if (fileIo) { // Optimization if src is another instance of FileIo fileIo->close(); @@ -1146,7 +1146,7 @@ namespace Exiv2 { if (!isMalloced_) { // Minimum size for 1st block long size = EXV_MAX(blockSize * (1 + need / blockSize), size_); - byte* data = (byte*)std::malloc(size); + auto data = (byte*)std::malloc(size); if ( data == NULL ) { throw Error(kerMallocFailed); } @@ -1205,7 +1205,7 @@ namespace Exiv2 { void MemIo::transfer(BasicIo& src) { - MemIo *memIo = dynamic_cast(&src); + auto memIo = dynamic_cast(&src); if (memIo) { // Optimization if src is another instance of MemIo if (p_->isMalloced_) { @@ -1525,7 +1525,7 @@ namespace Exiv2 { } std::string data = orgPath.substr(base64Pos+7); - char* decodeData = new char[data.length()]; + auto decodeData = new char[data.length()]; long size = base64decode(data.c_str(), decodeData, data.length()); if (size > 0) { fs.write(decodeData, size); @@ -1645,7 +1645,7 @@ namespace Exiv2 { if (rcount == 0) { throw Error(kerErrorMessage, "Data By Range is empty. Please check the permission."); } - byte* source = (byte*)data.c_str(); + auto source = (byte*)data.c_str(); size_t remain = rcount, totalRead = 0; size_t iBlock = (rcount == size_) ? 0 : lowBlock; @@ -1686,7 +1686,7 @@ namespace Exiv2 { size_t nBlocks = (p_->size_ + p_->blockSize_ - 1) / p_->blockSize_; p_->blocksMap_ = new BlockMap[nBlocks]; p_->isMalloced_ = true; - byte* source = (byte*)data.c_str(); + auto source = (byte*)data.c_str(); size_t remain = p_->size_, iBlock = 0, totalRead = 0; while (remain) { size_t allow = EXV_MIN(remain, p_->blockSize_); @@ -1746,7 +1746,7 @@ namespace Exiv2 { size_t i = 0; size_t readCount = 0; size_t blockSize = 0; - byte* buf = (byte*) std::malloc(p_->blockSize_); + auto buf = (byte*)std::malloc(p_->blockSize_); size_t nBlocks = (p_->size_ + p_->blockSize_ - 1) / p_->blockSize_; // find $left @@ -1796,7 +1796,7 @@ namespace Exiv2 { // submit to the remote machine. long dataSize = (long) (src.size() - left - right); if (dataSize > 0) { - byte* data = (byte*) std::malloc(dataSize); + auto data = (byte*)std::malloc(dataSize); src.seek(left, BasicIo::beg); src.read(data, dataSize); p_->writeRemote(data, (size_t)dataSize, (long)left, (long) (p_->size_ - right)); @@ -1830,7 +1830,7 @@ namespace Exiv2 { // connect to the remote machine & populate the blocks just in time. p_->populateBlocks(lowBlock, highBlock); - byte* fakeData = (byte*) std::calloc(p_->blockSize_, sizeof(byte)); + auto fakeData = (byte*)std::calloc(p_->blockSize_, sizeof(byte)); if (!fakeData) { throw Error(kerErrorMessage, "Unable to allocate data"); } @@ -2127,7 +2127,7 @@ namespace Exiv2 { // encode base64 size_t encodeLength = ((size + 2) / 3) * 4 + 1; - char* encodeData = new char[encodeLength]; + auto encodeData = new char[encodeLength]; base64encode(data, size, encodeData, encodeLength); // url encode const std::string urlencodeData = urlencode(encodeData); @@ -2348,7 +2348,7 @@ namespace Exiv2 { // encode base64 size_t encodeLength = ((size + 2) / 3) * 4 + 1; - char* encodeData = new char[encodeLength]; + auto encodeData = new char[encodeLength]; base64encode(data, size, encodeData, encodeLength); // url encode const std::string urlencodeData = urlencode(encodeData); diff --git a/src/bmffimage.cpp b/src/bmffimage.cpp index 845aadb391..935c220a25 100644 --- a/src/bmffimage.cpp +++ b/src/bmffimage.cpp @@ -111,7 +111,7 @@ namespace Exiv2 std::string BmffImage::toAscii(long n) { - const char* p = (const char*)&n; + const auto p = (const char*)&n; std::string result; for (int i = 0; i < 4; i++) { char c = p[isBigEndianPlatform() ? i : (3 - i)]; @@ -289,7 +289,7 @@ namespace Exiv2 std::string id; // Check that the string has a '\0' terminator. const char* str = (const char*)data.pData_ + skip; - const size_t maxlen = static_cast(data.size_ - skip); + const auto maxlen = static_cast(data.size_ - skip); enforce(strnlen(str, maxlen) < maxlen, Exiv2::kerCorruptedMetadata); std::string name(str); if ( !name.find("Exif") ) { // "Exif" or "ExifExif" diff --git a/src/canonmn_int.cpp b/src/canonmn_int.cpp index 8c8b257559..d0818bda08 100644 --- a/src/canonmn_int.cpp +++ b/src/canonmn_int.cpp @@ -3212,7 +3212,7 @@ namespace Exiv2 { val = -val; } // remove fraction - float frac = static_cast(val & 0x1f); + auto frac = static_cast(val & 0x1f); val -= long(frac); // convert 1/3 (0x0c) and 2/3 (0x14) codes if (frac == 0x0c) { diff --git a/src/convert.cpp b/src/convert.cpp index 39b537eefb..aeb92706ae 100644 --- a/src/convert.cpp +++ b/src/convert.cpp @@ -526,7 +526,7 @@ namespace Exiv2 { auto pos = exifData_->findKey(ExifKey(from)); if (pos == exifData_->end()) return; if (!prepareXmpTarget(to)) return; - const CommentValue* cv = dynamic_cast(&pos->value()); + const auto cv = dynamic_cast(&pos->value()); if (cv == 0) { #ifndef SUPPRESS_WARNINGS EXV_WARNING << "Failed to convert " << from << " to " << to << "\n"; @@ -1530,7 +1530,7 @@ namespace { return false; } std::string outstr; - EXV_ICONV_CONST char* inptr = const_cast(str.c_str()); + auto inptr = const_cast(str.c_str()); size_t inbytesleft = str.length(); while (inbytesleft) { char outbuf[256]; diff --git a/src/crwimage_int.cpp b/src/crwimage_int.cpp index 3326be7299..5c15530553 100644 --- a/src/crwimage_int.cpp +++ b/src/crwimage_int.cpp @@ -1041,7 +1041,7 @@ namespace Exiv2 { CiffComponent* cc = pHead->findComponent(pCrwMapping->crwTagId_, pCrwMapping->crwDir_); if (!comment.empty()) { - uint32_t size = static_cast(comment.size()); + auto size = static_cast(comment.size()); if (cc && cc->size() > size) size = cc->size(); DataBuf buf(size); std::memset(buf.pData_, 0x0, buf.size_); diff --git a/src/easyaccess.cpp b/src/easyaccess.cpp index 3b26130355..2b021920d2 100644 --- a/src/easyaccess.cpp +++ b/src/easyaccess.cpp @@ -43,7 +43,7 @@ namespace { int count) { for (int i = 0; i < count; ++i) { - ExifData::const_iterator pos = ed.findKey(ExifKey(keys[i])); + auto pos = ed.findKey(ExifKey(keys[i])); if (pos != ed.end()) return pos; } return ed.end(); @@ -127,7 +127,7 @@ namespace Exiv2 { // Find the first ISO value which is not "0" const int cnt = EXV_COUNTOF(keys); - ExifData::const_iterator md = ed.end(); + auto md = ed.end(); long iso_val = -1; for (int idx = 0; idx < cnt; ) { md = findMetadatum(ed, keys + idx, cnt - idx); @@ -146,7 +146,7 @@ namespace Exiv2 { // ISO value (see EXIF 2.3 Annex G) long iso_tmp_val = -1; while (iso_tmp_val == -1 && (iso_val == 65535 || md == ed.end())) { - ExifData::const_iterator md_st = findMetadatum(ed, sensitivityType, 1); + auto md_st = findMetadatum(ed, sensitivityType, 1); // no SensitivityType? exit with existing data if (md_st == ed.end()) break; diff --git a/src/exif.cpp b/src/exif.cpp index 75e76a6e75..77147e9c67 100644 --- a/src/exif.cpp +++ b/src/exif.cpp @@ -558,7 +558,7 @@ namespace Exiv2 { Exifdatum& ExifData::operator[](const std::string& key) { ExifKey exifKey(key); - iterator pos = findKey(exifKey); + auto pos = findKey(exifKey); if (pos == end()) { add(Exifdatum(exifKey)); pos = findKey(exifKey); diff --git a/src/exiv2.cpp b/src/exiv2.cpp index abf7fa0e0e..e68655851b 100644 --- a/src/exiv2.cpp +++ b/src/exiv2.cpp @@ -473,7 +473,7 @@ int Params::evalGrep( const std::string& optArg) // there was an error compiling the regexp if( errcode ) { size_t length = regerror (errcode, pRegex, NULL, 0); - char *buffer = new char[ length]; + auto buffer = new char[length]; regerror (errcode, pRegex, buffer, length); std::cerr << progname() << ": " << _("Option") << " -g: " @@ -958,7 +958,7 @@ int Params::nonoption(const std::string& argv) static int readFileToBuf(FILE* f,Exiv2::DataBuf& buf) { const int buff_size = 4*1028; - Exiv2::byte* bytes = (Exiv2::byte*)::malloc(buff_size); + auto bytes = (Exiv2::byte*)::malloc(buff_size); int nBytes = 0 ; bool more = bytes != NULL; while ( more ) { @@ -1039,7 +1039,7 @@ using long_t = std::map; int Params::getopt(int argc, char* const Argv[]) { - char** argv = new char* [argc+1]; + auto argv = new char*[argc + 1]; argv[argc] = NULL; long_t longs; @@ -1167,7 +1167,7 @@ namespace { bool parseTime(const std::string& ts, long& time) { std::string hstr, mstr, sstr; - char *cts = new char[ts.length() + 1]; + auto cts = new char[ts.length() + 1]; strcpy(cts, ts.c_str()); char *tmp = ::strtok(cts, ":"); if (tmp) hstr = tmp; diff --git a/src/futils.cpp b/src/futils.cpp index d17509b8ec..5c97751c78 100644 --- a/src/futils.cpp +++ b/src/futils.cpp @@ -95,7 +95,7 @@ namespace Exiv2 { const char* pstr = str; // \todo try to use std::string for buf and avoid the creation of another string for just // returning the final value - char* buf = new char[strlen(str) * 3 + 1]; + auto buf = new char[strlen(str) * 3 + 1]; char* pbuf = buf; while (*pstr) { if (isalnum(*pstr) || *pstr == '-' || *pstr == '_' || *pstr == '.' || *pstr == '~') @@ -114,7 +114,7 @@ namespace Exiv2 { char* urldecode(const char* str) { const char* pstr = str; - char* buf = new char [(strlen(str) + 1)]; + auto buf = new char[(strlen(str) + 1)]; char* pbuf = buf; while (*pstr) { if (*pstr == '%') { @@ -150,13 +150,13 @@ namespace Exiv2 { '4', '5', '6', '7', '8', '9', '+', '/'}; int base64encode(const void* data_buf, size_t dataLength, char* result, size_t resultSize) { - char* encoding_table = (char*)base64_encode; + auto encoding_table = (char*)base64_encode; size_t mod_table[] = {0, 2, 1}; size_t output_length = 4 * ((dataLength + 2) / 3); int rc = result && data_buf && output_length < resultSize ? 1 : 0; if ( rc ) { - const unsigned char* data = (const unsigned char*) data_buf ; + const auto data = (const unsigned char*)data_buf; for (size_t i = 0, j = 0 ; i < dataLength;) { uint32_t octet_a = i < dataLength ? data[i++] : 0 ; @@ -183,13 +183,13 @@ namespace Exiv2 { size_t input_length = in ? ::strlen(in) : 0; if (!in || input_length % 4 != 0) return result; - unsigned char* encoding_table = (unsigned char*)base64_encode; + auto encoding_table = (unsigned char*)base64_encode; unsigned char decoding_table[256]; for (unsigned char i = 0; i < 64; i++) decoding_table[encoding_table[i]] = i; size_t output_length = input_length / 4 * 3; - const unsigned char* buff = (const unsigned char*) in; + const auto buff = (const unsigned char*)in; if (buff[input_length - 1] == '=') (output_length)--; if (buff[input_length - 2] == '=') (output_length)--; diff --git a/src/image.cpp b/src/image.cpp index 512a1a14fc..bee555f4a0 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -228,8 +228,8 @@ namespace Exiv2 { uint64_t Image::byteSwap(uint64_t value,bool bSwap) const { uint64_t result = 0; - byte* source_value = reinterpret_cast(&value); - byte* destination_value = reinterpret_cast(&result); + auto source_value = reinterpret_cast(&value); + auto destination_value = reinterpret_cast(&result); for (int i = 0; i < 8; i++) destination_value[i] = source_value[8 - i - 1]; @@ -258,7 +258,7 @@ namespace Exiv2 { uint16_t Image::byteSwap2(const DataBuf& buf,size_t offset,bool bSwap) const { uint16_t v; - char* p = (char*) &v; + auto p = (char*)&v; p[0] = buf.pData_[offset]; p[1] = buf.pData_[offset+1]; return Image::byteSwap(v,bSwap); @@ -267,7 +267,7 @@ namespace Exiv2 { uint32_t Image::byteSwap4(const DataBuf& buf,size_t offset,bool bSwap) const { uint32_t v; - char* p = (char*) &v; + auto p = (char*)&v; p[0] = buf.pData_[offset]; p[1] = buf.pData_[offset+1]; p[2] = buf.pData_[offset+2]; @@ -278,7 +278,7 @@ namespace Exiv2 { uint64_t Image::byteSwap8(const DataBuf& buf,size_t offset,bool bSwap) const { uint64_t v; - byte* p = reinterpret_cast(&v); + auto p = reinterpret_cast(&v); for(int i = 0; i < 8; i++) p[i] = buf.pData_[offset + i]; @@ -467,13 +467,13 @@ namespace Exiv2 { uint32_t jump= 10 ; byte bytes[20] ; - const char* chars = (const char*) &bytes[0] ; + const auto chars = (const char*)&bytes[0]; io.seek(offset,BasicIo::beg); // position io.read(bytes,jump ) ; // read bytes[jump]=0 ; if ( ::strcmp("Nikon",chars) == 0 ) { // tag is an embedded tiff - byte* bytes2=new byte[count-jump] ; // allocate memory + auto bytes2 = new byte[count - jump]; // allocate memory io.read(bytes2,count-jump) ; // read MemIo memIo(bytes2,count-jump) ; // create a file printTiffStructure(memIo,out,option,depth); diff --git a/src/image_int.cpp b/src/image_int.cpp index c7c4802a10..428d53bc89 100644 --- a/src/image_int.cpp +++ b/src/image_int.cpp @@ -61,8 +61,8 @@ namespace Exiv2 { std::stringstream hexOutput; - unsigned long tl = (unsigned long)((size / 16) * 16); - unsigned long tl_offset = (unsigned long)(size - tl); + auto tl = (unsigned long)((size / 16) * 16); + auto tl_offset = (unsigned long)(size - tl); for (unsigned long loop = 0; loop < (unsigned long)size; loop++) { if (data[loop] < 16) { diff --git a/src/ini.cpp b/src/ini.cpp index 1ec8ea2a28..bea9e08038 100755 --- a/src/ini.cpp +++ b/src/ini.cpp @@ -286,7 +286,7 @@ string INIReader::MakeKey(string section, string name) int INIReader::ValueHandler(void* user, const char* section, const char* name, const char* value) { - INIReader* reader = (INIReader*)user; + auto reader = (INIReader*)user; string key = MakeKey(section, name); if (!reader->_values[key].empty()) reader->_values[key] += "\n"; diff --git a/src/iptc.cpp b/src/iptc.cpp index 1aaf4ff646..18a14eba2b 100644 --- a/src/iptc.cpp +++ b/src/iptc.cpp @@ -257,7 +257,7 @@ namespace Exiv2 { Iptcdatum& IptcData::operator[](const std::string& key) { IptcKey iptcKey(key); - iterator pos = findKey(iptcKey); + auto pos = findKey(iptcKey); if (pos == end()) { add(Iptcdatum(iptcKey)); pos = findKey(iptcKey); @@ -268,12 +268,10 @@ namespace Exiv2 { long IptcData::size() const { long newSize = 0; - const_iterator iter = iptcMetadata_.begin(); - const_iterator end = iptcMetadata_.end(); - for ( ; iter != end; ++iter) { + for (auto&& iptc : iptcMetadata_) { // marker, record Id, dataset num, first 2 bytes of size newSize += 5; - long dataSize = iter->size(); + long dataSize = iptc.size(); newSize += dataSize; if (dataSize > 32767) { // extended dataset (we always use 4 bytes) @@ -367,7 +365,7 @@ namespace Exiv2 { const char *IptcData::detectCharset() const { - const_iterator pos = findKey(IptcKey("Iptc.Envelope.CharacterSet")); + auto pos = findKey(IptcKey("Iptc.Envelope.CharacterSet")); if (pos != end()) { const std::string value = pos->toString(); if (pos->value().ok()) { diff --git a/src/jp2image.cpp b/src/jp2image.cpp index 5e4e51fa93..93a25a992d 100644 --- a/src/jp2image.cpp +++ b/src/jp2image.cpp @@ -185,7 +185,7 @@ namespace Exiv2 static std::string toAscii(long n) { - const char* p = (const char*) &n; + const auto p = (const char*)&n; std::string result; bool bBigEndian = isBigEndian(); for ( int i = 0 ; i < 4 ; i++) { @@ -648,16 +648,16 @@ static void boxes_check(size_t b,size_t m) long outlen = sizeof(Jp2BoxHeader) ; // now many bytes have we written to output? long inlen = sizeof(Jp2BoxHeader) ; // how many bytes have we read from boxBuf? enforce(sizeof(Jp2BoxHeader) <= static_cast(output.size_), Exiv2::kerCorruptedMetadata); - Jp2BoxHeader* pBox = (Jp2BoxHeader*) boxBuf.pData_; + auto pBox = (Jp2BoxHeader*)boxBuf.pData_; uint32_t length = getLong((byte*)&pBox->length, bigEndian); enforce(length <= static_cast(output.size_), Exiv2::kerCorruptedMetadata); uint32_t count = sizeof (Jp2BoxHeader); - char* p = (char*) boxBuf.pData_; + auto p = (char*)boxBuf.pData_; bool bWroteColor = false ; while ( count < length || !bWroteColor ) { enforce(sizeof(Jp2BoxHeader) <= length - count, Exiv2::kerCorruptedMetadata); - Jp2BoxHeader* pSubBox = (Jp2BoxHeader*) (p+count) ; + auto pSubBox = (Jp2BoxHeader*)(p + count); // copy data. pointer could be into a memory mapped file which we will decode! Jp2BoxHeader subBox ; memcpy(&subBox,pSubBox,sizeof(subBox)); diff --git a/src/jpgimage.cpp b/src/jpgimage.cpp index a027180e64..df43d94726 100644 --- a/src/jpgimage.cpp +++ b/src/jpgimage.cpp @@ -254,7 +254,7 @@ namespace Exiv2 { return rc; } Blob psBlob; - const uint32_t sizeFront = static_cast(record - pPsData); + const auto sizeFront = static_cast(record - pPsData); // Write data before old record. if (sizePsData > 0 && sizeFront > 0) { append(psBlob, pPsData, sizeFront); @@ -749,7 +749,7 @@ namespace Exiv2 { out << std::endl; // allocate storage and current file position - byte* exif = new byte[size]; + auto exif = new byte[size]; uint32_t restore = io_->tell(); // copy the data to memory @@ -844,10 +844,10 @@ namespace Exiv2 { std::cout << ' '; } #endif - uint32_t count = (uint32_t)iptcDataSegs.size(); + auto count = (uint32_t)iptcDataSegs.size(); // figure out which blocks to copy - uint64_t* pos = new uint64_t[count + 2]; + auto pos = new uint64_t[count + 2]; pos[0] = 0; // copy the data that is not iptc auto it = iptcDataSegs.begin(); diff --git a/src/makernote_int.cpp b/src/makernote_int.cpp index 8f013f3c6c..faff7cac0e 100644 --- a/src/makernote_int.cpp +++ b/src/makernote_int.cpp @@ -1145,9 +1145,9 @@ namespace Exiv2 { // Find Exif.Nikon3.ShutterCount TiffFinder finder(0x00a7, nikon3Id); pRoot->accept(finder); - TiffEntryBase* te = dynamic_cast(finder.result()); + auto te = dynamic_cast(finder.result()); if (!te || !te->pValue() || te->pValue()->count() == 0) return buf; - uint32_t count = static_cast(te->pValue()->toLong()); + auto count = static_cast(te->pValue()->toLong()); // Find Exif.Nikon3.SerialNumber finder.init(0x001d, nikon3Id); @@ -1155,7 +1155,7 @@ namespace Exiv2 { te = dynamic_cast(finder.result()); if (!te || !te->pValue() || te->pValue()->count() == 0) return buf; bool ok(false); - uint32_t serial = stringTo(te->pValue()->toString(), ok); + auto serial = stringTo(te->pValue()->toString(), ok); if (!ok) { std::string model = getExifModel(pRoot); if (model.empty()) return buf; @@ -1208,7 +1208,7 @@ namespace { { Exiv2::Internal::TiffFinder finder(0x0110, Exiv2::Internal::ifd0Id); // Exif.Image.Model pRoot->accept(finder); - Exiv2::Internal::TiffEntryBase* te = dynamic_cast(finder.result()); + auto te = dynamic_cast(finder.result()); if (!te || !te->pValue() || te->pValue()->count() == 0) return std::string(); return te->pValue()->toString(); } diff --git a/src/nikonmn_int.cpp b/src/nikonmn_int.cpp index dca9df30df..75b7726797 100644 --- a/src/nikonmn_int.cpp +++ b/src/nikonmn_int.cpp @@ -1735,7 +1735,7 @@ namespace Exiv2 { } } - uint16_t val = static_cast(value.toLong()); + auto val = static_cast(value.toLong()); if (dModel) val = (val >> 8) | ((val & 0x00ff) << 8); if (val == 0x07ff) return os << _("All 11 Points"); @@ -2924,32 +2924,35 @@ fmountlens[] = { return os << "(" << value << ")"; } -// from https://github.com/exiftool/exiftool/blob/12.12/lib/Image/ExifTool/Nikon.pm#L4646 -static const struct ZMntLens {uint16_t lid; const char *manuf, *lensname;} -zmountlens[] = { - {1 , "Nikon", "Nikkor Z 24-70mm f/4 S"}, - {2 , "Nikon", "Nikkor Z 14-30mm f/4 S"}, - {4 , "Nikon", "Nikkor Z 35mm f/1.8 S"}, - {8 , "Nikon", "Nikkor Z 58mm f/0.95 S Noct"}, //IB - {9 , "Nikon", "Nikkor Z 50mm f/1.8 S"}, - {11 , "Nikon", "Nikkor Z DX 16-50mm f/3.5-6.3 VR"}, - {12 , "Nikon", "Nikkor Z DX 50-250mm f/4.5-6.3 VR"}, - {13 , "Nikon", "Nikkor Z 24-70mm f/2.8 S"}, - {14 , "Nikon", "Nikkor Z 85mm f/1.8 S"}, - {15 , "Nikon", "Nikkor Z 24mm f/1.8 S"}, //IB - {16 , "Nikon", "Nikkor Z 70-200mm f/2.8 VR S"}, //IB - {17 , "Nikon", "Nikkor Z 20mm f/1.8 S"}, //IB - {18 , "Nikon", "Nikkor Z 24-200mm f/4-6.3 VR"}, //IB - {21 , "Nikon", "Nikkor Z 50mm f/1.2 S"}, //IB - {22 , "Nikon", "Nikkor Z 24-50mm f/4-6.3"}, //IB - {23 , "Nikon", "Nikkor Z 14-24mm f/2.8 S"}, //IB - {0 , "", ""} //end of array -}; + // from https://github.com/exiftool/exiftool/blob/12.12/lib/Image/ExifTool/Nikon.pm#L4646 + static const struct ZMntLens + { + uint16_t lid; + const char *manuf, *lensname; + } zmountlens[] = { + {1, "Nikon", "Nikkor Z 24-70mm f/4 S"}, + {2, "Nikon", "Nikkor Z 14-30mm f/4 S"}, + {4, "Nikon", "Nikkor Z 35mm f/1.8 S"}, + {8, "Nikon", "Nikkor Z 58mm f/0.95 S Noct"}, // IB + {9, "Nikon", "Nikkor Z 50mm f/1.8 S"}, + {11, "Nikon", "Nikkor Z DX 16-50mm f/3.5-6.3 VR"}, + {12, "Nikon", "Nikkor Z DX 50-250mm f/4.5-6.3 VR"}, + {13, "Nikon", "Nikkor Z 24-70mm f/2.8 S"}, + {14, "Nikon", "Nikkor Z 85mm f/1.8 S"}, + {15, "Nikon", "Nikkor Z 24mm f/1.8 S"}, // IB + {16, "Nikon", "Nikkor Z 70-200mm f/2.8 VR S"}, // IB + {17, "Nikon", "Nikkor Z 20mm f/1.8 S"}, // IB + {18, "Nikon", "Nikkor Z 24-200mm f/4-6.3 VR"}, // IB + {21, "Nikon", "Nikkor Z 50mm f/1.2 S"}, // IB + {22, "Nikon", "Nikkor Z 24-50mm f/4-6.3"}, // IB + {23, "Nikon", "Nikkor Z 14-24mm f/2.8 S"}, // IB + }; - uint16_t lid = static_cast(value.toLong()); - for(int i = 0; zmountlens[i].lid != 0; ++i){ - if ( zmountlens[i].lid == lid ) return os << zmountlens[i].manuf << " " << zmountlens[i].lensname; - } + auto lid = static_cast(value.toLong()); + auto it = + std::find_if(std::begin(zmountlens), std::end(zmountlens), [=](const ZMntLens& z) { return z.lid == lid; }); + if (it != std::end(zmountlens)) + return os << it->manuf << " " << it->lensname; return os << lid; } diff --git a/src/olympusmn_int.cpp b/src/olympusmn_int.cpp index 437a523a3f..662a2bb304 100644 --- a/src/olympusmn_int.cpp +++ b/src/olympusmn_int.cpp @@ -1199,7 +1199,7 @@ namespace Exiv2 { return os << value; } if (value.count() == 1) { - short l0 = (short)value.toLong(0); + auto l0 = (short)value.toLong(0); if (l0 == 1) { os << _("Auto"); } @@ -1208,8 +1208,8 @@ namespace Exiv2 { } } else if (value.count() == 2) { - short l0 = (short)value.toLong(0); - short l1 = (short)value.toLong(1); + auto l0 = (short)value.toLong(0); + auto l1 = (short)value.toLong(1); if (l0 == 1) { switch (l1) { case 0: os << _("Auto"); break; @@ -1546,8 +1546,8 @@ namespace Exiv2 { return os << value; } - uint16_t v0 = (uint16_t)value.toLong(0); - uint16_t v1 = (uint16_t)value.toLong(1); + auto v0 = (uint16_t)value.toLong(0); + auto v1 = (uint16_t)value.toLong(1); for (auto&& filter : artFilters) { if (filter.val[0] == v0 && filter.val[1] == v1) { @@ -1659,7 +1659,7 @@ value, const ExifData* metadata) } } - uint16_t v = (uint16_t) value.toLong(0); + auto v = (uint16_t)value.toLong(0); if (!E3_E30model) { for (auto&& point : afPoints) { diff --git a/src/pgfimage.cpp b/src/pgfimage.cpp index df99c4f2e3..c853d596ca 100644 --- a/src/pgfimage.cpp +++ b/src/pgfimage.cpp @@ -67,7 +67,7 @@ namespace Exiv2 { static uint32_t byteSwap_(Exiv2::DataBuf& buf,size_t offset,bool bSwap) { uint32_t v; - char* p = (char*) &v; + auto p = (char*)&v; int i; for ( i = 0 ; i < 4 ; i++ ) p[i] = buf.pData_[offset+i]; uint32_t result = byteSwap_(v,bSwap); diff --git a/src/pngchunk_int.cpp b/src/pngchunk_int.cpp index e40c7a34c8..81c70886a0 100644 --- a/src/pngchunk_int.cpp +++ b/src/pngchunk_int.cpp @@ -193,7 +193,7 @@ namespace Exiv2 { std::string translatedKeyText = string_from_unterminated((const char*)(data.pData_ + keysize + 3 + languageTextSize + 1), data.size_ - (keysize + 3 + languageTextSize + 1)); - const unsigned int translatedKeyTextSize = static_cast(translatedKeyText.size()); + const auto translatedKeyTextSize = static_cast(translatedKeyText.size()); if ((compressionFlag == 0x00) || (compressionFlag == 0x01 && compressionMethod == 0x00)) { enforce(Safe::add(static_cast(keysize + 3 + languageTextSize + 1), @@ -488,7 +488,7 @@ namespace Exiv2 { std::string PngChunk::zlibCompress(const std::string& text) { - uLongf compressedLen = static_cast(text.size() * 2); // just a starting point + auto compressedLen = static_cast(text.size() * 2); // just a starting point int zlibResult; DataBuf arr; diff --git a/src/pngimage.cpp b/src/pngimage.cpp index c755cd6ce9..a89fdd74bb 100644 --- a/src/pngimage.cpp +++ b/src/pngimage.cpp @@ -315,7 +315,7 @@ namespace Exiv2 { if( bDump ) { DataBuf dataBuf; - byte* data = new byte[dataOffset+1]; + auto data = new byte[dataOffset + 1]; data[dataOffset] = 0; bufRead = io_->read(data,dataOffset); enforce(bufRead == static_cast(dataOffset), kerFailedToReadImageData); @@ -369,7 +369,7 @@ namespace Exiv2 { DataBuf s(dataBuf.size_+1); // allocate buffer with an extra byte memcpy(s.pData_,dataBuf.pData_,dataBuf.size_);// copy in the dataBuf s.pData_[dataBuf.size_] = 0 ; // nul terminate it - const char* str = (const char*) s.pData_; // give it name + const auto str = (const char*)s.pData_; // give it name out << Internal::indent(depth) << (const char*) buff.pData_ << ": " << str ; bLF=true; } @@ -643,10 +643,9 @@ namespace Exiv2 { if ( iccProfileDefined() ) { DataBuf compressed; if ( zlibToCompressed(iccProfile_.pData_,iccProfile_.size_,compressed) ) { - - const byte* nullComp = (const byte*) "\0\0"; - const byte* type = (const byte*) "iCCP"; - const uint32_t nameLength = static_cast(profileName_.size()); + const auto nullComp = (const byte*)"\0\0"; + const auto type = (const byte*)"iCCP"; + const auto nameLength = static_cast(profileName_.size()); const uint32_t chunkLength = nameLength + 2 + compressed.size_ ; byte length[4]; ul2Data (length,chunkLength,bigEndian); diff --git a/src/preview.cpp b/src/preview.cpp index fe03662d34..d2e1766c65 100644 --- a/src/preview.cpp +++ b/src/preview.cpp @@ -844,13 +844,13 @@ namespace { prefix = "xapGImg"; } - XmpData::const_iterator imageDatum = xmpData.findKey(XmpKey("Xmp.xmp.Thumbnails[1]/" + prefix + ":image")); + auto imageDatum = xmpData.findKey(XmpKey("Xmp.xmp.Thumbnails[1]/" + prefix + ":image")); if (imageDatum == xmpData.end()) return; - XmpData::const_iterator formatDatum = xmpData.findKey(XmpKey("Xmp.xmp.Thumbnails[1]/" + prefix + ":format")); + auto formatDatum = xmpData.findKey(XmpKey("Xmp.xmp.Thumbnails[1]/" + prefix + ":format")); if (formatDatum == xmpData.end()) return; - XmpData::const_iterator widthDatum = xmpData.findKey(XmpKey("Xmp.xmp.Thumbnails[1]/" + prefix + ":width")); + auto widthDatum = xmpData.findKey(XmpKey("Xmp.xmp.Thumbnails[1]/" + prefix + ":width")); if (widthDatum == xmpData.end()) return; - XmpData::const_iterator heightDatum = xmpData.findKey(XmpKey("Xmp.xmp.Thumbnails[1]/" + prefix + ":height")); + auto heightDatum = xmpData.findKey(XmpKey("Xmp.xmp.Thumbnails[1]/" + prefix + ":height")); if (heightDatum == xmpData.end()) return; if (formatDatum->toString() != "JPEG") return; @@ -1018,7 +1018,7 @@ namespace { } const std::string header = "P6\n" + toString(width) + " " + toString(height) + "\n255\n"; - const byte *headerBytes = reinterpret_cast(header.data()); + const auto headerBytes = reinterpret_cast(header.data()); DataBuf dest(static_cast(header.size() + rgb.size_)); std::copy(headerBytes, headerBytes + header.size(), dest.pData_); diff --git a/src/properties.cpp b/src/properties.cpp index fd24c53008..7202d24dc1 100644 --- a/src/properties.cpp +++ b/src/properties.cpp @@ -2515,7 +2515,7 @@ namespace Exiv2 { // Using malloc/free for better system compatibility in case // users don't unregister their namespaces explicitly. XmpNsInfo xn; - char* c = static_cast(std::malloc(ns2.size() + 1)); + auto c = static_cast(std::malloc(ns2.size() + 1)); std::strcpy(c, ns2.c_str()); xn.ns_ = c; c = static_cast(std::malloc(prefix.size() + 1)); @@ -2534,7 +2534,7 @@ namespace Exiv2 { void XmpProperties::unregisterNsUnsafe(const std::string& ns) { - NsRegistry::iterator i = nsRegistry_.find(ns); + auto i = nsRegistry_.find(ns); if (i != nsRegistry_.end()) { std::free(const_cast(i->second.prefix_)); std::free(const_cast(i->second.ns_)); @@ -2545,9 +2545,9 @@ namespace Exiv2 { void XmpProperties::unregisterNs() { std::lock_guard scoped_write_lock(mutex_); - NsRegistry::iterator i = nsRegistry_.begin(); + auto i = nsRegistry_.begin(); while (i != nsRegistry_.end()) { - NsRegistry::iterator kill = i++; + auto kill = i++; unregisterNsUnsafe(kill->first); } } diff --git a/src/tags.cpp b/src/tags.cpp index 8d11d55c6b..1e063318cb 100644 --- a/src/tags.cpp +++ b/src/tags.cpp @@ -323,7 +323,7 @@ namespace Exiv2 { ExifKey::ExifKey(const TagInfo& ti) : p_(new Impl) { - IfdId ifdId = static_cast(ti.ifdId_); + auto ifdId = static_cast(ti.ifdId_); if (!Internal::isExifIfd(ifdId) && !Internal::isMakerIfd(ifdId)) { throw Error(kerInvalidIfdId, ifdId); } diff --git a/src/tags_int.cpp b/src/tags_int.cpp index 7cd25850a4..cac13f9416 100644 --- a/src/tags_int.cpp +++ b/src/tags_int.cpp @@ -2556,7 +2556,7 @@ namespace Exiv2 { uint16_t bit = 0; uint16_t comma = 0; for (uint16_t i = 0; i < value.count(); i++ ) { // for each element in value array - uint16_t bits = static_cast(value.toLong(i)); + auto bits = static_cast(value.toLong(i)); for (uint16_t b = 0; b < 16; ++b) { // for every bit if (bits & (1 << b)) { if ( comma++ ) { diff --git a/src/tiffcomposite_int.cpp b/src/tiffcomposite_int.cpp index 81c59fbe17..28aa35c873 100644 --- a/src/tiffcomposite_int.cpp +++ b/src/tiffcomposite_int.cpp @@ -402,7 +402,7 @@ namespace Exiv2 { for (int i = 0; i < pSize->count(); ++i) { size += static_cast(pSize->toLong(i)); } - uint32_t offset = static_cast(pValue()->toLong(0)); + auto offset = static_cast(pValue()->toLong(0)); // Todo: Remove limitation of JPEG writer: strips must be contiguous // Until then we check: last offset + last size - first offset == size? if ( static_cast(pValue()->toLong(pValue()->count()-1)) @@ -457,9 +457,9 @@ namespace Exiv2 { return; } for (int i = 0; i < pValue()->count(); ++i) { - const uint32_t offset = static_cast(pValue()->toLong(i)); + const auto offset = static_cast(pValue()->toLong(i)); const byte* pStrip = pData + baseOffset + offset; - const uint32_t size = static_cast(pSize->toLong(i)); + const auto size = static_cast(pSize->toLong(i)); if ( offset > sizeData || size > sizeData @@ -581,10 +581,10 @@ namespace Exiv2 { uint32_t TiffBinaryArray::addElement(uint32_t idx, const ArrayDef& def) { - uint16_t tag = static_cast(idx / cfg()->tagStep()); + auto tag = static_cast(idx / cfg()->tagStep()); int32_t sz = EXV_MIN(def.size(tag, cfg()->group_), TiffEntryBase::doSize() - idx); TiffComponent::UniquePtr tc = TiffCreator::create(tag, cfg()->group_); - TiffBinaryElement* tp = dynamic_cast(tc.get()); + auto tp = dynamic_cast(tc.get()); // The assertion typically fails if a component is not configured in // the TIFF structure table (TiffCreator::tiffTreeStruct_) assert(tp); @@ -790,7 +790,7 @@ namespace Exiv2 { TiffComponent* TiffSubIfd::doAddChild(TiffComponent::UniquePtr tiffComponent) { - TiffDirectory* d = dynamic_cast(tiffComponent.release()); + auto d = dynamic_cast(tiffComponent.release()); assert(d); ifds_.push_back(d); return d; @@ -1185,7 +1185,7 @@ namespace Exiv2 { uint32_t& imageIdx) const { assert(pTiffComponent); - TiffEntryBase* pDirEntry = dynamic_cast(pTiffComponent); + auto pDirEntry = dynamic_cast(pTiffComponent); assert(pDirEntry); byte buf[8]; us2Data(buf, pDirEntry->tag(), byteOrder); @@ -1402,7 +1402,7 @@ namespace Exiv2 { } if (cfg()->hasFillers_ && def()) { const ArrayDef* lastDef = def() + defSize() - 1; - uint16_t lastTag = static_cast(lastDef->idx_ / cfg()->tagStep()); + auto lastTag = static_cast(lastDef->idx_ / cfg()->tagStep()); idx += fillGap(mioWrapper, idx, lastDef->idx_ + lastDef->size(lastTag, cfg()->group_)); } @@ -1704,7 +1704,7 @@ namespace Exiv2 { if (cfg()->hasFillers_ && def()) { const ArrayDef* lastDef = def() + defSize() - 1; - uint16_t lastTag = static_cast(lastDef->idx_ / cfg()->tagStep()); + auto lastTag = static_cast(lastDef->idx_ / cfg()->tagStep()); idx = EXV_MAX(idx, lastDef->idx_ + lastDef->size(lastTag, cfg()->group_)); } return idx; @@ -1833,7 +1833,7 @@ namespace Exiv2 { // free functions TypeId toTypeId(TiffType tiffType, uint16_t tag, IfdId group) { - TypeId ti = TypeId(tiffType); + auto ti = TypeId(tiffType); // On the fly type conversion for Exif.Photo.UserComment, Exif.GPSProcessingMethod, GPSAreaInformation if ( const TagInfo* pTag = ti == undefined ? findTagInfo(tag,group) : NULL ) { if ( pTag->typeId_ == comment ) { diff --git a/src/tiffimage_int.cpp b/src/tiffimage_int.cpp index 5c0fb0ae96..50c5f2b8d2 100644 --- a/src/tiffimage_int.cpp +++ b/src/tiffimage_int.cpp @@ -1676,7 +1676,7 @@ namespace Exiv2 { IfdId group) { TiffComponent::UniquePtr tc; - uint16_t tag = static_cast(extendedTag & 0xffff); + auto tag = static_cast(extendedTag & 0xffff); const TiffGroupStruct* ts = find(tiffGroupStruct_, TiffGroupStruct::Key(extendedTag, group)); if (ts && ts->newTiffCompFct_) { @@ -1805,7 +1805,7 @@ namespace Exiv2 { BasicIo::UniquePtr tempIo(new MemIo); assert(tempIo.get() != 0); IoWrapper ioWrapper(*tempIo, header.pData_, header.size_, pOffsetWriter); - uint32_t imageIdx(uint32_t(-1)); + auto imageIdx(uint32_t(-1)); createdTree->write(ioWrapper, pHeader->byteOrder(), header.size_, @@ -1873,7 +1873,7 @@ namespace Exiv2 { for (auto&& imageGroup : imageGroups) { TiffFinder finder(0x00fe, imageGroup); pSourceDir->accept(finder); - TiffEntryBase* te = dynamic_cast(finder.result()); + auto te = dynamic_cast(finder.result()); const Value* pV = te != NULL ? te->pValue() : NULL; if (pV && pV->typeId() == unsignedLong && pV->count() == 1 && (pV->toLong() & 1) == 0) { primaryGroups.push_back(te->group()); @@ -2122,7 +2122,7 @@ namespace Exiv2 { void OffsetWriter::setTarget(OffsetId id, uint32_t target) { - OffsetList::iterator it = offsetList_.find(id); + auto it = offsetList_.find(id); if (it != offsetList_.end()) it->second.target_ = target; } diff --git a/src/tiffvisitor_int.cpp b/src/tiffvisitor_int.cpp index bdb140691b..0bddc1e4ea 100644 --- a/src/tiffvisitor_int.cpp +++ b/src/tiffvisitor_int.cpp @@ -283,7 +283,7 @@ namespace Exiv2 { // Find camera make by looking for tag 0x010f in IFD0 TiffFinder finder(0x010f, ifd0Id); pRoot_->accept(finder); - TiffEntryBase* te = dynamic_cast(finder.result()); + auto te = dynamic_cast(finder.result()); if (te && te->pValue()) { make_ = te->pValue()->toString(); } @@ -597,7 +597,7 @@ namespace Exiv2 { if (make_.empty() && pRoot_) { TiffFinder finder(0x010f, ifd0Id); pRoot_->accept(finder); - TiffEntryBase* te = dynamic_cast(finder.result()); + auto te = dynamic_cast(finder.result()); if (te && te->pValue()) { make_ = te->pValue()->toString(); } @@ -742,7 +742,7 @@ namespace Exiv2 { { assert(buf); assert(pTiffComponent); - TiffEntryBase* pTiffEntry = dynamic_cast(pTiffComponent); + auto pTiffEntry = dynamic_cast(pTiffComponent); assert(pTiffEntry); us2Data(buf + 2, pTiffEntry->tiffType(), byteOrder); ul2Data(buf + 4, pTiffEntry->count(), byteOrder); @@ -1028,7 +1028,7 @@ namespace Exiv2 { if (pSourceTree_) { TiffFinder finder(object->tag(), object->group()); pSourceTree_->accept(finder); - TiffImageEntry* ti = dynamic_cast(finder.result()); + auto ti = dynamic_cast(finder.result()); if (ti) { object->strips_ = ti->strips_; } @@ -1146,7 +1146,7 @@ namespace Exiv2 { TiffPath tiffPath; TiffCreator::getPath(tiffPath, i->tag(), group, root); TiffComponent* tc = pRootDir->addPath(i->tag(), tiffPath, pRootDir); - TiffEntryBase* object = dynamic_cast(tc); + auto object = dynamic_cast(tc); #ifdef EXIV2_DEBUG_MESSAGES if (object == 0) { std::cerr << "Warning: addPath() didn't add an entry for " @@ -1171,9 +1171,9 @@ namespace Exiv2 { TiffFinder finder(0x927c, exifId); pRootDir->accept(finder); - TiffMnEntry* te = dynamic_cast(finder.result()); + auto te = dynamic_cast(finder.result()); if (te) { - TiffIfdMakernote* tim = dynamic_cast(te->mn_); + auto tim = dynamic_cast(te->mn_); if (tim) { // Set Makernote byte order ByteOrder bo = stringToByteOrder(posBo->toString()); @@ -1239,7 +1239,7 @@ namespace Exiv2 { readTiffEntry(object); TiffFinder finder(object->szTag(), object->szGroup()); pRoot_->accept(finder); - TiffEntryBase* te = dynamic_cast(finder.result()); + auto te = dynamic_cast(finder.result()); if (te && te->pValue()) { object->setStrips(te->pValue(), pData_, size_, baseOffset()); } @@ -1267,7 +1267,7 @@ namespace Exiv2 { readTiffEntry(object); TiffFinder finder(object->dtTag(), object->dtGroup()); pRoot_->accept(finder); - TiffDataEntryBase* te = dynamic_cast(finder.result()); + auto te = dynamic_cast(finder.result()); if (te && te->pValue()) { te->setStrips(object->pValue(), pData_, size_, baseOffset()); } @@ -1441,7 +1441,7 @@ namespace Exiv2 { // Find camera make TiffFinder finder(0x010f, ifd0Id); pRoot_->accept(finder); - TiffEntryBase* te = dynamic_cast(finder.result()); + auto te = dynamic_cast(finder.result()); std::string make; if (te && te->pValue()) { make = te->pValue()->toString(); @@ -1606,7 +1606,7 @@ namespace Exiv2 { // #1143 Write a "hollow" buffer for the preview image // Sadly: we don't know the exact location of the image in the source (it's near offset) // And neither TiffReader nor TiffEntryBase have access to the BasicIo object being processed - byte* buffer = (byte*) ::malloc(isize); + auto buffer = (byte*)::malloc(isize); ::memset(buffer,0,isize); v->read(buffer,isize, byteOrder()); ::free(buffer); @@ -1634,7 +1634,7 @@ namespace Exiv2 { // Check duplicates TiffFinder finder(object->tag(), object->group()); pRoot_->accept(finder); - TiffEntryBase* te = dynamic_cast(finder.result()); + auto te = dynamic_cast(finder.result()); if (te && te->idx() != object->idx()) { #ifndef SUPPRESS_WARNINGS EXV_WARNING << "Not decoding duplicate binary array tag 0x" diff --git a/src/types.cpp b/src/types.cpp index 4c5ab56c23..addf8274ec 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -615,7 +615,7 @@ namespace Exiv2 { long ret = stringTo(s, ok); if (ok) return ret; - float f = stringTo(s, ok); + auto f = stringTo(s, ok); if (ok) return static_cast(f); Rational r = stringTo(s, ok); @@ -636,7 +636,7 @@ namespace Exiv2 { float parseFloat(const std::string& s, bool& ok) { - float ret = stringTo(s, ok); + auto ret = stringTo(s, ok); if (ok) return ret; Rational r = stringTo(s, ok); @@ -665,7 +665,7 @@ namespace Exiv2 { if (ok) return {l, 1}; - float f = stringTo(s, ok); + auto f = stringTo(s, ok); if (ok) return floatToRationalCast(f); bool b = stringTo(s, ok); @@ -698,7 +698,7 @@ namespace Exiv2 { den = 1; } const float rnd = f >= 0 ? 0.5F : -0.5F; - const int32_t nom = static_cast(f * den + rnd); + const auto nom = static_cast(f * den + rnd); const int32_t g = gcd(nom, den); return {nom / g, den / g}; diff --git a/src/value.cpp b/src/value.cpp index 633879d464..a0b91ddd72 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -761,8 +761,7 @@ namespace Exiv2 { std::ostream& XmpArrayValue::write(std::ostream& os) const { - for (std::vector::const_iterator i = value_.begin(); - i != value_.end(); ++i) { + for (auto i = value_.begin(); i != value_.end(); ++i) { if (i != value_.begin()) os << ", "; os << *i; } @@ -861,7 +860,7 @@ namespace Exiv2 { bool first = true; // Write the default entry first - ValueType::const_iterator i = value_.find(x_default); + auto i = value_.find(x_default); if (i != value_.end()) { os << "lang=\"" << i->first << "\" " << i->second; first = false; @@ -885,7 +884,7 @@ namespace Exiv2 { std::string LangAltValue::toString(const std::string& qualifier) const { - ValueType::const_iterator i = value_.find(qualifier); + auto i = value_.find(qualifier); if (i != value_.end()) { ok_ = true; return i->second; diff --git a/src/version.cpp b/src/version.cpp index f44a3d4f4f..b50b8de493 100644 --- a/src/version.cpp +++ b/src/version.cpp @@ -115,9 +115,7 @@ namespace Exiv2 { static bool shouldOutput(const exv_grep_keys_t& greps,const char* key,const std::string& value) { bool bPrint = greps.empty(); - for( exv_grep_keys_t::const_iterator g = greps.begin(); - !bPrint && g != greps.end() ; ++g - ) { + for (auto g = greps.begin(); !bPrint && g != greps.end(); ++g) { std::string Key(key); #if defined(EXV_HAVE_REGEX_H) bPrint = ( 0 == regexec( &(*g), key , 0, NULL, 0) diff --git a/src/webpimage.cpp b/src/webpimage.cpp index 1de6021828..0fadc1e262 100644 --- a/src/webpimage.cpp +++ b/src/webpimage.cpp @@ -464,7 +464,7 @@ namespace Exiv2 { io_->seek(0,BasicIo::beg); // rewind while ( !io_->eof() && (uint64_t) io_->tell() < filesize) { - uint64_t offset = (uint64_t) io_->tell(); + auto offset = (uint64_t)io_->tell(); byte size_buff[WEBP_TAG_SIZE]; io_->read(chunkId.pData_, WEBP_TAG_SIZE); io_->read(size_buff, WEBP_TAG_SIZE); diff --git a/src/xmp.cpp b/src/xmp.cpp index 3fe5501a60..ef18cd9198 100644 --- a/src/xmp.cpp +++ b/src/xmp.cpp @@ -304,7 +304,7 @@ namespace Exiv2 { Xmpdatum& XmpData::operator[](const std::string& key) { XmpKey xmpKey(key); - iterator pos = findKey(xmpKey); + auto pos = findKey(xmpKey); if (pos == end()) { add(Xmpdatum(xmpKey)); pos = findKey(xmpKey); @@ -499,7 +499,7 @@ namespace Exiv2 { } if ( bURI || bNS ) { - std::map* p = (std::map*) refCon; + auto p = (std::map*)refCon; std::map& m = *p; std::string b; @@ -757,7 +757,7 @@ namespace Exiv2 { if (i.typeId() == langAlt) { // Encode Lang Alt property - const LangAltValue* la = dynamic_cast(&i.value()); + const auto la = dynamic_cast(&i.value()); if (la == 0) throw Error(kerEncodeLangAltPropertyFailed, i.key()); @@ -775,7 +775,7 @@ namespace Exiv2 { } // Todo: Xmpdatum should have an XmpValue, not a Value - const XmpValue* val = dynamic_cast(&i.value()); + const auto val = dynamic_cast(&i.value()); if (val == 0) throw Error(kerInvalidKeyXmpValue, i.key(), i.typeName()); options = xmpArrayOptionBits(val->xmpArrayType()) diff --git a/unitTests/test_futils.cpp b/unitTests/test_futils.cpp index 0d4690cbcb..723ed7121c 100644 --- a/unitTests/test_futils.cpp +++ b/unitTests/test_futils.cpp @@ -161,7 +161,7 @@ TEST(base64encode, encodesValidString) const std::string original ("This is a unit test"); const std::string expected ("VGhpcyBpcyBhIHVuaXQgdGVzdA=="); size_t encodeLength = ((original.size() + 2) / 3) * 4 + 1; - char * result = new char [encodeLength]; + auto result = new char[encodeLength]; ASSERT_EQ(1, base64encode(original.c_str(), original.size(), result, encodeLength)); ASSERT_STREQ(expected.c_str(), result); delete [] result; @@ -171,7 +171,7 @@ TEST(base64encode, doesNotEncodeWithNotBigEnoughResultSize) { const std::string original ("This is a unit test"); size_t encodeLength = (original.size()); - char * result = new char [encodeLength]; + auto result = new char[encodeLength]; ASSERT_EQ(0, base64encode(original.c_str(), original.size(), result, encodeLength)); delete [] result; } @@ -180,7 +180,7 @@ TEST(base64decode, decodesValidString) { const std::string original ("VGhpcyBpcyBhIHVuaXQgdGVzdA=="); const std::string expected ("This is a unit test"); - char * result = new char [original.size()]; + auto result = new char[original.size()]; ASSERT_EQ(static_cast(expected.size()), base64decode(original.c_str(), result, original.size())); ASSERT_STREQ(expected.c_str(), result); diff --git a/unitTests/test_slice.cpp b/unitTests/test_slice.cpp index e324762d76..427f19e18a 100644 --- a/unitTests/test_slice.cpp +++ b/unitTests/test_slice.cpp @@ -165,8 +165,8 @@ TYPED_TEST_P(slice, iteratorAccess) { Slice sl = this->getTestSlice(); - std::vector::const_iterator vec_it = this->vec_.begin() + 1; - for (typename Slice::const_iterator it = sl.cbegin(); it < sl.cend(); ++it, ++vec_it) { + auto vec_it = this->vec_.begin() + 1; + for (auto it = sl.cbegin(); it < sl.cend(); ++it, ++vec_it) { ASSERT_EQ(*it, *vec_it); } @@ -246,7 +246,7 @@ void checkConstSliceValueAt(const Slice& sl, typename Slice::value_type va template void checkConstSliceIterator(const Slice& sl, typename Slice::value_type first_value) { - for (typename Slice::const_iterator it = sl.cbegin(); it < sl.cend(); ++it) { + for (auto it = sl.cbegin(); it < sl.cend(); ++it) { ASSERT_EQ(*it, first_value++); } } @@ -287,7 +287,7 @@ TYPED_TEST_P(mutableSlice, iterators) ASSERT_EQ(*sl.begin(), static_cast(1)); ASSERT_EQ(*sl.end(), static_cast(this->vec_size - 1)); - for (typename slice_t::iterator it = sl.begin(); it < sl.end(); ++it) { + for (auto it = sl.begin(); it < sl.end(); ++it) { *it = 2 * (*it); }