aboutsummaryrefslogtreecommitdiff
path: root/src/Platform.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-10-10 07:59:51 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-06 07:39:33 +0200
commit7c24c5d0de4d3584d6d2f9f3c26b4d757b0a0df2 (patch)
tree81585a1be9126c4bc1be946e74b4b6e1d706279b /src/Platform.cpp
parent6b238d4bc3c142f6337a73d858e069cae778dc54 (diff)
Fix sibs test not including parent library correctly
Refactor config parsing to reduce number of changes when introducing a new platform to support
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));
+ }
}