mirror of
https://github.com/stenzek/duckstation.git
synced 2026-02-10 08:24:32 +00:00
Common: Eliminate more static functions in headers
This commit is contained in:
@@ -15,42 +15,42 @@
|
||||
|
||||
namespace Common {
|
||||
template<typename T>
|
||||
constexpr bool IsAligned(T value, unsigned int alignment)
|
||||
ALWAYS_INLINE constexpr bool IsAligned(T value, unsigned int alignment)
|
||||
{
|
||||
return (value % static_cast<T>(alignment)) == 0;
|
||||
}
|
||||
template<typename T>
|
||||
constexpr T AlignUp(T value, unsigned int alignment)
|
||||
ALWAYS_INLINE constexpr T AlignUp(T value, unsigned int alignment)
|
||||
{
|
||||
return (value + static_cast<T>(alignment - 1)) / static_cast<T>(alignment) * static_cast<T>(alignment);
|
||||
}
|
||||
template<typename T>
|
||||
constexpr T AlignDown(T value, unsigned int alignment)
|
||||
ALWAYS_INLINE constexpr T AlignDown(T value, unsigned int alignment)
|
||||
{
|
||||
return value / static_cast<T>(alignment) * static_cast<T>(alignment);
|
||||
}
|
||||
template<typename T>
|
||||
constexpr bool IsAlignedPow2(T value, unsigned int alignment)
|
||||
ALWAYS_INLINE constexpr bool IsAlignedPow2(T value, unsigned int alignment)
|
||||
{
|
||||
return (value & static_cast<T>(alignment - 1)) == 0;
|
||||
}
|
||||
template<typename T>
|
||||
constexpr T AlignUpPow2(T value, unsigned int alignment)
|
||||
ALWAYS_INLINE constexpr T AlignUpPow2(T value, unsigned int alignment)
|
||||
{
|
||||
return (value + static_cast<T>(alignment - 1)) & static_cast<T>(~static_cast<T>(alignment - 1));
|
||||
}
|
||||
template<typename T>
|
||||
constexpr T AlignDownPow2(T value, unsigned int alignment)
|
||||
ALWAYS_INLINE constexpr T AlignDownPow2(T value, unsigned int alignment)
|
||||
{
|
||||
return value & static_cast<T>(~static_cast<T>(alignment - 1));
|
||||
}
|
||||
template<typename T>
|
||||
constexpr bool IsPow2(T value)
|
||||
ALWAYS_INLINE constexpr bool IsPow2(T value)
|
||||
{
|
||||
return (value & (value - 1)) == 0;
|
||||
}
|
||||
template<typename T>
|
||||
constexpr T PreviousPow2(T value)
|
||||
ALWAYS_INLINE constexpr T PreviousPow2(T value)
|
||||
{
|
||||
if (value == static_cast<T>(0))
|
||||
return 0;
|
||||
@@ -70,7 +70,7 @@ constexpr T PreviousPow2(T value)
|
||||
|
||||
/// NOTE: Undefined for values greater than (1 << BITS-1), i.e. 0x80000000 for 32-bit.
|
||||
template<typename T>
|
||||
constexpr T NextPow2(T value)
|
||||
ALWAYS_INLINE constexpr T NextPow2(T value)
|
||||
{
|
||||
// https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
|
||||
if (value == static_cast<T>(0))
|
||||
@@ -90,7 +90,7 @@ constexpr T NextPow2(T value)
|
||||
return value;
|
||||
}
|
||||
|
||||
ALWAYS_INLINE static void* AlignedMalloc(size_t size, size_t alignment)
|
||||
ALWAYS_INLINE void* AlignedMalloc(size_t size, size_t alignment)
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
return _aligned_malloc(size, alignment);
|
||||
@@ -105,7 +105,7 @@ ALWAYS_INLINE static void* AlignedMalloc(size_t size, size_t alignment)
|
||||
#endif
|
||||
}
|
||||
|
||||
ALWAYS_INLINE static void AlignedFree(void* ptr)
|
||||
ALWAYS_INLINE void AlignedFree(void* ptr)
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
_aligned_free(ptr);
|
||||
|
||||
@@ -14,14 +14,14 @@
|
||||
|
||||
// Zero-extending helper
|
||||
template<typename TReturn, typename TValue>
|
||||
ALWAYS_INLINE static constexpr TReturn ZeroExtend(TValue value)
|
||||
ALWAYS_INLINE constexpr TReturn ZeroExtend(TValue value)
|
||||
{
|
||||
return static_cast<TReturn>(static_cast<typename std::make_unsigned<TReturn>::type>(
|
||||
static_cast<typename std::make_unsigned<TValue>::type>(value)));
|
||||
}
|
||||
// Sign-extending helper
|
||||
template<typename TReturn, typename TValue>
|
||||
ALWAYS_INLINE static constexpr TReturn SignExtend(TValue value)
|
||||
ALWAYS_INLINE constexpr TReturn SignExtend(TValue value)
|
||||
{
|
||||
return static_cast<TReturn>(
|
||||
static_cast<typename std::make_signed<TReturn>::type>(static_cast<typename std::make_signed<TValue>::type>(value)));
|
||||
@@ -29,101 +29,101 @@ ALWAYS_INLINE static constexpr TReturn SignExtend(TValue value)
|
||||
|
||||
// Type-specific helpers
|
||||
template<typename TValue>
|
||||
ALWAYS_INLINE static constexpr u16 ZeroExtend16(TValue value)
|
||||
ALWAYS_INLINE constexpr u16 ZeroExtend16(TValue value)
|
||||
{
|
||||
return ZeroExtend<u16, TValue>(value);
|
||||
}
|
||||
template<typename TValue>
|
||||
ALWAYS_INLINE static constexpr u32 ZeroExtend32(TValue value)
|
||||
ALWAYS_INLINE constexpr u32 ZeroExtend32(TValue value)
|
||||
{
|
||||
return ZeroExtend<u32, TValue>(value);
|
||||
}
|
||||
template<typename TValue>
|
||||
ALWAYS_INLINE static constexpr u64 ZeroExtend64(TValue value)
|
||||
ALWAYS_INLINE constexpr u64 ZeroExtend64(TValue value)
|
||||
{
|
||||
return ZeroExtend<u64, TValue>(value);
|
||||
}
|
||||
template<typename TValue>
|
||||
ALWAYS_INLINE static constexpr u16 SignExtend16(TValue value)
|
||||
ALWAYS_INLINE constexpr u16 SignExtend16(TValue value)
|
||||
{
|
||||
return SignExtend<u16, TValue>(value);
|
||||
}
|
||||
template<typename TValue>
|
||||
ALWAYS_INLINE static constexpr u32 SignExtend32(TValue value)
|
||||
ALWAYS_INLINE constexpr u32 SignExtend32(TValue value)
|
||||
{
|
||||
return SignExtend<u32, TValue>(value);
|
||||
}
|
||||
template<typename TValue>
|
||||
ALWAYS_INLINE static constexpr u64 SignExtend64(TValue value)
|
||||
ALWAYS_INLINE constexpr u64 SignExtend64(TValue value)
|
||||
{
|
||||
return SignExtend<u64, TValue>(value);
|
||||
}
|
||||
template<typename TValue>
|
||||
ALWAYS_INLINE static constexpr u8 Truncate8(TValue value)
|
||||
ALWAYS_INLINE constexpr u8 Truncate8(TValue value)
|
||||
{
|
||||
return static_cast<u8>(static_cast<typename std::make_unsigned<decltype(value)>::type>(value));
|
||||
}
|
||||
template<typename TValue>
|
||||
ALWAYS_INLINE static constexpr u16 Truncate16(TValue value)
|
||||
ALWAYS_INLINE constexpr u16 Truncate16(TValue value)
|
||||
{
|
||||
return static_cast<u16>(static_cast<typename std::make_unsigned<decltype(value)>::type>(value));
|
||||
}
|
||||
template<typename TValue>
|
||||
ALWAYS_INLINE static constexpr u32 Truncate32(TValue value)
|
||||
ALWAYS_INLINE constexpr u32 Truncate32(TValue value)
|
||||
{
|
||||
return static_cast<u32>(static_cast<typename std::make_unsigned<decltype(value)>::type>(value));
|
||||
}
|
||||
|
||||
// BCD helpers
|
||||
ALWAYS_INLINE static constexpr u8 BinaryToBCD(u8 value)
|
||||
ALWAYS_INLINE constexpr u8 BinaryToBCD(u8 value)
|
||||
{
|
||||
return ((value / 10) << 4) + (value % 10);
|
||||
}
|
||||
ALWAYS_INLINE static constexpr u8 PackedBCDToBinary(u8 value)
|
||||
ALWAYS_INLINE constexpr u8 PackedBCDToBinary(u8 value)
|
||||
{
|
||||
return ((value >> 4) * 10) + (value % 16);
|
||||
}
|
||||
ALWAYS_INLINE static constexpr u8 IsValidBCDDigit(u8 digit)
|
||||
ALWAYS_INLINE constexpr u8 IsValidBCDDigit(u8 digit)
|
||||
{
|
||||
return (digit <= 9);
|
||||
}
|
||||
ALWAYS_INLINE static constexpr u8 IsValidPackedBCD(u8 value)
|
||||
ALWAYS_INLINE constexpr u8 IsValidPackedBCD(u8 value)
|
||||
{
|
||||
return IsValidBCDDigit(value & 0x0F) && IsValidBCDDigit(value >> 4);
|
||||
}
|
||||
|
||||
// Boolean to integer
|
||||
ALWAYS_INLINE static constexpr u8 BoolToUInt8(bool value)
|
||||
ALWAYS_INLINE constexpr u8 BoolToUInt8(bool value)
|
||||
{
|
||||
return static_cast<u8>(value);
|
||||
}
|
||||
ALWAYS_INLINE static constexpr u16 BoolToUInt16(bool value)
|
||||
ALWAYS_INLINE constexpr u16 BoolToUInt16(bool value)
|
||||
{
|
||||
return static_cast<u16>(value);
|
||||
}
|
||||
ALWAYS_INLINE static constexpr u32 BoolToUInt32(bool value)
|
||||
ALWAYS_INLINE constexpr u32 BoolToUInt32(bool value)
|
||||
{
|
||||
return static_cast<u32>(value);
|
||||
}
|
||||
ALWAYS_INLINE static constexpr u64 BoolToUInt64(bool value)
|
||||
ALWAYS_INLINE constexpr u64 BoolToUInt64(bool value)
|
||||
{
|
||||
return static_cast<u64>(value);
|
||||
}
|
||||
ALWAYS_INLINE static constexpr float BoolToFloat(bool value)
|
||||
ALWAYS_INLINE constexpr float BoolToFloat(bool value)
|
||||
{
|
||||
return static_cast<float>(value);
|
||||
}
|
||||
|
||||
// Integer to boolean
|
||||
template<typename TValue>
|
||||
ALWAYS_INLINE static constexpr bool ConvertToBool(TValue value)
|
||||
ALWAYS_INLINE constexpr bool ConvertToBool(TValue value)
|
||||
{
|
||||
return static_cast<bool>(value);
|
||||
}
|
||||
|
||||
// Unsafe integer to boolean
|
||||
template<typename TValue>
|
||||
ALWAYS_INLINE static bool ConvertToBoolUnchecked(TValue value)
|
||||
ALWAYS_INLINE bool ConvertToBoolUnchecked(TValue value)
|
||||
{
|
||||
// static_assert(sizeof(uint8) == sizeof(bool));
|
||||
bool ret;
|
||||
@@ -133,7 +133,7 @@ ALWAYS_INLINE static bool ConvertToBoolUnchecked(TValue value)
|
||||
|
||||
// Generic sign extension
|
||||
template<int NBITS, typename T>
|
||||
ALWAYS_INLINE static constexpr T SignExtendN(T value)
|
||||
ALWAYS_INLINE constexpr T SignExtendN(T value)
|
||||
{
|
||||
// http://graphics.stanford.edu/~seander/bithacks.html#VariableSignExtend
|
||||
constexpr int shift = 8 * sizeof(T) - NBITS;
|
||||
@@ -142,7 +142,7 @@ ALWAYS_INLINE static constexpr T SignExtendN(T value)
|
||||
|
||||
/// Returns the number of zero bits before the first set bit, going MSB->LSB.
|
||||
template<typename T>
|
||||
ALWAYS_INLINE static unsigned CountLeadingZeros(T value)
|
||||
ALWAYS_INLINE unsigned CountLeadingZeros(T value)
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
if constexpr (sizeof(value) >= sizeof(u64))
|
||||
@@ -169,7 +169,7 @@ ALWAYS_INLINE static unsigned CountLeadingZeros(T value)
|
||||
|
||||
/// Returns the number of zero bits before the first set bit, going LSB->MSB.
|
||||
template<typename T>
|
||||
ALWAYS_INLINE static unsigned CountTrailingZeros(T value)
|
||||
ALWAYS_INLINE unsigned CountTrailingZeros(T value)
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
if constexpr (sizeof(value) >= sizeof(u64))
|
||||
@@ -194,7 +194,7 @@ ALWAYS_INLINE static unsigned CountTrailingZeros(T value)
|
||||
|
||||
// C++23-like std::byteswap()
|
||||
template<typename T>
|
||||
ALWAYS_INLINE static T ByteSwap(T value)
|
||||
ALWAYS_INLINE T ByteSwap(T value)
|
||||
{
|
||||
if constexpr (std::is_signed_v<T>)
|
||||
{
|
||||
|
||||
@@ -11,75 +11,75 @@ namespace Easing {
|
||||
inline constexpr float pi = 3.1415926545f;
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE_RELEASE static T InSine(T t)
|
||||
ALWAYS_INLINE_RELEASE T InSine(T t)
|
||||
{
|
||||
return std::sin(1.5707963f * t);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE_RELEASE static T OutSine(T t)
|
||||
ALWAYS_INLINE_RELEASE T OutSine(T t)
|
||||
{
|
||||
return 1 + std::sin(1.5707963f * (--t));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE_RELEASE static T InOutSine(T t)
|
||||
ALWAYS_INLINE_RELEASE T InOutSine(T t)
|
||||
{
|
||||
return 0.5f * (1 + std::sin(3.1415926f * (t - 0.5f)));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE_RELEASE static T InQuad(T t)
|
||||
ALWAYS_INLINE_RELEASE T InQuad(T t)
|
||||
{
|
||||
return t * t;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE_RELEASE static T OutQuad(T t)
|
||||
ALWAYS_INLINE_RELEASE T OutQuad(T t)
|
||||
{
|
||||
return t * (2 - t);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE_RELEASE static T InOutQuad(T t)
|
||||
ALWAYS_INLINE_RELEASE T InOutQuad(T t)
|
||||
{
|
||||
return t < 0.5f ? 2 * t * t : t * (4 - 2 * t) - 1;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE_RELEASE static T InCubic(T t)
|
||||
ALWAYS_INLINE_RELEASE T InCubic(T t)
|
||||
{
|
||||
return t * t * t;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE_RELEASE static T OutCubic(T t)
|
||||
ALWAYS_INLINE_RELEASE T OutCubic(T t)
|
||||
{
|
||||
return 1 + (--t) * t * t;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE_RELEASE static T InOutCubic(T t)
|
||||
ALWAYS_INLINE_RELEASE T InOutCubic(T t)
|
||||
{
|
||||
return t < 0.5f ? 4 * t * t * t : 1 + (--t) * (2 * (--t)) * (2 * t);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE_RELEASE static T InQuart(T t)
|
||||
ALWAYS_INLINE_RELEASE T InQuart(T t)
|
||||
{
|
||||
t *= t;
|
||||
return t * t;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE_RELEASE static T OutQuart(T t)
|
||||
ALWAYS_INLINE_RELEASE T OutQuart(T t)
|
||||
{
|
||||
t = (--t) * t;
|
||||
return 1 - t * t;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE_RELEASE static T InOutQuart(T t)
|
||||
ALWAYS_INLINE_RELEASE T InOutQuart(T t)
|
||||
{
|
||||
if (t < 0.5)
|
||||
{
|
||||
@@ -94,21 +94,21 @@ ALWAYS_INLINE_RELEASE static T InOutQuart(T t)
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE_RELEASE static T InQuint(T t)
|
||||
ALWAYS_INLINE_RELEASE T InQuint(T t)
|
||||
{
|
||||
T t2 = t * t;
|
||||
return t * t2 * t2;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE_RELEASE static T OutQuint(T t)
|
||||
ALWAYS_INLINE_RELEASE T OutQuint(T t)
|
||||
{
|
||||
T t2 = (--t) * t;
|
||||
return 1 + t * t2 * t2;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE_RELEASE static T InOutQuint(T t)
|
||||
ALWAYS_INLINE_RELEASE T InOutQuint(T t)
|
||||
{
|
||||
T t2;
|
||||
if (t < 0.5)
|
||||
@@ -124,19 +124,19 @@ ALWAYS_INLINE_RELEASE static T InOutQuint(T t)
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE_RELEASE static T InExpo(T t)
|
||||
ALWAYS_INLINE_RELEASE T InExpo(T t)
|
||||
{
|
||||
return (std::pow(static_cast<T>(2), static_cast<T>(8) * t) - static_cast<T>(1)) / static_cast<T>(255);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE_RELEASE static T OutExpo(T t)
|
||||
ALWAYS_INLINE_RELEASE T OutExpo(T t)
|
||||
{
|
||||
return static_cast<T>(1) - std::pow(static_cast<T>(2), static_cast<T>(-8) * t);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE_RELEASE static T InOutExpo(T t)
|
||||
ALWAYS_INLINE_RELEASE T InOutExpo(T t)
|
||||
{
|
||||
if (t < 0.5f)
|
||||
{
|
||||
@@ -149,19 +149,19 @@ ALWAYS_INLINE_RELEASE static T InOutExpo(T t)
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE_RELEASE static T InCirc(T t)
|
||||
ALWAYS_INLINE_RELEASE T InCirc(T t)
|
||||
{
|
||||
return 1 - std::sqrt(1 - t);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE_RELEASE static T OutCirc(T t)
|
||||
ALWAYS_INLINE_RELEASE T OutCirc(T t)
|
||||
{
|
||||
return std::sqrt(t);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE_RELEASE static T InOutCirc(T t)
|
||||
ALWAYS_INLINE_RELEASE T InOutCirc(T t)
|
||||
{
|
||||
if (t < 0.5f)
|
||||
{
|
||||
@@ -174,20 +174,20 @@ ALWAYS_INLINE_RELEASE static T InOutCirc(T t)
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE_RELEASE static T InBack(T t)
|
||||
ALWAYS_INLINE_RELEASE T InBack(T t)
|
||||
{
|
||||
return t * t * (2.70158f * t - 1.70158f);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static T OutBack(T t)
|
||||
ALWAYS_INLINE_RELEASE T OutBack(T t)
|
||||
{
|
||||
t -= 1;
|
||||
return 1 + t * t * (2.70158f * t + 1.70158f);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE_RELEASE static T InOutBack(T t)
|
||||
ALWAYS_INLINE_RELEASE T InOutBack(T t)
|
||||
{
|
||||
if (t < 0.5f)
|
||||
{
|
||||
@@ -200,21 +200,21 @@ ALWAYS_INLINE_RELEASE static T InOutBack(T t)
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE_RELEASE static T InElastic(T t)
|
||||
ALWAYS_INLINE_RELEASE T InElastic(T t)
|
||||
{
|
||||
T t2 = t * t;
|
||||
return t2 * t2 * std::sin(t * pi * 4.5f);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE_RELEASE static T OutElastic(T t)
|
||||
ALWAYS_INLINE_RELEASE T OutElastic(T t)
|
||||
{
|
||||
T t2 = (t - 1) * (t - 1);
|
||||
return 1 - t2 * t2 * std::cos(t * pi * 4.5f);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE_RELEASE static T InOutElastic(T t)
|
||||
ALWAYS_INLINE_RELEASE T InOutElastic(T t)
|
||||
{
|
||||
T t2;
|
||||
if (t < 0.45f)
|
||||
@@ -234,19 +234,19 @@ ALWAYS_INLINE_RELEASE static T InOutElastic(T t)
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE_RELEASE static T InBounce(T t)
|
||||
ALWAYS_INLINE_RELEASE T InBounce(T t)
|
||||
{
|
||||
return std::pow(2, 6 * (t - 1)) * std::abs(sin(t * pi * 3.5f));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE_RELEASE static T OutBounce(T t)
|
||||
ALWAYS_INLINE_RELEASE T OutBounce(T t)
|
||||
{
|
||||
return 1 - std::pow(2, -6 * t) * std::abs(std::cos(t * pi * 3.5f));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE_RELEASE static T InOutBounce(T t)
|
||||
ALWAYS_INLINE_RELEASE T InOutBounce(T t)
|
||||
{
|
||||
if (t < 0.5f)
|
||||
{
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
namespace MinizipHelpers {
|
||||
|
||||
[[maybe_unused]] static unzFile OpenUnzMemoryFile(const void* memory, size_t memory_size)
|
||||
inline unzFile OpenUnzMemoryFile(const void* memory, size_t memory_size)
|
||||
{
|
||||
struct MemoryFileInfo
|
||||
{
|
||||
@@ -70,7 +70,7 @@ namespace MinizipHelpers {
|
||||
return unzOpen2_64("", &funcs);
|
||||
}
|
||||
|
||||
[[maybe_unused]] static unzFile OpenUnzFile(const char* filename)
|
||||
inline unzFile OpenUnzFile(const char* filename)
|
||||
{
|
||||
zlib_filefunc64_def funcs;
|
||||
fill_fopen64_filefunc(&funcs);
|
||||
@@ -90,8 +90,8 @@ namespace MinizipHelpers {
|
||||
return unzOpen2_64(filename, &funcs);
|
||||
}
|
||||
|
||||
[[maybe_unused]] static std::optional<std::string> ReadZipFileToString(unzFile zf, const char* filename,
|
||||
bool case_sensitivity, Error* error)
|
||||
inline std::optional<std::string> ReadZipFileToString(unzFile zf, const char* filename, bool case_sensitivity,
|
||||
Error* error)
|
||||
{
|
||||
std::optional<std::string> ret;
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
namespace ZipHelpers {
|
||||
|
||||
[[maybe_unused]] static void SetErrorObject(Error* error, std::string_view msg, zip_error_t* ze)
|
||||
inline void SetErrorObject(Error* error, std::string_view msg, zip_error_t* ze)
|
||||
{
|
||||
Error::SetStringFmt(error, "{}{}", msg, ze ? zip_error_strerror(ze) : "UNKNOWN");
|
||||
if (ze)
|
||||
@@ -53,7 +53,7 @@ struct ZipFileDeleter
|
||||
using ManagedZipT = std::unique_ptr<zip_t, ZipDeleter>;
|
||||
using ManagedZipFileT = std::unique_ptr<zip_file_t, ZipFileDeleter>;
|
||||
|
||||
[[maybe_unused]] static inline ManagedZipT OpenManagedZipFile(const char* filename, int flags, Error* error = nullptr)
|
||||
inline ManagedZipT OpenManagedZipFile(const char* filename, int flags, Error* error = nullptr)
|
||||
{
|
||||
zip_error_t ze;
|
||||
zip_source_t* zs = zip_source_file_create(filename, 0, 0, &ze);
|
||||
@@ -76,7 +76,7 @@ using ManagedZipFileT = std::unique_ptr<zip_file_t, ZipFileDeleter>;
|
||||
return ManagedZipT(zip);
|
||||
}
|
||||
|
||||
[[maybe_unused]] static inline ManagedZipT OpenManagedZipCFile(std::FILE* fp, int flags, Error* error = nullptr)
|
||||
inline ManagedZipT OpenManagedZipCFile(std::FILE* fp, int flags, Error* error = nullptr)
|
||||
{
|
||||
zip_error_t ze;
|
||||
zip_source_t* zs = zip_source_filep_create(fp, 0, 0, &ze);
|
||||
@@ -100,8 +100,8 @@ using ManagedZipFileT = std::unique_ptr<zip_file_t, ZipFileDeleter>;
|
||||
return ManagedZipT(zip);
|
||||
}
|
||||
|
||||
[[maybe_unused]] static inline ManagedZipT OpenManagedZipBuffer(const void* buffer, size_t size, int flags,
|
||||
bool free_buffer, Error* error = nullptr)
|
||||
inline ManagedZipT OpenManagedZipBuffer(const void* buffer, size_t size, int flags, bool free_buffer,
|
||||
Error* error = nullptr)
|
||||
{
|
||||
zip_error_t ze;
|
||||
zip_source_t* zs = zip_source_buffer_create(buffer, size, free_buffer, &ze);
|
||||
@@ -126,8 +126,7 @@ using ManagedZipFileT = std::unique_ptr<zip_file_t, ZipFileDeleter>;
|
||||
return ManagedZipT(zip);
|
||||
}
|
||||
|
||||
[[maybe_unused]] static inline ManagedZipFileT OpenManagedFileInZip(zip_t* zip, const char* filename, zip_flags_t flags,
|
||||
Error* error = nullptr)
|
||||
inline ManagedZipFileT OpenManagedFileInZip(zip_t* zip, const char* filename, zip_flags_t flags, Error* error = nullptr)
|
||||
{
|
||||
zip_file_t* zf = zip_fopen(zip, filename, flags);
|
||||
if (!zf)
|
||||
@@ -135,8 +134,8 @@ using ManagedZipFileT = std::unique_ptr<zip_file_t, ZipFileDeleter>;
|
||||
return ManagedZipFileT(zf);
|
||||
}
|
||||
|
||||
[[maybe_unused]] static inline ManagedZipFileT OpenManagedFileIndexInZip(zip_t* zip, zip_uint64_t index,
|
||||
zip_flags_t flags, Error* error = nullptr)
|
||||
inline ManagedZipFileT OpenManagedFileIndexInZip(zip_t* zip, zip_uint64_t index, zip_flags_t flags,
|
||||
Error* error = nullptr)
|
||||
{
|
||||
zip_file_t* zf = zip_fopen_index(zip, index, flags);
|
||||
if (!zf)
|
||||
@@ -145,8 +144,8 @@ using ManagedZipFileT = std::unique_ptr<zip_file_t, ZipFileDeleter>;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
[[maybe_unused]] static inline std::optional<T>
|
||||
ReadFileInZipToContainer(zip_t* zip, const char* name, bool case_sensitive = true, Error* error = nullptr)
|
||||
inline std::optional<T> ReadFileInZipToContainer(zip_t* zip, const char* name, bool case_sensitive = true,
|
||||
Error* error = nullptr)
|
||||
{
|
||||
const int flags = case_sensitive ? 0 : ZIP_FL_NOCASE;
|
||||
|
||||
@@ -185,8 +184,7 @@ ReadFileInZipToContainer(zip_t* zip, const char* name, bool case_sensitive = tru
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
[[maybe_unused]] static inline std::optional<T> ReadFileInZipToContainer(zip_file_t* file, u32 chunk_size = 4096,
|
||||
Error* error = nullptr)
|
||||
inline std::optional<T> ReadFileInZipToContainer(zip_file_t* file, u32 chunk_size = 4096, Error* error = nullptr)
|
||||
{
|
||||
std::optional<T> ret = T();
|
||||
for (;;)
|
||||
@@ -212,26 +210,25 @@ template<typename T>
|
||||
return ret;
|
||||
}
|
||||
|
||||
[[maybe_unused]] static inline std::optional<std::string>
|
||||
ReadFileInZipToString(zip_t* zip, const char* name, bool case_sensitive = true, Error* error = nullptr)
|
||||
inline std::optional<std::string> ReadFileInZipToString(zip_t* zip, const char* name, bool case_sensitive = true,
|
||||
Error* error = nullptr)
|
||||
{
|
||||
return ReadFileInZipToContainer<std::string>(zip, name, case_sensitive, error);
|
||||
}
|
||||
|
||||
[[maybe_unused]] static inline std::optional<std::string> ReadFileInZipToString(zip_file_t* file, u32 chunk_size = 4096,
|
||||
Error* error = nullptr)
|
||||
inline std::optional<std::string> ReadFileInZipToString(zip_file_t* file, u32 chunk_size = 4096, Error* error = nullptr)
|
||||
{
|
||||
return ReadFileInZipToContainer<std::string>(file, chunk_size, error);
|
||||
}
|
||||
|
||||
[[maybe_unused]] static inline std::optional<std::vector<u8>>
|
||||
ReadBinaryFileInZip(zip_t* zip, const char* name, bool case_sensitive = true, Error* error = nullptr)
|
||||
inline std::optional<std::vector<u8>> ReadBinaryFileInZip(zip_t* zip, const char* name, bool case_sensitive = true,
|
||||
Error* error = nullptr)
|
||||
{
|
||||
return ReadFileInZipToContainer<std::vector<u8>>(zip, name, case_sensitive, error);
|
||||
}
|
||||
|
||||
[[maybe_unused]] static inline std::optional<std::vector<u8>>
|
||||
ReadBinaryFileInZip(zip_file_t* file, u32 chunk_size = 4096, Error* error = nullptr)
|
||||
inline std::optional<std::vector<u8>> ReadBinaryFileInZip(zip_file_t* file, u32 chunk_size = 4096,
|
||||
Error* error = nullptr)
|
||||
{
|
||||
return ReadFileInZipToContainer<std::vector<u8>>(file, chunk_size, error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user