garnet: added orion2.0 for network power calculation
[gem5.git] / src / base / str.cc
index 0a517dff5d44f63848f6c131a0a76316ad21b16c..1e2be95a8819bcc573243e88d0c9c41f2221635a 100644 (file)
  * Authors: Nathan Binkert
  */
 
-#include <ctype.h>
-
+#include <cctype>
 #include <cstring>
 #include <iostream>
+#include <limits>
 #include <string>
 #include <vector>
 
@@ -117,12 +117,11 @@ inline bool
 __to_number(string value, T &retval)
 {
     static const T maxnum = ((T)-1);
-    static const bool sign = maxnum < 0;
-    static const int bits = sizeof(T) * 8;
-    static const T hexmax = maxnum & (((T)1 << (bits - 4 - sign)) - 1);
-    static const T octmax = maxnum & (((T)1 << (bits - 3 - sign)) - 1);
-    static const T signmax =
-        (sign) ? maxnum & (((T)1 << (bits - 1)) - 1) : maxnum;
+    static const bool sign = numeric_limits<T>::is_signed;
+    static const int bits = numeric_limits<T>::digits;
+    static const T hexmax = maxnum & (((T)1 << (bits - 4)) - 1);
+    static const T octmax = maxnum & (((T)1 << (bits - 3)) - 1);
+    static const T signmax = numeric_limits<T>::max();
     static const T decmax = signmax / 10;
 
 #if 0
@@ -335,6 +334,7 @@ STN(unsigned short);
 STN(signed short);
 STN(unsigned char);
 STN(signed char);
+STN(char);
 
 template<>
 bool to_number<bool>(const string &value, bool &retval)