implement blocks data saving/loading

This commit is contained in:
MihailRis
2024-09-30 23:42:16 +03:00
parent e84c79839c
commit 28d746f371
11 changed files with 107 additions and 15 deletions
+9 -1
View File
@@ -4,6 +4,8 @@
#include <cstring>
namespace util {
/// @brief Template similar to std::unique_ptr stores a buffer with its size
/// @tparam T buffer elements type
template<typename T>
class Buffer {
std::unique_ptr<T[]> ptr;
@@ -12,7 +14,9 @@ namespace util {
Buffer(size_t length)
: ptr(std::make_unique<T[]>(length)), length(length) {
}
Buffer(const Buffer<T>& o) : Buffer(o.data(), o.size()) {}
explicit Buffer(const Buffer<T>& o) : Buffer(o.data(), o.size()) {}
Buffer(Buffer<T>&& o) : ptr(std::move(o.ptr)), length(o.length) {}
Buffer(std::unique_ptr<T[]> ptr, size_t length)
: ptr(std::move(ptr)), length(length) {}
@@ -42,14 +46,18 @@ namespace util {
return length;
}
/// @brief Take ownership over the buffer unique_ptr
std::unique_ptr<T[]> release() {
return std::move(ptr);
}
/// @brief Create a buffer copy
Buffer clone() const {
return Buffer(ptr.get(), length);
}
/// @brief Update buffer size without releasing used memory
/// @param size new size (must be less or equal to current)
void resizeFast(size_t size) {
length = size;
}