MLBookProc 2.1
Loading...
Searching...
No Matches
CreateCollection Class Reference

The CreateCollection class. More...

#include <CreateCollection.h>

Inheritance diagram for CreateCollection:
Collaboration diagram for CreateCollection:

Public Member Functions

 CreateCollection (const std::shared_ptr< MLBookProc > &mlbp, const int &threads_num=int(1))
 CreateCollection constructor.
void createCollection (const std::vector< std::filesystem::path > &files_and_dirs, const std::filesystem::path &base_path)
void createInpxCollection (const std::filesystem::path &path_to_inpx, const std::filesystem::path &base_path)
virtual void stopAll ()

Static Public Member Functions

static void saveBase (const std::filesystem::path &base_path, UDBase &col_base)

Public Attributes

std::function< void(const size_t &files_found)> signal_files_collecting
std::function< void(double processed, double total)> signal_parsing_progress

Protected Member Functions

void filesCollecting (const std::vector< std::filesystem::path > &files_and_dirs, UDBase &col_base)
size_t countFiles (const std::vector< UDBElement > &el_v)
std::vector< std::tuple< const std::vector< UDBElement > *, std::vector< UDBElement >::const_iterator > > getAllFiles (const std::vector< UDBElement > &el_v)
void removeDublicates (std::vector< std::tuple< const std::vector< UDBElement > *, std::vector< UDBElement >::const_iterator > > &files)
void processFiles (const std::vector< UDBElement > &items)
void fileParsing (UDBElement *file)
void cleanBase (std::vector< UDBElement > &items)
void fb2Parsing (UDBElement *file, const std::filesystem::path &file_path)
void epubParsing (UDBElement *file, const std::filesystem::path &file_path)
void pdfParsing (UDBElement *file, const std::filesystem::path &file_path)
void djvuParsing (UDBElement *file, const std::filesystem::path &file_path)
void odtParsing (UDBElement *file, const std::filesystem::path &file_path)
void txtParsing (UDBElement *file, const std::filesystem::path &file_path)
void docParsing (UDBElement *file, const std::filesystem::path &file_path)
void rtfParsing (UDBElement *file, const std::filesystem::path &file_path)
void docxParsing (UDBElement *file, const std::filesystem::path &file_path)
void mobiParsing (UDBElement *file, const std::filesystem::path &file_path)
void archiveParsing (UDBElement *file, const std::filesystem::path &file_path)
std::string bufferHash (const std::string &buf)
std::string fileHash (const std::filesystem::path &file_path)
void bufHash (UDBElement *file, const std::filesystem::path &file_path, const std::string &buf)

Protected Attributes

std::shared_ptr< MLBookProc > mlbp
std::shared_ptr< std::vector< std::tuple< unsigned, bool > > > threads_v
std::shared_ptr< std::mutex > threads_v_mtx
std::shared_ptr< std::condition_variable > threads_v_var
std::atomic< bool > cancel
std::vector< std::shared_ptr< ArchiveParser > > arch_proc
std::mutex arch_proc_mtx
std::vector< std::tuple< std::filesystem::path, std::string > > already_hashed
BaseID bid
std::atomic< double > processed
double total

Detailed Description

The CreateCollection class.

This class contains methods for collection database creation.

Constructor & Destructor Documentation

◆ CreateCollection()

CreateCollection::CreateCollection ( const std::shared_ptr< MLBookProc > & mlbp,
const int & threads_num = int(1) )

CreateCollection constructor.

Parameters
mlbpSmart pointer to MLBookProc object.
threads_numMaximum permitted number of working threads.

Member Function Documentation

◆ archiveParsing()

void CreateCollection::archiveParsing ( UDBElement * file,
const std::filesystem::path & file_path )
protected

Parses archive file.

Parameters
filePointer to BaseID::File object.
file_pathPath to file to be parsed.

◆ bufferHash()

std::string CreateCollection::bufferHash ( const std::string & buf)
protected

Calcultes hash sum for given buffer.

Parameters
bufBuffer hash sum to be calculated for.
Returns
std::string containing raw hash sum.

◆ bufHash()

void CreateCollection::bufHash ( UDBElement * file,
const std::filesystem::path & file_path,
const std::string & buf )
protected

Calcultes hash sum for given BaseID::File object.

Caller can provide file_path ot buf on his choice.

Parameters
filePointer to BaseID::File object.
file_pathPath to file hash sum to be calculated for.
bufBuffer hash sum to be calculted for.

◆ cleanBase()

void CreateCollection::cleanBase ( std::vector< UDBElement > & items)
protected

Removes all BaseID::File objects, not containing BaseID::Book objects.

Parameters
itemsItems to be cleaned.

◆ countFiles()

size_t CreateCollection::countFiles ( const std::vector< UDBElement > & el_v)
protected

Counts BaseID::File objects in given vector.

Parameters
el_vVector to be processed.
Returns
Quantity of BaseID::File objects.

◆ createCollection()

void CreateCollection::createCollection ( const std::vector< std::filesystem::path > & files_and_dirs,
const std::filesystem::path & base_path )

Creates collection database.

Parameters
files_and_dirsFiles, directories and symlinks to be included in collection.
base_pathPath to result database file.

◆ createInpxCollection()

void CreateCollection::createInpxCollection ( const std::filesystem::path & path_to_inpx,
const std::filesystem::path & base_path )

Creates database from inpx file.

Parameters
path_to_inpxPath to inpx file.
base_pathPath to result database file.

◆ djvuParsing()

void CreateCollection::djvuParsing ( UDBElement * file,
const std::filesystem::path & file_path )
protected

Parses djvu file.

Parameters
filePointer to BaseID::File object.
file_pathPath to file to be parsed.

◆ docParsing()

void CreateCollection::docParsing ( UDBElement * file,
const std::filesystem::path & file_path )
protected

Parses doc files.

Parameters
filePointer to BaseID::File object.
file_pathPath to file to be parsed.

◆ docxParsing()

void CreateCollection::docxParsing ( UDBElement * file,
const std::filesystem::path & file_path )
protected

Parses docx files.

Parameters
filePointer to BaseID::File object.
file_pathPath to file to be parsed.

◆ epubParsing()

void CreateCollection::epubParsing ( UDBElement * file,
const std::filesystem::path & file_path )
protected

Parses epub file.

Parameters
filePointer to BaseID::File object.
file_pathPath to file to be parsed.

◆ fb2Parsing()

void CreateCollection::fb2Parsing ( UDBElement * file,
const std::filesystem::path & file_path )
protected

Parses fb2 and fbd file.

Parameters
filePointer to BaseID::File object.
file_pathPath to file to be parsed.

◆ fileHash()

std::string CreateCollection::fileHash ( const std::filesystem::path & file_path)
protected

Calculates file hash sum.

Parameters
file_pathPath to file hash sum to be calculated for.
Returns
std::string containing raw hash sum.

◆ fileParsing()

void CreateCollection::fileParsing ( UDBElement * file)
protected

Parses given BaseID::File object.

Parameters
filePointer to BaseID::File object.

◆ filesCollecting()

void CreateCollection::filesCollecting ( const std::vector< std::filesystem::path > & files_and_dirs,
UDBase & col_base )
protected

Collects supported files and creates base template. In most cases you do not need to call this method yourself.

Parameters
files_and_dirsFiles, directories and symlinks to be included in collection.
col_baseResult database.

◆ getAllFiles()

std::vector< std::tuple< const std::vector< UDBElement > *, std::vector< UDBElement >::const_iterator > > CreateCollection::getAllFiles ( const std::vector< UDBElement > & el_v)
protected

Collects all BaseID::File objects.

Parameters
el_vVector to be processed.
Returns
std::tuple. First element is pointer to vector where BaseID::File object has been found. Second element is objects iterator.

◆ mobiParsing()

void CreateCollection::mobiParsing ( UDBElement * file,
const std::filesystem::path & file_path )
protected

Parses mobi files.

Parameters
filePointer to BaseID::File object.
file_pathPath to file to be parsed.

◆ odtParsing()

void CreateCollection::odtParsing ( UDBElement * file,
const std::filesystem::path & file_path )
protected

Parses odt file.

Parameters
filePointer to BaseID::File object.
file_pathPath to file to be parsed.

◆ pdfParsing()

void CreateCollection::pdfParsing ( UDBElement * file,
const std::filesystem::path & file_path )
protected

Parses pdf file.

Parameters
filePointer to BaseID::File object.
file_pathPath to file to be parsed.

◆ processFiles()

void CreateCollection::processFiles ( const std::vector< UDBElement > & items)
protected

Processed given items.

Parameters
itemsDatabase template vector.

◆ removeDublicates()

void CreateCollection::removeDublicates ( std::vector< std::tuple< const std::vector< UDBElement > *, std::vector< UDBElement >::const_iterator > > & files)
protected

Cleans given vector from repeated BaseID::File objects.

Parameters
filesVector obtained from getAllFiles() method.

◆ rtfParsing()

void CreateCollection::rtfParsing ( UDBElement * file,
const std::filesystem::path & file_path )
protected

Parses rtf files.

Parameters
filePointer to BaseID::File object.
file_pathPath to file to be parsed.

◆ saveBase()

void CreateCollection::saveBase ( const std::filesystem::path & base_path,
UDBase & col_base )
static

Writes given base to file.

Parameters
base_pathPath to database file.
col_baseCollection database.

◆ stopAll()

virtual void CreateCollection::stopAll ( )
virtual

Stops all operations.

Reimplemented in RefreshCollection.

◆ txtParsing()

void CreateCollection::txtParsing ( UDBElement * file,
const std::filesystem::path & file_path )
protected

Parses txt and md files.

Parameters
filePointer to BaseID::File object.
file_pathPath to file to be parsed.

Member Data Documentation

◆ already_hashed

std::vector<std::tuple<std::filesystem::path, std::string> > CreateCollection::already_hashed
protected

Vector of files for which hash sums has been calculated erlear (in RefreshCollection methods).

First element of tuple - path to file. Second element - raw hash sum.

Warning
Do not set or modify this object yourself.

◆ arch_proc

std::vector<std::shared_ptr<ArchiveParser> > CreateCollection::arch_proc
protected

Vector of active archives parsing processes.

Warning
Do not set or modify this object yourself.

◆ arch_proc_mtx

std::mutex CreateCollection::arch_proc_mtx
protected

std::mutex locking arch_proc vector.

Warning
Do not set or modify this object yourself.

◆ bid

BaseID CreateCollection::bid
protected

BaseID object.

◆ cancel

std::atomic<bool> CreateCollection::cancel
protected

If set to true all processes will be stopped.

Warning
Do not set or modify this object yourself.

◆ mlbp

std::shared_ptr<MLBookProc> CreateCollection::mlbp
protected

Smart pointer to MlBookProc object.

Warning
Do not set or modify this object yourself.

◆ processed

std::atomic<double> CreateCollection::processed
protected

Number of processed items.

Warning
Do not set or modify this object yourself.

◆ signal_files_collecting

std::function<void(const size_t &files_found)> CreateCollection::signal_files_collecting

This callback function will be called during files collecting to indicate progress if set. files_found - total number of found files.

◆ signal_parsing_progress

std::function<void(double processed, double total)> CreateCollection::signal_parsing_progress

This callback function will be called during files parsing to indicate progress, if set. processed - number of processed items, total - total number of items to be processed.

◆ threads_v

std::shared_ptr<std::vector<std::tuple<unsigned, bool> > > CreateCollection::threads_v
protected

Smart pointer to processors identificators buffer.

First element of tuple - processor number. Second element indicates if processor is busy by any working thread of current collection creation process.

Warning
Do not set or modify this object yourself.

◆ threads_v_mtx

std::shared_ptr<std::mutex> CreateCollection::threads_v_mtx
protected

Smart pointer to mutex locking threads_v.

Warning
Do not set or modify this object yourself.

◆ threads_v_var

std::shared_ptr<std::condition_variable> CreateCollection::threads_v_var
protected

Smart pointer to conditional variable locking threads_v.

Warning
Do not set or modify this object yourself.

◆ total

double CreateCollection::total
protected

Total number of items to be processed.

Warning
Do not set or modify this object yourself.