From: Giacomo Travaglini Date: Thu, 7 Feb 2019 07:34:56 +0000 (+0000) Subject: base: Fix enums checkpointing X-Git-Tag: v19.0.0.0~1130 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3264c824894c81be3842824eee4de589ad72fbdc;p=gem5.git base: Fix enums checkpointing Creating an extra version of string to number converters (__to_number) in base/str.hh; it will be used by enums only when unserializing them. The reason not to have a single helper for both enums and integers is that std::numeric_limits trait is not specialized for enums. We fix this by using the std::underlying_type trait. Change-Id: I819e35c0df8c094de7b7a6390152964fa47d513d Signed-off-by: Giacomo Travaglini Reviewed-by: Ciro Santilli Signed-off-by: Giacomo Travaglini Reviewed-on: https://gem5-review.googlesource.com/c/16382 Reviewed-by: Daniel Carvalho Reviewed-by: Andreas Sandberg Maintainer: Jason Lowe-Power --- diff --git a/src/base/str.hh b/src/base/str.hh index 61022bd26..1ea18b70d 100644 --- a/src/base/str.hh +++ b/src/base/str.hh @@ -40,6 +40,7 @@ #include #include #include +#include #include #include "base/logging.hh" @@ -108,8 +109,7 @@ tokenize(std::vector &vector, const std::string &s, * integeral type, as well as enums and floating-point types. */ template -typename std::enable_if<(std::is_integral::value || - std::is_enum::value) && +typename std::enable_if::value && std::is_signed::value, T>::type __to_number(const std::string &value) { @@ -121,8 +121,7 @@ __to_number(const std::string &value) } template -typename std::enable_if<(std::is_integral::value || - std::is_enum::value) && +typename std::enable_if::value && !std::is_signed::value, T>::type __to_number(const std::string &value) { @@ -133,6 +132,14 @@ __to_number(const std::string &value) return static_cast(r); } +template +typename std::enable_if::value, T>::type +__to_number(const std::string &value) +{ + auto r = __to_number::type>(value); + return static_cast(r); +} + template typename std::enable_if::value, T>::type __to_number(const std::string &value)