MLBookProc 1.0
 
Loading...
Searching...
No Matches
AuxFunc Class Reference

The AuxFunc class. More...

#include <AuxFunc.h>

Public Member Functions

virtual ~AuxFunc ()
 AuxFunc destructor.
 
std::string to_utf_8 (const std::string &input, const char *conv_name)
 Converts string to UTF-8 string.
 
std::string utf8_to_system (const std::string &input)
 Converts UTF-8 string to string in system default encoding.
 
std::string utf_8_to (const std::string &input, const char *conv_name)
 Converts UTF-8 string to string in chosen encoding.
 
const char * get_converter_by_number (const int32_t &num)
 Returns converter name.
 
std::string detect_encoding (const std::string &buf)
 Tries to detect string encoding.
 
std::filesystem::path homePath ()
 Returns user home directory path.
 
std::filesystem::path get_selfpath ()
 Returns absolute path to program executable file.
 
std::filesystem::path temp_path ()
 Returns absolute path to system temporary directory.
 
std::filesystem::path share_path ()
 Returns absolute path to share directory, used by MLBookProc.
 
std::vector< GenreGroupget_genre_list ()
 Returns translated genre groups and genres names.
 
std::string libgcrypt_error_handling (const gcry_error_t &err)
 Auxiliary method to reinterpret libgcrypt errors as strings.
 
std::string to_hex (const std::string &source)
 Converts given string to hex format.
 
std::string stringToLower (const std::string &line)
 Converts all letters of the string to lowercase letters.
 
std::string randomFileName ()
 Returns random string.
 
std::string time_t_to_date (const time_t &tt)
 Converts time_t value to calendar date.
 
bool if_supported_type (const std::filesystem::path &ch_p)
 Checks if given file is supported by MLBookProc.
 
void html_to_utf8 (std::string &input)
 Converst 'html' symbols to UTF-8 characters.
 
void open_book_callback (const std::filesystem::path &path)
 Opens given file in default system application.
 
void copy_book_callback (const std::filesystem::path &source, const std::filesystem::path &out)
 Replaces out file by source file.
 
std::vector< std::string > get_supported_types ()
 Returns supported file types.
 
std::vector< std::string > get_supported_archive_types_packing ()
 Same as get_supported_types(), but returns only archives types, available for packing.
 
std::vector< std::string > get_supported_archive_types_unpacking ()
 Same as get_supported_types(), but returns only archives types, available for unpacking.
 
std::string get_extension (const std::filesystem::path &p)
 Returns file extesion.
 
int32_t get_charset_conv_quantity ()
 Returns number of available converters.
 
bool get_activated ()
 Checks if depencies have been successfully activated.
 
std::shared_ptr< ddjvu_context_t > getDJVUContext ()
 Returns smart pointer to djvu context object.
 

Static Public Member Functions

template<class InputIt, class T = typename std::iterator_traits<InputIt>::value_type>
static InputIt parallelFind (InputIt start, InputIt end, const T &val)
 'Find' method for C++ standard containers.
 
template<class InputIt, class UnaryPred>
static InputIt parallelFindIf (InputIt start, InputIt end, UnaryPred predicate)
 'Find' method for C++ standard containers.
 
template<class InputIt, class T = typename std::iterator_traits<InputIt>::value_type>
static InputIt parallelRemove (InputIt start, InputIt end, const T &val)
 "Remove" method for C++ containers.
 
template<class InputIt, class UnaryPred>
static InputIt parallelRemoveIf (InputIt start, InputIt end, UnaryPred predicate)
 'Remove' method for C++ containers.
 
static std::shared_ptr< AuxFunccreate ()
 Creats AuxFunc object.
 

Detailed Description

The AuxFunc class.

AuxFunc class contains various useful auxiliary methods. AuxFunc object must be created (see create()) before using of any MLBookProc methods or classes. create() method should be called only once per program. Also it is strongly recommended to call get_activated() method immediately after AuxFunc object creation.

Member Function Documentation

◆ copy_book_callback()

void AuxFunc::copy_book_callback ( const std::filesystem::path & source,
const std::filesystem::path & out )

Replaces out file by source file.

This method acts like std::filesystem::copy. It was introduced due to MinGW bug (MinGW ignores std::filesystem::copy_options::overwrite_existing).

Parameters
sourcefile to be copied.
outfile to be replaced.

◆ create()

static std::shared_ptr< AuxFunc > AuxFunc::create ( )
static

Creats AuxFunc object.

This method must be called before using of any MLBookProc classes or methods.

Warning
This method should be called only once per program.
Returns
Smart pointer to AuxFunc object.

◆ detect_encoding()

std::string AuxFunc::detect_encoding ( const std::string & buf)

Tries to detect string encoding.

Parameters
bufstring which encoding is to be detected.
Returns
String containing encoding name.

◆ get_activated()

bool AuxFunc::get_activated ( )

Checks if depencies have been successfully activated.

Returns
true if all dependencies have been successfully activated, false otherwise.

◆ get_charset_conv_quantity()

int32_t AuxFunc::get_charset_conv_quantity ( )

Returns number of available converters.

See icu documentation for details.

Returns
Signed 32-bit integer number of available convertrs.

◆ get_converter_by_number()

const char * AuxFunc::get_converter_by_number ( const int32_t & num)

Returns converter name.

Parameters
numconverter number (see icu documentation for details).
Returns
Pointer to string, containing converter name.

◆ get_extension()

std::string AuxFunc::get_extension ( const std::filesystem::path & p)

Returns file extesion.

Parameters
pabsolute path to file.
Returns
File extension with beginning dot (looks like ".tar.gz").

◆ get_genre_list()

std::vector< GenreGroup > AuxFunc::get_genre_list ( )

Returns translated genre groups and genres names.

Resulting genre groups and genres will be in default system language, if translations are available, or in English.

Returns
Vector of GenreGroup objects.

◆ get_selfpath()

std::filesystem::path AuxFunc::get_selfpath ( )

Returns absolute path to program executable file.

Returns
Absolute path to executable file.

◆ get_supported_archive_types_packing()

std::vector< std::string > AuxFunc::get_supported_archive_types_packing ( )

Same as get_supported_types(), but returns only archives types, available for packing.

Returns
Vector of supported archives types.

◆ get_supported_archive_types_unpacking()

std::vector< std::string > AuxFunc::get_supported_archive_types_unpacking ( )

Same as get_supported_types(), but returns only archives types, available for unpacking.

Returns
Vector of supported archives types.

◆ get_supported_types()

std::vector< std::string > AuxFunc::get_supported_types ( )

Returns supported file types.

Returns
Vector of supported files extensions without beginning dot (looks like "fb2").

◆ getDJVUContext()

std::shared_ptr< ddjvu_context_t > AuxFunc::getDJVUContext ( )

Returns smart pointer to djvu context object.

Warning
Resulting smart pointer can be nullptr (see get_activated()).
Returns
Smart pointer to djvu context object.

◆ homePath()

std::filesystem::path AuxFunc::homePath ( )

Returns user home directory path.

Returns
Absolute path to home directory.

◆ html_to_utf8()

void AuxFunc::html_to_utf8 ( std::string & input)

Converst 'html' symbols to UTF-8 characters.

Replaces "&#<unicode_number>;" symbols by UTF-8 characters.

Parameters
inputstring to be converted.

◆ if_supported_type()

bool AuxFunc::if_supported_type ( const std::filesystem::path & ch_p)

Checks if given file is supported by MLBookProc.

'Supported types' check is carried out by file extension.

Parameters
ch_pabsolute path to file.
Returns
true if file is supported, false otherwise.

◆ libgcrypt_error_handling()

std::string AuxFunc::libgcrypt_error_handling ( const gcry_error_t & err)

Auxiliary method to reinterpret libgcrypt errors as strings.

In most cases you do not need to call this method directly.

Parameters
errlibgcrypt error code (see libgcrypt documentation for details).
Returns
Human-readable string explaining error code.

◆ open_book_callback()

void AuxFunc::open_book_callback ( const std::filesystem::path & path)

Opens given file in default system application.

Parameters
pathabsolute path to file to be opened.

◆ parallelFind()

template<class InputIt, class T = typename std::iterator_traits<InputIt>::value_type>
static InputIt AuxFunc::parallelFind ( InputIt start,
InputIt end,
const T & val )
inlinestatic

'Find' method for C++ standard containers.

This method acts like std::find, but uses OpenMP multithreading for acceleration.

Parameters
startstart iterator.
endend iterator.
valvalue to be found.
Returns
Iterator of found value or end iterator.

◆ parallelFindIf()

template<class InputIt, class UnaryPred>
static InputIt AuxFunc::parallelFindIf ( InputIt start,
InputIt end,
UnaryPred predicate )
inlinestatic

'Find' method for C++ standard containers.

This method acts like std::find_if, but uses OpenMP multithreading for acceleration.

Parameters
startstart iterator.
endend iterator.
predicatemethod to be used to check values.
Returns
Iterator of found value or end iterator.

◆ parallelRemove()

template<class InputIt, class T = typename std::iterator_traits<InputIt>::value_type>
static InputIt AuxFunc::parallelRemove ( InputIt start,
InputIt end,
const T & val )
inlinestatic

"Remove" method for C++ containers.

This method acts like std::remove, but uses OpenMP multithreading for acceleration.

Parameters
startstart iterator.
endend iterator.
valvalue to be removed.
Returns
Past-the-end iterator for the new range of values (if this is not end, then it points to an unspecified value, and so do iterators to any values between this iterator and end).

◆ parallelRemoveIf()

template<class InputIt, class UnaryPred>
static InputIt AuxFunc::parallelRemoveIf ( InputIt start,
InputIt end,
UnaryPred predicate )
inlinestatic

'Remove' method for C++ containers.

This method acts like std::remove_if, but uses OpenMP multithreading for acceleration.

Parameters
startstart iterator.
endend iterator.
predicatemethod to be used to check values.
Returns
Past-the-end iterator for the new range of values (if this is not end, then it points to an unspecified value, and so do iterators to any values between this iterator and end).

◆ randomFileName()

std::string AuxFunc::randomFileName ( )

Returns random string.

Returns
Random string (it will look like "<random_hex_numbe>MLBookProc").

◆ share_path()

std::filesystem::path AuxFunc::share_path ( )

Returns absolute path to share directory, used by MLBookProc.

Result path is calculating as path relative to program executable file path ('absolute_path_to_executable_file/../share').

Returns
Absolute path to share directory, used by MLBookProc.

◆ stringToLower()

std::string AuxFunc::stringToLower ( const std::string & line)

Converts all letters of the string to lowercase letters.

Parameters
lineUTF-8 encoded string to be converted to lowercase.
Returns
Lowercase string.

◆ temp_path()

std::filesystem::path AuxFunc::temp_path ( )

Returns absolute path to system temporary directory.

Returns
Absolute path to system temporary directory.

◆ time_t_to_date()

std::string AuxFunc::time_t_to_date ( const time_t & tt)

Converts time_t value to calendar date.

Parameters
tttime_t value.
Returns
Date string (it will look like "<day_number>.<month_number>.<year>")

◆ to_hex()

std::string AuxFunc::to_hex ( const std::string & source)

Converts given string to hex format.

Each char element will be converted to two hexidecimal digits.

Parameters
sourcestring to be converted.
Returns
String in hex format.

◆ to_utf_8()

std::string AuxFunc::to_utf_8 ( const std::string & input,
const char * conv_name )

Converts string to UTF-8 string.

Parameters
inputstring to be converted.
conv_nameinput string encoding name (see icu documentation for details).
Returns
UTF-8 encoded string or empty string in case of any error.

◆ utf8_to_system()

std::string AuxFunc::utf8_to_system ( const std::string & input)

Converts UTF-8 string to string in system default encoding.

Parameters
inputUTF-8 string to be converted.
Returns
String in system encoding or empty string in case of any error.

◆ utf_8_to()

std::string AuxFunc::utf_8_to ( const std::string & input,
const char * conv_name )

Converts UTF-8 string to string in chosen encoding.

Parameters
inputstring to be converted.
conv_nameoutput string encoding name (see icu documentation for details).
Returns
String in chosen encoding or empty string in case of any error.