From 7c24c5d0de4d3584d6d2f9f3c26b4d757b0a0df2 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 10 Oct 2018 07:59:51 +0200 Subject: Fix sibs test not including parent library correctly Refactor config parsing to reduce number of changes when introducing a new platform to support --- src/Platform.cpp | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'src/Platform.cpp') 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 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 &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)); + } } -- cgit v1.2.3