Danny Robson
f6056153e3
This places, at long last, the core library code into the same namespace as the extended library code.
87 lines
2.7 KiB
C++
87 lines
2.7 KiB
C++
/*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
*
|
|
* Copyright 2016 Danny Robson <danny@nerdcruft.net>
|
|
*/
|
|
|
|
#ifndef CRUFT_UTIL_ALLOC_RAW_ALIGNED_DIRECT_HPP
|
|
#define CRUFT_UTIL_ALLOC_RAW_ALIGNED_DIRECT_HPP
|
|
|
|
#include "../../../debug.hpp"
|
|
#include "../../../view.hpp"
|
|
|
|
#include <cstddef>
|
|
#include <utility>
|
|
|
|
namespace cruft::alloc::raw::aligned {
|
|
/// wraps a child allocator and enforces a fixed alignment
|
|
template <typename ChildT>
|
|
class direct {
|
|
public:
|
|
///////////////////////////////////////////////////////////////////////
|
|
template <typename ...Args>
|
|
direct (cruft::view<std::byte*> _data, std::size_t _alignment, Args &&...args):
|
|
m_successor (_data, std::forward<Args> (args)...),
|
|
m_alignment (_alignment)
|
|
{ ; }
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
template <typename T>
|
|
auto
|
|
allocate (std::size_t count)
|
|
{
|
|
return m_successor.template allocate<T> (count, m_alignment);
|
|
}
|
|
|
|
//---------------------------------------------------------------------
|
|
template <typename T>
|
|
auto
|
|
deallocate (cruft::view<T*> ptr)
|
|
{
|
|
return m_successor.template deallocate<T> (ptr);
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
constexpr auto alignment (void) const noexcept { return m_alignment; }
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
auto data (void) { return m_successor.data (); }
|
|
|
|
//---------------------------------------------------------------------
|
|
auto begin (void) { return m_successor.begin (); }
|
|
auto begin (void) const { return m_successor.begin (); }
|
|
|
|
auto end (void) { return m_successor.end (); }
|
|
auto end (void) const { return m_successor.end (); }
|
|
|
|
//---------------------------------------------------------------------
|
|
auto
|
|
offset (const void *ptr) const
|
|
{
|
|
return m_successor.offset (ptr);
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
auto reset (void) { return m_successor.reset (); }
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
auto capacity (void) const { return m_successor.capacity (); }
|
|
auto used (void) const { return m_successor.used (); }
|
|
auto remain (void) const { return m_successor.remain (); }
|
|
|
|
|
|
private:
|
|
ChildT m_successor;
|
|
std::size_t m_alignment;
|
|
};
|
|
}
|
|
|
|
#endif
|