MLBookProc 1.3
Loading...
Searching...
No Matches
BaseKeeper.h
1/*
2 * Copyright (C) 2024-2025 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
17#ifndef BASEKEEPER_H
18#define BASEKEEPER_H
19
20#include <AuxFunc.h>
21#include <BookBaseEntry.h>
22#include <FileParseEntry.h>
23#include <NotesBaseEntry.h>
24#include <filesystem>
25#include <functional>
26#include <memory>
27#include <mutex>
28#include <string>
29#include <vector>
30
31#ifdef USE_OPENMP
32#include <omp.h>
33#else
34#include <atomic>
35#endif
36
44{
45public:
50 BaseKeeper(const std::shared_ptr<AuxFunc> &af);
51
55 virtual ~BaseKeeper();
56
64 void
65 loadCollection(const std::string &col_name);
66
85 std::vector<BookBaseEntry>
87 const double &coef_coincedence = double(0.7));
88
93 std::vector<std::string>
95
101 std::vector<BookBaseEntry>
102 booksWithNotes(const std::vector<NotesBaseEntry> &notes);
103
107 void
109
113 void
115
120 std::vector<FileParseEntry>
122
134 static std::filesystem::path
135 get_books_path(const std::string &collection_name,
136 const std::shared_ptr<AuxFunc> &af);
137
146 size_t
148
157 std::function<void(const double &progr, const double &sz)> auth_show_progr;
158
159private:
161 readFileEntry(const std::string &base, size_t &rb);
162
163 std::vector<BookParseEntry>
164 readBookEntry(const std::string &entry, size_t &rb);
165
166 void
167 parseBookEntry(const std::string &e, std::string &read_val, size_t &rb);
168
169 enum Normalization
170 {
171 Author,
172 Other
173 };
174
175 bool
176 searchLineFunc(const std::string &to_search, const std::string &source,
177 const double &coef_coincidence,
178 const Normalization &variant = Normalization::Other);
179
180 bool
181 searchSurname(const BookBaseEntry &search,
182 std::vector<BookBaseEntry> &result,
183 const double &coef_coincidence);
184 bool
185 searchFirstName(const BookBaseEntry &search,
186 std::vector<BookBaseEntry> &result,
187 const double &coef_coincidence);
188
189 bool
190 searchLastName(const BookBaseEntry &search,
191 std::vector<BookBaseEntry> &result,
192 const double &coef_coincidence);
193
194 void
195 searchBook(const BookBaseEntry &search, std::vector<BookBaseEntry> &result,
196 const double &coef_coincidence);
197
198 void
199 searchSeries(const BookBaseEntry &search, std::vector<BookBaseEntry> &result,
200 const double &coef_coincidence);
201
202 void
203 searchGenre(const BookBaseEntry &search, std::vector<BookBaseEntry> &result,
204 const double &coef_coincidence);
205
206 bool
207 exactMatchSearchFunc(const BookBaseEntry &el, const BookBaseEntry &search);
208
209 void
210 normalizeString(std::string &str, const Normalization &variant);
211
212 std::shared_ptr<AuxFunc> af;
213
214 std::vector<FileParseEntry> base;
215 std::string collection_name;
216 std::filesystem::path collection_path;
217 size_t books_in_base = 0;
218#ifdef USE_OPENMP
219 omp_lock_t basemtx;
220 bool cancel_search;
221#else
222 std::mutex basemtx;
223 std::atomic<bool> cancel_search;
224#endif
225};
226
227#endif // BASEKEEPER_H
std::vector< FileParseEntry > get_base_vector()
Returns copy of inner database vector.
std::vector< BookBaseEntry > booksWithNotes(const std::vector< NotesBaseEntry > &notes)
Lists all books of current collection, which have notes.
void clearBase()
Unloads collection base from memory.
std::vector< BookBaseEntry > searchBook(const BookBaseEntry &search, const double &coef_coincedence=double(0.7))
Searches book in collection.
BaseKeeper(const std::shared_ptr< AuxFunc > &af)
BaseKeeper constructor.
size_t getBooksQuantity()
Returns total quantity of books in loaded collection.
virtual ~BaseKeeper()
BaseKeeper destructor.
void stopSearch()
Stops all search operations.
std::function< void(const double &progr, const double &sz)> auth_show_progr
collectionAuthors() progress callback
Definition BaseKeeper.h:157
void loadCollection(const std::string &col_name)
Loads collection database to memory.
std::vector< std::string > collectionAuthors()
Lists all authors, found in collection.
static std::filesystem::path get_books_path(const std::string &collection_name, const std::shared_ptr< AuxFunc > &af)
Returns absolute path to directory containing collection books.
The BookBaseEntry class.
Definition BookBaseEntry.h:30
The FileParseEntry class.
Definition FileParseEntry.h:31