From 72fe8dd2d6d6a3a5592646950a4e43b9a79ed9b4 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Mon, 2 Dec 2024 00:35:56 +0100 Subject: Start work on buffer --- asl/buffer.hpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 asl/buffer.hpp (limited to 'asl/buffer.hpp') diff --git a/asl/buffer.hpp b/asl/buffer.hpp new file mode 100644 index 0000000..abf29fe --- /dev/null +++ b/asl/buffer.hpp @@ -0,0 +1,46 @@ +#pragma once + +#include "asl/meta.hpp" +#include "asl/allocator.hpp" +#include "asl/annotations.hpp" + +namespace asl +{ + +template +class buffer +{ + + T* m_data{}; + isize_t m_capacity{}; + + // bit 63 : 0 = on heap, 1 = inline + // bits [62:56] : size when inline + // bits [52:0] : size when on heap + size_t m_size_encoded{}; + + ASL_NO_UNIQUE_ADDRESS Allocator m_allocator; + + static_assert(align_of <= align_of); + static_assert(align_of == align_of); + static_assert(align_of == align_of); + +public: + + static constexpr isize_t kInlineCapacity = []() { + // 1 byte is used for size inline in m_size_encoded. + // This is enough because we have at most 24 bytes available, + // so 23 chars of capacity. + const isize_t available_size = size_of + size_of + size_of - 1; + return available_size / size_of; + }(); + + constexpr buffer() requires default_constructible = default; + + explicit constexpr buffer(Allocator allocator) + : m_allocator{ASL_MOVE(allocator)} + {} +}; + +} // namespace asl + -- cgit