#include "../include/Platform.hpp" #include namespace sibs { static std::unordered_map platformNames; static bool platformNamesSet = false; static int countSetBits(u64 value) { int count = 0; while(value) { count += (value & 1ULL); value >>= 1ULL; } return count; } // Returns -1 if no bit is set static u64 getLeastSignificantBitSetPosition(u64 value) { for(u64 i = 0; i < sizeof(u64); ++i) { if(value & 1ULL) return i; value >>= 1ULL; } return -1ULL; } bool containsPlatform(const std::vector &platforms, Platform platform) { for (Platform vecPlatform : platforms) { if(platform & vecPlatform) return true; } return false; } const char* asString(Platform platform) { if(!platformNamesSet) { 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) { auto it = PLATFORM_BY_NAME.find(name); if(it != PLATFORM_BY_NAME.end()) return it->second; return PLATFORM_INVALID; } bool isSamePlatformFamily(Platform a, Platform b) { return a & b; } bool isBaseForPlatform(Platform base, Platform platform) { return base == PLATFORM_ANY || base == platform || (isSamePlatformFamily(platform, base) && countSetBits(base) < countSetBits(platform)); } Platform getPlatformGenericType(Platform platform) { if(platform == PLATFORM_INVALID || platform == PLATFORM_ANY) return PLATFORM_INVALID; return (Platform)(1ULL << (u64)getLeastSignificantBitSetPosition(platform)); } }