// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed // under the Academic Free License. // His code is available here: https://github.com/SuperV1234/cppcon2015 #ifndef EC_BITSET_HPP #define EC_BITSET_HPP #include #include "Meta/TypeList.hpp" #include "Meta/Combine.hpp" #include "Meta/IndexOf.hpp" #include "Meta/ForEach.hpp" #include "Meta/Contains.hpp" namespace EC { // Note bitset size is sizes of components and tags + 1 // This is to use the last extra bit as the result of a query // with a Component or Tag not known to the Bitset. // Those queries will return a false bit every time. template struct Bitset : public std::bitset { using Combined = EC::Meta::Combine; Bitset() { (*this)[Combined::size] = false; } // TODO find a better way to handle non-member type in const template constexpr auto getComponentBit() const { auto index = EC::Meta::IndexOf::value; return (*this)[index]; } template constexpr auto getComponentBit() { auto index = EC::Meta::IndexOf::value; (*this)[Combined::size] = false; return (*this)[index]; } template constexpr auto getTagBit() const { auto index = EC::Meta::IndexOf::value; return (*this)[index]; } template constexpr auto getTagBit() { auto index = EC::Meta::IndexOf::value; (*this)[Combined::size] = false; return (*this)[index]; } template static constexpr Bitset generateBitset() { Bitset bitset; EC::Meta::forEach([&bitset] (auto t) { if(EC::Meta::Contains::value) { bitset[EC::Meta::IndexOf::value] = true; } }); return bitset; } }; } #endif