summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiacomo Travaglini <giacomo.travaglini@arm.com>2019-01-08 10:17:39 +0000
committerGiacomo Travaglini <giacomo.travaglini@arm.com>2019-01-10 12:36:31 +0000
commit7d5696d1a9f0776f51ec20e81a413fcdcc748c4e (patch)
treeb036a33cdcc7fea89911c331a20a8461cba7f0be
parent85931deb5dee9f465811a2dd792cc398521e55d4 (diff)
downloadgem5-7d5696d1a9f0776f51ec20e81a413fcdcc748c4e.tar.xz
base: Make it possible to convert strings to enums
The __to_number helper function defined in base/str.hh is used by unserializing code. Its purpose is to convert a string into an integral/floating point number. Since enums underlying type can only be an integer type, it makes sense to extend the helper function for enums as well. In this way it will be possible to unserialize Enums and containers of Enums without the need of casting. Change-Id: I74069cc4c04ec8b5eb80939acea7ab18fb366dd4 Signed-off-by: Giacomo Travaglini <giacomo.travaglini@arm.com> Reviewed-by: Ciro Santilli <ciro.santilli@arm.com> Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com> Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com> Reviewed-on: https://gem5-review.googlesource.com/c/15336 Reviewed-by: Gabe Black <gabeblack@google.com> Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>
-rw-r--r--src/base/str.hh11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/base/str.hh b/src/base/str.hh
index 52ab977fc..61022bd26 100644
--- a/src/base/str.hh
+++ b/src/base/str.hh
@@ -1,4 +1,7 @@
/*
+ * Copyright (c) 2018 ARM Limited
+ * All rights reserved
+ *
* Copyright (c) 2001-2005 The Regents of The University of Michigan
* All rights reserved.
*
@@ -102,10 +105,11 @@ tokenize(std::vector<std::string> &vector, const std::string &s,
* @{
*
* @name String to number helper functions for signed and unsigned
- * integeral type, as well as floating-point types.
+ * integeral type, as well as enums and floating-point types.
*/
template <class T>
-typename std::enable_if<std::is_integral<T>::value &&
+typename std::enable_if<(std::is_integral<T>::value ||
+ std::is_enum<T>::value) &&
std::is_signed<T>::value, T>::type
__to_number(const std::string &value)
{
@@ -117,7 +121,8 @@ __to_number(const std::string &value)
}
template <class T>
-typename std::enable_if<std::is_integral<T>::value &&
+typename std::enable_if<(std::is_integral<T>::value ||
+ std::is_enum<T>::value) &&
!std::is_signed<T>::value, T>::type
__to_number(const std::string &value)
{