diff --git a/src/asfvideo.cpp b/src/asfvideo.cpp index 952802da61..fee03b4d35 100644 --- a/src/asfvideo.cpp +++ b/src/asfvideo.cpp @@ -10,67 +10,17 @@ #include "helper_functions.hpp" #include "image_int.hpp" -// ***************************************************************************** -// class member definitions -namespace Exiv2 { - -/*! - Look-up list for ASF Type Video Files - Associates the GUID with its Name(i.e. Human Readable Form) - Tags have been differentiated into Various Categories. - The categories have been listed above Groups - see : - - https://fr.wikipedia.org/wiki/Advanced_Systems_Format - - https://exse.eyewated.com/fls/54b3ed95bbfb1a92.pdf - */ -/* - * @class GUID_struct - * - * @brief A class to represent a globally unique identifier (GUID) structure - * - * This class represents a globally unique identifier (GUID) structure which is used to identify objects in a - * distributed environment. A GUID is a unique identifier that is generated on a computer and can be used to - * identify an object across different systems. The GUID structure is comprised of four 32-bit values and an - * array of 8 bytes. - * - * @note The byte order of the GUID structure is in little endian. - * - * @see https://en.wikipedia.org/wiki/Globally_unique_identifier - * - */ - -bool AsfVideo::GUIDTag::operator==(const AsfVideo::GUIDTag& other) const { - return data1_ == other.data1_ && data2_ == other.data2_ && data3_ == other.data3_ && data4_ == other.data4_; -} +namespace { +constexpr Exiv2::AsfVideo::GUIDTag Header(0x75B22630, 0x668E, 0x11CF, {0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C}); -AsfVideo::GUIDTag::GUIDTag(const uint8_t* bytes) { - data1_ = Exiv2::getULong(bytes, ByteOrder::littleEndian); - data2_ = Exiv2::getUShort(bytes + DWORD, ByteOrder::littleEndian); - data3_ = Exiv2::getUShort(bytes + DWORD + WORD, ByteOrder::littleEndian); - std::copy(bytes + QWORD, bytes + (2 * QWORD), data4_.begin()); -} +constexpr struct tags { + Exiv2::AsfVideo::GUIDTag first; + std::string_view second; -std::string AsfVideo::GUIDTag::to_string() const { - // Concatenate all strings into a single string - // Convert the string to uppercase - // Example of output 399595EC-8667-4E2D-8FDB-98814CE76C1E - return stringFormat("{:08X}-{:04X}-{:04X}-{:02X}{:02X}-{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}", data1_, data2_, data3_, - data4_[0], data4_[1], data4_[2], data4_[3], data4_[4], data4_[5], data4_[6], data4_[7]); -} - -bool AsfVideo::GUIDTag::operator<(const GUIDTag& other) const { - if (data1_ != other.data1_) - return data1_ < other.data1_; - if (data2_ != other.data2_) - return data2_ < other.data2_; - if (data3_ != other.data3_) - return data3_ < other.data3_; - return std::lexicographical_compare(data4_.begin(), data4_.end(), other.data4_.begin(), other.data4_.end()); -} - -constexpr AsfVideo::GUIDTag Header(0x75B22630, 0x668E, 0x11CF, {0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C}); - -const std::map GUIDReferenceTags = { + bool operator==(const Exiv2::DataBuf& tag) const { + return Exiv2::AsfVideo::GUIDTag(tag.c_data()) == first; + }; +} GUIDReferenceTags[] = { //!< Top-level ASF object GUIDS {Header, "Header"}, {{0x75B22636, 0x668E, 0x11CF, {0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C}}, "Data"}, @@ -175,8 +125,68 @@ const std::map GUIDReferenceTags = { @param buf Exiv2 byte buffer @return Returns true if the buffer data is equivalent to Header GUID. */ -static bool isASFType(const byte buf[]) { - return Header == AsfVideo::GUIDTag(buf); +bool isASFType(const Exiv2::byte buf[]) { + return Header == Exiv2::AsfVideo::GUIDTag(buf); +} + +} // namespace + +// ***************************************************************************** +// class member definitions +namespace Exiv2 { + +/*! + Look-up list for ASF Type Video Files + Associates the GUID with its Name(i.e. Human Readable Form) + Tags have been differentiated into Various Categories. + The categories have been listed above Groups + see : + - https://fr.wikipedia.org/wiki/Advanced_Systems_Format + - https://exse.eyewated.com/fls/54b3ed95bbfb1a92.pdf + */ +/* + * @class GUID_struct + * + * @brief A class to represent a globally unique identifier (GUID) structure + * + * This class represents a globally unique identifier (GUID) structure which is used to identify objects in a + * distributed environment. A GUID is a unique identifier that is generated on a computer and can be used to + * identify an object across different systems. The GUID structure is comprised of four 32-bit values and an + * array of 8 bytes. + * + * @note The byte order of the GUID structure is in little endian. + * + * @see https://en.wikipedia.org/wiki/Globally_unique_identifier + * + */ + +bool AsfVideo::GUIDTag::operator==(const AsfVideo::GUIDTag& other) const { + return data1_ == other.data1_ && data2_ == other.data2_ && data3_ == other.data3_ && data4_ == other.data4_; +} + +AsfVideo::GUIDTag::GUIDTag(const uint8_t* bytes) { + data1_ = Exiv2::getULong(bytes, ByteOrder::littleEndian); + data2_ = Exiv2::getUShort(bytes + DWORD, ByteOrder::littleEndian); + data3_ = Exiv2::getUShort(bytes + DWORD + WORD, ByteOrder::littleEndian); + std::copy(bytes + QWORD, bytes + (2 * QWORD), data4_.begin()); +} + +std::string AsfVideo::GUIDTag::to_string() const { + // Concatenate all strings into a single string + // Convert the string to uppercase + // Example of output 399595EC-8667-4E2D-8FDB-98814CE76C1E + return stringFormat("{:08X}-{:04X}-{:04X}-{:02X}{:02X}-{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}", data1_, data2_, data3_, + data4_[0], data4_[1], data4_[2], data4_[3], data4_[4], data4_[5], data4_[6], data4_[7]); +} + +bool AsfVideo::GUIDTag::operator<(const GUIDTag& other) const { + if (data1_ != other.data1_) + return data1_ < other.data1_; + if (data2_ != other.data2_) + return data2_ < other.data2_; + if (data3_ != other.data3_) + return data3_ < other.data3_; + return std::lexicographical_compare(data4_.begin(), data4_.end(), other.data4_.begin(), other.data4_.end()); } AsfVideo::AsfVideo(BasicIo::UniquePtr io) : Image(ImageType::asf, mdNone, std::move(io)) { @@ -231,9 +241,8 @@ void AsfVideo::decodeBlock() { << "\tsize= " << objectHeader.getSize() << "\t " << io_->tell() << "/" << io_->size() << '\n'; #endif Internal::enforce(objectHeader.getSize() <= io_->size() - io_->tell(), Exiv2::ErrorCode::kerCorruptedMetadata); - auto tag = GUIDReferenceTags.find(GUIDTag(objectHeader.getId().data())); - if (tag != GUIDReferenceTags.end()) { + if (auto tag = Exiv2::find(GUIDReferenceTags, objectHeader.getId())) { if (tag->second == "Header") decodeHeader(); else if (tag->second == "File_Properties") @@ -339,8 +348,7 @@ void AsfVideo::streamProperties() { enum class streamTypeInfo { Audio = 1, Video = 2 }; auto stream = streamTypeInfo{0}; - auto tag_stream_type = GUIDReferenceTags.find(GUIDTag(streamTypedBuf.data())); - if (tag_stream_type != GUIDReferenceTags.end()) { + if (auto tag_stream_type = Exiv2::find(GUIDReferenceTags, streamTypedBuf)) { if (tag_stream_type->second == "Audio_Media") stream = streamTypeInfo::Audio; else if (tag_stream_type->second == "Video_Media") diff --git a/src/convert.cpp b/src/convert.cpp index 3f4ed29dfa..6a89f92889 100644 --- a/src/convert.cpp +++ b/src/convert.cpp @@ -59,7 +59,7 @@ bool convertStringCharsetWindows(std::string& str, std::string_view from, std::s exactly one entry, \em value is set to this entry, without the qualifier. The return code indicates if the operation was successful. */ -bool getTextValue(std::string& value, const Exiv2::XmpData::iterator& pos); +bool getTextValue(std::string& value, Exiv2::XmpData::iterator pos); } // namespace // ***************************************************************************** @@ -1586,7 +1586,7 @@ bool convertStringCharsetWindows(std::string& str, std::string_view from, std::s } #endif // EXV_HAVE_ICONV -bool getTextValue(std::string& value, const XmpData::iterator& pos) { +bool getTextValue(std::string& value, XmpData::iterator pos) { if (pos->typeId() == langAlt) { // get the default language entry without x-default qualifier value = pos->toString(0); diff --git a/src/crwimage_int.hpp b/src/crwimage_int.hpp index e7025cf2cd..1d12635bb3 100644 --- a/src/crwimage_int.hpp +++ b/src/crwimage_int.hpp @@ -70,6 +70,8 @@ class CiffComponent { CiffComponent(uint16_t tag, uint16_t dir); //! Virtual destructor. virtual ~CiffComponent() = default; + CiffComponent(const CiffComponent&) = delete; + CiffComponent& operator=(const CiffComponent&) = delete; //@} //! @name Manipulators diff --git a/src/exif.cpp b/src/exif.cpp index ad489238a2..7aa1bef788 100644 --- a/src/exif.cpp +++ b/src/exif.cpp @@ -64,8 +64,11 @@ class Thumbnail { //! @name Creators //@{ + Thumbnail() = default; //! Virtual destructor virtual ~Thumbnail() = default; + Thumbnail(const Thumbnail&) = delete; + Thumbnail& operator=(const Thumbnail&) = delete; //@} //! Factory function to create a thumbnail for the Exif metadata provided. diff --git a/src/image.cpp b/src/image.cpp index eaa78c8fd4..88650b3cd1 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -129,6 +129,12 @@ std::string pathOfFileUrl(const std::string& url) { } #endif +bool typeValid(uint16_t type) { + return type >= 1 && type <= 13; +} + +std::set visits; // #547 + } // namespace // ***************************************************************************** @@ -305,12 +311,6 @@ const char* Image::typeName(uint16_t tag) { return result; } -static bool typeValid(uint16_t type) { - return type >= 1 && type <= 13; -} - -static std::set visits; // #547 - void Image::printIFDStructure(BasicIo& io, std::ostream& out, Exiv2::PrintStructureOption option, size_t start, bool bSwap, char c, size_t depth) { if (depth == 1) diff --git a/src/makernote_int.cpp b/src/makernote_int.cpp index 84fdf0736e..490b8b3902 100644 --- a/src/makernote_int.cpp +++ b/src/makernote_int.cpp @@ -39,7 +39,7 @@ namespace fs = std::filesystem; namespace { // Todo: Can be generalized further - get any tag as a string/long/... //! Get the Value for a tag within a particular group -const Exiv2::Value* getExifValue(Exiv2::Internal::TiffComponent* pRoot, const uint16_t& tag, const Exiv2::IfdId& group); +const Exiv2::Value* getExifValue(Exiv2::Internal::TiffComponent* pRoot, uint16_t tag, Exiv2::IfdId group); //! Get the model name from tag Exif.Image.Model std::string getExifModel(Exiv2::Internal::TiffComponent* pRoot); @@ -1034,8 +1034,7 @@ int sonyMisc3cSelector(uint16_t /*tag*/, const byte* /*pData*/, size_t /*size*/, // ***************************************************************************** // local definitions namespace { -const Exiv2::Value* getExifValue(Exiv2::Internal::TiffComponent* pRoot, const uint16_t& tag, - const Exiv2::IfdId& group) { +const Exiv2::Value* getExifValue(Exiv2::Internal::TiffComponent* pRoot, uint16_t tag, Exiv2::IfdId group) { Exiv2::Internal::TiffFinder finder(tag, group); if (!pRoot) return nullptr; diff --git a/src/makernote_int.hpp b/src/makernote_int.hpp index 6b948874e6..fd488dcad9 100644 --- a/src/makernote_int.hpp +++ b/src/makernote_int.hpp @@ -89,8 +89,11 @@ class MnHeader { public: //! @name Creators //@{ + MnHeader() = default; //! Virtual destructor. virtual ~MnHeader() = default; + MnHeader(const MnHeader&) = delete; + MnHeader& operator=(const MnHeader&) = delete; //@} //! @name Manipulators //@{ diff --git a/src/riffvideo.cpp b/src/riffvideo.cpp index f90d2f09bf..92a9ba6f42 100644 --- a/src/riffvideo.cpp +++ b/src/riffvideo.cpp @@ -16,9 +16,16 @@ #include -namespace Exiv2::Internal { +namespace { -const std::map infoTags = { +constexpr struct tags { + std::string_view first; + const char* second; + + bool operator==(std::string_view tag) const { + return tag == first; + }; +} infoTags[] = { {"AGES", "Xmp.video.Rated"}, {"CMNT", "Xmp.video.Comment"}, {"CODE", "Xmp.video.EncodedBy"}, @@ -105,7 +112,14 @@ const std::map infoTags = { {"YEAR", "Xmp.video.Year"}, }; -const std::map audioEncodingValues = { +constexpr struct encoding { + uint16_t first; + std::string_view second; + + bool operator==(uint16_t tag) const { + return tag == first; + }; +} audioEncodingValues[] = { {0x1, "Microsoft PCM"}, {0x2, "Microsoft ADPCM"}, {0x3, "Microsoft IEEE float"}, @@ -351,7 +365,7 @@ const std::map audioEncodingValues = { {0xffff, "Development"}, }; -} // namespace Exiv2::Internal +} // namespace // ***************************************************************************** // class member definitions @@ -625,7 +639,7 @@ void RiffVideo::readStreamFormat(uint64_t size_) { xmpData_["Xmp.video.NumIfImpColours"] = "All"; } else if (streamType_ == Audio) { uint16_t format_tag = readWORDTag(io_); - if (auto it = Internal::audioEncodingValues.find(format_tag); it != Internal::audioEncodingValues.end()) + if (auto it = Exiv2::find(audioEncodingValues, format_tag)) xmpData_["Xmp.audio.Compressor"] = it->second; else xmpData_["Xmp.audio.Compressor"] = format_tag; @@ -657,7 +671,7 @@ void RiffVideo::readInfoListChunk(uint64_t size_) { std::string type = readStringTag(io_); size_t size = readDWORDTag(io_); std::string content = readStringTag(io_, size); - if (auto it = Internal::infoTags.find(type); it != Internal::infoTags.end()) + if (auto it = Exiv2::find(infoTags, type)) xmpData_[it->second] = content; current_size += DWORD * 2; current_size += size; diff --git a/src/tiffimage_int.hpp b/src/tiffimage_int.hpp index c7586dbfb6..48c4ef2b8c 100644 --- a/src/tiffimage_int.hpp +++ b/src/tiffimage_int.hpp @@ -39,6 +39,8 @@ class TiffHeaderBase { TiffHeaderBase(uint16_t tag, uint32_t size, ByteOrder byteOrder, uint32_t offset); //! Virtual destructor. virtual ~TiffHeaderBase() = default; + TiffHeaderBase(const TiffHeaderBase&) = delete; + TiffHeaderBase& operator=(const TiffHeaderBase&) = delete; //@} //! @name Manipulators @@ -138,7 +140,7 @@ class TiffHeader : public TiffHeaderBase { using TiffGroupKey = std::pair; struct TiffGroupKey_hash { - std::size_t operator()(const TiffGroupKey& pair) const noexcept { + std::size_t operator()(TiffGroupKey pair) const noexcept { return std::hash{}(static_cast(pair.first) << 32 | static_cast(pair.second)); } }; diff --git a/src/tiffvisitor_int.hpp b/src/tiffvisitor_int.hpp index 1a814553fb..6eb83b8ab5 100644 --- a/src/tiffvisitor_int.hpp +++ b/src/tiffvisitor_int.hpp @@ -54,8 +54,11 @@ class TiffVisitor { public: //! @name Creators //@{ + TiffVisitor() = default; //! Virtual destructor virtual ~TiffVisitor() = default; + TiffVisitor(const TiffVisitor&) = delete; + TiffVisitor& operator=(const TiffVisitor&) = delete; //@} //! @name Manipulators diff --git a/src/xmp.cpp b/src/xmp.cpp index 1a92dc9ac7..06b9aa2492 100644 --- a/src/xmp.cpp +++ b/src/xmp.cpp @@ -206,16 +206,16 @@ class FindXmpdatum { #ifdef EXV_HAVE_XMP_TOOLKIT //! Convert XMP Toolkit struct option bit to Value::XmpStruct -Exiv2::XmpValue::XmpStruct xmpStruct(const XMP_OptionBits& opt); +Exiv2::XmpValue::XmpStruct xmpStruct(XMP_OptionBits opt); //! Convert Value::XmpStruct to XMP Toolkit array option bits XMP_OptionBits xmpArrayOptionBits(Exiv2::XmpValue::XmpStruct xs); //! Convert XMP Toolkit array option bits to array TypeId -Exiv2::TypeId arrayValueTypeId(const XMP_OptionBits& opt); +Exiv2::TypeId arrayValueTypeId(XMP_OptionBits opt); //! Convert XMP Toolkit array option bits to Value::XmpArrayType -Exiv2::XmpValue::XmpArrayType xmpArrayType(const XMP_OptionBits& opt); +Exiv2::XmpValue::XmpArrayType xmpArrayType(XMP_OptionBits opt); //! Convert Value::XmpArrayType to XMP Toolkit array option bits XMP_OptionBits xmpArrayOptionBits(Exiv2::XmpValue::XmpArrayType xat); @@ -225,7 +225,7 @@ XMP_OptionBits xmpFormatOptionBits(Exiv2::XmpParser::XmpFormatFlags flags); //! Print information about a parsed XMP node void printNode(const std::string& schemaNs, const std::string& propPath, const std::string& propValue, - const XMP_OptionBits& opt); + XMP_OptionBits opt); //! Make an XMP key from a schema namespace and property path Exiv2::XmpKey::UniquePtr makeXmpKey(const std::string& schemaNs, const std::string& propPath); @@ -904,7 +904,7 @@ int XmpParser::encode(std::string& /*xmpPacket*/, const XmpData& xmpData, uint16 // local definitions namespace { #ifdef EXV_HAVE_XMP_TOOLKIT -Exiv2::XmpValue::XmpStruct xmpStruct(const XMP_OptionBits& opt) { +Exiv2::XmpValue::XmpStruct xmpStruct(XMP_OptionBits opt) { Exiv2::XmpValue::XmpStruct var(Exiv2::XmpValue::xsNone); if (XMP_PropIsStruct(opt)) { var = Exiv2::XmpValue::xsStruct; @@ -924,7 +924,7 @@ XMP_OptionBits xmpArrayOptionBits(Exiv2::XmpValue::XmpStruct xs) { return var; } -Exiv2::TypeId arrayValueTypeId(const XMP_OptionBits& opt) { +Exiv2::TypeId arrayValueTypeId(XMP_OptionBits opt) { Exiv2::TypeId typeId(Exiv2::invalidTypeId); if (XMP_PropIsArray(opt)) { if (XMP_ArrayIsAlternate(opt)) @@ -937,7 +937,7 @@ Exiv2::TypeId arrayValueTypeId(const XMP_OptionBits& opt) { return typeId; } -Exiv2::XmpValue::XmpArrayType xmpArrayType(const XMP_OptionBits& opt) { +Exiv2::XmpValue::XmpArrayType xmpArrayType(XMP_OptionBits opt) { return Exiv2::XmpValue::xmpArrayType(arrayValueTypeId(opt)); } @@ -986,7 +986,7 @@ XMP_OptionBits xmpFormatOptionBits(Exiv2::XmpParser::XmpFormatFlags flags) { #ifdef EXIV2_DEBUG_MESSAGES void printNode(const std::string& schemaNs, const std::string& propPath, const std::string& propValue, - const XMP_OptionBits& opt) { + XMP_OptionBits opt) { static bool first = true; if (first) { first = false; @@ -1041,7 +1041,7 @@ void printNode(const std::string& schemaNs, const std::string& propPath, const s std::cout << '\n'; } #else -void printNode(const std::string&, const std::string&, const std::string&, const XMP_OptionBits&) { +void printNode(const std::string&, const std::string&, const std::string&, XMP_OptionBits) { } #endif // EXIV2_DEBUG_MESSAGES