sf: fix OutArray/InArray constructors to behave as expected

This commit is contained in:
Michael Scire 2020-04-02 00:28:39 -07:00
parent 612d846132
commit 8b19fdfd51

View file

@ -191,10 +191,7 @@ namespace ams::sf {
public:
constexpr InArrayImpl() : BaseType() { /* ... */ }
constexpr InArrayImpl(const cmif::PointerAndSize &_pas) : BaseType(_pas) { /* ... */ }
constexpr InArrayImpl(uintptr_t ptr, size_t sz) : BaseType(ptr, sz) { /* ... */ }
constexpr InArrayImpl(const void *ptr, size_t sz) : BaseType(reinterpret_cast<uintptr_t>(ptr), sz) { /* ... */ }
constexpr InArrayImpl(const T *ptr, size_t sz) : BaseType(reinterpret_cast<uintptr_t>(ptr), sz) { /* ... */ }
constexpr InArrayImpl(const T *ptr, size_t num_elements) : BaseType(reinterpret_cast<uintptr_t>(ptr), num_elements * sizeof(T)) { /* ... */ }
constexpr const T *GetPointer() const {
return reinterpret_cast<const T *>(this->GetAddressImpl());
@ -207,6 +204,14 @@ namespace ams::sf {
constexpr const T &operator[](size_t i) const {
return this->GetPointer()[i];
}
constexpr explicit operator Span<const T>() const {
return {this->GetPointer(), static_cast<ptrdiff_t>(this->GetSize())};
}
constexpr Span<const T> ToSpan() const {
return {this->GetPointer(), static_cast<ptrdiff_t>(this->GetSize())};
}
};
template<typename T, BufferTransferMode TMode = PreferredTransferMode<T>>
@ -218,10 +223,7 @@ namespace ams::sf {
public:
constexpr OutArrayImpl() : BaseType() { /* ... */ }
constexpr OutArrayImpl(const cmif::PointerAndSize &_pas) : BaseType(_pas) { /* ... */ }
constexpr OutArrayImpl(uintptr_t ptr, size_t sz) : BaseType(ptr, sz) { /* ... */ }
constexpr OutArrayImpl(void *ptr, size_t sz) : BaseType(reinterpret_cast<uintptr_t>(ptr), sz) { /* ... */ }
constexpr OutArrayImpl(T *ptr, size_t sz) : BaseType(reinterpret_cast<uintptr_t>(ptr), sz) { /* ... */ }
constexpr OutArrayImpl(T *ptr, size_t num_elements) : BaseType(reinterpret_cast<uintptr_t>(ptr), num_elements * sizeof(T)) { /* ... */ }
constexpr T *GetPointer() const {
return reinterpret_cast<T *>(this->GetAddressImpl());
@ -234,6 +236,14 @@ namespace ams::sf {
constexpr T &operator[](size_t i) const {
return this->GetPointer()[i];
}
constexpr explicit operator Span<T>() const {
return {this->GetPointer(), static_cast<ptrdiff_t>(this->GetSize())};
}
constexpr Span<T> ToSpan() const {
return {this->GetPointer(), static_cast<ptrdiff_t>(this->GetSize())};
}
};
}