Skip to content

Commit

Permalink
replace structs with std::pair
Browse files Browse the repository at this point in the history
Simpler.

Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb committed Aug 2, 2022
1 parent ee5dae4 commit 8b976f4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 27 deletions.
8 changes: 4 additions & 4 deletions src/tiffimage_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1803,7 +1803,7 @@ EncoderFct TiffMapping::findEncoder(const std::string& make, uint32_t extendedTa
}

bool TiffTreeStruct::operator==(const TiffTreeStruct::Key& key) const {
return key.r_ == root_ && key.g_ == group_;
return key.first == root_ && key.second == group_;
}

TiffComponent::UniquePtr TiffCreator::create(uint32_t extendedTag, IfdId group) {
Expand Down Expand Up @@ -2036,7 +2036,7 @@ bool TiffHeaderBase::isImageTag(uint16_t /*tag*/, IfdId /*group*/, const Primary

bool isTiffImageTag(uint16_t tag, IfdId group) {
//! List of TIFF image tags
static const TiffImgTagStruct tiffImageTags[] = {
static constexpr TiffImgTagStruct tiffImageTags[] = {
{0x00fe, IfdId::ifd0Id}, // Exif.Image.NewSubfileType
{0x00ff, IfdId::ifd0Id}, // Exif.Image.SubfileType
{0x0100, IfdId::ifd0Id}, // Exif.Image.ImageWidth
Expand Down Expand Up @@ -2107,15 +2107,15 @@ bool isTiffImageTag(uint16_t tag, IfdId group) {

// If tag, group is one of the image tags listed above -> bingo!
#ifdef EXIV2_DEBUG_MESSAGES
if (find(tiffImageTags, TiffImgTagStruct::Key(tag, group))) {
if (find(tiffImageTags, TiffImgTagStruct(tag, group))) {
ExifKey key(tag, groupName(group));
std::cerr << "Image tag: " << key << " (3)\n";
return true;
}
std::cerr << "Not an image tag: " << tag << " (4)\n";
return false;
#endif
return find(tiffImageTags, TiffImgTagStruct::Key(tag, group));
return find(tiffImageTags, TiffImgTagStruct(tag, group));
}

TiffHeader::TiffHeader(ByteOrder byteOrder, uint32_t offset, bool hasImageTags) :
Expand Down
25 changes: 2 additions & 23 deletions src/tiffimage_int.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,7 @@ class TiffHeader : public TiffHeaderBase {
/*!
@brief Data structure used to list image tags for TIFF and TIFF-like images.
*/
struct TiffImgTagStruct {
//! Search key for TIFF image tag structure.
using Key = std::pair<uint16_t, IfdId>;
//! Comparison operator to compare a TiffImgTagStruct with a TiffImgTagStruct::Key
bool operator==(const Key& key) const {
auto [t, g] = key;
return g == group_ && t == tag_;
}

// DATA
uint16_t tag_; //!< Image tag
IfdId group_; //!< Group that contains the image tag
}; // struct TiffImgTagStruct
using TiffImgTagStruct = std::pair<uint16_t, IfdId>;

/*!
@brief Data structure used as a row (element) of a table (array)
Expand Down Expand Up @@ -176,7 +164,7 @@ struct TiffGroupStruct {
use standard TIFF layout.
*/
struct TiffTreeStruct {
struct Key;
using Key = std::pair<uint32_t, IfdId>;
//! Comparison operator to compare a TiffTreeStruct with a TiffTreeStruct::Key
bool operator==(const Key& key) const;

Expand All @@ -187,15 +175,6 @@ struct TiffTreeStruct {
uint32_t parentExtTag_; //!< Parent tag (32 bit so that it can contain special tags)
};

//! Search key for TIFF tree structure.
struct TiffTreeStruct::Key {
//! Constructor
Key(uint32_t r, IfdId g) : r_(r), g_(g) {
}
uint32_t r_; //!< Root
IfdId g_; //!< %Group
};

/*!
@brief TIFF component factory.
*/
Expand Down

0 comments on commit 8b976f4

Please sign in to comment.