[gem5-dev] Change in gem5/gem5[master]: base: Make it possible to convert strings to enums

2019-01-10 Thread Giacomo Travaglini (Gerrit)
Giacomo Travaglini has submitted this change and it was merged. (  
https://gem5-review.googlesource.com/c/public/gem5/+/15336 )


Change subject: base: Make it possible to convert strings to enums
..

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 
Reviewed-by: Ciro Santilli 
Reviewed-by: Andreas Sandberg 
Reviewed-by: Nikos Nikoleris 
Reviewed-on: https://gem5-review.googlesource.com/c/15336
Reviewed-by: Gabe Black 
Maintainer: Andreas Sandberg 
---
M src/base/str.hh
1 file changed, 8 insertions(+), 3 deletions(-)

Approvals:
  Gabe Black: Looks good to me, approved
  Andreas Sandberg: Looks good to me, approved



diff --git a/src/base/str.hh b/src/base/str.hh
index 52ab977..61022bd 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 @@
  * @{
  *
  * @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 
-typename std::enable_if::value &&
+typename std::enable_if<(std::is_integral::value ||
+std::is_enum::value) &&
 std::is_signed::value, T>::type
 __to_number(const std::string )
 {
@@ -117,7 +121,8 @@
 }

 template 
-typename std::enable_if::value &&
+typename std::enable_if<(std::is_integral::value ||
+std::is_enum::value) &&
 !std::is_signed::value, T>::type
 __to_number(const std::string )
 {

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/15336
To unsubscribe, or for help writing mail filters, visit  
https://gem5-review.googlesource.com/settings


Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: I74069cc4c04ec8b5eb80939acea7ab18fb366dd4
Gerrit-Change-Number: 15336
Gerrit-PatchSet: 2
Gerrit-Owner: Giacomo Travaglini 
Gerrit-Reviewer: Andreas Sandberg 
Gerrit-Reviewer: Ciro Santilli 
Gerrit-Reviewer: Gabe Black 
Gerrit-Reviewer: Giacomo Travaglini 
Gerrit-Reviewer: Nikos Nikoleris 
Gerrit-MessageType: merged
___
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev

[gem5-dev] Change in gem5/gem5[master]: base: Make it possible to convert strings to enums

2019-01-08 Thread Giacomo Travaglini (Gerrit)

Hello Nikos Nikoleris, Andreas Sandberg, Ciro Santilli,

I'd like you to do a code review. Please visit

https://gem5-review.googlesource.com/c/public/gem5/+/15336

to review the following change.


Change subject: base: Make it possible to convert strings to enums
..

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 
Reviewed-by: Ciro Santilli 
Reviewed-by: Andreas Sandberg 
Reviewed-by: Nikos Nikoleris 
---
M src/base/str.hh
1 file changed, 8 insertions(+), 3 deletions(-)



diff --git a/src/base/str.hh b/src/base/str.hh
index 52ab977..61022bd 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 @@
  * @{
  *
  * @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 
-typename std::enable_if::value &&
+typename std::enable_if<(std::is_integral::value ||
+std::is_enum::value) &&
 std::is_signed::value, T>::type
 __to_number(const std::string )
 {
@@ -117,7 +121,8 @@
 }

 template 
-typename std::enable_if::value &&
+typename std::enable_if<(std::is_integral::value ||
+std::is_enum::value) &&
 !std::is_signed::value, T>::type
 __to_number(const std::string )
 {

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/15336
To unsubscribe, or for help writing mail filters, visit  
https://gem5-review.googlesource.com/settings


Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: I74069cc4c04ec8b5eb80939acea7ab18fb366dd4
Gerrit-Change-Number: 15336
Gerrit-PatchSet: 1
Gerrit-Owner: Giacomo Travaglini 
Gerrit-Reviewer: Andreas Sandberg 
Gerrit-Reviewer: Ciro Santilli 
Gerrit-Reviewer: Nikos Nikoleris 
Gerrit-MessageType: newchange
___
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev