Skip to content

Commit 262d0ee

Browse files
committed
struct to std::pair conversions
Signed-off-by: Rosen Penev <[email protected]>
1 parent e82be13 commit 262d0ee

File tree

4 files changed

+27
-50
lines changed

4 files changed

+27
-50
lines changed

src/crwimage_int.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ class RotationMap {
2222

2323
private:
2424
//! Helper structure for the mapping list
25-
struct OmList {
26-
uint16_t orientation; //!< Exif orientation value
27-
int32_t degrees; //!< CRW Rotation degrees
28-
};
25+
using OmList = std::pair<uint16_t, int32_t>;
2926
// DATA
3027
static const OmList omList_[];
3128
}; // class RotationMap
@@ -520,7 +517,7 @@ CiffComponent* CiffDirectory::doFindComponent(uint16_t crwTagId, uint16_t crwDir
520517
void CiffHeader::add(uint16_t crwTagId, uint16_t crwDir, DataBuf&& buf) {
521518
CrwDirs crwDirs;
522519
CrwMap::loadStack(crwDirs, crwDir);
523-
[[maybe_unused]] uint16_t rootDirectory = crwDirs.top().crwDir_;
520+
[[maybe_unused]] auto [rootDirectory, _] = crwDirs.top();
524521
crwDirs.pop();
525522
if (!pRootDir_) {
526523
pRootDir_ = std::make_unique<CiffDirectory>();
@@ -553,18 +550,18 @@ CiffComponent* CiffDirectory::doAdd(CrwDirs& crwDirs, uint16_t crwTagId) {
553550
set value
554551
*/
555552
if (!crwDirs.empty()) {
556-
CrwSubDir csd = crwDirs.top();
553+
auto [dir, parent] = crwDirs.top();
557554
crwDirs.pop();
558555
// Find the directory
559556
for (auto&& component : components_) {
560-
if (component->tag() == csd.crwDir_) {
557+
if (component->tag() == dir) {
561558
cc_ = component;
562559
break;
563560
}
564561
}
565562
if (!cc_) {
566563
// Directory doesn't exist yet, add it
567-
m_ = std::make_unique<CiffDirectory>(csd.crwDir_, csd.parent_);
564+
m_ = std::make_unique<CiffDirectory>(dir, parent);
568565
cc_ = m_.get();
569566
add(std::move(m_));
570567
}
@@ -592,7 +589,6 @@ void CiffHeader::remove(uint16_t crwTagId, uint16_t crwDir) {
592589
if (pRootDir_) {
593590
CrwDirs crwDirs;
594591
CrwMap::loadStack(crwDirs, crwDir);
595-
[[maybe_unused]] uint16_t rootDirectory = crwDirs.top().crwDir_;
596592
crwDirs.pop();
597593
pRootDir_->remove(crwDirs, crwTagId);
598594
}
@@ -608,11 +604,11 @@ void CiffComponent::doRemove(CrwDirs& /*crwDirs*/, uint16_t /*crwTagId*/) {
608604

609605
void CiffDirectory::doRemove(CrwDirs& crwDirs, uint16_t crwTagId) {
610606
if (!crwDirs.empty()) {
611-
CrwSubDir csd = crwDirs.top();
607+
auto [dir, _] = crwDirs.top();
612608
crwDirs.pop();
613609
// Find the directory
614610
for (auto i = components_.begin(); i != components_.end(); ++i) {
615-
if ((*i)->tag() == csd.crwDir_) {
611+
if ((*i)->tag() == dir) {
616612
// Recursive call to next lower level directory
617613
(*i)->remove(crwDirs, crwTagId);
618614
if ((*i)->empty())
@@ -743,8 +739,8 @@ void CrwMap::decodeArray(const CiffComponent& ciffComponent, const CrwMapping* p
743739
if (ifdId == canonSiId) {
744740
// Exif.Photo.FNumber
745741
float f = fnumber(canonEv(aperture));
746-
Rational r = floatToRationalCast(f);
747-
URational ur(r.first, r.second);
742+
auto [r, s] = floatToRationalCast(f);
743+
auto ur = URational(r, s);
748744
URationalValue fn;
749745
fn.value_.push_back(ur);
750746
image.exifData().add(ExifKey("Exif.Photo.FNumber"), &fn);
@@ -835,9 +831,10 @@ void CrwMap::decodeBasic(const CiffComponent& ciffComponent, const CrwMapping* p
835831

836832
void CrwMap::loadStack(CrwDirs& crwDirs, uint16_t crwDir) {
837833
for (auto&& crw : crwSubDir_) {
838-
if (crw.crwDir_ == crwDir) {
834+
auto&& [dir, parent] = crw;
835+
if (dir == crwDir) {
839836
crwDirs.push(crw);
840-
crwDir = crw.parent_;
837+
crwDir = parent;
841838
}
842839
}
843840
} // CrwMap::loadStack

src/crwimage_int.hpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace Exiv2::Internal {
2020
class CiffHeader;
2121
class CiffComponent;
2222
struct CrwMapping;
23-
struct CrwSubDir;
23+
using CrwSubDir = std::pair<uint16_t, uint16_t>;
2424

2525
// *****************************************************************************
2626
// type definitions
@@ -486,12 +486,6 @@ class CiffHeader {
486486

487487
}; // class CiffHeader
488488

489-
//! Structure for the CIFF directory hierarchy
490-
struct CrwSubDir {
491-
uint16_t crwDir_; //!< Directory tag
492-
uint16_t parent_; //!< Parent directory tag
493-
}; // struct CrwSubDir
494-
495489
/*!
496490
@brief Structure for a mapping table for conversion of CIFF entries to
497491
image metadata and vice versa.

src/tags_int.hpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,7 @@ struct TagDetails {
213213
@brief Helper structure for lookup tables for translations of bitmask
214214
values to human readable labels.
215215
*/
216-
struct TagDetailsBitmask {
217-
uint32_t mask_; //!< Bitmask value
218-
const char* label_; //!< Description of the tag value
219-
}; // struct TagDetailsBitmask
216+
using TagDetailsBitmask = std::pair<uint32_t, const char*>;
220217

221218
/*!
222219
@brief Helper structure for lookup tables for translations of controlled
@@ -271,20 +268,20 @@ template <int N, const TagDetailsBitmask (&array)[N]>
271268
std::ostream& printTagBitmask(std::ostream& os, const Value& value, const ExifData*) {
272269
const auto val = value.toUint32();
273270
if (val == 0 && N > 0) {
274-
const TagDetailsBitmask* td = *(&array);
275-
if (td->mask_ == 0)
276-
return os << exvGettext(td->label_);
271+
auto [mask, label] = *array;
272+
if (mask == 0)
273+
return os << exvGettext(label);
277274
}
278275
bool sep = false;
279276
for (int i = 0; i < N; ++i) {
280277
// *& acrobatics is a workaround for a MSVC 7.1 bug
281-
const TagDetailsBitmask* td = *(&array) + i;
278+
auto [mask, label] = *(array + i);
282279

283-
if (val & td->mask_) {
280+
if (val & mask) {
284281
if (sep) {
285-
os << ", " << exvGettext(td->label_);
282+
os << ", " << exvGettext(label);
286283
} else {
287-
os << exvGettext(td->label_);
284+
os << exvGettext(label);
288285
sep = true;
289286
}
290287
}

src/tiffimage_int.hpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,11 @@ class TiffHeader : public TiffHeaderBase {
134134
*/
135135
struct TiffImgTagStruct {
136136
//! Search key for TIFF image tag structure.
137-
struct Key {
138-
//! Constructor
139-
Key(uint16_t t, IfdId g) : t_(t), g_(g) {
140-
}
141-
uint16_t t_; //!< %Tag
142-
IfdId g_; //!< %Group
143-
};
144-
137+
using Key = std::pair<uint16_t, IfdId>;
145138
//! Comparison operator to compare a TiffImgTagStruct with a TiffImgTagStruct::Key
146139
bool operator==(const Key& key) const {
147-
return key.g_ == group_ && key.t_ == tag_;
140+
auto [t, g] = key;
141+
return g == group_ && t == tag_;
148142
}
149143

150144
// DATA
@@ -158,17 +152,12 @@ struct TiffImgTagStruct {
158152
*/
159153
struct TiffGroupStruct {
160154
//! Search key for TIFF group structure.
161-
struct Key {
162-
//! Constructor
163-
Key(uint32_t e, IfdId g) : e_(e), g_(g) {
164-
}
165-
uint32_t e_; //!< Extended tag
166-
IfdId g_; //!< %Group
167-
};
155+
using Key = std::pair<uint32_t, IfdId>;
168156

169157
//! Comparison operator to compare a TiffGroupStruct with a TiffGroupStruct::Key
170158
bool operator==(const Key& key) const {
171-
return key.g_ == group_ && (Tag::all == extendedTag_ || key.e_ == extendedTag_);
159+
auto [e, g] = key;
160+
return g == group_ && (Tag::all == extendedTag_ || e == extendedTag_);
172161
}
173162
//! Return the tag corresponding to the extended tag
174163
[[nodiscard]] uint16_t tag() const {

0 commit comments

Comments
 (0)