1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-28 22:30:30 +00:00

Permits ::get from a reflective enum to an int.

This commit is contained in:
Thomas Harte 2020-05-13 23:48:28 -04:00
parent 80f2836cb8
commit 4f619de675

View File

@ -11,6 +11,7 @@
#include <algorithm>
#include <iomanip>
#include <sstream>
#include <type_traits>
// MARK: - Setters
@ -113,11 +114,20 @@ template <typename Type> bool Reflection::get(const Struct &target, const std::s
const auto target_type = target.type_of(name);
if(!target_type) return false;
// If type is a direct match, copy.
if(*target_type == typeid(Type)) {
memcpy(&value, target.get(name), sizeof(Type));
return true;
}
// If the type is a registered enum and the value type is int, copy.
if constexpr (std::is_integral<Type>::value && sizeof(Type) == sizeof(int)) {
if(!Enum::name(*target_type).empty()) {
memcpy(&value, target.get(name), sizeof(int));
return true;
}
}
return false;
}