Skip to content

Commit

Permalink
return make_unique directly
Browse files Browse the repository at this point in the history
Simpler

Signed-off-by: Rosen Penev <rosenp@gmail.com>
  • Loading branch information
neheb committed Jul 25, 2022
1 parent 02b0ff3 commit ac3ac4a
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 94 deletions.
27 changes: 9 additions & 18 deletions app/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,34 +199,25 @@ int setModeAndPrintStructure(Exiv2::PrintStructureOption option, const std::stri
int Print::run(const std::string& path) {
try {
path_ = path;
int rc = 0;
switch (Params::instance().printMode_) {
case Params::pmSummary:
rc = Params::instance().greps_.empty() ? printSummary() : printList();
break;
return Params::instance().greps_.empty() ? printSummary() : printList();
case Params::pmList:
rc = printList();
break;
return printList();
case Params::pmComment:
rc = printComment();
break;
return printComment();
case Params::pmPreview:
rc = printPreviewList();
break;
return printPreviewList();
case Params::pmStructure:
rc = printStructure(std::cout, Exiv2::kpsBasic, path_);
break;
return printStructure(std::cout, Exiv2::kpsBasic, path_);
case Params::pmRecursive:
rc = printStructure(std::cout, Exiv2::kpsRecursive, path_);
break;
return printStructure(std::cout, Exiv2::kpsRecursive, path_);
case Params::pmXMP:
rc = setModeAndPrintStructure(Exiv2::kpsXMP, path_, binary());
break;
return setModeAndPrintStructure(Exiv2::kpsXMP, path_, binary());
case Params::pmIccProfile:
rc = setModeAndPrintStructure(Exiv2::kpsIccProfile, path_, binary());
break;
return setModeAndPrintStructure(Exiv2::kpsIccProfile, path_, binary());
}
return rc;
return 0;
} catch (const Exiv2::Error& e) {
std::cerr << "Exiv2 exception in print action for file " << path << ":\n" << e << "\n";
return 1;
Expand Down
14 changes: 5 additions & 9 deletions src/crwimage_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,11 @@ void CiffDirectory::readDirectory(const byte* pData, size_t size, ByteOrder byte

for (uint16_t i = 0; i < count; ++i) {
uint16_t tag = getUShort(pData + o, byteOrder);
std::unique_ptr<CiffComponent> m;
switch (CiffComponent::typeId(tag)) {
case directory:
m = std::make_unique<CiffDirectory>();
break;
default:
m = std::make_unique<CiffEntry>();
break;
}
auto m = [tag]() -> std::unique_ptr<CiffComponent> {
if (CiffComponent::typeId(tag) == TypeId::directory)
return std::make_unique<CiffDirectory>();
return std::make_unique<CiffEntry>();
}();
m->setDir(this->tag());
m->read(pData, size, o, byteOrder);
add(std::move(m));
Expand Down
24 changes: 10 additions & 14 deletions src/exif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,26 +681,22 @@ WriteMethod ExifParser::encode(Blob& blob, const byte* pData, size_t size, ByteO
namespace {
//! @cond IGNORE
Thumbnail::UniquePtr Thumbnail::create(const Exiv2::ExifData& exifData) {
std::unique_ptr<Thumbnail> thumbnail;
const Exiv2::ExifKey k1("Exif.Thumbnail.Compression");
auto pos = exifData.findKey(k1);
if (pos != exifData.end()) {
if (pos->count() == 0)
return thumbnail;
return nullptr;
auto compression = pos->toInt64();
if (compression == 6) {
thumbnail = std::make_unique<JpegThumbnail>();
} else {
thumbnail = std::make_unique<TiffThumbnail>();
}
} else {
const Exiv2::ExifKey k2("Exif.Thumbnail.JPEGInterchangeFormat");
pos = exifData.findKey(k2);
if (pos != exifData.end()) {
thumbnail = std::make_unique<JpegThumbnail>();
}
if (compression == 6)
return std::make_unique<JpegThumbnail>();
return std::make_unique<TiffThumbnail>();
}
return thumbnail;

const Exiv2::ExifKey k2("Exif.Thumbnail.JPEGInterchangeFormat");
pos = exifData.findKey(k2);
if (pos != exifData.end())
return std::make_unique<JpegThumbnail>();
return nullptr;
}

const char* TiffThumbnail::mimeType() const {
Expand Down
22 changes: 9 additions & 13 deletions src/tiffimage_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1807,24 +1807,20 @@ bool TiffTreeStruct::operator==(const TiffTreeStruct::Key& key) const {
}

TiffComponent::UniquePtr TiffCreator::create(uint32_t extendedTag, IfdId group) {
std::unique_ptr<TiffComponent> tc;
auto tag = static_cast<uint16_t>(extendedTag & 0xffff);
const TiffGroupStruct* ts = find(tiffGroupStruct_, TiffGroupStruct::Key(extendedTag, group));
if (ts && ts->newTiffCompFct_) {
tc = ts->newTiffCompFct_(tag, group);
}
if (ts && ts->newTiffCompFct_)
return ts->newTiffCompFct_(tag, group);
#ifdef EXIV2_DEBUG_MESSAGES
else {
if (!ts) {
std::cerr << "Warning: No TIFF structure entry found for ";
} else {
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
<< ", group " << groupName(group) << "\n";
if (!ts)
std::cerr << "Warning: No TIFF structure entry found for ";
else
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
<< ", group " << groupName(group) << "\n";
}
#endif
return tc;
return nullptr;
} // TiffCreator::create

void TiffCreator::getPath(TiffPath& tiffPath, uint32_t extendedTag, IfdId group, uint32_t root) {
Expand Down
59 changes: 19 additions & 40 deletions src/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,72 +19,51 @@ Value::Value(TypeId typeId) : type_(typeId) {
}

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

int Value::setDataArea(const byte* /*buf*/, size_t /*len*/) {
Expand Down

0 comments on commit ac3ac4a

Please sign in to comment.