aboutsummaryrefslogtreecommitdiff
path: root/src/Platform.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Platform.cpp')
-rw-r--r--src/Platform.cpp50
1 files changed, 22 insertions, 28 deletions
diff --git a/src/Platform.cpp b/src/Platform.cpp
index dd81667..b011d93 100644
--- a/src/Platform.cpp
+++ b/src/Platform.cpp
@@ -3,27 +3,29 @@
namespace sibs
{
- static int countSetBits(u32 value)
+ static std::unordered_map<Platform, const char*> platformNames;
+ static bool platformNamesSet = false;
+ static int countSetBits(u64 value)
{
int count = 0;
while(value)
{
- count += (value & 1U);
- value >>= 1U;
+ count += (value & 1ULL);
+ value >>= 1ULL;
}
return count;
}
// Returns -1 if no bit is set
- static int getLeastSignificantBitSetPosition(u32 value)
+ static u64 getLeastSignificantBitSetPosition(u64 value)
{
- for(u32 i = 0; i < sizeof(u32); ++i)
+ for(u64 i = 0; i < sizeof(u64); ++i)
{
- if(value & 1U)
+ if(value & 1ULL)
return i;
- value >>= 1U;
+ value >>= 1ULL;
}
- return -1;
+ return -1ULL;
}
bool containsPlatform(const std::vector<Platform> &platforms, Platform platform)
@@ -38,27 +40,19 @@ namespace sibs
const char* asString(Platform platform)
{
- switch (platform)
+ if(!platformNamesSet)
{
- case PLATFORM_ANY: return "any";
- case PLATFORM_LINUX: return "linux";
- case PLATFORM_LINUX32: return "linux32";
- case PLATFORM_LINUX64: return "linux64";
- case PLATFORM_WIN: return "win";
- case PLATFORM_WIN32: return "win32";
- case PLATFORM_WIN64: return "win64";
- case PLATFORM_MACOS: return "macos";
- case PLATFORM_MACOS32: return "macos32";
- case PLATFORM_MACOS64: return "macos64";
- case PLATFORM_BSD: return "bsd";
- case PLATFORM_OPENBSD: return "openbsd";
- case PLATFORM_OPENBSD32: return "openbsd32";
- case PLATFORM_OPENBSD64: return "openbsd64";
- case PLATFORM_HAIKU: return "haiku";
- case PLATFORM_HAIKU32: return "haiku32";
- case PLATFORM_HAIKU64: return "haiku64";
- default: assert(false); return nullptr;
+ platformNamesSet = true;
+ for(auto &it : PLATFORM_BY_NAME)
+ {
+ platformNames[it.second] = it.first.data;
+ }
}
+
+ auto it = platformNames.find(platform);
+ if(it != platformNames.end())
+ return it->second;
+ return nullptr;
}
Platform getPlatformByName(StringView name)
@@ -83,6 +77,6 @@ namespace sibs
{
if(platform == PLATFORM_INVALID || platform == PLATFORM_ANY)
return PLATFORM_INVALID;
- return (Platform)(1U << (u32)getLeastSignificantBitSetPosition(platform));
+ return (Platform)(1ULL << (u64)getLeastSignificantBitSetPosition(platform));
}
}