Luna/libluna/include/luna/Buffer.h

53 lines
797 B
C
Raw Normal View History

#pragma once
#include <luna/Result.h>
#include <luna/Types.h>
class Buffer
{
public:
Buffer();
~Buffer();
Buffer(Buffer&& other);
Buffer(const Buffer& other) = delete; // For now.
static Result<Buffer> create_sized(usize size);
Result<void> try_resize(usize new_size);
Result<u8*> slice_at_end(usize size);
Result<u8*> slice(usize offset, usize size);
u8* data()
{
return m_data;
}
const u8* data() const
{
return m_data;
}
u8* end()
{
return m_data + m_size;
}
const u8* end() const
{
return m_data + m_size;
}
usize size() const
{
return m_size;
}
private:
Buffer(u8* data, usize size);
u8* m_data { nullptr };
usize m_size { 0 };
};