diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 224cfba0eb..07e23f5c45 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -29,6 +29,7 @@ add_files( string_consumer.hpp string_inplace.cpp string_inplace.hpp + strong_bitset_type.hpp strong_typedef_type.hpp utf8.cpp utf8.hpp diff --git a/src/core/strong_bitset_type.hpp b/src/core/strong_bitset_type.hpp new file mode 100644 index 0000000000..0cf3f5a474 --- /dev/null +++ b/src/core/strong_bitset_type.hpp @@ -0,0 +1,42 @@ +/* + * This file is part of OpenTTD. + * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. + * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . + */ + +/** @file strong_bitset_type.hpp Type helper for making a BitSet out of a Strong Typedef. */ + +#ifndef STRONG_BITSET_TYPE_HPP +#define STRONG_BITSET_TYPE_HPP + +#include "base_bitset_type.hpp" + +/** + * Strong bit set. + * @tparam Tvalue_type Type of values to wrap. + * @tparam Tstorage Storage type required to hold values. + */ +template ::max()> +class StrongBitSet : public BaseBitSet, Tvalue_type, Tstorage> { +public: + constexpr StrongBitSet() : BaseClass() {} + constexpr StrongBitSet(Tvalue_type value) : BaseClass() { this->Set(value); } + explicit constexpr StrongBitSet(Tstorage data) : BaseClass(data) {} + + constexpr StrongBitSet(std::initializer_list values) : BaseClass() + { + for (const Tvalue_type &value : values) { + this->Set(value); + } + } + + static constexpr size_t DecayValueType(Tvalue_type value) { return value.base(); } + + constexpr auto operator <=>(const StrongBitSet &) const noexcept = default; + +private: + using BaseClass = BaseBitSet, Tvalue_type, Tstorage, Tmask>; +}; + +#endif /* STRONG_BITSET_TYPE_HPP */