2024-07-23 21:14:22 +01:00
|
|
|
#include "TargetBitFieldDescriptor.hpp"
|
|
|
|
|
|
2024-12-18 01:11:41 +00:00
|
|
|
#include <bitset>
|
|
|
|
|
#include <limits>
|
|
|
|
|
#include <numeric>
|
|
|
|
|
|
2024-07-23 21:14:22 +01:00
|
|
|
namespace Targets
|
|
|
|
|
{
|
|
|
|
|
TargetBitFieldDescriptor::TargetBitFieldDescriptor(
|
|
|
|
|
const std::string& key,
|
|
|
|
|
const std::string& name,
|
|
|
|
|
std::uint64_t mask,
|
|
|
|
|
std::optional<std::string> description
|
|
|
|
|
)
|
|
|
|
|
: key(key)
|
|
|
|
|
, name(name)
|
|
|
|
|
, mask(mask)
|
|
|
|
|
, description(description)
|
|
|
|
|
{}
|
|
|
|
|
|
2024-12-18 01:11:41 +00:00
|
|
|
std::size_t TargetBitFieldDescriptor::width() const {
|
|
|
|
|
const auto maskBitset = std::bitset<std::numeric_limits<decltype(TargetBitFieldDescriptor::mask)>::digits>{
|
|
|
|
|
this->mask
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto width = std::size_t{0};
|
|
|
|
|
for (auto maskIndex = std::size_t{0}; maskIndex < maskBitset.size(); ++maskIndex) {
|
|
|
|
|
if (maskBitset[maskIndex]) {
|
|
|
|
|
++width;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return width;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-23 21:14:22 +01:00
|
|
|
TargetBitFieldDescriptor TargetBitFieldDescriptor::clone() const {
|
|
|
|
|
return {*this};
|
|
|
|
|
}
|
|
|
|
|
}
|