std::function conversions

Signed-off-by: Rosen Penev <rosenp@gmail.com>
main
Rosen Penev 3 years ago
parent d466c1e9eb
commit 2e721a716e

@ -331,8 +331,8 @@ int Print::printTag(const Exiv2::ExifData& exifData, const std::string& key, con
return rc; return rc;
} // Print::printTag } // Print::printTag
int Print::printTag(const Exiv2::ExifData& exifData, EasyAccessFct easyAccessFct, const std::string& label, int Print::printTag(const Exiv2::ExifData& exifData, const EasyAccessFct& easyAccessFct, const std::string& label,
EasyAccessFct easyAccessFctFallback) const { const EasyAccessFct& easyAccessFctFallback) const {
int rc = 0; int rc = 0;
if (!label.empty()) { if (!label.empty()) {
printLabel(label); printLabel(label);

@ -155,14 +155,14 @@ class Print : public Task {
*/ */
int printTag(const Exiv2::ExifData& exifData, const std::string& key, const std::string& label = "") const; int printTag(const Exiv2::ExifData& exifData, const std::string& key, const std::string& label = "") const;
//! Type for an Exiv2 Easy access function //! Type for an Exiv2 Easy access function
using EasyAccessFct = Exiv2::ExifData::const_iterator (*)(const Exiv2::ExifData& ed); using EasyAccessFct = std::function<Exiv2::ExifData::const_iterator(const Exiv2::ExifData& ed)>;
/*! /*!
@brief Print one summary line with a label (if provided) and requested @brief Print one summary line with a label (if provided) and requested
data. A line break is printed only if a label is provided. data. A line break is printed only if a label is provided.
@return 1 if a line was written, 0 if the information was not found. @return 1 if a line was written, 0 if the information was not found.
*/ */
int printTag(const Exiv2::ExifData& exifData, EasyAccessFct easyAccessFct, const std::string& label = "", int printTag(const Exiv2::ExifData& exifData, const EasyAccessFct& easyAccessFct, const std::string& label = "",
EasyAccessFct easyAccessFctFallback = nullptr) const; const EasyAccessFct& easyAccessFctFallback = nullptr) const;
private: private:
std::string path_; std::string path_;

@ -5,14 +5,11 @@
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
using EasyAccessFct = Exiv2::ExifData::const_iterator (*)(const Exiv2::ExifData&); using EasyAccessFct = std::function<Exiv2::ExifData::const_iterator(const Exiv2::ExifData&)>;
using EasyAccess = std::pair<const char*, EasyAccessFct>;
struct EasyAccess { static const EasyAccess easyAccess[] = {
const char* label_; {"Orientation", Exiv2::orientation},
EasyAccessFct findFct_;
};
static const EasyAccess easyAccess[] = {{"Orientation", Exiv2::orientation},
{"ISO speed", Exiv2::isoSpeed}, {"ISO speed", Exiv2::isoSpeed},
{"Date & time original", Exiv2::dateTimeOriginal}, {"Date & time original", Exiv2::dateTimeOriginal},
{"Flash bias", Exiv2::flashBias}, {"Flash bias", Exiv2::flashBias},
@ -45,7 +42,8 @@ static const EasyAccess easyAccess[] = {{"Orientation", Exiv2::orientation},
{"Flash energy", Exiv2::flashEnergy}, {"Flash energy", Exiv2::flashEnergy},
{"Exposure index", Exiv2::exposureIndex}, {"Exposure index", Exiv2::exposureIndex},
{"Sensing method", Exiv2::sensingMethod}, {"Sensing method", Exiv2::sensingMethod},
{"AF point", Exiv2::afPoint}}; {"AF point", Exiv2::afPoint},
};
int main(int argc, char** argv) { int main(int argc, char** argv) {
try { try {
@ -64,9 +62,9 @@ int main(int argc, char** argv) {
image->readMetadata(); image->readMetadata();
Exiv2::ExifData& ed = image->exifData(); Exiv2::ExifData& ed = image->exifData();
for (auto&& ea : easyAccess) { for (auto&& [label, fct] : easyAccess) {
auto pos = ea.findFct_(ed); auto pos = fct(ed);
std::cout << std::setw(21) << std::left << ea.label_; std::cout << std::setw(21) << std::left << label;
if (pos != ed.end()) { if (pos != ed.end()) {
std::cout << " (" << std::setw(35) << pos->key() << ") : " << pos->print(&ed) << "\n"; std::cout << " (" << std::setw(35) << pos->key() << ") : " << pos->print(&ed) << "\n";
} else { } else {

@ -8,6 +8,8 @@
#include "tags_int.hpp" #include "tags_int.hpp"
#include "types.hpp" #include "types.hpp"
#include <functional>
// namespace extensions // namespace extensions
namespace Exiv2::Internal { namespace Exiv2::Internal {
class IoWrapper; class IoWrapper;
@ -28,11 +30,10 @@ std::string readExiv2Config(const std::string& section, const std::string& value
// class definitions // class definitions
//! Type for a pointer to a function creating a makernote (image) //! Type for a pointer to a function creating a makernote (image)
using NewMnFct = TiffComponent* (*)(uint16_t tag, IfdId group, IfdId mnGroup, const byte* pData, size_t size, using NewMnFct = std::function<TiffComponent*(uint16_t, IfdId, IfdId, const byte*, size_t, ByteOrder)>;
ByteOrder byteOrder);
//! Type for a pointer to a function creating a makernote (group) //! Type for a pointer to a function creating a makernote (group)
using NewMnFct2 = TiffComponent* (*)(uint16_t tag, IfdId group, IfdId mnGroup); using NewMnFct2 = std::function<TiffComponent*(uint16_t tag, IfdId group, IfdId mnGroup)>;
//! Makernote registry structure //! Makernote registry structure
struct TiffMnRegistry { struct TiffMnRegistry {

@ -1240,10 +1240,10 @@ class TiffIfdMakernote : public TiffComponent {
@brief Function pointer type for a function to determine which cfg + def @brief Function pointer type for a function to determine which cfg + def
of a corresponding array set to use. of a corresponding array set to use.
*/ */
using CfgSelFct = int (*)(uint16_t, const byte*, size_t, TiffComponent* const); using CfgSelFct = int (*)(uint16_t, const byte*, size_t, TiffComponent*);
//! Function pointer type for a crypt function used for binary arrays. //! Function pointer type for a crypt function used for binary arrays.
using CryptFct = DataBuf (*)(uint16_t, const byte*, size_t, TiffComponent* const); using CryptFct = DataBuf (*)(uint16_t, const byte*, size_t, TiffComponent*);
//! Defines one tag in a binary array //! Defines one tag in a binary array
struct ArrayDef { struct ArrayDef {

@ -9,6 +9,7 @@
#include "types.hpp" #include "types.hpp"
// + standard includes // + standard includes
#include <functional>
#include <stack> #include <stack>
// ***************************************************************************** // *****************************************************************************
@ -61,17 +62,17 @@ using EncoderFct = void (TiffEncoder::*)(TiffEntryBase*, const Exifdatum*);
/*! /*!
@brief Type for a function pointer for a function to decode a TIFF component. @brief Type for a function pointer for a function to decode a TIFF component.
*/ */
using FindDecoderFct = DecoderFct (*)(const std::string& make, uint32_t extendedTag, IfdId group); using FindDecoderFct = std::function<DecoderFct(const std::string& make, uint32_t extendedTag, IfdId group)>;
/*! /*!
@brief Type for a function pointer for a function to encode a TIFF component. @brief Type for a function pointer for a function to encode a TIFF component.
*/ */
using FindEncoderFct = EncoderFct (*)(const std::string& make, uint32_t extendedTag, IfdId group); using FindEncoderFct = std::function<EncoderFct(const std::string& make, uint32_t extendedTag, IfdId group)>;
/*! /*!
@brief Type for a function pointer for a function to create a TIFF component. @brief Type for a function pointer for a function to create a TIFF component.
Use TiffComponent::UniquePtr, it is not used in this declaration only Use TiffComponent::UniquePtr, it is not used in this declaration only
to reduce dependencies. to reduce dependencies.
*/ */
using NewTiffCompFct = std::unique_ptr<TiffComponent> (*)(uint16_t tag, IfdId group); using NewTiffCompFct = std::function<std::unique_ptr<TiffComponent>(uint16_t tag, IfdId group)>;
//! Stack to hold a path from the TIFF root element to a TIFF entry //! Stack to hold a path from the TIFF root element to a TIFF entry
using TiffPath = std::stack<TiffPathItem>; using TiffPath = std::stack<TiffPathItem>;

@ -1848,7 +1848,7 @@ ByteOrder TiffParserWorker::decode(ExifData& exifData, IptcData& iptcData, XmpDa
auto rootDir = parse(pData, size, root, pHeader); auto rootDir = parse(pData, size, root, pHeader);
if (rootDir) { if (rootDir) {
TiffDecoder decoder(exifData, iptcData, xmpData, rootDir.get(), findDecoderFct); TiffDecoder decoder(exifData, iptcData, xmpData, rootDir.get(), std::move(findDecoderFct));
rootDir->accept(decoder); rootDir->accept(decoder);
} }
return pHeader->byteOrder(); return pHeader->byteOrder();
@ -1857,7 +1857,7 @@ ByteOrder TiffParserWorker::decode(ExifData& exifData, IptcData& iptcData, XmpDa
WriteMethod TiffParserWorker::encode(BasicIo& io, const byte* pData, size_t size, const ExifData& exifData, WriteMethod TiffParserWorker::encode(BasicIo& io, const byte* pData, size_t size, const ExifData& exifData,
const IptcData& iptcData, const XmpData& xmpData, uint32_t root, const IptcData& iptcData, const XmpData& xmpData, uint32_t root,
FindEncoderFct findEncoderFct, TiffHeaderBase* pHeader, const FindEncoderFct& findEncoderFct, TiffHeaderBase* pHeader,
OffsetWriter* pOffsetWriter) { OffsetWriter* pOffsetWriter) {
/* /*
1) parse the binary image, if one is provided, and 1) parse the binary image, if one is provided, and

@ -263,7 +263,7 @@ class TiffParserWorker {
*/ */
static WriteMethod encode(BasicIo& io, const byte* pData, size_t size, const ExifData& exifData, static WriteMethod encode(BasicIo& io, const byte* pData, size_t size, const ExifData& exifData,
const IptcData& iptcData, const XmpData& xmpData, uint32_t root, const IptcData& iptcData, const XmpData& xmpData, uint32_t root,
FindEncoderFct findEncoderFct, TiffHeaderBase* pHeader, OffsetWriter* pOffsetWriter); const FindEncoderFct& findEncoderFct, TiffHeaderBase* pHeader, OffsetWriter* pOffsetWriter);
private: private:
/*! /*!

@ -193,7 +193,7 @@ TiffDecoder::TiffDecoder(ExifData& exifData, IptcData& iptcData, XmpData& xmpDat
iptcData_(iptcData), iptcData_(iptcData),
xmpData_(xmpData), xmpData_(xmpData),
pRoot_(pRoot), pRoot_(pRoot),
findDecoderFct_(findDecoderFct), findDecoderFct_(std::move(findDecoderFct)),
decodedIptc_(false) { decodedIptc_(false) {
// #1402 Fujifilm RAF. Search for the make // #1402 Fujifilm RAF. Search for the make
// Find camera make in existing metadata (read from the JPEG) // Find camera make in existing metadata (read from the JPEG)
@ -460,7 +460,7 @@ TiffEncoder::TiffEncoder(ExifData exifData, const IptcData& iptcData, const XmpD
isNewImage_(isNewImage), isNewImage_(isNewImage),
pPrimaryGroups_(pPrimaryGroups), pPrimaryGroups_(pPrimaryGroups),
pSourceTree_(nullptr), pSourceTree_(nullptr),
findEncoderFct_(findEncoderFct), findEncoderFct_(std::move(findEncoderFct)),
dirty_(false), dirty_(false),
writeMethod_(wmNonIntrusive) { writeMethod_(wmNonIntrusive) {
byteOrder_ = pHeader->byteOrder(); byteOrder_ = pHeader->byteOrder();

Loading…
Cancel
Save