25 static DiskReadView borrowed(
const void* data,
size_t size);
27 explicit operator bool()
const {
28 return m_Data !=
nullptr;
30 const void* data()
const {
36 bool truncate(
size_t length) {
42 bool copyTo(
void* destination,
size_t length,
size_t offset = 0)
const {
43 if ((!destination && length) || offset > m_Size || length > m_Size - offset)
46 MemoryCopy(destination, m_Data + offset, length);
50 bool readAt(T& into,
size_t offset = 0)
const {
51 static_assert(__is_trivially_copyable(T),
"Disk values must be trivially copyable");
52 if (offset > m_Size ||
sizeof(T) > m_Size - offset)
55 __builtin_memcpy(&into, m_Data + offset,
sizeof(T));
67 const uint8_t* m_Data;
82 explicit operator bool()
const {
83 return static_cast<bool>(m_View);
86 return const_cast<void*
>(m_View.data());
91 bool truncate(
size_t length) {
92 return m_View.truncate(length);
95 bool readAt(T& into,
size_t offset = 0)
const {
96 return m_View.readAt(into, offset);
99 bool writeAt(
const T& value,
size_t offset = 0) {
100 static_assert(__is_trivially_copyable(T),
"Disk values must be trivially copyable");
101 if (offset > size() ||
sizeof(T) > size() - offset)
103 __builtin_memcpy(
static_cast<uint8_t*
>(data()) + offset, &value,
sizeof(T));
106 bool copyFrom(
const void* source,
size_t length,
size_t offset = 0) {
107 if ((!source && length) || offset > size() || length > size() - offset)
110 MemoryCopy(
static_cast<uint8_t*
>(data()) + offset, source, length);
120 : m_View(owner, location, view,
true,
static_cast<DiskUse&&
>(use)) {}