synth/arm/buffer.h

31 lines
632 B
C
Raw Permalink Normal View History

2022-05-17 03:56:25 +00:00
#pragma once
#include <span>
#include <utility>
2022-05-17 17:17:56 +00:00
2022-05-17 03:56:25 +00:00
struct buffer {
2022-05-17 17:17:56 +00:00
std::span<std::byte> data;
buffer() = default;
buffer(std::span<std::byte> d) : data(d) {}
static buffer make(size_t size) {
return buffer({new std::byte[size], size});
}
buffer(buffer& other) = delete;
buffer& operator=(buffer& other) = delete;
buffer(buffer&& other) : data(std::exchange(other.data, {})) {}
buffer& operator=(buffer&& other) {
data = std::exchange(other.data, {});
return *this;
}
~buffer() {
if (data.data()) {
delete[] data.data();
};
}
2022-05-17 03:56:25 +00:00
};