0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-29 08:54:02 +01:00

ircd::buffer: Minor cleanup.

This commit is contained in:
Jason Volk 2017-09-22 19:29:51 -07:00
parent b29224aa3a
commit 798f87cac9

View file

@ -209,6 +209,67 @@ struct ircd::buffer::const_raw_buffer
{}
};
/// Like unique_ptr, this template holds ownership of an allocated buffer
///
///
template<class buffer,
size_t align = 16>
struct ircd::buffer::unique_buffer
:buffer
{
unique_buffer(std::unique_ptr<uint8_t[]> &&, const size_t &size);
unique_buffer(const size_t &size);
unique_buffer() = default;
unique_buffer(unique_buffer &&) noexcept;
unique_buffer(const unique_buffer &) = delete;
~unique_buffer() noexcept;
};
template<class buffer,
size_t alignment>
ircd::buffer::unique_buffer<buffer, alignment>::unique_buffer(std::unique_ptr<uint8_t[]> &&b,
const size_t &size)
:buffer
{
typename buffer::value_type(b.release()), size
}
{
}
template<class buffer,
size_t alignment>
ircd::buffer::unique_buffer<buffer, alignment>::unique_buffer(const size_t &size)
:unique_buffer<buffer, alignment>
{
std::unique_ptr<uint8_t[]>
{
new __attribute__((aligned(alignment))) uint8_t[size]
},
size
}
{
}
template<class buffer,
size_t alignment>
ircd::buffer::unique_buffer<buffer, alignment>::unique_buffer(unique_buffer &&other)
noexcept
:buffer
{
std::move(other)
}
{
get<0>(other) = nullptr;
}
template<class buffer,
size_t alignment>
ircd::buffer::unique_buffer<buffer, alignment>::~unique_buffer()
noexcept
{
delete[] data(*this);
}
template<template<class>
class buffers,
class T>
@ -427,64 +488,3 @@ const
{
return { get<0>(*this), get<1>(*this) };
}
/// Like unique_ptr, this template holds ownership of an allocated buffer
///
///
template<class buffer,
size_t align = 16>
struct ircd::buffer::unique_buffer
:buffer
{
unique_buffer(std::unique_ptr<uint8_t[]> &&, const size_t &size);
unique_buffer(const size_t &size);
unique_buffer() = default;
unique_buffer(unique_buffer &&) noexcept;
unique_buffer(const unique_buffer &) = delete;
~unique_buffer() noexcept;
};
template<class buffer,
size_t alignment>
ircd::buffer::unique_buffer<buffer, alignment>::unique_buffer(std::unique_ptr<uint8_t[]> &&b,
const size_t &size)
:buffer
{
typename buffer::value_type(b.release()), size
}
{
}
template<class buffer,
size_t alignment>
ircd::buffer::unique_buffer<buffer, alignment>::unique_buffer(const size_t &size)
:unique_buffer<buffer, alignment>
{
std::unique_ptr<uint8_t[]>
{
new __attribute__((aligned(alignment))) uint8_t[size]
},
size
}
{
}
template<class buffer,
size_t alignment>
ircd::buffer::unique_buffer<buffer, alignment>::unique_buffer(unique_buffer &&other)
noexcept
:buffer
{
std::move(other)
}
{
get<0>(other) = nullptr;
}
template<class buffer,
size_t alignment>
ircd::buffer::unique_buffer<buffer, alignment>::~unique_buffer()
noexcept
{
delete[] data(*this);
}