aboutsummaryrefslogtreecommitdiff
path: root/src/Platform.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Platform.cpp')
-rw-r--r--src/Platform.cpp38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/Platform.cpp b/src/Platform.cpp
index 9b02ca5..dd81667 100644
--- a/src/Platform.cpp
+++ b/src/Platform.cpp
@@ -1,7 +1,31 @@
#include "../include/Platform.hpp"
+#include <cassert>
namespace sibs
{
+ static int countSetBits(u32 value)
+ {
+ int count = 0;
+ while(value)
+ {
+ count += (value & 1U);
+ value >>= 1U;
+ }
+ return count;
+ }
+
+ // Returns -1 if no bit is set
+ static int getLeastSignificantBitSetPosition(u32 value)
+ {
+ for(u32 i = 0; i < sizeof(u32); ++i)
+ {
+ if(value & 1U)
+ return i;
+ value >>= 1U;
+ }
+ return -1;
+ }
+
bool containsPlatform(const std::vector<Platform> &platforms, Platform platform)
{
for (Platform vecPlatform : platforms)
@@ -33,7 +57,7 @@ namespace sibs
case PLATFORM_HAIKU: return "haiku";
case PLATFORM_HAIKU32: return "haiku32";
case PLATFORM_HAIKU64: return "haiku64";
- default: return nullptr;
+ default: assert(false); return nullptr;
}
}
@@ -49,4 +73,16 @@ namespace sibs
{
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)(1U << (u32)getLeastSignificantBitSetPosition(platform));
+ }
}