/*
* Copyright (c) Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#pragma once
#include
namespace ams::sf {
namespace impl {
struct StatelessDummyAllocator;
}
template
class StatelessAllocationPolicy {
public:
static constexpr bool HasStatefulAllocator = false;
using Allocator = impl::StatelessDummyAllocator;
template
using StatelessAllocator = A;
template
static void *AllocateAligned(size_t size, size_t align) {
AMS_UNUSED(align);
return A().Allocate(size);
}
template
static void DeallocateAligned(void *ptr, size_t size, size_t align) {
AMS_UNUSED(align);
A().Deallocate(ptr, size);
}
};
template typename A>
class StatelessTypedAllocationPolicy {
public:
static constexpr bool HasStatefulAllocator = false;
using Allocator = impl::StatelessDummyAllocator;
template
using StatelessAllocator = A;
template
static void *AllocateAligned(size_t size, size_t align) {
AMS_UNUSED(align);
return StatelessAllocator().Allocate(size);
}
template
static void DeallocateAligned(void *ptr, size_t size, size_t align) {
AMS_UNUSED(align);
StatelessAllocator().Deallocate(ptr, size);
}
};
template
class StatefulAllocationPolicy {
public:
static constexpr bool HasStatefulAllocator = true;
using Allocator = A;
static void *AllocateAligned(Allocator *allocator, size_t size, size_t align) {
AMS_UNUSED(align);
return allocator->Allocate(size);
}
static void DeallocateAligned(Allocator *allocator, void *ptr, size_t size, size_t align) {
AMS_UNUSED(align);
allocator->Deallocate(ptr, size);
}
};
template
concept IsStatefulPolicy = T::HasStatefulAllocator;
}