Skip to content

Commit

Permalink
WIP: use fs::path for app
Browse files Browse the repository at this point in the history
Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb committed Jan 19, 2025
1 parent 7e9a94e commit 9f9a7c5
Show file tree
Hide file tree
Showing 8 changed files with 345 additions and 130 deletions.
198 changes: 98 additions & 100 deletions app/actions.cpp

Large diffs are not rendered by default.

50 changes: 29 additions & 21 deletions app/actions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@

#include <unordered_map>

#if __has_include(<filesystem>)
#include <filesystem>
namespace fs = std::filesystem;
#else
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#endif

// *****************************************************************************
// class declarations

Expand Down Expand Up @@ -70,7 +78,7 @@ class Task {
/// @brief Application interface to perform a task.
/// @param path Path of the file to process.
/// @return 0 if successful.
virtual int run(const std::string& path) = 0;
virtual int run(const fs::path& path) = 0;

bool setBinary(bool b) {
bool bResult = binary_;
Expand Down Expand Up @@ -133,7 +141,7 @@ class TaskFactory {
//! %Print the Exif (or other metadata) of a file to stdout
class Print : public Task {
public:
int run(const std::string& path) override;
int run(const fs::path& path) override;
[[nodiscard]] Task::UniquePtr clone() const override;

//! Print the Jpeg comment
Expand Down Expand Up @@ -171,25 +179,25 @@ class Print : public Task {
EasyAccessFct easyAccessFctFallback = nullptr) const;

private:
std::string path_;
fs::path path_;
int align_{0}; // for the alignment of the summary output
};

/// @brief %Rename a file to its metadata creation timestamp, in the specified format.
class Rename : public Task {
public:
int run(const std::string& path) override;
int run(const fs::path& path) override;
[[nodiscard]] Task::UniquePtr clone() const override;
}; // class Rename

//! %Adjust the Exif (or other metadata) timestamps
class Adjust : public Task {
public:
int run(const std::string& path) override;
int run(const fs::path& path) override;
[[nodiscard]] Task::UniquePtr clone() const override;

private:
int adjustDateTime(Exiv2::ExifData& exifData, const std::string& key, const std::string& path) const;
int adjustDateTime(Exiv2::ExifData& exifData, const std::string& key, const fs::path& path) const;

int64_t adjustment_{0};
int64_t yearAdjustment_{0};
Expand All @@ -201,7 +209,7 @@ class Adjust : public Task {
/// @brief %Erase the entire exif data or only the thumbnail section.
class Erase : public Task {
public:
int run(const std::string& path) override;
int run(const fs::path& path) override;
[[nodiscard]] Task::UniquePtr clone() const override;

/// @brief Delete the thumbnail image, incl IFD1 metadata from the file.
Expand All @@ -223,13 +231,13 @@ class Erase : public Task {
static int eraseIccProfile(Exiv2::Image* image);

private:
std::string path_;
fs::path path_;
};

/// @brief %Extract the entire exif data or only the thumbnail section.
class Extract : public Task {
public:
int run(const std::string& path) override;
int run(const fs::path& path) override;
[[nodiscard]] Task::UniquePtr clone() const override;

/*!
Expand All @@ -252,39 +260,39 @@ class Extract : public Task {
[[nodiscard]] int writeIccProfile(const std::string& target) const;

private:
std::string path_;
fs::path path_;
};

/// @brief %Insert the Exif data from corresponding *.exv files.
class Insert : public Task {
public:
int run(const std::string& path) override;
int run(const fs::path& path) override;
[[nodiscard]] Task::UniquePtr clone() const override;

/*!
@brief Insert a Jpeg thumbnail image from a file into file \em path.
The filename of the thumbnail is expected to be the image
filename (\em path) minus its suffix plus "-thumb.jpg".
*/
static int insertThumbnail(const std::string& path);
static int insertThumbnail(const fs::path& path);

/// @brief Insert an XMP packet from a xmpPath into file \em path.
static int insertXmpPacket(const std::string& path, const std::string& xmpPath);
static int insertXmpPacket(const fs::path& path, const std::string& xmpPath);

/// @brief Insert xmp from a DataBuf into file \em path.
static int insertXmpPacket(const std::string& path, const Exiv2::DataBuf& xmpBlob, bool usePacket = false);
static int insertXmpPacket(const fs::path& path, const Exiv2::DataBuf& xmpBlob, bool usePacket = false);

/// @brief Insert an ICC profile from iccPath into file \em path.
static int insertIccProfile(const std::string& path, const std::string& iccPath);
static int insertIccProfile(const fs::path& path, const std::string& iccPath);

/// @brief Insert an ICC profile from binary DataBuf into file \em path.
static int insertIccProfile(const std::string& path, Exiv2::DataBuf&& iccProfileBlob);
static int insertIccProfile(const fs::path& path, Exiv2::DataBuf&& iccProfileBlob);
};

/// @brief %Modify the Exif data according to the commands in the modification table.
class Modify : public Task {
public:
int run(const std::string& path) override;
int run(const fs::path& path) override;
[[nodiscard]] Task::UniquePtr clone() const override;
//! Apply modification commands to the \em pImage, return 0 if successful.
static int applyCommands(Exiv2::Image* pImage);
Expand All @@ -303,23 +311,23 @@ class Modify : public Task {
/// @brief %Copy ISO settings from any of the Nikon makernotes to the regular Exif tag, Exif.Photo.ISOSpeedRatings.
class FixIso : public Task {
public:
int run(const std::string& path) override;
int run(const fs::path& path) override;
[[nodiscard]] Task::UniquePtr clone() const override;

private:
std::string path_;
fs::path path_;
};

/// @brief Fix the character encoding of Exif UNICODE user comments.
///
/// Decodes the comment using the auto-detected or specified character encoding and writes it back in UCS-2.
class FixCom : public Task {
public:
int run(const std::string& path) override;
int run(const fs::path& path) override;
[[nodiscard]] Task::UniquePtr clone() const override;

private:
std::string path_;
fs::path path_;
};

} // namespace Action
Expand Down
37 changes: 36 additions & 1 deletion include/exiv2/basicio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,14 @@ class EXIV2API FileIo : public BasicIo {
@param path The full path of a file
*/
explicit FileIo(const std::string& path);

#ifdef _WIN32
explicit FileIo(const std::wstring& path);
/*!
@brief Like FileIo(const std::string& path) but accepts a
unicode path in an std::wstring.
@note This constructor is only available on Windows.
*/
explicit FileIo(const std::wstring& wpath);
#endif

//! Destructor. Flushes and closes an open file.
Expand Down Expand Up @@ -680,6 +686,9 @@ class EXIV2API XPathIo : public MemIo {
//@{
//! Default constructor
XPathIo(const std::string& path);
#ifdef _WIN32
XPathIo(const std::wstring& path);
#endif
//@}
private:
/*!
Expand Down Expand Up @@ -713,6 +722,15 @@ class EXIV2API XPathIo : public FileIo {
//! Default constructor that reads data from stdin/data uri path and writes them to the temp file.
explicit XPathIo(const std::string& orgPath);

#ifdef _WIN32
/*!
@brief Like XPathIo(const std::string& path) but accepts a
unicode url in an std::wstring.
@note This constructor is only available on Windows.
*/
explicit XPathIo(const std::wstring& wpath);
#endif

//! Destructor. Releases all managed memory and removes the temp file.
~XPathIo() override;
//@}
Expand All @@ -739,6 +757,14 @@ class EXIV2API XPathIo : public FileIo {
@throw Error if it fails.
*/
static std::string writeDataToFile(const std::string& orgPath);
#ifdef _WIN32
/*!
@brief Like writeDataToFile(const std::string& orgPath) but accepts a
unicode url in an std::wstring.
@note This constructor is only available on Windows.
*/
static std::string writeDataToFile(const std::wstring& wOrgPath);
#endif
//@}

private:
Expand Down Expand Up @@ -932,6 +958,15 @@ class EXIV2API HttpIo : public RemoteIo {
*/
explicit HttpIo(const std::string& url, size_t blockSize = 1024);

#ifdef _WIN32
/*!
@brief Like HttpIo(const std::string& url, size_t blockSize = 1024) but accepts a
unicode url in an std::wstring.
@note This constructor is only available on Windows.
*/
explicit HttpIo(const std::wstring& wurl, size_t blockSize = 1024);
#endif

private:
// Pimpl idiom
class HttpImpl;
Expand Down
17 changes: 17 additions & 0 deletions include/exiv2/futils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ EXIV2API size_t base64decode(const char* in, char* out, size_t out_size);
*/
EXIV2API Protocol fileProtocol(const std::string& path);

#ifdef _WIN32
/*!
@brief Like fileProtocol() but accepts a unicode path in an std::wstring.
@note This function is only available on Windows.
*/
EXIV2API Protocol fileProtocol(const std::wstring& path);
#endif

/*!
@brief Test if a file exists.
Expand All @@ -83,6 +91,15 @@ EXIV2API Protocol fileProtocol(const std::string& path);
*/
EXIV2API bool fileExists(const std::string& path);

#ifdef _WIN32
/*!
@brief Like fileExists(const std::string& path) but
accepts a unicode path in an std::wstring.
@note This function is only available on Windows.
*/
EXIV2API bool fileExists(const std::wstring& path);
#endif

/*!
@brief Return a system error message and the error code (errno).
See %strerror(3).
Expand Down
23 changes: 21 additions & 2 deletions include/exiv2/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,15 @@ class EXIV2API ImageFactory {
read the remote file.
*/
static BasicIo::UniquePtr createIo(const std::string& path, bool useCurl = true);

#ifdef _WIN32
static BasicIo::UniquePtr createIo(const std::wstring& path);
/*!
@brief Like createIo() but accepts a unicode path in an std::wstring.
@note This function is only available on Windows.
*/
static BasicIo::UniquePtr createIo(const std::wstring& wpath, bool useCurl = true);
#endif

/*!
@brief Create an Image subclass of the appropriate type by reading
the specified file. %Image type is derived from the file
Expand All @@ -539,9 +545,15 @@ class EXIV2API ImageFactory {
unknown image type.
*/
static Image::UniquePtr open(const std::string& path, bool useCurl = true);

#ifdef _WIN32
static Image::UniquePtr open(const std::wstring& path);
/*!
@brief Like open() but accepts a unicode path in an std::wstring.
@note This function is only available on Windows.
*/
static Image::UniquePtr open(const std::wstring& wpath, bool useCurl = true);
#endif

/*!
@brief Create an Image subclass of the appropriate type by reading
the provided memory. %Image type is derived from the memory
Expand Down Expand Up @@ -582,6 +594,13 @@ class EXIV2API ImageFactory {
@throw Error If the image type is not supported.
*/
static Image::UniquePtr create(ImageType type, const std::string& path);
#ifdef _WIN32
/*!
@brief Like create() but accepts a unicode path in an std::wstring.
@note This function is only available on Windows.
*/
static Image::UniquePtr create(ImageType type, const std::wstring& wpath);
#endif
/*!
@brief Create an Image subclass of the requested type by creating a
new image in memory.
Expand Down
Loading

0 comments on commit 9f9a7c5

Please sign in to comment.