return make_unique directly

Simpler

Signed-off-by: Rosen Penev <rosenp@gmail.com>
main
Rosen Penev 3 years ago
parent 02b0ff39d7
commit 3ae1d3b48e

@ -199,34 +199,25 @@ int setModeAndPrintStructure(Exiv2::PrintStructureOption option, const std::stri
int Print::run(const std::string& path) { int Print::run(const std::string& path) {
try { try {
path_ = path; path_ = path;
int rc = 0;
switch (Params::instance().printMode_) { switch (Params::instance().printMode_) {
case Params::pmSummary: case Params::pmSummary:
rc = Params::instance().greps_.empty() ? printSummary() : printList(); return Params::instance().greps_.empty() ? printSummary() : printList();
break;
case Params::pmList: case Params::pmList:
rc = printList(); return printList();
break;
case Params::pmComment: case Params::pmComment:
rc = printComment(); return printComment();
break;
case Params::pmPreview: case Params::pmPreview:
rc = printPreviewList(); return printPreviewList();
break;
case Params::pmStructure: case Params::pmStructure:
rc = printStructure(std::cout, Exiv2::kpsBasic, path_); return printStructure(std::cout, Exiv2::kpsBasic, path_);
break;
case Params::pmRecursive: case Params::pmRecursive:
rc = printStructure(std::cout, Exiv2::kpsRecursive, path_); return printStructure(std::cout, Exiv2::kpsRecursive, path_);
break;
case Params::pmXMP: case Params::pmXMP:
rc = setModeAndPrintStructure(Exiv2::kpsXMP, path_, binary()); return setModeAndPrintStructure(Exiv2::kpsXMP, path_, binary());
break;
case Params::pmIccProfile: case Params::pmIccProfile:
rc = setModeAndPrintStructure(Exiv2::kpsIccProfile, path_, binary()); return setModeAndPrintStructure(Exiv2::kpsIccProfile, path_, binary());
break;
} }
return rc; return 0;
} catch (const Exiv2::Error& e) { } catch (const Exiv2::Error& e) {
std::cerr << "Exiv2 exception in print action for file " << path << ":\n" << e << "\n"; std::cerr << "Exiv2 exception in print action for file " << path << ":\n" << e << "\n";
return 1; return 1;

@ -246,15 +246,11 @@ void CiffDirectory::readDirectory(const byte* pData, size_t size, ByteOrder byte
for (uint16_t i = 0; i < count; ++i) { for (uint16_t i = 0; i < count; ++i) {
uint16_t tag = getUShort(pData + o, byteOrder); uint16_t tag = getUShort(pData + o, byteOrder);
std::unique_ptr<CiffComponent> m; auto m = [this, tag]() -> std::unique_ptr<CiffComponent> {
switch (CiffComponent::typeId(tag)) { if (this->typeId(tag) == TypeId::directory)
case directory: return std::make_unique<CiffDirectory>();
m = std::make_unique<CiffDirectory>(); return std::make_unique<CiffEntry>();
break; }();
default:
m = std::make_unique<CiffEntry>();
break;
}
m->setDir(this->tag()); m->setDir(this->tag());
m->read(pData, size, o, byteOrder); m->read(pData, size, o, byteOrder);
add(std::move(m)); add(std::move(m));

@ -681,26 +681,22 @@ WriteMethod ExifParser::encode(Blob& blob, const byte* pData, size_t size, ByteO
namespace { namespace {
//! @cond IGNORE //! @cond IGNORE
Thumbnail::UniquePtr Thumbnail::create(const Exiv2::ExifData& exifData) { Thumbnail::UniquePtr Thumbnail::create(const Exiv2::ExifData& exifData) {
std::unique_ptr<Thumbnail> thumbnail;
const Exiv2::ExifKey k1("Exif.Thumbnail.Compression"); const Exiv2::ExifKey k1("Exif.Thumbnail.Compression");
auto pos = exifData.findKey(k1); auto pos = exifData.findKey(k1);
if (pos != exifData.end()) { if (pos != exifData.end()) {
if (pos->count() == 0) if (pos->count() == 0)
return thumbnail; return nullptr;
auto compression = pos->toInt64(); auto compression = pos->toInt64();
if (compression == 6) { if (compression == 6)
thumbnail = std::make_unique<JpegThumbnail>(); return std::make_unique<JpegThumbnail>();
} else { return std::make_unique<TiffThumbnail>();
thumbnail = std::make_unique<TiffThumbnail>();
} }
} else {
const Exiv2::ExifKey k2("Exif.Thumbnail.JPEGInterchangeFormat"); const Exiv2::ExifKey k2("Exif.Thumbnail.JPEGInterchangeFormat");
pos = exifData.findKey(k2); pos = exifData.findKey(k2);
if (pos != exifData.end()) { if (pos != exifData.end())
thumbnail = std::make_unique<JpegThumbnail>(); return std::make_unique<JpegThumbnail>();
} return nullptr;
}
return thumbnail;
} }
const char* TiffThumbnail::mimeType() const { const char* TiffThumbnail::mimeType() const {

@ -1807,24 +1807,19 @@ bool TiffTreeStruct::operator==(const TiffTreeStruct::Key& key) const {
} }
TiffComponent::UniquePtr TiffCreator::create(uint32_t extendedTag, IfdId group) { TiffComponent::UniquePtr TiffCreator::create(uint32_t extendedTag, IfdId group) {
std::unique_ptr<TiffComponent> tc;
auto tag = static_cast<uint16_t>(extendedTag & 0xffff); auto tag = static_cast<uint16_t>(extendedTag & 0xffff);
const TiffGroupStruct* ts = find(tiffGroupStruct_, TiffGroupStruct::Key(extendedTag, group)); const TiffGroupStruct* ts = find(tiffGroupStruct_, TiffGroupStruct::Key(extendedTag, group));
if (ts && ts->newTiffCompFct_) { if (ts && ts->newTiffCompFct_)
tc = ts->newTiffCompFct_(tag, group); return ts->newTiffCompFct_(tag, group);
}
#ifdef EXIV2_DEBUG_MESSAGES #ifdef EXIV2_DEBUG_MESSAGES
else { if (!ts)
if (!ts) {
std::cerr << "Warning: No TIFF structure entry found for "; std::cerr << "Warning: No TIFF structure entry found for ";
} else { else
std::cerr << "Warning: No TIFF component creator found for "; std::cerr << "Warning: No TIFF component creator found for ";
}
std::cerr << "extended tag 0x" << std::setw(4) << std::setfill('0') << std::hex << std::right << extendedTag std::cerr << "extended tag 0x" << std::setw(4) << std::setfill('0') << std::hex << std::right << extendedTag
<< ", group " << groupName(group) << "\n"; << ", group " << groupName(group) << "\n";
}
#endif #endif
return tc; return nullptr;
} // TiffCreator::create } // TiffCreator::create
void TiffCreator::getPath(TiffPath& tiffPath, uint32_t extendedTag, IfdId group, uint32_t root) { void TiffCreator::getPath(TiffPath& tiffPath, uint32_t extendedTag, IfdId group, uint32_t root) {

@ -19,72 +19,51 @@ Value::Value(TypeId typeId) : type_(typeId) {
} }
Value::UniquePtr Value::create(TypeId typeId) { Value::UniquePtr Value::create(TypeId typeId) {
std::unique_ptr<Value> value;
switch (typeId) { switch (typeId) {
case invalidTypeId: case invalidTypeId:
case signedByte: case signedByte:
case unsignedByte: case unsignedByte:
value = std::make_unique<DataValue>(typeId); return std::make_unique<DataValue>(typeId);
break;
case asciiString: case asciiString:
value = std::make_unique<AsciiValue>(); return std::make_unique<AsciiValue>();
break;
case unsignedShort: case unsignedShort:
value = std::make_unique<ValueType<uint16_t>>(); return std::make_unique<ValueType<uint16_t>>();
break;
case unsignedLong: case unsignedLong:
case tiffIfd: case tiffIfd:
value = std::make_unique<ValueType<uint32_t>>(typeId); return std::make_unique<ValueType<uint32_t>>(typeId);
break;
case unsignedRational: case unsignedRational:
value = std::make_unique<ValueType<URational>>(); return std::make_unique<ValueType<URational>>();
break;
case undefined: case undefined:
value = std::make_unique<DataValue>(); return std::make_unique<DataValue>();
break;
case signedShort: case signedShort:
value = std::make_unique<ValueType<int16_t>>(); return std::make_unique<ValueType<int16_t>>();
break;
case signedLong: case signedLong:
value = std::make_unique<ValueType<int32_t>>(); return std::make_unique<ValueType<int32_t>>();
break;
case signedRational: case signedRational:
value = std::make_unique<ValueType<Rational>>(); return std::make_unique<ValueType<Rational>>();
break;
case tiffFloat: case tiffFloat:
value = std::make_unique<ValueType<float>>(); return std::make_unique<ValueType<float>>();
break;
case tiffDouble: case tiffDouble:
value = std::make_unique<ValueType<double>>(); return std::make_unique<ValueType<double>>();
break;
case string: case string:
value = std::make_unique<StringValue>(); return std::make_unique<StringValue>();
break;
case date: case date:
value = std::make_unique<DateValue>(); return std::make_unique<DateValue>();
break;
case time: case time:
value = std::make_unique<TimeValue>(); return std::make_unique<TimeValue>();
break;
case comment: case comment:
value = std::make_unique<CommentValue>(); return std::make_unique<CommentValue>();
break;
case xmpText: case xmpText:
value = std::make_unique<XmpTextValue>(); return std::make_unique<XmpTextValue>();
break;
case xmpBag: case xmpBag:
case xmpSeq: case xmpSeq:
case xmpAlt: case xmpAlt:
value = std::make_unique<XmpArrayValue>(typeId); return std::make_unique<XmpArrayValue>(typeId);
break;
case langAlt: case langAlt:
value = std::make_unique<LangAltValue>(); return std::make_unique<LangAltValue>();
break;
default: default:
value = std::make_unique<DataValue>(typeId); return std::make_unique<DataValue>(typeId);
break;
} }
return value;
} // Value::create } // Value::create
int Value::setDataArea(const byte* /*buf*/, size_t /*len*/) { int Value::setDataArea(const byte* /*buf*/, size_t /*len*/) {

Loading…
Cancel
Save