Revision 65b83771
Added by david.sorber 8 months ago
| software/photo_compress_archiver/CMakeLists.txt | ||
|---|---|---|
|
|
||
|
FIND_PACKAGE(Threads)
|
||
|
|
||
|
FIND_PACKAGE(Boost 1.58.0 COMPONENTS system regex REQUIRED)
|
||
|
IF (Boost_FOUND)
|
||
|
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
|
||
|
SET(EXTERNAL_LIBS ${EXTERNAL_LIBS} ${Boost_LIBRARIES})
|
||
|
ENDIF()
|
||
|
|
||
|
|
||
|
################################################################################
|
||
|
# External projects
|
||
| software/photo_compress_archiver/src/PhotoCompressArchiver.cc | ||
|---|---|---|
|
#include <climits>
|
||
|
#include <cmath>
|
||
|
#include <cstdio>
|
||
|
#include <cstring>
|
||
|
#include <fstream>
|
||
|
#include <iomanip>
|
||
|
#include <iostream>
|
||
| ... | ... | |
|
#include <sys/wait.h>
|
||
|
#include <unistd.h>
|
||
|
|
||
|
|
||
|
#include <packjpg.h>
|
||
|
|
||
|
#include "PhotoCompressArchiver.hh"
|
||
| ... | ... | |
|
uint32_t num_threads,
|
||
|
bool decompress,
|
||
|
bool delete_orig,
|
||
|
bool verbose,
|
||
|
boost::regex& filter_regex)
|
||
|
bool verbose,
|
||
|
bool filter_empty,
|
||
|
std::regex& filter_regex)
|
||
|
: m_path(path),
|
||
|
m_num_threads(num_threads),
|
||
|
m_decompress(decompress),
|
||
| ... | ... | |
|
m_total_compressed_size(0),
|
||
|
m_running_compressed_size(0),
|
||
|
p_finder_thread(nullptr),
|
||
|
m_filter_empty(true),
|
||
|
m_filter_empty(filter_empty),
|
||
|
m_filter_regex(filter_regex)
|
||
|
{
|
||
|
// This is a somewhat crude way to determining if the filter regex is empty
|
||
|
m_filter_empty = std::string("") == filter_regex.str();
|
||
|
}
|
||
|
|
||
|
PhotoCompressArchiver::~PhotoCompressArchiver()
|
||
| ... | ... | |
|
|
||
|
void PhotoCompressArchiver::find_files(
|
||
|
const sfs::path& dir_path,
|
||
|
const boost::regex& file_regex)
|
||
|
const std::regex& file_regex)
|
||
|
{
|
||
|
// Check the terminate flag before proceeding
|
||
|
if (m_terminate_flag)
|
||
| ... | ... | |
|
// Found directory recurse
|
||
|
find_files(dir_iter->path(), file_regex);
|
||
|
}
|
||
|
else if (boost::regex_match(dir_iter->path().filename().string(), file_regex) &&
|
||
|
else if (std::regex_match(dir_iter->path().filename().string(), file_regex) &&
|
||
|
sfs::is_regular_file(dir_iter->path()))
|
||
|
{
|
||
|
// Found file match
|
||
| ... | ... | |
|
// If the filter is not empty, then check against it before proceeding
|
||
|
if (! m_filter_empty)
|
||
|
{
|
||
|
if (boost::regex_match(dir_iter->path().filename().string(),
|
||
|
m_filter_regex))
|
||
|
if (std::regex_match(dir_iter->path().filename().string(), m_filter_regex))
|
||
|
{
|
||
|
// The filter regex matched, skip this file
|
||
|
continue;
|
||
| software/photo_compress_archiver/src/PhotoCompressArchiver.hh | ||
|---|---|---|
|
#include <cstdint>
|
||
|
#include <filesystem>
|
||
|
#include <mutex>
|
||
|
#include <regex>
|
||
|
#include <sstream>
|
||
|
#include <string>
|
||
|
#include <thread>
|
||
|
#include <vector>
|
||
|
|
||
|
#include <boost/regex.hpp>
|
||
|
|
||
|
#include "ProtectedQueue.h"
|
||
|
|
||
|
// Alias the namespace to keep the code readable
|
||
| ... | ... | |
|
|
||
|
const std::string version("v0.5.1");
|
||
|
|
||
|
const boost::regex JPEG_REGEX("^.+\\.((jpg)|(jpeg))$", boost::regex::icase);
|
||
|
const boost::regex PJG_REGEX("^.+\\.pjg$", boost::regex::icase);
|
||
|
const std::regex JPEG_REGEX("^.+\\.((jpg)|(jpeg))$", std::regex_constants::ECMAScript | std::regex::icase);
|
||
|
const std::regex PJG_REGEX("^.+\\.pjg$", std::regex_constants::ECMAScript | std::regex::icase);
|
||
|
|
||
|
const std::string JPG_EXTENSION(".jpg");
|
||
|
const std::string PJG_EXTENSION(".pjg");
|
||
| ... | ... | |
|
bool decompress,
|
||
|
bool delete_orig,
|
||
|
bool verbose,
|
||
|
boost::regex& filter_regex);
|
||
|
bool filter_empty,
|
||
|
std::regex& filter_regex);
|
||
|
|
||
|
~PhotoCompressArchiver();
|
||
|
|
||
| ... | ... | |
|
*/
|
||
|
void find_files(
|
||
|
const sfs::path& dir_path,
|
||
|
const boost::regex& file_regex);
|
||
|
const std::regex& file_regex);
|
||
|
|
||
|
/**
|
||
|
* Compress/decompress worker thread body
|
||
| ... | ... | |
|
std::thread* p_finder_thread; // file finder thread
|
||
|
std::vector<std::thread*> m_worker_threads; // worker threads
|
||
|
|
||
|
bool m_filter_empty; // is the filter regex empty
|
||
|
boost::regex& m_filter_regex; // filter regular expression
|
||
|
bool m_filter_empty; // is the filter regex empty
|
||
|
std::regex& m_filter_regex; // filter regular expression
|
||
|
};
|
||
|
|
||
|
#endif // PHOTOCOMPRESSARCHIVER_H
|
||
| software/photo_compress_archiver/src/main.cc | ||
|---|---|---|
|
#include <iostream>
|
||
|
#include <regex>
|
||
|
#include <sstream>
|
||
|
#include <string>
|
||
|
|
||
|
#include <boost/regex.hpp>
|
||
|
|
||
|
#include "cli11/CLI11.hpp"
|
||
|
|
||
|
#include "PhotoCompressArchiver.hh"
|
||
| ... | ... | |
|
}
|
||
|
|
||
|
// Check for, and if present validate the filter regex
|
||
|
boost::regex filter_regex("");
|
||
|
std::regex filter_regex("");
|
||
|
if (! filter_str.empty())
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
filter_regex = filter_str;
|
||
|
filter_regex.assign(filter_str, std::regex_constants::ECMAScript);
|
||
|
}
|
||
|
catch (std::exception& e)
|
||
|
{
|
||
| ... | ... | |
|
decompress,
|
||
|
delete_orig,
|
||
|
verbose,
|
||
|
filter_str.empty(),
|
||
|
filter_regex);
|
||
|
pca->execute();
|
||
|
delete pca;
|
||
Replace boost::regex with std::regex. Goodbye to Boost!