Skip to content

Commit ecfb739

Browse files
committed
use unique_ptr
Signed-off-by: Rosen Penev <[email protected]>
1 parent 0a8d06c commit ecfb739

5 files changed

+106
-123
lines changed

src/makernote_int.cpp

+55-55
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,14 @@ bool TiffMnRegistry::operator==(IfdId key) const {
139139
return mnGroup_ == key;
140140
}
141141

142-
TiffComponent* TiffMnCreator::create(uint16_t tag, IfdId group, const std::string& make, const byte* pData, size_t size,
143-
ByteOrder byteOrder) {
142+
std::unique_ptr<TiffComponent> TiffMnCreator::create(uint16_t tag, IfdId group, const std::string& make,
143+
const byte* pData, size_t size, ByteOrder byteOrder) {
144144
if (auto tmr = Exiv2::find(registry_, make))
145145
return tmr->newMnFct_(tag, group, tmr->mnGroup_, pData, size, byteOrder);
146146
return nullptr;
147147
} // TiffMnCreator::create
148148

149-
TiffComponent* TiffMnCreator::create(uint16_t tag, IfdId group, IfdId mnGroup) {
149+
std::unique_ptr<TiffComponent> TiffMnCreator::create(uint16_t tag, IfdId group, IfdId mnGroup) {
150150
if (auto tmr = Exiv2::find(registry_, mnGroup)) {
151151
if (tmr->newMnFct2_) {
152152
return tmr->newMnFct2_(tag, group, mnGroup);
@@ -637,20 +637,20 @@ size_t Casio2MnHeader::write(IoWrapper& ioWrapper, ByteOrder /*byteOrder*/) cons
637637
// *************************************************************************
638638
// free functions
639639

640-
TiffComponent* newIfdMn(uint16_t tag, IfdId group, IfdId mnGroup, const byte* /*pData*/, size_t size,
641-
ByteOrder /*byteOrder*/) {
640+
std::unique_ptr<TiffComponent> newIfdMn(uint16_t tag, IfdId group, IfdId mnGroup, const byte* /*pData*/, size_t size,
641+
ByteOrder /*byteOrder*/) {
642642
// Require at least an IFD with 1 entry, but not necessarily a next pointer
643643
if (size < 14)
644644
return nullptr;
645645
return newIfdMn2(tag, group, mnGroup);
646646
}
647647

648-
TiffComponent* newIfdMn2(uint16_t tag, IfdId group, IfdId mnGroup) {
649-
return new TiffIfdMakernote(tag, group, mnGroup, nullptr);
648+
std::unique_ptr<TiffComponent> newIfdMn2(uint16_t tag, IfdId group, IfdId mnGroup) {
649+
return std::make_unique<TiffIfdMakernote>(tag, group, mnGroup, nullptr);
650650
}
651651

652-
TiffComponent* newOlympusMn(uint16_t tag, IfdId group, IfdId /*mnGroup*/, const byte* pData, size_t size,
653-
ByteOrder /*byteOrder*/) {
652+
std::unique_ptr<TiffComponent> newOlympusMn(uint16_t tag, IfdId group, IfdId /*mnGroup*/, const byte* pData,
653+
size_t size, ByteOrder /*byteOrder*/) {
654654
// FIXME: workaround for overwritten OM System header in Olympus files (https://github.com/Exiv2/exiv2/issues/2542)
655655
if (size >= 14 && std::string(reinterpret_cast<const char*>(pData), 14) == std::string("OM SYSTEM\0\0\0II", 14)) {
656656
// Require at least the header and an IFD with 1 entry
@@ -670,40 +670,40 @@ TiffComponent* newOlympusMn(uint16_t tag, IfdId group, IfdId /*mnGroup*/, const
670670
return newOlympus2Mn2(tag, group, IfdId::olympus2Id);
671671
}
672672

673-
TiffComponent* newOlympusMn2(uint16_t tag, IfdId group, IfdId mnGroup) {
674-
return new TiffIfdMakernote(tag, group, mnGroup, new OlympusMnHeader);
673+
std::unique_ptr<TiffComponent> newOlympusMn2(uint16_t tag, IfdId group, IfdId mnGroup) {
674+
return std::make_unique<TiffIfdMakernote>(tag, group, mnGroup, std::make_unique<OlympusMnHeader>());
675675
}
676676

677-
TiffComponent* newOlympus2Mn2(uint16_t tag, IfdId group, IfdId mnGroup) {
678-
return new TiffIfdMakernote(tag, group, mnGroup, new Olympus2MnHeader);
677+
std::unique_ptr<TiffComponent> newOlympus2Mn2(uint16_t tag, IfdId group, IfdId mnGroup) {
678+
return std::make_unique<TiffIfdMakernote>(tag, group, mnGroup, std::make_unique<Olympus2MnHeader>());
679679
}
680680

681-
TiffComponent* newOMSystemMn(uint16_t tag, IfdId group, IfdId mnGroup, const byte* /*pData*/, size_t size,
682-
ByteOrder /*byteOrder*/) {
681+
std::unique_ptr<TiffComponent> newOMSystemMn(uint16_t tag, IfdId group, IfdId mnGroup, const byte* /*pData*/,
682+
size_t size, ByteOrder /*byteOrder*/) {
683683
// Require at least the header and an IFD with 1 entry
684684
if (size < OMSystemMnHeader::sizeOfSignature() + 18)
685685
return nullptr;
686686
return newOMSystemMn2(tag, group, mnGroup);
687687
}
688688

689-
TiffComponent* newOMSystemMn2(uint16_t tag, IfdId group, IfdId mnGroup) {
690-
return new TiffIfdMakernote(tag, group, mnGroup, new OMSystemMnHeader);
689+
std::unique_ptr<TiffComponent> newOMSystemMn2(uint16_t tag, IfdId group, IfdId mnGroup) {
690+
return std::make_unique<TiffIfdMakernote>(tag, group, mnGroup, std::make_unique<OMSystemMnHeader>());
691691
}
692692

693-
TiffComponent* newFujiMn(uint16_t tag, IfdId group, IfdId mnGroup, const byte* /*pData*/, size_t size,
694-
ByteOrder /*byteOrder*/) {
693+
std::unique_ptr<TiffComponent> newFujiMn(uint16_t tag, IfdId group, IfdId mnGroup, const byte* /*pData*/, size_t size,
694+
ByteOrder /*byteOrder*/) {
695695
// Require at least the header and an IFD with 1 entry
696696
if (size < FujiMnHeader::sizeOfSignature() + 18)
697697
return nullptr;
698698
return newFujiMn2(tag, group, mnGroup);
699699
}
700700

701-
TiffComponent* newFujiMn2(uint16_t tag, IfdId group, IfdId mnGroup) {
702-
return new TiffIfdMakernote(tag, group, mnGroup, new FujiMnHeader);
701+
std::unique_ptr<TiffComponent> newFujiMn2(uint16_t tag, IfdId group, IfdId mnGroup) {
702+
return std::make_unique<TiffIfdMakernote>(tag, group, mnGroup, std::make_unique<FujiMnHeader>());
703703
}
704704

705-
TiffComponent* newNikonMn(uint16_t tag, IfdId group, IfdId /*mnGroup*/, const byte* pData, size_t size,
706-
ByteOrder /*byteOrder*/) {
705+
std::unique_ptr<TiffComponent> newNikonMn(uint16_t tag, IfdId group, IfdId /*mnGroup*/, const byte* pData, size_t size,
706+
ByteOrder /*byteOrder*/) {
707707
// If there is no "Nikon" string it must be Nikon1 format
708708
if (size < 6 || std::string(reinterpret_cast<const char*>(pData), 6) != std::string("Nikon\0", 6)) {
709709
// Require at least an IFD with 1 entry
@@ -727,28 +727,28 @@ TiffComponent* newNikonMn(uint16_t tag, IfdId group, IfdId /*mnGroup*/, const by
727727
return newNikon3Mn2(tag, group, IfdId::nikon3Id);
728728
}
729729

730-
TiffComponent* newNikon2Mn2(uint16_t tag, IfdId group, IfdId mnGroup) {
731-
return new TiffIfdMakernote(tag, group, mnGroup, new Nikon2MnHeader);
730+
std::unique_ptr<TiffComponent> newNikon2Mn2(uint16_t tag, IfdId group, IfdId mnGroup) {
731+
return std::make_unique<TiffIfdMakernote>(tag, group, mnGroup, std::make_unique<Nikon2MnHeader>());
732732
}
733733

734-
TiffComponent* newNikon3Mn2(uint16_t tag, IfdId group, IfdId mnGroup) {
735-
return new TiffIfdMakernote(tag, group, mnGroup, new Nikon3MnHeader);
734+
std::unique_ptr<TiffComponent> newNikon3Mn2(uint16_t tag, IfdId group, IfdId mnGroup) {
735+
return std::make_unique<TiffIfdMakernote>(tag, group, mnGroup, std::make_unique<Nikon3MnHeader>());
736736
}
737737

738-
TiffComponent* newPanasonicMn(uint16_t tag, IfdId group, IfdId mnGroup, const byte* /*pData*/, size_t size,
739-
ByteOrder /*byteOrder*/) {
738+
std::unique_ptr<TiffComponent> newPanasonicMn(uint16_t tag, IfdId group, IfdId mnGroup, const byte* /*pData*/,
739+
size_t size, ByteOrder /*byteOrder*/) {
740740
// Require at least the header and an IFD with 1 entry, but without a next pointer
741741
if (size < PanasonicMnHeader::sizeOfSignature() + 14)
742742
return nullptr;
743743
return newPanasonicMn2(tag, group, mnGroup);
744744
}
745745

746-
TiffComponent* newPanasonicMn2(uint16_t tag, IfdId group, IfdId mnGroup) {
747-
return new TiffIfdMakernote(tag, group, mnGroup, new PanasonicMnHeader, false);
746+
std::unique_ptr<TiffComponent> newPanasonicMn2(uint16_t tag, IfdId group, IfdId mnGroup) {
747+
return std::make_unique<TiffIfdMakernote>(tag, group, mnGroup, std::make_unique<PanasonicMnHeader>(), false);
748748
}
749749

750-
TiffComponent* newPentaxMn(uint16_t tag, IfdId group, IfdId /*mnGroup*/, const byte* pData, size_t size,
751-
ByteOrder /*byteOrder*/) {
750+
std::unique_ptr<TiffComponent> newPentaxMn(uint16_t tag, IfdId group, IfdId /*mnGroup*/, const byte* pData, size_t size,
751+
ByteOrder /*byteOrder*/) {
752752
if (size > 8 && std::string(reinterpret_cast<const char*>(pData), 8) == std::string("PENTAX \0", 8)) {
753753
// Require at least the header and an IFD with 1 entry
754754
if (size < PentaxDngMnHeader::sizeOfSignature() + 18)
@@ -764,16 +764,16 @@ TiffComponent* newPentaxMn(uint16_t tag, IfdId group, IfdId /*mnGroup*/, const b
764764
return nullptr;
765765
}
766766

767-
TiffComponent* newPentaxMn2(uint16_t tag, IfdId group, IfdId mnGroup) {
768-
return new TiffIfdMakernote(tag, group, mnGroup, new PentaxMnHeader);
767+
std::unique_ptr<TiffComponent> newPentaxMn2(uint16_t tag, IfdId group, IfdId mnGroup) {
768+
return std::make_unique<TiffIfdMakernote>(tag, group, mnGroup, std::make_unique<PentaxMnHeader>());
769769
}
770770

771-
TiffComponent* newPentaxDngMn2(uint16_t tag, IfdId group, IfdId mnGroup) {
772-
return new TiffIfdMakernote(tag, group, mnGroup, new PentaxDngMnHeader);
771+
std::unique_ptr<TiffComponent> newPentaxDngMn2(uint16_t tag, IfdId group, IfdId mnGroup) {
772+
return std::make_unique<TiffIfdMakernote>(tag, group, mnGroup, std::make_unique<PentaxDngMnHeader>());
773773
}
774774

775-
TiffComponent* newSamsungMn(uint16_t tag, IfdId group, IfdId mnGroup, const byte* pData, size_t size,
776-
ByteOrder /*byteOrder*/) {
775+
std::unique_ptr<TiffComponent> newSamsungMn(uint16_t tag, IfdId group, IfdId mnGroup, const byte* pData, size_t size,
776+
ByteOrder /*byteOrder*/) {
777777
if (size > 4 && std::string(reinterpret_cast<const char*>(pData), 4) == std::string("AOC\0", 4)) {
778778
// Samsung branded Pentax camera:
779779
// Require at least the header and an IFD with 1 entry
@@ -788,24 +788,24 @@ TiffComponent* newSamsungMn(uint16_t tag, IfdId group, IfdId mnGroup, const byte
788788
return newSamsungMn2(tag, group, mnGroup);
789789
}
790790

791-
TiffComponent* newSamsungMn2(uint16_t tag, IfdId group, IfdId mnGroup) {
792-
return new TiffIfdMakernote(tag, group, mnGroup, new SamsungMnHeader);
791+
std::unique_ptr<TiffComponent> newSamsungMn2(uint16_t tag, IfdId group, IfdId mnGroup) {
792+
return std::make_unique<TiffIfdMakernote>(tag, group, mnGroup, std::make_unique<SamsungMnHeader>());
793793
}
794794

795-
TiffComponent* newSigmaMn(uint16_t tag, IfdId group, IfdId mnGroup, const byte* /*pData*/, size_t size,
796-
ByteOrder /*byteOrder*/) {
795+
std::unique_ptr<TiffComponent> newSigmaMn(uint16_t tag, IfdId group, IfdId mnGroup, const byte* /*pData*/, size_t size,
796+
ByteOrder /*byteOrder*/) {
797797
// Require at least the header and an IFD with 1 entry
798798
if (size < SigmaMnHeader::sizeOfSignature() + 18)
799799
return nullptr;
800800
return newSigmaMn2(tag, group, mnGroup);
801801
}
802802

803-
TiffComponent* newSigmaMn2(uint16_t tag, IfdId group, IfdId mnGroup) {
804-
return new TiffIfdMakernote(tag, group, mnGroup, new SigmaMnHeader);
803+
std::unique_ptr<TiffComponent> newSigmaMn2(uint16_t tag, IfdId group, IfdId mnGroup) {
804+
return std::make_unique<TiffIfdMakernote>(tag, group, mnGroup, std::make_unique<SigmaMnHeader>());
805805
}
806806

807-
TiffComponent* newSonyMn(uint16_t tag, IfdId group, IfdId /*mnGroup*/, const byte* pData, size_t size,
808-
ByteOrder /*byteOrder*/) {
807+
std::unique_ptr<TiffComponent> newSonyMn(uint16_t tag, IfdId group, IfdId /*mnGroup*/, const byte* pData, size_t size,
808+
ByteOrder /*byteOrder*/) {
809809
// If there is no "SONY DSC " string we assume it's a simple IFD Makernote
810810
if (size < 12 || std::string(reinterpret_cast<const char*>(pData), 12) != std::string("SONY DSC \0\0\0", 12)) {
811811
// Require at least an IFD with 1 entry
@@ -819,16 +819,16 @@ TiffComponent* newSonyMn(uint16_t tag, IfdId group, IfdId /*mnGroup*/, const byt
819819
return newSony1Mn2(tag, group, IfdId::sony1Id);
820820
}
821821

822-
TiffComponent* newSony1Mn2(uint16_t tag, IfdId group, IfdId mnGroup) {
823-
return new TiffIfdMakernote(tag, group, mnGroup, new SonyMnHeader, false);
822+
std::unique_ptr<TiffComponent> newSony1Mn2(uint16_t tag, IfdId group, IfdId mnGroup) {
823+
return std::make_unique<TiffIfdMakernote>(tag, group, mnGroup, std::make_unique<SonyMnHeader>(), false);
824824
}
825825

826-
TiffComponent* newSony2Mn2(uint16_t tag, IfdId group, IfdId mnGroup) {
827-
return new TiffIfdMakernote(tag, group, mnGroup, nullptr, true);
826+
std::unique_ptr<TiffComponent> newSony2Mn2(uint16_t tag, IfdId group, IfdId mnGroup) {
827+
return std::make_unique<TiffIfdMakernote>(tag, group, mnGroup, nullptr, true);
828828
}
829829

830-
TiffComponent* newCasioMn(uint16_t tag, IfdId group, IfdId /* mnGroup*/, const byte* pData, size_t size,
831-
ByteOrder /* byteOrder */) {
830+
std::unique_ptr<TiffComponent> newCasioMn(uint16_t tag, IfdId group, IfdId /* mnGroup*/, const byte* pData, size_t size,
831+
ByteOrder /* byteOrder */) {
832832
if (size > 6 && std::string(reinterpret_cast<const char*>(pData), 6) == std::string("QVC\0\0\0", 6))
833833
return newCasio2Mn2(tag, group, IfdId::casio2Id);
834834
// Require at least an IFD with 1 entry, but not necessarily a next pointer
@@ -837,8 +837,8 @@ TiffComponent* newCasioMn(uint16_t tag, IfdId group, IfdId /* mnGroup*/, const b
837837
return newIfdMn2(tag, group, IfdId::casioId);
838838
}
839839

840-
TiffComponent* newCasio2Mn2(uint16_t tag, IfdId group, IfdId mnGroup) {
841-
return new TiffIfdMakernote(tag, group, mnGroup, new Casio2MnHeader);
840+
std::unique_ptr<TiffComponent> newCasio2Mn2(uint16_t tag, IfdId group, IfdId mnGroup) {
841+
return std::make_unique<TiffIfdMakernote>(tag, group, mnGroup, std::make_unique<Casio2MnHeader>());
842842
}
843843

844844
//! Structure for an index into the array set of complex binary arrays.

0 commit comments

Comments
 (0)