mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-28 01:20:58 +01:00
util: add pointer utils, use to constrain fs pointers
This commit is contained in:
parent
141ae5c7ab
commit
dfa475a769
@ -20,7 +20,7 @@ namespace ams::fs {
|
||||
|
||||
namespace fsa {
|
||||
|
||||
class IFile;
|
||||
class IFileSystem;
|
||||
|
||||
}
|
||||
|
||||
|
@ -110,4 +110,7 @@ namespace ams::fs {
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
concept PointerToStorage = ::ams::util::RawOrSmartPointerTo<T, ::ams::fs::IStorage>;
|
||||
|
||||
}
|
||||
|
@ -181,4 +181,7 @@ namespace ams::fs::fsa {
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
concept PointerToFileSystem = ::ams::util::RawOrSmartPointerTo<T, ::ams::fs::fsa::IFileSystem>;
|
||||
|
||||
}
|
||||
|
@ -21,7 +21,7 @@
|
||||
namespace ams::fssystem {
|
||||
|
||||
/* ACCURATE_TO_VERSION: Unknown */
|
||||
template<typename BasePointer>
|
||||
template<fs::PointerToStorage BasePointer>
|
||||
class AesCtrStorage : public ::ams::fs::IStorage, public ::ams::fs::impl::Newable {
|
||||
NON_COPYABLE(AesCtrStorage);
|
||||
NON_MOVEABLE(AesCtrStorage);
|
||||
|
@ -22,7 +22,7 @@
|
||||
namespace ams::fssystem {
|
||||
|
||||
/* ACCURATE_TO_VERSION: Unknown */
|
||||
template<typename BasePointer>
|
||||
template<fs::PointerToStorage BasePointer>
|
||||
class AesXtsStorage : public ::ams::fs::IStorage, public ::ams::fs::impl::Newable {
|
||||
NON_COPYABLE(AesXtsStorage);
|
||||
NON_MOVEABLE(AesXtsStorage);
|
||||
|
@ -133,7 +133,7 @@ namespace ams::fssystem {
|
||||
};
|
||||
|
||||
/* ACCURATE_TO_VERSION: Unknown */
|
||||
template<typename BaseStorageType, size_t _BufferAlign>
|
||||
template<fs::PointerToStorage BasePointer, size_t _BufferAlign>
|
||||
class AlignmentMatchingStoragePooledBuffer : public ::ams::fs::IStorage, public ::ams::fs::impl::Newable {
|
||||
NON_COPYABLE(AlignmentMatchingStoragePooledBuffer);
|
||||
NON_MOVEABLE(AlignmentMatchingStoragePooledBuffer);
|
||||
@ -142,12 +142,12 @@ namespace ams::fssystem {
|
||||
|
||||
static_assert(util::IsPowerOfTwo(BufferAlign));
|
||||
private:
|
||||
BaseStorageType m_base_storage;
|
||||
BasePointer m_base_storage;
|
||||
s64 m_base_storage_size;
|
||||
size_t m_data_align;
|
||||
bool m_is_base_storage_size_dirty;
|
||||
public:
|
||||
explicit AlignmentMatchingStoragePooledBuffer(BaseStorageType bs, size_t da) : m_base_storage(std::move(bs)), m_data_align(da), m_is_base_storage_size_dirty(true) {
|
||||
explicit AlignmentMatchingStoragePooledBuffer(BasePointer bs, size_t da) : m_base_storage(std::move(bs)), m_data_align(da), m_is_base_storage_size_dirty(true) {
|
||||
AMS_ASSERT(util::IsPowerOfTwo(da));
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <vapours/util/util_alignment.hpp>
|
||||
#include <vapours/util/util_size.hpp>
|
||||
#include <vapours/util/util_int_util.hpp>
|
||||
#include <vapours/util/util_pointer_util.hpp>
|
||||
#include <vapours/util/util_aligned_buffer.hpp>
|
||||
#include <vapours/util/util_enum.hpp>
|
||||
#include <vapours/util/util_endian.hpp>
|
||||
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours/common.hpp>
|
||||
#include <vapours/assert.hpp>
|
||||
|
||||
namespace ams::util {
|
||||
|
||||
namespace impl {
|
||||
|
||||
template<typename T>
|
||||
struct IsSharedPointerImpl : public std::false_type{};
|
||||
|
||||
template<typename T>
|
||||
struct IsSharedPointerImpl<std::shared_ptr<T>> : public std::true_type{};
|
||||
|
||||
template<typename T>
|
||||
struct IsUniquePointerImpl : public std::false_type{};
|
||||
|
||||
template<typename T>
|
||||
struct IsUniquePointerImpl<std::unique_ptr<T>> : public std::true_type{};
|
||||
|
||||
template<typename T, typename U>
|
||||
concept PointerToImpl = std::same_as<typename std::pointer_traits<T>::element_type, U>;
|
||||
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
concept IsRawPointer = std::is_pointer<T>::value;
|
||||
|
||||
template<typename T>
|
||||
concept IsSharedPointer = impl::IsSharedPointerImpl<T>::value;
|
||||
|
||||
template<typename T>
|
||||
concept IsUniquePointer = impl::IsUniquePointerImpl<T>::value;
|
||||
|
||||
template<typename T>
|
||||
concept IsSmartPointer = IsSharedPointer<T> || IsUniquePointer<T>;
|
||||
|
||||
template<typename T>
|
||||
concept IsRawOrSmartPointer = IsRawPointer<T> || IsSmartPointer<T>;
|
||||
|
||||
template<typename T, typename U>
|
||||
concept SmartPointerTo = IsSmartPointer<T> && impl::PointerToImpl<T, U>;
|
||||
|
||||
template<typename T, typename U>
|
||||
concept RawOrSmartPointerTo = IsRawOrSmartPointer<T> && impl::PointerToImpl<T, U>;
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user