From 9dc5335e3e4e07371cfae96eca2cb5b2a93c8dd2 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 1 Mar 2014 07:36:59 +0100 Subject: util/{Const,Writable}Buffer: add template specialization for "void" Omit a few methods that are not applicable. --- src/util/ConstBuffer.hxx | 34 ++++++++++++++++++++++++++++++++++ src/util/WritableBuffer.hxx | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) (limited to 'src/util') diff --git a/src/util/ConstBuffer.hxx b/src/util/ConstBuffer.hxx index 35cffecc2..7f1fa5aa6 100644 --- a/src/util/ConstBuffer.hxx +++ b/src/util/ConstBuffer.hxx @@ -38,6 +38,40 @@ #include #endif +template +struct ConstBuffer; + +template<> +struct ConstBuffer { + typedef size_t size_type; + typedef const void *pointer_type; + typedef pointer_type const_pointer_type; + typedef pointer_type iterator; + typedef pointer_type const_iterator; + + pointer_type data; + size_type size; + + ConstBuffer() = default; + + constexpr ConstBuffer(std::nullptr_t):data(nullptr), size(0) {} + + constexpr ConstBuffer(pointer_type _data, size_type _size) + :data(_data), size(_size) {} + + constexpr static ConstBuffer Null() { + return ConstBuffer(nullptr, 0); + } + + constexpr bool IsNull() const { + return data == nullptr; + } + + constexpr bool IsEmpty() const { + return size == 0; + } +}; + /** * A reference to a memory area that is read-only. */ diff --git a/src/util/WritableBuffer.hxx b/src/util/WritableBuffer.hxx index 7267813f5..64e6d0c62 100644 --- a/src/util/WritableBuffer.hxx +++ b/src/util/WritableBuffer.hxx @@ -38,6 +38,40 @@ #include #endif +template +struct WritableBuffer; + +template<> +struct WritableBuffer { + typedef size_t size_type; + typedef void *pointer_type; + typedef const void *const_pointer_type; + typedef pointer_type iterator; + typedef const_pointer_type const_iterator; + + pointer_type data; + size_type size; + + WritableBuffer() = default; + + constexpr WritableBuffer(std::nullptr_t):data(nullptr), size(0) {} + + constexpr WritableBuffer(pointer_type _data, size_type _size) + :data(_data), size(_size) {} + + constexpr static WritableBuffer Null() { + return { nullptr, 0 }; + } + + constexpr bool IsNull() const { + return data == nullptr; + } + + constexpr bool IsEmpty() const { + return size == 0; + } +}; + /** * A reference to a memory area that is writable. * -- cgit v1.2.3