mirror of
https://github.com/RPCS3/rpcs3.git
synced 2026-03-17 18:55:19 +01:00
utils: Implement enum size computation
This commit is contained in:
parent
7240cbfdab
commit
dbb6c87a10
|
|
@ -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())
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Reference in a new issue