diff --git a/include/exiv2/basicio.hpp b/include/exiv2/basicio.hpp index c456344d..d6952b09 100644 --- a/include/exiv2/basicio.hpp +++ b/include/exiv2/basicio.hpp @@ -916,7 +916,7 @@ namespace Exiv2 { // Pimpl idiom class Impl; //! Pointer to implementation - Impl* p_ {nullptr}; + std::unique_ptr p_; }; // class RemoteIo /*! diff --git a/src/basicio.cpp b/src/basicio.cpp index 807d75c8..d1627a16 100644 --- a/src/basicio.cpp +++ b/src/basicio.cpp @@ -219,7 +219,7 @@ namespace Exiv2 { } // FileIo::Impl::stat FileIo::FileIo(const std::string& path) - : p_(new Impl(path)) + : p_(std::make_unique(path)) { } @@ -548,9 +548,11 @@ namespace Exiv2 { int FileIo::close() { int rc = 0; - if (munmap() != 0) rc = 2; + if (munmap() != 0) + rc = 2; if (p_->fp_ != nullptr) { - if (std::fclose(p_->fp_) != 0) rc |= 1; + if (std::fclose(p_->fp_) != 0) + rc |= 1; p_->fp_ = nullptr; } return rc; @@ -738,12 +740,12 @@ namespace Exiv2 { } MemIo::MemIo() - : p_(new Impl()) + : p_(std::make_unique()) { } MemIo::MemIo(const byte* data, long size) - : p_(new Impl(data, size)) + : p_(std::make_unique(data, size)) { } @@ -1172,7 +1174,6 @@ namespace Exiv2 { { if (p_) { close(); - delete p_; } } @@ -1588,11 +1589,10 @@ namespace Exiv2 { // encode base64 size_t encodeLength = ((size + 2) / 3) * 4 + 1; - auto encodeData = new char[encodeLength]; - base64encode(data, size, encodeData, encodeLength); + std::vector encodeData (encodeLength); + base64encode(data, size, encodeData.data(), encodeLength); // url encode - const std::string urlencodeData = urlencode(encodeData); - delete[] encodeData; + const std::string urlencodeData = urlencode(encodeData.data()); std::stringstream ss; ss << "path=" << hostInfo_.Path << "&" @@ -1613,9 +1613,10 @@ namespace Exiv2 { throw Error(kerFileOpenFailed, "http",Exiv2::Internal::stringFormat("%d",serverCode), hostInfo_.Path); } } + HttpIo::HttpIo(const std::string& url, size_t blockSize) { - p_ = new HttpImpl(url, blockSize); + p_ = std::make_unique(url, blockSize); } #ifdef EXV_USE_CURL @@ -1776,11 +1777,10 @@ namespace Exiv2 { // encode base64 size_t encodeLength = ((size + 2) / 3) * 4 + 1; - auto encodeData = new char[encodeLength]; - base64encode(data, size, encodeData, encodeLength); + std::vector encodeData (encodeLength); + base64encode(data, size, encodeData.data(), encodeLength); // url encode - const std::string urlencodeData = urlencode(encodeData); - delete[] encodeData; + const std::string urlencodeData = urlencode(encodeData.data()); std::stringstream ss; ss << "path=" << hostInfo.Path << "&" << "from=" << from << "&" @@ -1824,7 +1824,7 @@ namespace Exiv2 { CurlIo::CurlIo(const std::string& url, size_t blockSize) { - p_ = new CurlImpl(url, blockSize); + p_ = std::make_unique(url, blockSize); } #endif diff --git a/src/cr2image.cpp b/src/cr2image.cpp index cbbcecbe..f2e99f17 100644 --- a/src/cr2image.cpp +++ b/src/cr2image.cpp @@ -177,7 +177,7 @@ namespace Exiv2 { ed.erase(std::remove_if(ed.begin(), ed.end(), FindExifdatum(filteredIfd)), ed.end()); } - std::unique_ptr header(new Cr2Header(byteOrder)); + Cr2Header header(byteOrder); OffsetWriter offsetWriter; offsetWriter.setOrigin(OffsetWriter::cr2RawIfdOffset, Cr2Header::offset2addr(), byteOrder); return TiffParserWorker::encode(io, @@ -188,7 +188,7 @@ namespace Exiv2 { xmpData, Tag::root, TiffMapping::findEncoder, - header.get(), + &header, &offsetWriter); } diff --git a/src/crwimage_int.cpp b/src/crwimage_int.cpp index c869b325..76f71242 100644 --- a/src/crwimage_int.cpp +++ b/src/crwimage_int.cpp @@ -169,8 +169,6 @@ namespace Exiv2 { CiffHeader::~CiffHeader() { - delete pRootDir_; - delete[] pPadding_; } CiffDirectory::~CiffDirectory() @@ -214,12 +212,12 @@ namespace Exiv2 { throw Error(kerNotACrwImage); } - delete[] pPadding_; - pPadding_ = new byte[offset_ - 14]; + pPadding_.clear(); + pPadding_.resize(offset_ - 14); padded_ = offset_ - 14; - std::memcpy(pPadding_, pData + 14, padded_); + std::copy_n(pData+14, padded_, pPadding_.begin()); - pRootDir_ = new CiffDirectory; + pRootDir_ = std::make_unique(); pRootDir_->readDirectory(pData + offset_, size - offset_, byteOrder_); } // CiffHeader::read @@ -329,8 +327,9 @@ namespace Exiv2 { void CiffHeader::decode(Image& image) const { // Nothing to decode from the header itself, just add correct byte order - if (pRootDir_) pRootDir_->decode(image, byteOrder_); - } // CiffHeader::decode + if (pRootDir_) + pRootDir_->decode(image, byteOrder_); + } void CiffComponent::decode(Image& image, ByteOrder byteOrder) const { @@ -369,9 +368,9 @@ namespace Exiv2 { append(blob, reinterpret_cast(signature_), 8); o += 8; // Pad as needed - if (pPadding_) { + if (pPadding_.empty() == false) { assert(padded_ == offset_ - o); - append(blob, pPadding_, padded_); + append(blob, pPadding_.data(), padded_); } else { for (uint32_t i = o; i < offset_; ++i) { @@ -622,7 +621,7 @@ namespace Exiv2 { assert(rootDirectory == 0x0000); crwDirs.pop(); if (!pRootDir_) { - pRootDir_ = new CiffDirectory; + pRootDir_ = std::make_unique(); } CiffComponent* child = pRootDir_->add(crwDirs, crwTagId); if (child) { @@ -683,7 +682,7 @@ namespace Exiv2 { } if (cc_ == nullptr) { // Tag doesn't exist yet, add it - m_ = UniquePtr(new CiffEntry(crwTagId, tag())); + m_ = std::make_unique(crwTagId, tag()); cc_ = m_.get(); add(std::move(m_)); } diff --git a/src/crwimage_int.hpp b/src/crwimage_int.hpp index 935802f6..0c0c3bfd 100644 --- a/src/crwimage_int.hpp +++ b/src/crwimage_int.hpp @@ -493,10 +493,10 @@ namespace Exiv2 { // DATA static const char signature_[]; //!< Canon CRW signature "HEAPCCDR" - CiffDirectory* pRootDir_ = nullptr; //!< Pointer to the root directory + std::unique_ptr pRootDir_; //!< Pointer to the root directory ByteOrder byteOrder_ = littleEndian; //!< Applicable byte order uint32_t offset_ = 0; //!< Offset to the start of the root dir - byte* pPadding_ = nullptr; //!< Pointer to the (unknown) remainder + std::vector pPadding_; //!< the (unknown) remainder uint32_t padded_ = 0; //!< Number of padding-bytes }; // class CiffHeader diff --git a/src/exif.cpp b/src/exif.cpp index a8054000..64d14134 100644 --- a/src/exif.cpp +++ b/src/exif.cpp @@ -181,7 +181,7 @@ namespace Exiv2 { template Exiv2::Exifdatum& setValue(Exiv2::Exifdatum& exifDatum, const T& value) { - auto v = std::unique_ptr >(new Exiv2::ValueType); + auto v = std::make_unique>(); v->value_.push_back(value); exifDatum.value_ = std::move(v); return exifDatum; @@ -696,9 +696,9 @@ namespace Exiv2 { // Encode and check if the result fits into a JPEG Exif APP1 segment MemIo mio1; - std::unique_ptr header(new TiffHeader(byteOrder, 0x00000008, false)); + TiffHeader header(byteOrder, 0x00000008, false); WriteMethod wm = TiffParserWorker::encode(mio1, pData, size, ed, emptyIptc, emptyXmp, Tag::root, - TiffMapping::findEncoder, header.get(), nullptr); + TiffMapping::findEncoder, &header, nullptr); if (mio1.size() <= 65527) { append(blob, mio1.mmap(), static_cast(mio1.size())); return wm; @@ -796,7 +796,7 @@ namespace Exiv2 { // Encode the remaining Exif tags again, don't care if it fits this time MemIo mio2; wm = TiffParserWorker::encode(mio2, pData, size, ed, emptyIptc, emptyXmp, Tag::root, TiffMapping::findEncoder, - header.get(), nullptr); + &header, nullptr); append(blob, mio2.mmap(), static_cast(mio2.size())); #ifdef EXIV2_DEBUG_MESSAGES if (wm == wmIntrusive) { diff --git a/src/jpgimage.cpp b/src/jpgimage.cpp index 9f55ada0..2c7b47ee 100644 --- a/src/jpgimage.cpp +++ b/src/jpgimage.cpp @@ -848,13 +848,12 @@ namespace Exiv2 { throw Error(kerDataSourceOpenFailed, io_->path(), strError()); } IoCloser closer(*io_); - BasicIo::UniquePtr tempIo(new MemIo); - assert (tempIo.get() != 0); + auto tempIo = std::make_unique(); doWriteMetadata(*tempIo); // may throw io_->close(); io_->transfer(*tempIo); // may throw - } // JpegBase::writeMetadata + } void JpegBase::doWriteMetadata(BasicIo& outIo) { diff --git a/src/orfimage.cpp b/src/orfimage.cpp index 645bb9aa..d5dae40c 100644 --- a/src/orfimage.cpp +++ b/src/orfimage.cpp @@ -183,9 +183,9 @@ namespace Exiv2 { ed.erase(std::remove_if(ed.begin(), ed.end(), FindExifdatum(filteredIfd)), ed.end()); } - std::unique_ptr header(new OrfHeader(byteOrder)); + OrfHeader header(byteOrder); return TiffParserWorker::encode(io, pData, size, ed, iptcData, xmpData, Tag::root, TiffMapping::findEncoder, - header.get(), nullptr); + &header, nullptr); } // ************************************************************************* diff --git a/src/properties.cpp b/src/properties.cpp index 31ed9c39..73caedbd 100644 --- a/src/properties.cpp +++ b/src/properties.cpp @@ -4186,19 +4186,20 @@ namespace Exiv2 { prefix_ = prefix; } - XmpKey::XmpKey(const std::string& key) : p_(new Impl) + XmpKey::XmpKey(const std::string& key) : p_(std::make_unique()) { p_->decomposeKey(key); } - XmpKey::XmpKey(const std::string& prefix, const std::string& property) : p_(new Impl(prefix, property)) + XmpKey::XmpKey(const std::string& prefix, const std::string& property) + : p_(std::make_unique(prefix, property)) { } XmpKey::~XmpKey() = default; XmpKey::XmpKey(const XmpKey& rhs) - : p_(new Impl(*rhs.p_)) + : p_(std::make_unique(*rhs.p_)) { } diff --git a/src/tags.cpp b/src/tags.cpp index d2b3dace..f63c4099 100644 --- a/src/tags.cpp +++ b/src/tags.cpp @@ -295,7 +295,7 @@ namespace Exiv2 { } ExifKey::ExifKey(uint16_t tag, const std::string& groupName) - : p_(new Impl) + : p_(std::make_unique()) { IfdId ifdId = groupId(groupName); // Todo: Test if this condition can be removed @@ -311,7 +311,7 @@ namespace Exiv2 { } ExifKey::ExifKey(const TagInfo& ti) - : p_(new Impl) + : p_(std::make_unique()) { auto ifdId = static_cast(ti.ifdId_); if (!Internal::isExifIfd(ifdId) && !Internal::isMakerIfd(ifdId)) { @@ -322,13 +322,13 @@ namespace Exiv2 { } ExifKey::ExifKey(const std::string& key) - : p_(new Impl) + : p_(std::make_unique()) { p_->decomposeKey(key); } ExifKey::ExifKey(const ExifKey& rhs) - : p_(new Impl(*rhs.p_)) + : p_(std::make_unique(*rhs.p_)) { } diff --git a/src/tiffimage.cpp b/src/tiffimage.cpp index e693c715..4353b5b3 100644 --- a/src/tiffimage.cpp +++ b/src/tiffimage.cpp @@ -298,9 +298,9 @@ namespace Exiv2 { ed.erase(std::remove_if(ed.begin(), ed.end(), FindExifdatum(filteredIfd)), ed.end()); } - std::unique_ptr header(new TiffHeader(byteOrder)); + TiffHeader header(byteOrder); return TiffParserWorker::encode(io, pData, size, ed, iptcData, xmpData, Tag::root, TiffMapping::findEncoder, - header.get(), nullptr); + &header, nullptr); } // TiffParser::encode // ************************************************************************* diff --git a/src/tiffimage_int.cpp b/src/tiffimage_int.cpp index 80aabf1e..e0eabf89 100644 --- a/src/tiffimage_int.cpp +++ b/src/tiffimage_int.cpp @@ -2057,7 +2057,7 @@ namespace Exiv2 { // Create standard TIFF header if necessary std::unique_ptr ph; if (!pHeader) { - ph = std::unique_ptr(new TiffHeader); + ph = std::make_unique(); pHeader = ph.get(); }