erpt: update for 11.0.0 (closes #1218)

This commit is contained in:
Michael Scire
2020-12-03 11:13:35 -08:00
parent bba99d49da
commit 6da28f4a27
24 changed files with 438 additions and 146 deletions

View File

@@ -31,6 +31,10 @@ namespace ams {
static constexpr BaseType DescriptionBits = 13;
static constexpr BaseType ReservedBits = 10;
static_assert(ModuleBits + DescriptionBits + ReservedBits == sizeof(BaseType) * CHAR_BIT, "ModuleBits + DescriptionBits + ReservedBits == sizeof(BaseType) * CHAR_BIT");
private:
static constexpr ALWAYS_INLINE BaseType GetBitsValue(BaseType v, int ofs, int num) {
return (v >> ofs) & ~(~BaseType() << num);
}
public:
static constexpr ALWAYS_INLINE BaseType MakeValue(BaseType module, BaseType description) {
return (module) | (description << ModuleBits);
@@ -43,11 +47,23 @@ namespace ams {
};
static constexpr ALWAYS_INLINE BaseType GetModuleFromValue(BaseType value) {
return value & ~(~BaseType() << ModuleBits);
return GetBitsValue(value, 0, ModuleBits);
}
static constexpr ALWAYS_INLINE BaseType GetDescriptionFromValue(BaseType value) {
return ((value >> ModuleBits) & ~(~BaseType() << DescriptionBits));
return GetBitsValue(value, ModuleBits, DescriptionBits);
}
static constexpr ALWAYS_INLINE BaseType GetReservedFromValue(BaseType value) {
return GetBitsValue(value, ModuleBits + DescriptionBits, ReservedBits);
}
static constexpr ALWAYS_INLINE BaseType MaskReservedFromValue(BaseType value) {
return value & ~(~(~BaseType() << ReservedBits) << (ModuleBits + DescriptionBits));
}
static constexpr ALWAYS_INLINE BaseType MergeValueWithReserved(BaseType value, BaseType reserved) {
return (value << 0) | (reserved << (ModuleBits + DescriptionBits));
}
};
@@ -62,14 +78,14 @@ namespace ams {
constexpr ALWAYS_INLINE BaseType GetDescription() const { return ResultTraits::GetDescriptionFromValue(static_cast<const Self *>(this)->GetValue()); }
};
class ResultConstructor;
class ResultInternalAccessor;
}
class ResultSuccess;
class Result final : public result::impl::ResultBase<Result> {
friend class ResultConstructor;
friend class result::impl::ResultInternalAccessor;
public:
using Base = typename result::impl::ResultBase<Result>;
private:
@@ -97,15 +113,23 @@ namespace ams {
namespace result::impl {
class ResultConstructor {
class ResultInternalAccessor {
public:
static constexpr ALWAYS_INLINE Result MakeResult(ResultTraits::BaseType value) {
return Result(value);
}
static constexpr ALWAYS_INLINE ResultTraits::BaseType GetReserved(Result result) {
return ResultTraits::GetReservedFromValue(result.value);
}
static constexpr ALWAYS_INLINE Result MergeReserved(Result result, ResultTraits::BaseType reserved) {
return Result(ResultTraits::MergeValueWithReserved(ResultTraits::MaskReservedFromValue(result.value), reserved));
}
};
constexpr ALWAYS_INLINE Result MakeResult(ResultTraits::BaseType value) {
return ResultConstructor::MakeResult(value);
return ResultInternalAccessor::MakeResult(value);
}
}
@@ -119,8 +143,6 @@ namespace ams {
constexpr ALWAYS_INLINE bool IsSuccess() const { return true; }
constexpr ALWAYS_INLINE bool IsFailure() const { return !this->IsSuccess(); }
constexpr ALWAYS_INLINE typename Base::BaseType GetModule() const { return Base::GetModule(); }
constexpr ALWAYS_INLINE typename Base::BaseType GetDescription() const { return Base::GetDescription(); }
constexpr ALWAYS_INLINE typename Base::BaseType GetValue() const { return Base::SuccessValue; }
};

View File

@@ -22,4 +22,19 @@ namespace ams {
template<typename T>
using Span = std::span<T>;
template<typename T>
constexpr Span<T> MakeSpan(T *ptr, size_t size) { return { ptr, size }; }
template <typename T>
constexpr Span<T> MakeSpan(T *begin, T *end) { return { begin, end }; }
template<typename T, size_t Size>
constexpr Span<T> MakeSpan(T (&arr)[Size]) { return Span<T>(arr); }
template<typename T, size_t Size>
constexpr Span<T> MakeSpan(std::array<T, Size> &arr) { return Span<T>(arr); }
template<typename T, size_t Size>
constexpr Span<T> MakeSpan(const std::array<T, Size> &arr) { return Span<const T>(arr); }
}

View File

@@ -41,3 +41,4 @@
#include <vapours/util/util_string_util.hpp>
#include <vapours/util/util_variadic.hpp>
#include <vapours/util/util_format_string.hpp>
#include <vapours/util/util_range.hpp>

View File

@@ -0,0 +1,47 @@
/*
* Copyright (c) 2018-2020 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::range {
template<typename T, typename F>
constexpr bool any_of(T &&t, F &&f) {
return std::any_of(std::begin(t), std::end(t), std::forward<F>(f));
}
template<typename T, typename F>
constexpr bool all_of(T &&t, F &&f) {
return std::all_of(std::begin(t), std::end(t), std::forward<F>(f));
}
template<typename T, typename F>
constexpr bool none_of(T &&t, F &&f) {
return std::none_of(std::begin(t), std::end(t), std::forward<F>(f));
}
template<typename T, typename F>
constexpr auto find_if(T &&t, F &&f) {
return std::find_if(std::begin(t), std::end(t), std::forward<F>(f));
}
template<typename T, typename F>
constexpr auto for_each(T &&t, F &&f) {
return std::for_each(std::begin(t), std::end(t), std::forward<F>(f));
}
}