MLBookProc 1.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 <string>
28#include <vector>
29
30#ifdef USE_OPENMP
31#include <omp.h>
32#else
33#include <atomic>
34#include <mutex>
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
78 std::vector<BookBaseEntry>
79 searchBook(const BookBaseEntry &search);
80
85 std::vector<std::string>
87
93 std::vector<BookBaseEntry>
94 booksWithNotes(const std::vector<NotesBaseEntry> &notes);
95
99 void
101
105 void
107
112 std::vector<FileParseEntry>
114
126 static std::filesystem::path
127 get_books_path(const std::string &collection_name,
128 const std::shared_ptr<AuxFunc> &af);
129
138 std::function<void(const double &progr, const double &sz)> auth_show_progr;
139
140private:
142 readFileEntry(const std::string &base, size_t &rb);
143
144 std::vector<BookParseEntry>
145 readBookEntry(const std::string &entry, size_t &rb);
146
147 void
148 parseBookEntry(const std::string &e, std::string &read_val, size_t &rb);
149
150 bool
151 searchLineFunc(const std::string &to_search, const std::string &source);
152
153 bool
154 searchSurname(const BookBaseEntry &search,
155 std::vector<BookBaseEntry> &result);
156 bool
157 searchFirstName(const BookBaseEntry &search,
158 std::vector<BookBaseEntry> &result);
159
160 bool
161 searchLastName(const BookBaseEntry &search,
162 std::vector<BookBaseEntry> &result);
163
164 void
165 searchBook(const BookBaseEntry &search, std::vector<BookBaseEntry> &result);
166 void
167 searchSeries(const BookBaseEntry &search,
168 std::vector<BookBaseEntry> &result);
169
170 void
171 searchGenre(const BookBaseEntry &search, std::vector<BookBaseEntry> &result);
172
173 std::shared_ptr<AuxFunc> af;
174
175 std::vector<FileParseEntry> base;
176 std::string collection_name;
177 std::filesystem::path collection_path;
178#ifdef USE_OPENMP
179 omp_lock_t basemtx;
180 bool cancel_search;
181#else
182 std::mutex basemtx;
183 std::atomic<bool> cancel_search;
184#endif
185};
186
187#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.
BaseKeeper(const std::shared_ptr< AuxFunc > &af)
BaseKeeper constructor.
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:138
void loadCollection(const std::string &col_name)
Loads collection database to memory.
std::vector< std::string > collectionAuthors()
Lists all authors, found in collection.
std::vector< BookBaseEntry > searchBook(const BookBaseEntry &search)
Searches book 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