ARM: Implement WFE/WFI/SEV semantics.
[gem5.git] / src / base / str.cc
index 5f7f50286efff3fd5a275e216781472014623886..1e2be95a8819bcc573243e88d0c9c41f2221635a 100644 (file)
  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Nathan Binkert
  */
 
-#include <ctype.h>
-
+#include <cctype>
 #include <cstring>
 #include <iostream>
+#include <limits>
 #include <string>
 #include <vector>
 
@@ -115,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
@@ -333,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)