Patch #967 » 0003-exif-convert-metadata-store-from-std-vector-to-std-m.patch
src/exif.cpp | ||
---|---|---|
61 | 61 |
// ***************************************************************************** |
62 | 62 |
namespace { |
63 | 63 | |
64 |
//! Unary predicate that matches a Exifdatum with a given key |
|
65 |
class FindExifdatumByKey { |
|
66 |
public: |
|
67 |
//! Constructor, initializes the object with the key to look for |
|
68 |
FindExifdatumByKey(const std::string& key) : key_(key) {} |
|
69 |
/*! |
|
70 |
@brief Returns true if the key of \em exifdatum is equal |
|
71 |
to that of the object. |
|
72 |
*/ |
|
73 |
bool operator()(const Exiv2::Exifdatum& exifdatum) const |
|
74 |
{ |
|
75 |
return key_ == exifdatum.key(); |
|
76 |
} |
|
77 | ||
78 |
private: |
|
79 |
const std::string& key_; |
|
80 | ||
81 |
}; // class FindExifdatumByKey |
|
82 | ||
83 | 64 |
/*! |
84 | 65 |
@brief Exif %Thumbnail image. This abstract base class provides the |
85 | 66 |
interface for the thumbnail image that is optionally embedded in |
... | ... | |
317 | 298 |
return value_.get() == 0 ? -1 : value_->setDataArea(buf, len); |
318 | 299 |
} |
319 | 300 | |
301 |
const ExifKey& Exifdatum::exifKey() const |
|
302 |
{ |
|
303 |
if (key_.get() == 0) throw Error(8); |
|
304 |
return *key_; |
|
305 |
} |
|
306 | ||
320 | 307 |
std::string Exifdatum::key() const |
321 | 308 |
{ |
322 | 309 |
return key_.get() == 0 ? "" : key_->key(); |
... | ... | |
562 | 549 | |
563 | 550 |
Exifdatum& ExifData::operator[](const std::string& key) |
564 | 551 |
{ |
565 |
ExifKey exifKey(key); |
|
566 |
iterator pos = findKey(exifKey); |
|
567 |
if (pos == end()) { |
|
568 |
add(Exifdatum(exifKey)); |
|
569 |
pos = findKey(exifKey); |
|
552 |
ExifKey k = ExifKey(key); |
|
553 |
ExifMetadata::iterator it = exifMetadata_.find(k); |
|
554 |
if (it != exifMetadata_.end()) { |
|
555 |
return it->second; |
|
570 | 556 |
} |
571 |
return *pos; |
|
557 | ||
558 |
add(Exifdatum(k)); |
|
559 |
return (*this)[key]; |
|
572 | 560 |
} |
573 | 561 | |
574 | 562 |
void ExifData::add(const ExifKey& key, const Value* pValue) |
... | ... | |
579 | 567 |
void ExifData::add(const Exifdatum& exifdatum) |
580 | 568 |
{ |
581 | 569 |
// allow duplicates |
582 |
exifMetadata_.push_back(exifdatum);
|
|
570 |
exifMetadata_.insert(std::make_pair(exifdatum.exifKey(), exifdatum));
|
|
583 | 571 |
} |
584 | 572 | |
585 | 573 |
ExifData::const_iterator ExifData::findKey(const ExifKey& key) const |
586 | 574 |
{ |
587 |
return std::find_if(exifMetadata_.begin(), exifMetadata_.end(), |
|
588 |
FindExifdatumByKey(key.key())); |
|
575 |
return exifMetadata_.find(key); |
|
589 | 576 |
} |
590 | 577 | |
591 | 578 |
ExifData::iterator ExifData::findKey(const ExifKey& key) |
592 | 579 |
{ |
593 |
return std::find_if(exifMetadata_.begin(), exifMetadata_.end(), |
|
594 |
FindExifdatumByKey(key.key())); |
|
580 |
return exifMetadata_.find(key); |
|
595 | 581 |
} |
596 | 582 | |
597 | 583 |
void ExifData::clear() |
... | ... | |
601 | 587 | |
602 | 588 |
void ExifData::sortByKey() |
603 | 589 |
{ |
604 |
exifMetadata_.sort(cmpMetadataByKey);
|
|
590 |
// map is sorted by ifdId then tag
|
|
605 | 591 |
} |
606 | 592 | |
607 | 593 |
void ExifData::sortByTag() |
608 | 594 |
{ |
609 |
exifMetadata_.sort(cmpMetadataByTag);
|
|
595 |
// map is already sorted by ifdId then tag
|
|
610 | 596 |
} |
611 | 597 | |
612 | 598 |
ExifData::iterator ExifData::erase(ExifData::iterator beg, ExifData::iterator end) |
613 | 599 |
{ |
614 |
return exifMetadata_.erase(beg, end); |
|
600 |
ExifData::iterator next = end; |
|
601 |
next++; |
|
602 |
exifMetadata_.erase(beg.it, end.it); |
|
603 |
return next; |
|
615 | 604 |
} |
616 | 605 | |
617 | 606 |
ExifData::iterator ExifData::erase(ExifData::iterator pos) |
618 | 607 |
{ |
619 |
return exifMetadata_.erase(pos); |
|
608 |
ExifData::iterator next = pos; |
|
609 |
next++; |
|
610 |
exifMetadata_.erase(pos.it); |
|
611 |
return next; |
|
620 | 612 |
} |
621 | 613 | |
622 | 614 |
ByteOrder ExifParser::decode( |
src/exif.hpp | ||
---|---|---|
156 | 156 |
//@{ |
157 | 157 |
//! Return the key of the %Exifdatum. |
158 | 158 |
std::string key() const; |
159 |
const ExifKey& exifKey() const; |
|
159 | 160 |
const char* familyName() const; |
160 | 161 |
std::string groupName() const; |
161 | 162 |
std::string tagName() const; |
... | ... | |
421 | 422 |
}; // class ExifThumb |
422 | 423 | |
423 | 424 |
//! Container type to hold all metadata |
424 |
typedef std::list<Exifdatum> ExifMetadata;
|
|
425 |
typedef std::multimap<ExifKey, Exifdatum> ExifMetadata;
|
|
425 | 426 | |
426 | 427 |
/*! |
427 | 428 |
@brief A container for Exif data. This is a top-level class of the %Exiv2 |
... | ... | |
438 | 439 |
class EXIV2API ExifData { |
439 | 440 |
public: |
440 | 441 |
//! ExifMetadata iterator type |
441 |
typedef ExifMetadata::iterator iterator;
|
|
442 |
typedef map_value_iterator<ExifMetadata, ExifMetadata::iterator> iterator;
|
|
442 | 443 |
//! ExifMetadata const iterator type |
443 |
typedef ExifMetadata::const_iterator const_iterator;
|
|
444 |
typedef map_value_iterator<ExifMetadata, ExifMetadata::const_iterator, const typename ExifMetadata::const_iterator::value_type::second_type> const_iterator;
|
|
444 | 445 | |
445 | 446 |
//! @name Manipulators |
446 | 447 |
//@{ |
... | ... | |
486 | 487 |
Note that this also removes thumbnails. |
487 | 488 |
*/ |
488 | 489 |
void clear(); |
489 |
//! Sort metadata by key |
|
490 |
/*! |
|
491 |
@deprecated Exif metadata is always kept sorted by IfdId, then tag. |
|
492 |
This method is a no-op. |
|
493 |
*/ |
|
490 | 494 |
void sortByKey(); |
491 |
//! Sort metadata by tag |
|
495 |
/*! |
|
496 |
@deprecated Exif metadata is always kept sorted by IfdId, then tag. |
|
497 |
This method is a no-op. |
|
498 |
*/ |
|
492 | 499 |
void sortByTag(); |
493 | 500 |
//! Begin of the metadata |
494 | 501 |
iterator begin() { return exifMetadata_.begin(); } |
src/tags.cpp | ||
---|---|---|
3036 | 3036 |
return *this; |
3037 | 3037 |
} |
3038 | 3038 | |
3039 |
bool ExifKey::operator<(const ExifKey& b) const |
|
3040 |
{ |
|
3041 |
if (this->ifdId() != b.ifdId()) { |
|
3042 |
return this->ifdId() < b.ifdId(); |
|
3043 |
} |
|
3044 | ||
3045 |
return this->tag() < b.tag(); |
|
3046 |
} |
|
3047 | ||
3039 | 3048 |
void ExifKey::setIdx(int idx) |
3040 | 3049 |
{ |
3041 | 3050 |
p_->idx_ = idx; |
src/tags.hpp | ||
---|---|---|
192 | 192 |
@brief Assignment operator. |
193 | 193 |
*/ |
194 | 194 |
ExifKey& operator=(const ExifKey& rhs); |
195 |
//! Comparison operator. |
|
196 |
bool operator<(const ExifKey& b) const; |
|
195 | 197 |
//! Set the index. |
196 | 198 |
void setIdx(int idx); |
197 | 199 |
//@} |
198 |
- |