MLBookProc 2.1
Loading...
Searching...
No Matches
CreateCollection.h
1/*
2 * Copyright (C) 2026 Yury Bobylev <bobilev_yury@mail.ru>
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation, version 3.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program. If not, see <https://www.gnu.org/licenses/>.
15 */
16#ifndef CREATECOLLECTION_H
17#define CREATECOLLECTION_H
18
19#include <ArchiveParser.h>
20#include <BaseID.h>
21#include <MLBookProc.h>
22#include <UDBase.h>
23#include <atomic>
24#include <condition_variable>
25#include <filesystem>
26#include <functional>
27#include <mutex>
28#include <tuple>
29#include <vector>
30
37{
38public:
44 CreateCollection(const std::shared_ptr<MLBookProc> &mlbp,
45 const int &threads_num = int(1));
46
47 virtual ~CreateCollection();
48
56 void
57 createCollection(const std::vector<std::filesystem::path> &files_and_dirs,
58 const std::filesystem::path &base_path);
59
66 void
67 createInpxCollection(const std::filesystem::path &path_to_inpx,
68 const std::filesystem::path &base_path);
69
73 virtual void
75
82 static void
83 saveBase(const std::filesystem::path &base_path, UDBase &col_base);
84
89 std::function<void(const size_t &files_found)> signal_files_collecting;
90
96 std::function<void(double processed, double total)> signal_parsing_progress;
97
98protected:
107 void
108 filesCollecting(const std::vector<std::filesystem::path> &files_and_dirs,
109 UDBase &col_base);
110
117 size_t
118 countFiles(const std::vector<UDBElement> &el_v);
119
127 std::vector<std::tuple<const std::vector<UDBElement> *,
128 std::vector<UDBElement>::const_iterator>>
129 getAllFiles(const std::vector<UDBElement> &el_v);
130
135 void
137 std::vector<std::tuple<const std::vector<UDBElement> *,
138 std::vector<UDBElement>::const_iterator>> &files);
139
145 void
146 processFiles(const std::vector<UDBElement> &items);
147
153 void
154 fileParsing(UDBElement *file);
155
160 void
161 cleanBase(std::vector<UDBElement> &items);
162
169 void
170 fb2Parsing(UDBElement *file, const std::filesystem::path &file_path);
171
178 void
179 epubParsing(UDBElement *file, const std::filesystem::path &file_path);
180
187 void
188 pdfParsing(UDBElement *file, const std::filesystem::path &file_path);
189
196 void
197 djvuParsing(UDBElement *file, const std::filesystem::path &file_path);
198
205 void
206 odtParsing(UDBElement *file, const std::filesystem::path &file_path);
207
214 void
215 txtParsing(UDBElement *file, const std::filesystem::path &file_path);
216
223 void
224 docParsing(UDBElement *file, const std::filesystem::path &file_path);
225
232 void
233 rtfParsing(UDBElement *file, const std::filesystem::path &file_path);
234
241 void
242 docxParsing(UDBElement *file, const std::filesystem::path &file_path);
243
250 void
251 mobiParsing(UDBElement *file, const std::filesystem::path &file_path);
252
259 void
260 archiveParsing(UDBElement *file, const std::filesystem::path &file_path);
261
268 std::string
269 bufferHash(const std::string &buf);
270
277 std::string
278 fileHash(const std::filesystem::path &file_path);
279
289 void
290 bufHash(UDBElement *file, const std::filesystem::path &file_path,
291 const std::string &buf);
292
298 std::shared_ptr<MLBookProc> mlbp;
299
309 std::shared_ptr<std::vector<std::tuple<unsigned, bool>>> threads_v;
310
316 std::shared_ptr<std::mutex> threads_v_mtx;
317
323 std::shared_ptr<std::condition_variable> threads_v_var;
324
330 std::atomic<bool> cancel;
331
337 std::vector<std::shared_ptr<ArchiveParser>> arch_proc;
338
344 std::mutex arch_proc_mtx;
345
354 std::vector<std::tuple<std::filesystem::path, std::string>> already_hashed;
355
360
366 std::atomic<double> processed;
367
373 double total;
374};
375
376#endif // CREATECOLLECTION_H
The BaseID class.
Definition BaseID.h:28
std::shared_ptr< std::vector< std::tuple< unsigned, bool > > > threads_v
Definition CreateCollection.h:309
void docParsing(UDBElement *file, const std::filesystem::path &file_path)
std::mutex arch_proc_mtx
Definition CreateCollection.h:344
std::vector< std::tuple< std::filesystem::path, std::string > > already_hashed
Definition CreateCollection.h:354
std::atomic< bool > cancel
Definition CreateCollection.h:330
CreateCollection(const std::shared_ptr< MLBookProc > &mlbp, const int &threads_num=int(1))
CreateCollection constructor.
void createInpxCollection(const std::filesystem::path &path_to_inpx, const std::filesystem::path &base_path)
size_t countFiles(const std::vector< UDBElement > &el_v)
void rtfParsing(UDBElement *file, const std::filesystem::path &file_path)
void filesCollecting(const std::vector< std::filesystem::path > &files_and_dirs, UDBase &col_base)
void docxParsing(UDBElement *file, const std::filesystem::path &file_path)
BaseID bid
Definition CreateCollection.h:359
void cleanBase(std::vector< UDBElement > &items)
void odtParsing(UDBElement *file, const std::filesystem::path &file_path)
void pdfParsing(UDBElement *file, const std::filesystem::path &file_path)
void archiveParsing(UDBElement *file, const std::filesystem::path &file_path)
static void saveBase(const std::filesystem::path &base_path, UDBase &col_base)
std::atomic< double > processed
Definition CreateCollection.h:366
void fileParsing(UDBElement *file)
double total
Definition CreateCollection.h:373
std::function< void(double processed, double total)> signal_parsing_progress
Definition CreateCollection.h:96
void epubParsing(UDBElement *file, const std::filesystem::path &file_path)
void processFiles(const std::vector< UDBElement > &items)
virtual void stopAll()
void bufHash(UDBElement *file, const std::filesystem::path &file_path, const std::string &buf)
void txtParsing(UDBElement *file, const std::filesystem::path &file_path)
void djvuParsing(UDBElement *file, const std::filesystem::path &file_path)
std::shared_ptr< std::mutex > threads_v_mtx
Definition CreateCollection.h:316
void removeDublicates(std::vector< std::tuple< const std::vector< UDBElement > *, std::vector< UDBElement >::const_iterator > > &files)
std::shared_ptr< MLBookProc > mlbp
Definition CreateCollection.h:298
std::string bufferHash(const std::string &buf)
void fb2Parsing(UDBElement *file, const std::filesystem::path &file_path)
std::string fileHash(const std::filesystem::path &file_path)
std::function< void(const size_t &files_found)> signal_files_collecting
Definition CreateCollection.h:89
std::vector< std::tuple< const std::vector< UDBElement > *, std::vector< UDBElement >::const_iterator > > getAllFiles(const std::vector< UDBElement > &el_v)
void createCollection(const std::vector< std::filesystem::path > &files_and_dirs, const std::filesystem::path &base_path)
std::vector< std::shared_ptr< ArchiveParser > > arch_proc
Definition CreateCollection.h:337
std::shared_ptr< std::condition_variable > threads_v_var
Definition CreateCollection.h:323
void mobiParsing(UDBElement *file, const std::filesystem::path &file_path)