strnumtest.cc revision 1762
13630SN/A/*
27090SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan
37090SN/A * All rights reserved.
47090SN/A *
57090SN/A * Redistribution and use in source and binary forms, with or without
67090SN/A * modification, are permitted provided that the following conditions are
77090SN/A * met: redistributions of source code must retain the above copyright
87090SN/A * notice, this list of conditions and the following disclaimer;
97090SN/A * redistributions in binary form must reproduce the above copyright
107090SN/A * notice, this list of conditions and the following disclaimer in the
117090SN/A * documentation and/or other materials provided with the distribution;
127090SN/A * neither the name of the copyright holders nor the names of its
137090SN/A * contributors may be used to endorse or promote products derived from
143630SN/A * this software without specific prior written permission.
153630SN/A *
163630SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
173630SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
183630SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
193630SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
203630SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
213630SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
223630SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
233630SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
243630SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
253630SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
263630SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
273630SN/A */
283630SN/A
293630SN/A#include <iostream.h>
303630SN/A
313630SN/A#include <string>
323630SN/A#include <vector>
333630SN/A
343630SN/A#include "base/str.hh"
353630SN/A
363630SN/Ausing namespace std;
373630SN/A
383630SN/Aint
393630SN/Amain(int argc, char *argv[])
403630SN/A{
413630SN/A  if (argc != 2) {
423630SN/A    cout << "Usage: " << argv[0] << " <number>\n";
433630SN/A    exit(1);
443630SN/A  }
457584SAli.Saidi@arm.com
463630SN/A  string s = argv[1];
473630SN/A
483630SN/A#define OUTVAL(valtype, type) do { \
497584SAli.Saidi@arm.com  valtype value; \
507584SAli.Saidi@arm.com  cout << "TYPE = " #valtype "\n"; \
513630SN/A  if (to_number(s, value)) { \
523630SN/A    cout << "Number(" << s << ") = " << dec \
537584SAli.Saidi@arm.com      << (unsigned long long)(unsigned type)value << "\n" \
543630SN/A      << "Number(" << s << ") = " << dec \
559525SAndreas.Sandberg@ARM.com      << (signed long long)(signed type)value << "\n" \
563630SN/A      << "Number(" << s << ") = 0x" << hex \
573630SN/A      << (unsigned long long)(unsigned type)value << "\n" \
583630SN/A      << "Number(" << s << ") = 0" << oct \
597584SAli.Saidi@arm.com      << (unsigned long long)(unsigned type)value << "\n\n"; \
603630SN/A  } else \
613630SN/A    cout << "Number(" << s << ") is invalid\n\n"; \
623630SN/A  } while (0)
633630SN/A
643630SN/A  OUTVAL(signed long long, long long);
659525SAndreas.Sandberg@ARM.com  OUTVAL(unsigned long long, long long);
668525SAli.Saidi@ARM.com  OUTVAL(signed long, long);
673630SN/A  OUTVAL(unsigned long, long);
687584SAli.Saidi@arm.com  OUTVAL(signed int, int);
698525SAli.Saidi@ARM.com  OUTVAL(unsigned int, int);
708525SAli.Saidi@ARM.com  OUTVAL(signed short, short);
718525SAli.Saidi@ARM.com  OUTVAL(unsigned short, short);
728525SAli.Saidi@ARM.com  OUTVAL(signed char, char);
738525SAli.Saidi@ARM.com  OUTVAL(unsigned char, char);
743630SN/A
753630SN/A  return 0;
763630SN/A}
773630SN/A