Skip to content

Commit 1360b5a

Browse files
committed
use unique_ptr for ExifData
Avoids needing a definition in header. Signed-off-by: Rosen Penev <[email protected]>
1 parent b3ef14e commit 1360b5a

File tree

2 files changed

+39
-41
lines changed

2 files changed

+39
-41
lines changed

src/tiffvisitor_int.cpp

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ void TiffDecoder::visitBinaryElement(TiffBinaryElement* object) {
447447
TiffEncoder::TiffEncoder(ExifData& exifData, IptcData& iptcData, XmpData& xmpData, TiffComponent* pRoot,
448448
bool isNewImage, PrimaryGroups pPrimaryGroups, const TiffHeaderBase* pHeader,
449449
FindEncoderFct findEncoderFct) :
450-
exifData_(exifData),
450+
exifData_(std::make_unique<ExifData>(exifData)),
451451
iptcData_(iptcData),
452452
xmpData_(xmpData),
453453
pHeader_(pHeader),
@@ -462,7 +462,7 @@ TiffEncoder::TiffEncoder(ExifData& exifData, IptcData& iptcData, XmpData& xmpDat
462462

463463
// Find camera make
464464
ExifKey key("Exif.Image.Make");
465-
if (auto pos = exifData_.findKey(key); pos != exifData_.end()) {
465+
if (auto pos = exifData_->findKey(key); pos != exifData_->end()) {
466466
make_ = pos->toString();
467467
}
468468
if (make_.empty() && pRoot_) {
@@ -482,19 +482,19 @@ void TiffEncoder::encodeIptc() {
482482
// not exist, create a new IPTCNAA Exif tag.
483483
bool del = false;
484484
ExifKey iptcNaaKey("Exif.Image.IPTCNAA");
485-
auto pos = exifData_.findKey(iptcNaaKey);
486-
if (pos != exifData_.end()) {
485+
auto pos = exifData_->findKey(iptcNaaKey);
486+
if (pos != exifData_->end()) {
487487
iptcNaaKey.setIdx(pos->idx());
488-
exifData_.erase(pos);
488+
exifData_->erase(pos);
489489
del = true;
490490
}
491491
DataBuf rawIptc = IptcParser::encode(iptcData_);
492492
ExifKey irbKey("Exif.Image.ImageResources");
493-
pos = exifData_.findKey(irbKey);
494-
if (pos != exifData_.end()) {
493+
pos = exifData_->findKey(irbKey);
494+
if (pos != exifData_->end()) {
495495
irbKey.setIdx(pos->idx());
496496
}
497-
if (!rawIptc.empty() && (del || pos == exifData_.end())) {
497+
if (!rawIptc.empty() && (del || pos == exifData_->end())) {
498498
auto value = Value::create(unsignedLong);
499499
DataBuf buf;
500500
if (rawIptc.size() % 4 != 0) {
@@ -506,21 +506,21 @@ void TiffEncoder::encodeIptc() {
506506
}
507507
value->read(buf.data(), buf.size(), byteOrder_);
508508
Exifdatum iptcDatum(iptcNaaKey, value.get());
509-
exifData_.add(iptcDatum);
510-
pos = exifData_.findKey(irbKey); // needed after add()
509+
exifData_->add(iptcDatum);
510+
pos = exifData_->findKey(irbKey); // needed after add()
511511
}
512512
// Also update IPTC IRB in Exif.Image.ImageResources if it exists,
513513
// but don't create it if not.
514-
if (pos != exifData_.end()) {
514+
if (pos != exifData_->end()) {
515515
DataBuf irbBuf(pos->value().size());
516516
pos->value().copy(irbBuf.data(), invalidByteOrder);
517517
irbBuf = Photoshop::setIptcIrb(irbBuf.c_data(), irbBuf.size(), iptcData_);
518-
exifData_.erase(pos);
518+
exifData_->erase(pos);
519519
if (!irbBuf.empty()) {
520520
auto value = Value::create(unsignedByte);
521521
value->read(irbBuf.data(), irbBuf.size(), invalidByteOrder);
522522
Exifdatum iptcDatum(irbKey, value.get());
523-
exifData_.add(iptcDatum);
523+
exifData_->add(iptcDatum);
524524
}
525525
}
526526
} // TiffEncoder::encodeIptc
@@ -529,9 +529,9 @@ void TiffEncoder::encodeXmp() {
529529
#ifdef EXV_HAVE_XMP_TOOLKIT
530530
ExifKey xmpKey("Exif.Image.XMLPacket");
531531
// Remove any existing XMP Exif tag
532-
if (auto pos = exifData_.findKey(xmpKey); pos != exifData_.end()) {
532+
if (auto pos = exifData_->findKey(xmpKey); pos != exifData_->end()) {
533533
xmpKey.setIdx(pos->idx());
534-
exifData_.erase(pos);
534+
exifData_->erase(pos);
535535
}
536536
std::string xmpPacket;
537537
if (xmpData_.usePacket()) {
@@ -548,7 +548,7 @@ void TiffEncoder::encodeXmp() {
548548
auto value = Value::create(unsignedByte);
549549
value->read(reinterpret_cast<const byte*>(xmpPacket.data()), xmpPacket.size(), invalidByteOrder);
550550
Exifdatum xmpDatum(xmpKey, value.get());
551-
exifData_.add(xmpDatum);
551+
exifData_->add(xmpDatum);
552552
}
553553
#endif
554554
} // TiffEncoder::encodeXmp
@@ -559,7 +559,7 @@ void TiffEncoder::setDirty(bool flag) {
559559
}
560560

561561
bool TiffEncoder::dirty() const {
562-
return dirty_ || !exifData_.empty();
562+
return dirty_ || !exifData_->empty();
563563
}
564564

565565
void TiffEncoder::visitEntry(TiffEntry* object) {
@@ -621,33 +621,33 @@ void TiffEncoder::visitMnEntry(TiffMnEntry* object) {
621621
} else if (del_) {
622622
// The makernote is made up of decoded tags, delete binary tag
623623
ExifKey key(object->tag(), groupName(object->group()));
624-
auto pos = exifData_.findKey(key);
625-
if (pos != exifData_.end())
626-
exifData_.erase(pos);
624+
auto pos = exifData_->findKey(key);
625+
if (pos != exifData_->end())
626+
exifData_->erase(pos);
627627
}
628628
}
629629

630630
void TiffEncoder::visitIfdMakernote(TiffIfdMakernote* object) {
631-
auto pos = exifData_.findKey(ExifKey("Exif.MakerNote.ByteOrder"));
632-
if (pos != exifData_.end()) {
631+
auto pos = exifData_->findKey(ExifKey("Exif.MakerNote.ByteOrder"));
632+
if (pos != exifData_->end()) {
633633
// Set Makernote byte order
634634
ByteOrder bo = stringToByteOrder(pos->toString());
635635
if (bo != invalidByteOrder && bo != object->byteOrder()) {
636636
object->setByteOrder(bo);
637637
setDirty();
638638
}
639639
if (del_)
640-
exifData_.erase(pos);
640+
exifData_->erase(pos);
641641
}
642642
if (del_) {
643643
// Remove remaining synthesized tags
644644
static constexpr auto synthesizedTags = std::array{
645645
"Exif.MakerNote.Offset",
646646
};
647647
for (auto synthesizedTag : synthesizedTags) {
648-
pos = exifData_.findKey(ExifKey(synthesizedTag));
649-
if (pos != exifData_.end())
650-
exifData_.erase(pos);
648+
pos = exifData_->findKey(ExifKey(synthesizedTag));
649+
if (pos != exifData_->end())
650+
exifData_->erase(pos);
651651
}
652652
}
653653
// Modify encoder for Makernote peculiarities, byte order
@@ -708,18 +708,18 @@ bool TiffEncoder::isImageTag(uint16_t tag, IfdId group) const {
708708
}
709709

710710
void TiffEncoder::encodeTiffComponent(TiffEntryBase* object, const Exifdatum* datum) {
711-
auto pos = exifData_.end();
711+
auto pos = exifData_->end();
712712
const Exifdatum* ed = datum;
713713
if (!ed) {
714714
// Non-intrusive writing: find matching tag
715715
ExifKey key(object->tag(), groupName(object->group()));
716-
pos = exifData_.findKey(key);
717-
if (pos != exifData_.end()) {
716+
pos = exifData_->findKey(key);
717+
if (pos != exifData_->end()) {
718718
ed = &(*pos);
719719
if (object->idx() != pos->idx()) {
720720
// Try to find exact match (in case of duplicate tags)
721-
auto pos2 = std::find_if(exifData_.begin(), exifData_.end(), FindExifdatum2(object->group(), object->idx()));
722-
if (pos2 != exifData_.end() && pos2->key() == key.key()) {
721+
auto pos2 = std::find_if(exifData_->begin(), exifData_->end(), FindExifdatum2(object->group(), object->idx()));
722+
if (pos2 != exifData_->end() && pos2->key() == key.key()) {
723723
ed = &(*pos2);
724724
pos = pos2; // make sure we delete the correct tag below
725725
}
@@ -747,8 +747,8 @@ void TiffEncoder::encodeTiffComponent(TiffEntryBase* object, const Exifdatum* da
747747
object->encode(*this, ed);
748748
}
749749
}
750-
if (del_ && pos != exifData_.end()) {
751-
exifData_.erase(pos);
750+
if (del_ && pos != exifData_->end()) {
751+
exifData_->erase(pos);
752752
}
753753
#ifdef EXIV2_DEBUG_MESSAGES
754754
std::cerr << "\n";
@@ -813,9 +813,9 @@ void TiffEncoder::encodeImageEntry(TiffImageEntry* object, const Exifdatum* datu
813813
#endif
814814
// Set pseudo strips (without a data pointer) from the size tag
815815
ExifKey key(object->szTag(), groupName(object->szGroup()));
816-
auto pos = exifData_.findKey(key);
816+
auto pos = exifData_->findKey(key);
817817
const byte* zero = nullptr;
818-
if (pos == exifData_.end()) {
818+
if (pos == exifData_->end()) {
819819
#ifndef SUPPRESS_WARNINGS
820820
EXV_ERROR << "Size tag " << key << " not found. Writing only one strip.\n";
821821
#endif
@@ -924,8 +924,8 @@ void TiffEncoder::add(TiffComponent* pRootDir, TiffComponent::UniquePtr pSourceD
924924
// iterate over all remaining entries.
925925
del_ = false;
926926

927-
auto posBo = exifData_.end();
928-
for (auto i = exifData_.begin(); i != exifData_.end(); ++i) {
927+
auto posBo = exifData_->end();
928+
for (auto i = exifData_->begin(); i != exifData_->end(); ++i) {
929929
IfdId group = groupId(i->groupName());
930930
// Skip synthesized info tags
931931
if (group == IfdId::mnId) {
@@ -962,7 +962,7 @@ void TiffEncoder::add(TiffComponent* pRootDir, TiffComponent::UniquePtr pSourceD
962962
visit/encodeIfdMakernote is not called in this case and there
963963
can't be an Exif tag which corresponds to this component.
964964
*/
965-
if (posBo == exifData_.end())
965+
if (posBo == exifData_->end())
966966
return;
967967

968968
TiffFinder finder(0x927c, IfdId::exifId);

src/tiffvisitor_int.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
#define TIFFVISITOR_INT_HPP_
55

66
// *****************************************************************************
7-
// included header files
8-
#include "exif.hpp"
97

108
#include "tiffcomposite_int.hpp"
119

@@ -508,7 +506,7 @@ class TiffEncoder : public TiffVisitor {
508506
//@}
509507

510508
// DATA
511-
ExifData exifData_; //!< Copy of the Exif data to encode
509+
std::unique_ptr<ExifData> exifData_; //!< Copy of the Exif data to encode
512510
const IptcData& iptcData_; //!< IPTC data to encode, just a reference
513511
const XmpData& xmpData_; //!< XMP data to encode, just a reference
514512
bool del_{true}; //!< Indicates if Exif data entries should be deleted after encoding

0 commit comments

Comments
 (0)