LibUDB 1.0
Loading...
Searching...
No Matches
UDBase.h
1/*
2 * Copyright (C) 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#ifndef UDBASE_H
17#define UDBASE_H
18
19#include <UDBElement.h>
20#include <filesystem>
21#include <functional>
22#include <omp.h>
23#include <vector>
24
52
57class UDBase
58{
59public:
60 UDBase();
61
62 virtual ~UDBase();
63
70 UDBase(const UDBase &other);
71
78 UDBase(UDBase &&other);
79
85 UDBase &
86 operator=(const UDBase &other);
87
93 UDBase &
94 operator=(UDBase &&other);
95
102 UDBase &
103 operator+=(const UDBase &other);
104
111 void
112 writeToBuffer(std::vector<char> &result);
113
126 void
127 readFromBuffer(const std::vector<char> &buf, const size_t &offset = 0,
128 const size_t &bytes_to_read = 0);
137 void
138 writeToFile(const std::filesystem::path &f_path);
139
147 void
148 readFromFile(const std::filesystem::path &f_path);
149
155 std::vector<UDBElement> *
156 getRawBase() const;
157
163 void
165
172 void
173 addElements(const std::vector<UDBElement> &elements);
174
181 virtual void
183
191 virtual void
192 removeElements(std::function<bool(const UDBElement &)> predicate);
193
201 virtual void
202 replaceElement(const UDBElement &old_el, const UDBElement &new_el);
203
207 void
209
213 void
215
224 virtual UDBase
225 searchElement(std::function<bool(const UDBElement &)> search_function);
226
233 virtual UDBase
235 std::function<void(const UDBElement &, UDBase &)> search_function);
236
244 virtual std::vector<UDBElement>
245 searchElementV(std::function<bool(const UDBElement &)> search_function);
246
253 virtual void
254 sortBase(std::function<bool(const UDBElement &, const UDBElement &)>
255 sort_function);
256
262 size_t
263 baseSize() const;
264
271 static UDBase
272 convertToBase(const std::vector<UDBElement> &elements);
273
280 size_t
282
292 std::vector<UDBase>
293 splitBase(const size_t &bytes_limit,
294 const size_t &minimum_elements = size_t(1));
295
296protected:
304 void
305 readFromBufferInner(const std::vector<char> &buf, const size_t &offset,
306 const size_t &bytes_to_read);
307
314 void
315 writeToBufferInner(std::vector<char> &result);
316
320 std::vector<UDBElement> base;
321
325 std::string base_version = "UDB 1.0";
326};
327
328#endif // UDBASE_H
The UDBElement class.
Definition UDBElement.h:28
virtual UDBase searchElement(std::function< void(const UDBElement &, UDBase &)> search_function)
std::vector< UDBase > splitBase(const size_t &bytes_limit, const size_t &minimum_elements=size_t(1))
virtual void removeElements(std::function< bool(const UDBElement &)> predicate)
virtual void replaceElement(const UDBElement &old_el, const UDBElement &new_el)
void readFromFile(const std::filesystem::path &f_path)
virtual void removeElement(const UDBElement &el)
void clearBase()
size_t baseSize() const
virtual void sortBase(std::function< bool(const UDBElement &, const UDBElement &)> sort_function)
static UDBase convertToBase(const std::vector< UDBElement > &elements)
void readFromBufferInner(const std::vector< char > &buf, const size_t &offset, const size_t &bytes_to_read)
void addElements(const std::vector< UDBElement > &elements)
UDBase & operator=(UDBase &&other)
UDBase & operator=(const UDBase &other)
UDBase(UDBase &&other)
virtual UDBase searchElement(std::function< bool(const UDBElement &)> search_function)
void readFromBuffer(const std::vector< char > &buf, const size_t &offset=0, const size_t &bytes_to_read=0)
size_t calculateWriteSize()
void addElement(const UDBElement &el)
std::vector< UDBElement > base
Internal base object.
Definition UDBase.h:320
UDBase(const UDBase &other)
void writeToBufferInner(std::vector< char > &result)
UDBase & operator+=(const UDBase &other)
void writeToBuffer(std::vector< char > &result)
void shrinkToFit()
std::vector< UDBElement > * getRawBase() const
std::string base_version
Base version string used to identify base in buffers and files.
Definition UDBase.h:325
void writeToFile(const std::filesystem::path &f_path)
virtual std::vector< UDBElement > searchElementV(std::function< bool(const UDBElement &)> search_function)