MLBookProc 1.0
 
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 <memory>
26#include <string>
27#include <vector>
28
29#ifdef USE_OPENMP
30#include <omp.h>
31#else
32#include <atomic>
33#include <mutex>
34#endif
35
43{
44public:
49 BaseKeeper(const std::shared_ptr<AuxFunc> &af);
50
54 virtual ~BaseKeeper();
55
63 void
64 loadCollection(const std::string &col_name);
65
77 std::vector<BookBaseEntry>
78 searchBook(const BookBaseEntry &search);
79
84 std::vector<std::string>
86
92 std::vector<BookBaseEntry>
93 booksWithNotes(const std::vector<NotesBaseEntry> &notes);
94
98 void
100
104 void
106
111 std::vector<FileParseEntry>
113
125 static std::filesystem::path
126 get_books_path(const std::string &collection_name,
127 const std::shared_ptr<AuxFunc> &af);
128
129private:
131 readFileEntry(const std::string &base, size_t &rb);
132
133 std::vector<BookParseEntry>
134 readBookEntry(const std::string &entry, size_t &rb);
135
136 void
137 parseBookEntry(const std::string &e, std::string &read_val, size_t &rb);
138
139 bool
140 searchLineFunc(const std::string &to_search, const std::string &source);
141
142 bool
143 searchSurname(const BookBaseEntry &search,
144 std::vector<BookBaseEntry> &result);
145 bool
146 searchFirstName(const BookBaseEntry &search,
147 std::vector<BookBaseEntry> &result);
148
149 bool
150 searchLastName(const BookBaseEntry &search,
151 std::vector<BookBaseEntry> &result);
152
153 void
154 searchBook(const BookBaseEntry &search, std::vector<BookBaseEntry> &result);
155 void
156 searchSeries(const BookBaseEntry &search,
157 std::vector<BookBaseEntry> &result);
158
159 void
160 searchGenre(const BookBaseEntry &search, std::vector<BookBaseEntry> &result);
161
162 std::shared_ptr<AuxFunc> af;
163
164 std::vector<FileParseEntry> base;
165 std::string collection_name;
166 std::filesystem::path collection_path;
167#ifdef USE_OPENMP
168 omp_lock_t basemtx;
169 bool cancel_search;
170#else
171 std::mutex basemtx;
172 std::atomic<bool> cancel_search;
173#endif
174};
175
176#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.
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