diff --git a/include/exiv2/datasets.hpp b/include/exiv2/datasets.hpp index d2b509b1ca..e64efbf56a 100644 --- a/include/exiv2/datasets.hpp +++ b/include/exiv2/datasets.hpp @@ -248,7 +248,7 @@ namespace Exiv2 { static int dataSetIdx(uint16_t number, uint16_t recordId); static int dataSetIdx(const std::string& dataSetName, uint16_t recordId); - static const DataSet* records_[]; + static const DataSet* const records_[]; static const RecordInfo recordInfo_[]; }; // class IptcDataSets diff --git a/include/exiv2/jpgimage.hpp b/include/exiv2/jpgimage.hpp index 36c98549d8..7f1345630c 100644 --- a/include/exiv2/jpgimage.hpp +++ b/include/exiv2/jpgimage.hpp @@ -24,6 +24,8 @@ // ***************************************************************************** #include "exiv2lib_export.h" +#include + // included header files #include "image.hpp" @@ -46,9 +48,9 @@ namespace Exiv2 { */ struct EXIV2API Photoshop { // Todo: Public for now - static const char ps3Id_[]; //!< %Photoshop marker - static const char* irbId_[]; //!< %Photoshop IRB markers - static const char bimId_[]; //!< %Photoshop IRB marker (deprecated) + static const char* const ps3Id_; //!< %Photoshop marker + static const std::array irbId_; //!< %Photoshop IRB markers + static const char* const bimId_; //!< %Photoshop IRB marker (deprecated) static const uint16_t iptc_; //!< %Photoshop IPTC marker static const uint16_t preview_; //!< %Photoshop preview marker @@ -232,10 +234,10 @@ namespace Exiv2 { static const byte sof13_; //!< JPEG Start-Of-Frame marker static const byte sof14_; //!< JPEG Start-Of-Frame marker static const byte sof15_; //!< JPEG Start-Of-Frame marker - static const char exifId_[]; //!< Exif identifier - static const char jfifId_[]; //!< JFIF identifier - static const char xmpId_[]; //!< XMP packet identifier - static const char iccId_[]; //!< ICC profile identifier + static const char* const exifId_; //!< Exif identifier + static const char* const jfifId_; //!< JFIF identifier + static const char* const xmpId_; //!< XMP packet identifier + static const char* const iccId_; //!< ICC profile identifier private: //! @name NOT implemented diff --git a/include/exiv2/webpimage.hpp b/include/exiv2/webpimage.hpp index c24ff1d6f5..9ca53ef409 100644 --- a/include/exiv2/webpimage.hpp +++ b/include/exiv2/webpimage.hpp @@ -97,21 +97,20 @@ namespace Exiv2 { //@} private: - const static byte WEBP_PAD_ODD; - const static int WEBP_TAG_SIZE; - const static int WEBP_VP8X_ICC_BIT; - const static int WEBP_VP8X_ALPHA_BIT; - const static int WEBP_VP8X_EXIF_BIT; - const static int WEBP_VP8X_XMP_BIT; - const static char* WEBP_CHUNK_HEADER_VP8X; - const static char* WEBP_CHUNK_HEADER_VP8L; - const static char* WEBP_CHUNK_HEADER_VP8; - const static char* WEBP_CHUNK_HEADER_ANMF; - const static char* WEBP_CHUNK_HEADER_ANIM; - const static char* WEBP_CHUNK_HEADER_ICCP; - const static char* WEBP_CHUNK_HEADER_EXIF; - const static char* WEBP_CHUNK_HEADER_XMP; - + static const byte WEBP_PAD_ODD; + static const int WEBP_TAG_SIZE; + static const int WEBP_VP8X_ICC_BIT; + static const int WEBP_VP8X_ALPHA_BIT; + static const int WEBP_VP8X_EXIF_BIT; + static const int WEBP_VP8X_XMP_BIT; + static const char* const WEBP_CHUNK_HEADER_VP8X; + static const char* const WEBP_CHUNK_HEADER_VP8L; + static const char* const WEBP_CHUNK_HEADER_VP8; + static const char* const WEBP_CHUNK_HEADER_ANMF; + static const char* const WEBP_CHUNK_HEADER_ANIM; + static const char* const WEBP_CHUNK_HEADER_ICCP; + static const char* const WEBP_CHUNK_HEADER_EXIF; + static const char* const WEBP_CHUNK_HEADER_XMP; }; //Class WebPImage diff --git a/src/cr2header_int.cpp b/src/cr2header_int.cpp index b76fffc7ca..db57286888 100644 --- a/src/cr2header_int.cpp +++ b/src/cr2header_int.cpp @@ -2,9 +2,6 @@ namespace Exiv2 { namespace Internal { - - const char* Cr2Header::cr2sig_ = "CR\2\0"; - Cr2Header::Cr2Header(ByteOrder byteOrder) : TiffHeaderBase(42, 16, byteOrder, 0x00000010), offset2_(0x00000000) diff --git a/src/cr2header_int.hpp b/src/cr2header_int.hpp index 3b47c7c26d..fc2476e268 100644 --- a/src/cr2header_int.hpp +++ b/src/cr2header_int.hpp @@ -69,7 +69,7 @@ namespace Exiv2 { private: // DATA uint32_t offset2_; //!< Bytes 12-15 from the header - static const char* cr2sig_; //!< Signature for CR2 type TIFF + static constexpr auto cr2sig_ = "CR\2\0"; //!< Signature for CR2 type TIFF }; // class Cr2Header }} // namespace Internal, Exiv2 diff --git a/src/datasets.cpp b/src/datasets.cpp index 2a534bf22c..402292dd7a 100644 --- a/src/datasets.cpp +++ b/src/datasets.cpp @@ -45,7 +45,7 @@ namespace Exiv2 { {IptcDataSets::application2, "Application2", N_("IIM application record 2")}, }; - static const DataSet envelopeRecord[] = { + constexpr DataSet envelopeRecord[] = { {IptcDataSets::ModelVersion, "ModelVersion", N_("Model Version"), N_("A binary number identifying the version of the Information " "Interchange Model, Part I, utilised by the provider. Version " @@ -130,7 +130,7 @@ namespace Exiv2 { return envelopeRecord; } - static const DataSet application2Record[] = { + constexpr DataSet application2Record[] = { {IptcDataSets::RecordVersion, "RecordVersion", N_("Record Version"), N_("A binary number identifying the version of the Information " "Interchange Model, Part II, utilised by the provider. " @@ -407,18 +407,19 @@ namespace Exiv2 { return application2Record; } - static const DataSet unknownDataSet{0xffff, "Unknown dataset", N_("Unknown dataset"), + constexpr DataSet unknownDataSet{0xffff, "Unknown dataset", N_("Unknown dataset"), N_("Unknown dataset"), false, true, 0, 0xffffffff, Exiv2::string, IptcDataSets::invalidRecord, - N_("Unknown dataset")}; + N_("Unknown dataset"),}; // Dataset lookup lists.This is an array with pointers to one list per IIM4 Record. // The record id is used as the index into the array. - const DataSet* IptcDataSets::records_[] = { + constexpr const DataSet* IptcDataSets::records_[] = { + 0, + envelopeRecord, + application2Record, 0, - envelopeRecord, application2Record, - 0 }; int IptcDataSets::dataSetIdx(uint16_t number, uint16_t recordId) diff --git a/src/futils.cpp b/src/futils.cpp index 5c97751c78..d2951c690d 100644 --- a/src/futils.cpp +++ b/src/futils.cpp @@ -29,6 +29,7 @@ // + standard includes #include #include +#include #include #include #include @@ -67,10 +68,17 @@ #endif namespace Exiv2 { - const char* ENVARDEF[] = {"/exiv2.php", "40"}; //!< @brief default URL for http exiv2 handler and time-out - const char* ENVARKEY[] = {"EXIV2_HTTP_POST", "EXIV2_TIMEOUT"}; //!< @brief request keys for http exiv2 handler and time-out -// ***************************************************************************** -// free functions + constexpr std::array ENVARDEF{ + "/exiv2.php", + "40", + }; //!< @brief default URL for http exiv2 handler and time-out + constexpr std::array ENVARKEY{ + "EXIV2_HTTP_POST", + "EXIV2_TIMEOUT", + }; //!< @brief request keys for http exiv2 handler and time-out + + // ***************************************************************************** + // free functions std::string getEnv(int env_var) { // this check is relying on undefined behavior and might not be effective @@ -140,14 +148,10 @@ namespace Exiv2 { } // https://stackoverflow.com/questions/342409/how-do-i-base64-encode-decode-in-c - static char base64_encode[]={'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', - 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', - 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', - 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', - 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', - 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', - 'w', 'x', 'y', 'z', '0', '1', '2', '3', - '4', '5', '6', '7', '8', '9', '+', '/'}; + static constexpr char base64_encode[] = { + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', + 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', + 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'}; int base64encode(const void* data_buf, size_t dataLength, char* result, size_t resultSize) { auto encoding_table = (char*)base64_encode; @@ -183,7 +187,7 @@ namespace Exiv2 { size_t input_length = in ? ::strlen(in) : 0; if (!in || input_length % 4 != 0) return result; - auto encoding_table = (unsigned char*)base64_encode; + auto encoding_table = reinterpret_cast(base64_encode); unsigned char decoding_table[256]; for (unsigned char i = 0; i < 64; i++) decoding_table[encoding_table[i]] = i; diff --git a/src/http.cpp b/src/http.cpp index 1d6e68131f..b2b0b325cc 100644 --- a/src/http.cpp +++ b/src/http.cpp @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -98,27 +99,26 @@ static void Sleep(int millisecs) //////////////////////////////////////// // code -static const char* httpTemplate = -"%s %s HTTP/%s\r\n" // $verb $page $version -"User-Agent: exiv2http/1.0.0\r\n" -"Accept: */*\r\n" -"Host: %s\r\n" // $servername -"%s" // $header -"\r\n" -; +static constexpr auto httpTemplate = + "%s %s HTTP/%s\r\n" // $verb $page $version + "User-Agent: exiv2http/1.0.0\r\n" + "Accept: */*\r\n" + "Host: %s\r\n" // $servername + "%s" // $header + "\r\n"; #define white(c) ((c == ' ') || (c == '\t')) #define FINISH -999 #define OK(s) (200 <= s && s < 300) -const char* blankLines[] = -{ "\r\n\r\n" // this is the standard -, "\n\n" // this is commonly sent by CGI scripts -} ; +static constexpr std::array blankLines{ + "\r\n\r\n", // this is the standard + "\n\n", // this is commonly sent by CGI scripts +}; -int snooze = SNOOZE ; -int sleep_ = SLEEP ; +static constexpr int snooze = SNOOZE; +static int sleep_ = SLEEP; static int forgive(int n,int& err) { diff --git a/src/jpgimage.cpp b/src/jpgimage.cpp index 35e3b40678..63bddadf40 100644 --- a/src/jpgimage.cpp +++ b/src/jpgimage.cpp @@ -51,49 +51,48 @@ // class member definitions namespace Exiv2 { - - const byte JpegBase::dht_ = 0xc4; - const byte JpegBase::dqt_ = 0xdb; - const byte JpegBase::dri_ = 0xdd; - const byte JpegBase::sos_ = 0xda; - const byte JpegBase::eoi_ = 0xd9; - const byte JpegBase::app0_ = 0xe0; - const byte JpegBase::app1_ = 0xe1; - const byte JpegBase::app2_ = 0xe2; - const byte JpegBase::app13_ = 0xed; - const byte JpegBase::com_ = 0xfe; - -// Start of Frame markers, nondifferential Huffman-coding frames - const byte JpegBase::sof0_ = 0xc0; // start of frame 0, baseline DCT - const byte JpegBase::sof1_ = 0xc1; // start of frame 1, extended sequential DCT, Huffman coding - const byte JpegBase::sof2_ = 0xc2; // start of frame 2, progressive DCT, Huffman coding - const byte JpegBase::sof3_ = 0xc3; // start of frame 3, lossless sequential, Huffman coding - -// Start of Frame markers, differential Huffman-coding frames - const byte JpegBase::sof5_ = 0xc5; // start of frame 5, differential sequential DCT, Huffman coding - const byte JpegBase::sof6_ = 0xc6; // start of frame 6, differential progressive DCT, Huffman coding - const byte JpegBase::sof7_ = 0xc7; // start of frame 7, differential lossless, Huffman coding - -// Start of Frame markers, nondifferential arithmetic-coding frames - const byte JpegBase::sof9_ = 0xc9; // start of frame 9, extended sequential DCT, arithmetic coding - const byte JpegBase::sof10_ = 0xca; // start of frame 10, progressive DCT, arithmetic coding - const byte JpegBase::sof11_ = 0xcb; // start of frame 11, lossless sequential, arithmetic coding - -// Start of Frame markers, differential arithmetic-coding frames - const byte JpegBase::sof13_ = 0xcd; // start of frame 13, differential sequential DCT, arithmetic coding - const byte JpegBase::sof14_ = 0xce; // start of frame 14, progressive DCT, arithmetic coding - const byte JpegBase::sof15_ = 0xcf; // start of frame 15, differential lossless, arithmetic coding - - const char JpegBase::exifId_[] = "Exif\0\0"; - const char JpegBase::jfifId_[] = "JFIF\0"; - const char JpegBase::xmpId_[] = "http://ns.adobe.com/xap/1.0/\0"; - const char JpegBase::iccId_[] = "ICC_PROFILE\0"; - - const char Photoshop::ps3Id_[] = "Photoshop 3.0\0"; - const char* Photoshop::irbId_[] = {"8BIM", "AgHg", "DCSR", "PHUT"}; - const char Photoshop::bimId_[] = "8BIM"; // deprecated - const uint16_t Photoshop::iptc_ = 0x0404; - const uint16_t Photoshop::preview_ = 0x040c; + constexpr byte JpegBase::dht_ = 0xc4; + constexpr byte JpegBase::dqt_ = 0xdb; + constexpr byte JpegBase::dri_ = 0xdd; + constexpr byte JpegBase::sos_ = 0xda; + constexpr byte JpegBase::eoi_ = 0xd9; + constexpr byte JpegBase::app0_ = 0xe0; + constexpr byte JpegBase::app1_ = 0xe1; + constexpr byte JpegBase::app2_ = 0xe2; + constexpr byte JpegBase::app13_ = 0xed; + constexpr byte JpegBase::com_ = 0xfe; + + // Start of Frame markers, nondifferential Huffman-coding frames + constexpr byte JpegBase::sof0_ = 0xc0; // start of frame 0, baseline DCT + constexpr byte JpegBase::sof1_ = 0xc1; // start of frame 1, extended sequential DCT, Huffman coding + constexpr byte JpegBase::sof2_ = 0xc2; // start of frame 2, progressive DCT, Huffman coding + constexpr byte JpegBase::sof3_ = 0xc3; // start of frame 3, lossless sequential, Huffman coding + + // Start of Frame markers, differential Huffman-coding frames + constexpr byte JpegBase::sof5_ = 0xc5; // start of frame 5, differential sequential DCT, Huffman coding + constexpr byte JpegBase::sof6_ = 0xc6; // start of frame 6, differential progressive DCT, Huffman coding + constexpr byte JpegBase::sof7_ = 0xc7; // start of frame 7, differential lossless, Huffman coding + + // Start of Frame markers, nondifferential arithmetic-coding frames + constexpr byte JpegBase::sof9_ = 0xc9; // start of frame 9, extended sequential DCT, arithmetic coding + constexpr byte JpegBase::sof10_ = 0xca; // start of frame 10, progressive DCT, arithmetic coding + constexpr byte JpegBase::sof11_ = 0xcb; // start of frame 11, lossless sequential, arithmetic coding + + // Start of Frame markers, differential arithmetic-coding frames + constexpr byte JpegBase::sof13_ = 0xcd; // start of frame 13, differential sequential DCT, arithmetic coding + constexpr byte JpegBase::sof14_ = 0xce; // start of frame 14, progressive DCT, arithmetic coding + constexpr byte JpegBase::sof15_ = 0xcf; // start of frame 15, differential lossless, arithmetic coding + + constexpr const char* JpegBase::exifId_ = "Exif\0\0"; + constexpr const char* JpegBase::jfifId_ = "JFIF\0"; + constexpr const char* JpegBase::xmpId_ = "http://ns.adobe.com/xap/1.0/\0"; + constexpr const char* JpegBase::iccId_ = "ICC_PROFILE\0"; + + constexpr const char* Photoshop::ps3Id_ = "Photoshop 3.0\0"; + constexpr std::array Photoshop::irbId_{"8BIM", "AgHg", "DCSR", "PHUT"}; + constexpr const char* Photoshop::bimId_ = "8BIM"; // deprecated + constexpr uint16_t Photoshop::iptc_ = 0x0404; + constexpr uint16_t Photoshop::preview_ = 0x040c; static inline bool inRange(int lo,int value, int hi) { diff --git a/src/properties.cpp b/src/properties.cpp index 1663fbfcf4..527008fadd 100644 --- a/src/properties.cpp +++ b/src/properties.cpp @@ -2697,7 +2697,7 @@ namespace Exiv2 { void decomposeKey(const std::string& key); //!< Misterious magic // DATA - static const char* familyName_; //!< "Xmp" + static constexpr auto familyName_ = "Xmp"; //!< "Xmp" std::string prefix_; //!< Prefix std::string property_; //!< Property name @@ -2714,8 +2714,6 @@ namespace Exiv2 { prefix_ = prefix; } - const char* XmpKey::Impl::familyName_ = "Xmp"; - XmpKey::XmpKey(const std::string& key) : p_(new Impl) { p_->decomposeKey(key); diff --git a/src/tags.cpp b/src/tags.cpp index 267d35deee..70401c912a 100644 --- a/src/tags.cpp +++ b/src/tags.cpp @@ -219,7 +219,7 @@ namespace Exiv2 { //@} // DATA - static const char* familyName_; //!< "Exif" + static constexpr auto familyName_ = "Exif"; //!< "Exif" const TagInfo* tagInfo_{0}; //!< Tag info uint16_t tag_{0}; //!< Tag value @@ -229,8 +229,6 @@ namespace Exiv2 { std::string key_; //!< %Key }; - const char* ExifKey::Impl::familyName_ = "Exif"; - std::string ExifKey::Impl::tagName() const { if (tagInfo_ != 0 && tagInfo_->tag_ != 0xffff) { diff --git a/src/tiffimage.cpp b/src/tiffimage.cpp index 5892228935..578dd2f256 100644 --- a/src/tiffimage.cpp +++ b/src/tiffimage.cpp @@ -82,10 +82,10 @@ namespace Exiv2 { }; //! List of TIFF compression to MIME type mappings - MimeTypeList mimeTypeList[] = { - { 32770, "image/x-samsung-srw" }, - { 34713, "image/x-nikon-nef" }, - { 65535, "image/x-pentax-pef" } + constexpr MimeTypeList mimeTypeList[] = { + {32770, "image/x-samsung-srw"}, + {34713, "image/x-nikon-nef"}, + {65535, "image/x-pentax-pef"}, }; std::string TiffImage::mimeType() const diff --git a/src/webpimage.cpp b/src/webpimage.cpp index 0fadc1e262..2129b5ffb2 100644 --- a/src/webpimage.cpp +++ b/src/webpimage.cpp @@ -81,24 +81,24 @@ namespace Exiv2 { /* =========================================== */ /* Misc. */ - const byte WebPImage::WEBP_PAD_ODD = 0; - const int WebPImage::WEBP_TAG_SIZE = 0x4; + constexpr byte WebPImage::WEBP_PAD_ODD = 0; + constexpr int WebPImage::WEBP_TAG_SIZE = 0x4; /* VP8X feature flags */ - const int WebPImage::WEBP_VP8X_ICC_BIT = 0x20; - const int WebPImage::WEBP_VP8X_ALPHA_BIT = 0x10; - const int WebPImage::WEBP_VP8X_EXIF_BIT = 0x8; - const int WebPImage::WEBP_VP8X_XMP_BIT = 0x4; + constexpr int WebPImage::WEBP_VP8X_ICC_BIT = 0x20; + constexpr int WebPImage::WEBP_VP8X_ALPHA_BIT = 0x10; + constexpr int WebPImage::WEBP_VP8X_EXIF_BIT = 0x8; + constexpr int WebPImage::WEBP_VP8X_XMP_BIT = 0x4; /* Chunk header names */ - const char* WebPImage::WEBP_CHUNK_HEADER_VP8X = "VP8X"; - const char* WebPImage::WEBP_CHUNK_HEADER_VP8L = "VP8L"; - const char* WebPImage::WEBP_CHUNK_HEADER_VP8 = "VP8 "; - const char* WebPImage::WEBP_CHUNK_HEADER_ANMF = "ANMF"; - const char* WebPImage::WEBP_CHUNK_HEADER_ANIM = "ANIM"; - const char* WebPImage::WEBP_CHUNK_HEADER_ICCP = "ICCP"; - const char* WebPImage::WEBP_CHUNK_HEADER_EXIF = "EXIF"; - const char* WebPImage::WEBP_CHUNK_HEADER_XMP = "XMP "; + constexpr const char*WebPImage::WEBP_CHUNK_HEADER_VP8X = "VP8X"; + constexpr const char*WebPImage::WEBP_CHUNK_HEADER_VP8L = "VP8L"; + constexpr const char*WebPImage::WEBP_CHUNK_HEADER_VP8 = "VP8 "; + constexpr const char*WebPImage::WEBP_CHUNK_HEADER_ANMF = "ANMF"; + constexpr const char*WebPImage::WEBP_CHUNK_HEADER_ANIM = "ANIM"; + constexpr const char*WebPImage::WEBP_CHUNK_HEADER_ICCP = "ICCP"; + constexpr const char*WebPImage::WEBP_CHUNK_HEADER_EXIF = "EXIF"; + constexpr const char*WebPImage::WEBP_CHUNK_HEADER_XMP = "XMP "; /* =========================================== */ diff --git a/src/xmpsidecar.cpp b/src/xmpsidecar.cpp index 4a71ae3af8..621eec7c28 100644 --- a/src/xmpsidecar.cpp +++ b/src/xmpsidecar.cpp @@ -36,10 +36,10 @@ // ***************************************************************************** namespace { - const char* xmlHeader = "\n"; - const long xmlHdrCnt = (long) std::strlen(xmlHeader); // without the trailing 0-character - const char* xmlFooter = ""; -} + constexpr auto xmlHeader = "\n"; + const auto xmlHdrCnt = static_cast(std::strlen(xmlHeader)); // without the trailing 0-character + constexpr auto xmlFooter = ""; +} // namespace // class member definitions namespace Exiv2 {