utils: Implement enum size computation

This commit is contained in:
kd-11 2026-03-15 19:55:55 +03:00 committed by kd-11
parent 7240cbfdab
commit dbb6c87a10
2 changed files with 29 additions and 0 deletions

View file

@ -362,6 +362,27 @@ std::vector<std::string> cfg::try_to_enum_list(decltype(&fmt_class_string<int>::
return result;
}
size_t cfg::try_to_enum_size(decltype(&fmt_class_string<int>::format) func)
{
size_t result = 0;
for (u64 i = 0;; i++)
{
std::string var;
func(var, i);
std::string hex;
fmt_class_string<u64>::format(hex, i);
if (var == hex)
{
break;
}
result++;
}
return result;
}
void cfg::encode(YAML::Emitter& out, const cfg::_base& rhs)
{
switch (rhs.get_type())

View file

@ -30,6 +30,9 @@ namespace cfg
// Internal hack
std::vector<std::string> try_to_enum_list(decltype(&fmt_class_string<int>::format) func);
// Internal hack
size_t try_to_enum_size(decltype(&fmt_class_string<int>::format) func);
// Config tree entry type.
enum class type : unsigned
{
@ -312,6 +315,11 @@ namespace cfg
{
return try_to_enum_list(&fmt_class_string<T>::format);
}
size_t size() const
{
return try_to_enum_size(&fmt_class_string<T>::format);
}
};
// Signed 32/64-bit integer entry with custom Min/Max range.