MLBookProc 1.2.1
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 bool
170 searchLineFunc(const std::string &to_search, const std::string &source,
171 const double &coef_coincidence);
172
173 bool
174 searchSurname(const BookBaseEntry &search,
175 std::vector<BookBaseEntry> &result,
176 const double &coef_coincidence);
177 bool
178 searchFirstName(const BookBaseEntry &search,
179 std::vector<BookBaseEntry> &result,
180 const double &coef_coincidence);
181
182 bool
183 searchLastName(const BookBaseEntry &search,
184 std::vector<BookBaseEntry> &result,
185 const double &coef_coincidence);
186
187 void
188 searchBook(const BookBaseEntry &search, std::vector<BookBaseEntry> &result,
189 const double &coef_coincidence);
190
191 void
192 searchSeries(const BookBaseEntry &search, std::vector<BookBaseEntry> &result,
193 const double &coef_coincidence);
194
195 void
196 searchGenre(const BookBaseEntry &search, std::vector<BookBaseEntry> &result,
197 const double &coef_coincidence);
198
199 bool
200 exactMatchSearchFunc(const BookBaseEntry &el, const BookBaseEntry &search);
201
202 std::shared_ptr<AuxFunc> af;
203
204 std::vector<FileParseEntry> base;
205 std::string collection_name;
206 std::filesystem::path collection_path;
207 size_t books_in_base = 0;
208#ifdef USE_OPENMP
209 omp_lock_t basemtx;
210 bool cancel_search;
211#else
212 std::mutex basemtx;
213 std::atomic<bool> cancel_search;
214#endif
215};
216
217#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