1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:47:35 +00:00

AK: Add span() / bytes() methods to container types.

This commit is contained in:
asynts 2020-07-27 14:15:37 +02:00 committed by Andreas Kling
parent c42450786c
commit a922abd9d7
4 changed files with 24 additions and 5 deletions

View file

@ -29,6 +29,7 @@
#include <AK/NonnullRefPtr.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h>
#include <AK/Span.h>
#include <AK/StdLibExtras.h>
#include <AK/Types.h>
#include <AK/kmalloc.h>
@ -71,6 +72,9 @@ public:
u8* data() { return m_data; }
const u8* data() const { return m_data; }
Bytes span() { return { data(), size() }; }
ReadonlyBytes span() const { return { data(), size() }; }
u8* offset_pointer(int offset) { return m_data + offset; }
const u8* offset_pointer(int offset) const { return m_data + offset; }
@ -93,10 +97,10 @@ private:
Wrap,
Adopt
};
explicit ByteBufferImpl(size_t); // For ConstructionMode=Uninitialized
explicit ByteBufferImpl(size_t); // For ConstructionMode=Uninitialized
ByteBufferImpl(const void*, size_t, ConstructionMode); // For ConstructionMode=Copy
ByteBufferImpl(void*, size_t, ConstructionMode); // For ConstructionMode=Wrap/Adopt
ByteBufferImpl() {}
ByteBufferImpl(void*, size_t, ConstructionMode); // For ConstructionMode=Wrap/Adopt
ByteBufferImpl() { }
u8* m_data { nullptr };
size_t m_size { 0 };
@ -105,8 +109,8 @@ private:
class ByteBuffer {
public:
ByteBuffer() {}
ByteBuffer(std::nullptr_t) {}
ByteBuffer() { }
ByteBuffer(std::nullptr_t) { }
ByteBuffer(const ByteBuffer& other)
: m_impl(other.m_impl)
{
@ -158,6 +162,9 @@ public:
u8* data() { return m_impl ? m_impl->data() : nullptr; }
const u8* data() const { return m_impl ? m_impl->data() : nullptr; }
Bytes span() { return m_impl ? m_impl->span() : nullptr; }
ReadonlyBytes span() const { return m_impl ? m_impl->span() : nullptr; }
u8* offset_pointer(int offset) { return m_impl ? m_impl->offset_pointer(offset) : nullptr; }
const u8* offset_pointer(int offset) const { return m_impl ? m_impl->offset_pointer(offset) : nullptr; }