mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-10 04:50:31 -04:00
refactor(fsinfo_features): simplify code and make more robust
This commit is contained in:
parent
b6f5df8185
commit
460cc4b0b2
@ -65,11 +65,11 @@ class fsinfo_features {
|
|||||||
std::vector<std::string_view> to_string_views() const;
|
std::vector<std::string_view> to_string_views() const;
|
||||||
|
|
||||||
constexpr bool has(fsinfo_feature f) const {
|
constexpr bool has(fsinfo_feature f) const {
|
||||||
return features_ & (1 << static_cast<size_t>(f));
|
return features_ & feature_bit(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr fsinfo_features& set(fsinfo_feature f) {
|
constexpr fsinfo_features& set(fsinfo_feature f) {
|
||||||
features_ |= (1 << static_cast<size_t>(f));
|
features_ |= feature_bit(f);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ class fsinfo_features {
|
|||||||
}
|
}
|
||||||
|
|
||||||
constexpr fsinfo_features& clear(fsinfo_feature f) {
|
constexpr fsinfo_features& clear(fsinfo_feature f) {
|
||||||
features_ &= ~(1 << static_cast<size_t>(f));
|
features_ &= ~feature_bit(f);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,6 +105,11 @@ class fsinfo_features {
|
|||||||
private:
|
private:
|
||||||
// can be upgraded to std::bitset if needed and when it's constexpr
|
// can be upgraded to std::bitset if needed and when it's constexpr
|
||||||
using feature_type = uint64_t;
|
using feature_type = uint64_t;
|
||||||
|
|
||||||
|
static constexpr feature_type feature_bit(fsinfo_feature n) {
|
||||||
|
return static_cast<feature_type>(1) << static_cast<size_t>(n);
|
||||||
|
}
|
||||||
|
|
||||||
static constexpr size_t max_feature_bits{
|
static constexpr size_t max_feature_bits{
|
||||||
std::numeric_limits<feature_type>::digits};
|
std::numeric_limits<feature_type>::digits};
|
||||||
static constexpr size_t num_feature_bits{
|
static constexpr size_t num_feature_bits{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user