diff --git a/include/kabufuda/Constants.hpp b/include/kabufuda/Constants.hpp index 998a1fd..e9ab761 100644 --- a/include/kabufuda/Constants.hpp +++ b/include/kabufuda/Constants.hpp @@ -59,10 +59,10 @@ enum class ECardSize : uint16_t { Card2043Mb = 0x80 }; -static constexpr uint32_t BannerWidth = 96; -static constexpr uint32_t BannerHeight = 64; -static constexpr uint32_t IconWidth = 32; -static constexpr uint32_t IconHeight = 32; +constexpr uint32_t BannerWidth = 96; +constexpr uint32_t BannerHeight = 64; +constexpr uint32_t IconWidth = 32; +constexpr uint32_t IconHeight = 32; /** * @brief The EEncoding enum diff --git a/include/kabufuda/Util.hpp b/include/kabufuda/Util.hpp index eb3d884..a7aebd8 100644 --- a/include/kabufuda/Util.hpp +++ b/include/kabufuda/Util.hpp @@ -75,7 +75,7 @@ namespace kabufuda { /* Type-sensitive byte swappers */ template -static inline T bswap16(T val) { +constexpr T bswap16(T val) { #if __GNUC__ return __builtin_bswap16(val); #elif _WIN32 @@ -86,7 +86,7 @@ static inline T bswap16(T val) { } template -static inline T bswap32(T val) { +constexpr T bswap32(T val) { #if __GNUC__ return __builtin_bswap32(val); #elif _WIN32 @@ -99,7 +99,7 @@ static inline T bswap32(T val) { } template -static inline T bswap64(T val) { +constexpr T bswap64(T val) { #if __GNUC__ return __builtin_bswap64(val); #elif _WIN32 @@ -113,18 +113,18 @@ static inline T bswap64(T val) { } #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ -static inline int16_t SBig(int16_t val) { return bswap16(val); } -static inline uint16_t SBig(uint16_t val) { return bswap16(val); } -static inline int32_t SBig(int32_t val) { return bswap32(val); } -static inline uint32_t SBig(uint32_t val) { return bswap32(val); } -static inline int64_t SBig(int64_t val) { return bswap64(val); } -static inline uint64_t SBig(uint64_t val) { return bswap64(val); } -inline float SBig(float val) { +constexpr int16_t SBig(int16_t val) { return bswap16(val); } +constexpr uint16_t SBig(uint16_t val) { return bswap16(val); } +constexpr int32_t SBig(int32_t val) { return bswap32(val); } +constexpr uint32_t SBig(uint32_t val) { return bswap32(val); } +constexpr int64_t SBig(int64_t val) { return bswap64(val); } +constexpr uint64_t SBig(uint64_t val) { return bswap64(val); } +constexpr float SBig(float val) { union { float f; int32_t i; } uval1 = {val}; union { int32_t i; float f; } uval2 = {bswap32(uval1.i)}; return uval2.f; } -inline double SBig(double val) { +constexpr double SBig(double val) { union { double f; int64_t i; } uval1 = {val}; union { int64_t i; double f; } uval2 = {bswap64(uval1.i)}; return uval2.f; @@ -133,29 +133,29 @@ inline double SBig(double val) { #define SBIG(q) (((q)&0x000000FF) << 24 | ((q)&0x0000FF00) << 8 | ((q)&0x00FF0000) >> 8 | ((q)&0xFF000000) >> 24) #endif -static inline int16_t SLittle(int16_t val) { return val; } -static inline uint16_t SLittle(uint16_t val) { return val; } -static inline int32_t SLittle(int32_t val) { return val; } -static inline uint32_t SLittle(uint32_t val) { return val; } -static inline int64_t SLittle(int64_t val) { return val; } -static inline uint64_t SLittle(uint64_t val) { return val; } -static inline float SLittle(float val) { return val; } -static inline double SLittle(double val) { return val; } +constexpr int16_t SLittle(int16_t val) { return val; } +constexpr uint16_t SLittle(uint16_t val) { return val; } +constexpr int32_t SLittle(int32_t val) { return val; } +constexpr uint32_t SLittle(uint32_t val) { return val; } +constexpr int64_t SLittle(int64_t val) { return val; } +constexpr uint64_t SLittle(uint64_t val) { return val; } +constexpr float SLittle(float val) { return val; } +constexpr double SLittle(double val) { return val; } #ifndef SLITTLE #define SLITTLE(q) (q) #endif #else -static inline int16_t SLittle(int16_t val) { return bswap16(val); } -static inline uint16_t SLittle(uint16_t val) { return bswap16(val); } -static inline int32_t SLittle(int32_t val) { return bswap32(val); } -static inline uint32_t SLittle(uint32_t val) { return bswap32(val); } -static inline int64_t SLittle(int64_t val) { return bswap64(val); } -static inline uint64_t SLittle(uint64_t val) { return bswap64(val); } -static inline float SLittle(float val) { +constexpr int16_t SLittle(int16_t val) { return bswap16(val); } +constexpr uint16_t SLittle(uint16_t val) { return bswap16(val); } +constexpr int32_t SLittle(int32_t val) { return bswap32(val); } +constexpr uint32_t SLittle(uint32_t val) { return bswap32(val); } +constexpr int64_t SLittle(int64_t val) { return bswap64(val); } +constexpr uint64_t SLittle(uint64_t val) { return bswap64(val); } +constexpr float SLittle(float val) { int32_t ival = bswap32(*((int32_t*)(&val))); return *((float*)(&ival)); } -static inline double SLittle(double val) { +constexpr double SLittle(double val) { int64_t ival = bswap64(*((int64_t*)(&val))); return *((double*)(&ival)); } @@ -163,14 +163,14 @@ static inline double SLittle(double val) { #define SLITTLE(q) (((q)&0x000000FF) << 24 | ((q)&0x0000FF00) << 8 | ((q)&0x00FF0000) >> 8 | ((q)&0xFF000000) >> 24) #endif -static inline int16_t SBig(int16_t val) { return val; } -static inline uint16_t SBig(uint16_t val) { return val; } -static inline int32_t SBig(int32_t val) { return val; } -static inline uint32_t SBig(uint32_t val) { return val; } -static inline int64_t SBig(int64_t val) { return val; } -static inline uint64_t SBig(uint64_t val) { return val; } -static inline float SBig(float val) { return val; } -static inline double SBig(double val) { return val; } +constexpr int16_t SBig(int16_t val) { return val; } +constexpr uint16_t SBig(uint16_t val) { return val; } +constexpr int32_t SBig(int32_t val) { return val; } +constexpr uint32_t SBig(uint32_t val) { return val; } +constexpr int64_t SBig(int64_t val) { return val; } +constexpr uint64_t SBig(uint64_t val) { return val; } +constexpr float SBig(float val) { return val; } +constexpr double SBig(double val) { return val; } #ifndef SBIG #define SBIG(q) (q) #endif @@ -178,11 +178,11 @@ static inline double SBig(double val) { return val; } #if CARD_UCS2 typedef wchar_t SystemChar; -static inline size_t StrLen(const SystemChar* str) { return wcslen(str); } +inline size_t StrLen(const SystemChar* str) { return wcslen(str); } typedef std::wstring SystemString; typedef std::wstring_view SystemStringView; -static inline void ToLower(SystemString& str) { std::transform(str.begin(), str.end(), str.begin(), towlower); } -static inline void ToUpper(SystemString& str) { std::transform(str.begin(), str.end(), str.begin(), towupper); } +inline void ToLower(SystemString& str) { std::transform(str.begin(), str.end(), str.begin(), towlower); } +inline void ToUpper(SystemString& str) { std::transform(str.begin(), str.end(), str.begin(), towupper); } class SystemUTF8Conv { std::string m_utf8; @@ -211,11 +211,11 @@ inline std::wstring operator+(const std::wstring_view lhs, const SystemStringCon typedef struct _stat Sstat; #else typedef char SystemChar; -static inline size_t StrLen(const SystemChar* str) { return strlen(str); } +inline size_t StrLen(const SystemChar* str) { return strlen(str); } typedef std::string SystemString; typedef std::string_view SystemStringView; -static inline void ToLower(SystemString& str) { std::transform(str.begin(), str.end(), str.begin(), tolower); } -static inline void ToUpper(SystemString& str) { std::transform(str.begin(), str.end(), str.begin(), toupper); } +inline void ToLower(SystemString& str) { std::transform(str.begin(), str.end(), str.begin(), tolower); } +inline void ToUpper(SystemString& str) { std::transform(str.begin(), str.end(), str.begin(), toupper); } class SystemUTF8Conv { std::string_view m_utf8; @@ -254,7 +254,7 @@ uint64_t getGCTime(); #define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) #endif -static inline int Stat(const SystemChar* path, Sstat* statOut) { +inline int Stat(const SystemChar* path, Sstat* statOut) { #if CARD_UCS2 size_t pos; for (pos = 0; pos < 3 && path[pos] != L'\0'; ++pos) {}