MLBookProc 2.1
Loading...
Searching...
No Matches
BaseKeeper.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 BASEKEEPER_H
17#define BASEKEEPER_H
18
19#include <BaseID.h>
20#include <MLBookProc.h>
21#include <NotesKeeper.h>
22#include <UDBase.h>
23#include <filesystem>
24#include <functional>
25#include <shared_mutex>
26
33class BaseKeeper : public UDBase
34{
35public:
40 BaseKeeper(const std::shared_ptr<MLBookProc> &mlbp);
41
42 virtual ~BaseKeeper();
43
51 void
52 loadCollection(const std::filesystem::path &base_path);
53
59 size_t
61
67 size_t
69
84 UDBase
85 searchBook(const std::vector<UDBElement> &requests,
86 const double &coef_coincedence);
87
91 void
93
101 std::string
103
111 std::filesystem::path
113
121 void
122 editBookEntry(const UDBElement &book_search_result);
123
133 UDBase
134 searchBooksWithNotes(const std::shared_ptr<NotesKeeper> &notes);
135
143 UDBase
145
151 UDBase
153
162 void
163 exportBase(const std::filesystem::path &result_path);
164
169 std::filesystem::path
171
178 static UDBElement
179 getBaseAnchorFileName(const std::filesystem::path &base_path);
180
192 static void
193 importCollectionBase(const std::filesystem::path &source_base_path,
194 const std::filesystem::path &coll_base_path,
195 const std::filesystem::path &anchor_file);
196
200 void
202
203private:
204 void
205 loadCollectionLegacy(const std::vector<char> &buf);
206
207 void
208 parseFileEntryLegacy(const std::string &buf, const std::string &books_path);
209
210 void
211 parseBookEntryLegacy(const std::string &buf,
212 std::vector<UDBElement> &result);
213
214 UDBase
215 searchElement(std::function<void(const UDBElement &, UDBase &)>
216 search_function) override;
217
218 void
219 searchFunc(const UDBElement &el, UDBase *result,
220 const std::vector<std::tuple<
221 UDBElement, std::function<bool(const UDBElement &book_el,
222 const UDBElement &to_search)>>>
223 &l_request);
224
225 bool
226 authorSearch(const UDBElement &book_el, const UDBElement &to_search,
227 const double &coef_coincidence);
228
229 bool
230 bookSearch(const UDBElement &book_el, const UDBElement &to_search,
231 const double &coef_coincidence);
232
233 bool
234 sequenceSearch(const UDBElement &book_el, const UDBElement &to_search,
235 const std::string &name, const std::string &number,
236 const std::string &content, const double &coef_coincidence);
237
238 bool
239 genreSearch(const UDBElement &book_el, const UDBElement &to_search,
240 const double &coef_coincidence);
241
242 std::vector<UDBElement *>
243 searchFile(const std::vector<UDBElement> &src, const std::string &file_path);
244
245 enum Normalization
246 {
247 Author,
248 Other
249 };
250
251 bool
252 searchLineFunc(const std::string &to_search, const std::string &source,
253 const double &coef_coincidence,
254 const Normalization &variant = Normalization::Other);
255
256 void
257 normalizeString(std::string &str, const Normalization &variant);
258
259 size_t
260 booksQuantity(const std::vector<UDBElement> &items);
261
262 size_t
263 filesQuantity(const std::vector<UDBElement> &items);
264
265 UDBase
266 searchInNotes(const std::vector<UDBElement> &src,
267 const std::shared_ptr<NotesKeeper> &notes);
268
269 UDBase
270 getFiles(const std::vector<UDBElement> &src);
271
272 void
273 listAuthors(const std::vector<UDBElement> &src,
274 std::vector<UDBElement> *result);
275
276 void
277 setRelativePath(std::vector<UDBElement> &src,
278 const std::filesystem::path &base_path);
279
280 static void
281 setAbsolutePath(std::vector<UDBElement> &src,
282 const std::filesystem::path &base_path);
283
284 std::shared_ptr<MLBookProc> mlbp;
285
286 bool cancel_search = false;
287
288 std::filesystem::path current_base_path;
289
290 BaseID bid;
291
292 std::shared_mutex base_mtx;
293};
294
295#endif // BASEKEEPER_H
The BaseID class.
Definition BaseID.h:28
std::filesystem::path getCurrentCollectionBasePath()
UDBase getAllFiles()
void unloadCollection()
UDBase listAllAuthors()
UDBase searchBook(const std::vector< UDBElement > &requests, const double &coef_coincedence)
size_t getFilesQuantity()
static UDBElement getBaseAnchorFileName(const std::filesystem::path &base_path)
void cancelSearch()
void loadCollection(const std::filesystem::path &base_path)
size_t getBooksQuantity()
void exportBase(const std::filesystem::path &result_path)
UDBase searchBooksWithNotes(const std::shared_ptr< NotesKeeper > &notes)
void editBookEntry(const UDBElement &book_search_result)
BaseKeeper(const std::shared_ptr< MLBookProc > &mlbp)
BaseKeeper constructor.
std::string getCollectionType()
std::filesystem::path getBooksDirectory()
static void importCollectionBase(const std::filesystem::path &source_base_path, const std::filesystem::path &coll_base_path, const std::filesystem::path &anchor_file)