#pragma once #include <bitset> #include <ecs/config.h> #include <ecs/core/mp/list.h> namespace ecs { namespace core { namespace utils { /** * bitset to store components flags in * * @tparam T_settings settings type the environmant is configured with */ template<typename T_settings> struct bitset { private: /** * get the component signature list * * @return component signature list */ static constexpr decltype(auto) csl() noexcept { return (T_settings { }).component_signatures(); } /** * get the tags of all components * * @return list of all component tags */ static constexpr decltype(auto) all_components() noexcept { return csl().all_components(); } public: /** * get the number of components * * @return integral constant with number of components */ static constexpr decltype(auto) component_count() noexcept { return hana::size(all_components()); } /** * get the ID of the given component tag * * @tparam T_component_tag component tag type to get ID for * * @param ct component tag to get the ID for * * @return integral constant with the ID of the requested component tag */ template<typename T_component_tag> static constexpr decltype(auto) component_id(T_component_tag&& ct) noexcept; /** * get the bitset from the given system signature * * @tparam T_system_signature system signature type to get bitmask for * * @param ssig system signature to get bitmask for * * @return bitmask for the passed system signature */ template<typename T_system_signature> static constexpr decltype(auto) from_system_signature(T_system_signature&& ssig) noexcept; /** * internal bitset type that contains all components */ using bitset_type = std::bitset<component_count()>; private: bitset_type _bitset; public: /** * return a string representation of the bitset * * @return string representation of the bitset */ inline decltype(auto) to_string() const; /** * clear all bits of the bitset */ inline void clear() noexcept; /** * check if the bitset contains another bitset * * @tparam T_other type of the other bitset * * @param other bitset to compare with * * @retval TRUE if this bitset contains the passed bitset * @retval FALSE if this bitset does not contain the passed bitset */ template<typename T_other> inline bool contains(const T_other& other) const noexcept; /** * check if the bitset contains the given component * * @tparam T_component_tag component tag type to check * * @param ct component tag to check * * @retval TRUE if this bitset contains the passed component tag * @retval FALSE if this bitset does not contain the passed component tag */ template<typename T_component_tag> inline bool has_component(T_component_tag ct) const; /** * set the bit value of the passed component tag * * @tparam T_component_tag component tag type to set * * @param ct component tag to set * @param value new bit value of the component inside the bitset */ template<typename T_component_tag> inline void set_component(T_component_tag ct, bool value); }; } } }