Make stuff constexpr

This commit is contained in:
Jack Andersen 2019-07-19 18:26:25 -10:00
parent 8053d1125b
commit dc436ffb32
2 changed files with 46 additions and 46 deletions

View File

@ -59,10 +59,10 @@ enum class ECardSize : uint16_t {
Card2043Mb = 0x80 Card2043Mb = 0x80
}; };
static constexpr uint32_t BannerWidth = 96; constexpr uint32_t BannerWidth = 96;
static constexpr uint32_t BannerHeight = 64; constexpr uint32_t BannerHeight = 64;
static constexpr uint32_t IconWidth = 32; constexpr uint32_t IconWidth = 32;
static constexpr uint32_t IconHeight = 32; constexpr uint32_t IconHeight = 32;
/** /**
* @brief The EEncoding enum * @brief The EEncoding enum

View File

@ -75,7 +75,7 @@ namespace kabufuda {
/* Type-sensitive byte swappers */ /* Type-sensitive byte swappers */
template <typename T> template <typename T>
static inline T bswap16(T val) { constexpr T bswap16(T val) {
#if __GNUC__ #if __GNUC__
return __builtin_bswap16(val); return __builtin_bswap16(val);
#elif _WIN32 #elif _WIN32
@ -86,7 +86,7 @@ static inline T bswap16(T val) {
} }
template <typename T> template <typename T>
static inline T bswap32(T val) { constexpr T bswap32(T val) {
#if __GNUC__ #if __GNUC__
return __builtin_bswap32(val); return __builtin_bswap32(val);
#elif _WIN32 #elif _WIN32
@ -99,7 +99,7 @@ static inline T bswap32(T val) {
} }
template <typename T> template <typename T>
static inline T bswap64(T val) { constexpr T bswap64(T val) {
#if __GNUC__ #if __GNUC__
return __builtin_bswap64(val); return __builtin_bswap64(val);
#elif _WIN32 #elif _WIN32
@ -113,18 +113,18 @@ static inline T bswap64(T val) {
} }
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
static inline int16_t SBig(int16_t val) { return bswap16(val); } constexpr int16_t SBig(int16_t val) { return bswap16(val); }
static inline uint16_t SBig(uint16_t val) { return bswap16(val); } constexpr uint16_t SBig(uint16_t val) { return bswap16(val); }
static inline int32_t SBig(int32_t val) { return bswap32(val); } constexpr int32_t SBig(int32_t val) { return bswap32(val); }
static inline uint32_t SBig(uint32_t val) { return bswap32(val); } constexpr uint32_t SBig(uint32_t val) { return bswap32(val); }
static inline int64_t SBig(int64_t val) { return bswap64(val); } constexpr int64_t SBig(int64_t val) { return bswap64(val); }
static inline uint64_t SBig(uint64_t val) { return bswap64(val); } constexpr uint64_t SBig(uint64_t val) { return bswap64(val); }
inline float SBig(float val) { constexpr float SBig(float val) {
union { float f; int32_t i; } uval1 = {val}; union { float f; int32_t i; } uval1 = {val};
union { int32_t i; float f; } uval2 = {bswap32(uval1.i)}; union { int32_t i; float f; } uval2 = {bswap32(uval1.i)};
return uval2.f; return uval2.f;
} }
inline double SBig(double val) { constexpr double SBig(double val) {
union { double f; int64_t i; } uval1 = {val}; union { double f; int64_t i; } uval1 = {val};
union { int64_t i; double f; } uval2 = {bswap64(uval1.i)}; union { int64_t i; double f; } uval2 = {bswap64(uval1.i)};
return uval2.f; 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) #define SBIG(q) (((q)&0x000000FF) << 24 | ((q)&0x0000FF00) << 8 | ((q)&0x00FF0000) >> 8 | ((q)&0xFF000000) >> 24)
#endif #endif
static inline int16_t SLittle(int16_t val) { return val; } constexpr int16_t SLittle(int16_t val) { return val; }
static inline uint16_t SLittle(uint16_t val) { return val; } constexpr uint16_t SLittle(uint16_t val) { return val; }
static inline int32_t SLittle(int32_t val) { return val; } constexpr int32_t SLittle(int32_t val) { return val; }
static inline uint32_t SLittle(uint32_t val) { return val; } constexpr uint32_t SLittle(uint32_t val) { return val; }
static inline int64_t SLittle(int64_t val) { return val; } constexpr int64_t SLittle(int64_t val) { return val; }
static inline uint64_t SLittle(uint64_t val) { return val; } constexpr uint64_t SLittle(uint64_t val) { return val; }
static inline float SLittle(float val) { return val; } constexpr float SLittle(float val) { return val; }
static inline double SLittle(double val) { return val; } constexpr double SLittle(double val) { return val; }
#ifndef SLITTLE #ifndef SLITTLE
#define SLITTLE(q) (q) #define SLITTLE(q) (q)
#endif #endif
#else #else
static inline int16_t SLittle(int16_t val) { return bswap16(val); } constexpr int16_t SLittle(int16_t val) { return bswap16(val); }
static inline uint16_t SLittle(uint16_t val) { return bswap16(val); } constexpr uint16_t SLittle(uint16_t val) { return bswap16(val); }
static inline int32_t SLittle(int32_t val) { return bswap32(val); } constexpr int32_t SLittle(int32_t val) { return bswap32(val); }
static inline uint32_t SLittle(uint32_t val) { return bswap32(val); } constexpr uint32_t SLittle(uint32_t val) { return bswap32(val); }
static inline int64_t SLittle(int64_t val) { return bswap64(val); } constexpr int64_t SLittle(int64_t val) { return bswap64(val); }
static inline uint64_t SLittle(uint64_t val) { return bswap64(val); } constexpr uint64_t SLittle(uint64_t val) { return bswap64(val); }
static inline float SLittle(float val) { constexpr float SLittle(float val) {
int32_t ival = bswap32(*((int32_t*)(&val))); int32_t ival = bswap32(*((int32_t*)(&val)));
return *((float*)(&ival)); return *((float*)(&ival));
} }
static inline double SLittle(double val) { constexpr double SLittle(double val) {
int64_t ival = bswap64(*((int64_t*)(&val))); int64_t ival = bswap64(*((int64_t*)(&val)));
return *((double*)(&ival)); 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) #define SLITTLE(q) (((q)&0x000000FF) << 24 | ((q)&0x0000FF00) << 8 | ((q)&0x00FF0000) >> 8 | ((q)&0xFF000000) >> 24)
#endif #endif
static inline int16_t SBig(int16_t val) { return val; } constexpr int16_t SBig(int16_t val) { return val; }
static inline uint16_t SBig(uint16_t val) { return val; } constexpr uint16_t SBig(uint16_t val) { return val; }
static inline int32_t SBig(int32_t val) { return val; } constexpr int32_t SBig(int32_t val) { return val; }
static inline uint32_t SBig(uint32_t val) { return val; } constexpr uint32_t SBig(uint32_t val) { return val; }
static inline int64_t SBig(int64_t val) { return val; } constexpr int64_t SBig(int64_t val) { return val; }
static inline uint64_t SBig(uint64_t val) { return val; } constexpr uint64_t SBig(uint64_t val) { return val; }
static inline float SBig(float val) { return val; } constexpr float SBig(float val) { return val; }
static inline double SBig(double val) { return val; } constexpr double SBig(double val) { return val; }
#ifndef SBIG #ifndef SBIG
#define SBIG(q) (q) #define SBIG(q) (q)
#endif #endif
@ -178,11 +178,11 @@ static inline double SBig(double val) { return val; }
#if CARD_UCS2 #if CARD_UCS2
typedef wchar_t SystemChar; 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 SystemString;
typedef std::wstring_view SystemStringView; typedef std::wstring_view SystemStringView;
static inline void ToLower(SystemString& str) { std::transform(str.begin(), str.end(), str.begin(), towlower); } 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 ToUpper(SystemString& str) { std::transform(str.begin(), str.end(), str.begin(), towupper); }
class SystemUTF8Conv { class SystemUTF8Conv {
std::string m_utf8; std::string m_utf8;
@ -211,11 +211,11 @@ inline std::wstring operator+(const std::wstring_view lhs, const SystemStringCon
typedef struct _stat Sstat; typedef struct _stat Sstat;
#else #else
typedef char SystemChar; 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 SystemString;
typedef std::string_view SystemStringView; typedef std::string_view SystemStringView;
static inline void ToLower(SystemString& str) { std::transform(str.begin(), str.end(), str.begin(), tolower); } 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 ToUpper(SystemString& str) { std::transform(str.begin(), str.end(), str.begin(), toupper); }
class SystemUTF8Conv { class SystemUTF8Conv {
std::string_view m_utf8; std::string_view m_utf8;
@ -254,7 +254,7 @@ uint64_t getGCTime();
#define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) #define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR)
#endif #endif
static inline int Stat(const SystemChar* path, Sstat* statOut) { inline int Stat(const SystemChar* path, Sstat* statOut) {
#if CARD_UCS2 #if CARD_UCS2
size_t pos; size_t pos;
for (pos = 0; pos < 3 && path[pos] != L'\0'; ++pos) {} for (pos = 0; pos < 3 && path[pos] != L'\0'; ++pos) {}