00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #include "sysc/utils/sc_iostream.h"
00047 #include "sysc/datatypes/int/sc_unsigned.h"
00048 #include "sysc/datatypes/int/sc_signed.h"
00049 #include "sysc/datatypes/int/sc_int_base.h"
00050 #include "sysc/datatypes/int/sc_uint_base.h"
00051
00052
00053 #if defined( _MSC_VER )
00054
00055 namespace sc_dt
00056 {
00057
00058 static void
00059 write_uint64(::std::ostream& os, uint64 val, int sign)
00060 {
00061 const int WRITE_BUF_SIZE = 10 + sizeof(uint64)*3;
00062 char buf[WRITE_BUF_SIZE];
00063 char* buf_ptr = buf + WRITE_BUF_SIZE;
00064 const char* show_base = "";
00065 int show_base_len = 0;
00066 int show_pos = 0;
00067 fmtflags flags = os.flags();
00068
00069 if ((flags & ::std::ios::basefield) == ::std::ios::oct) {
00070 do {
00071 *--buf_ptr = (char)((val & 7) + '0');
00072 val = val >> 3;
00073 } while (val != 0);
00074 if ((flags & ::std::ios::showbase) && (*buf_ptr != '0'))
00075 *--buf_ptr = '0';
00076 } else if ((flags & ::std::ios::basefield) == ::std::ios::hex) {
00077 const char* xdigs = (flags & ::std::ios::uppercase) ?
00078 "0123456789ABCDEF0X" :
00079 "0123456789abcdef0x";
00080 do {
00081 *--buf_ptr = xdigs[val & 15];
00082 val = val >> 4;
00083 } while (val != 0);
00084 if ((flags & ::std::ios::showbase)) {
00085 show_base = xdigs + 16;
00086 show_base_len = 2;
00087 }
00088 } else {
00089 while (val > UINT_MAX) {
00090 *--buf_ptr = (char)((val % 10) + '0');
00091 val /= 10;
00092 }
00093 unsigned ival = (unsigned) val;
00094 do {
00095 *--buf_ptr = (ival % 10) + '0';
00096 ival /= 10;
00097 } while (ival != 0);
00098 if (sign > 0 && (flags & ::std::ios::showpos))
00099 show_pos = 1;
00100 }
00101
00102 int buf_len = buf + WRITE_BUF_SIZE - buf_ptr;
00103 int w = os.width(0);
00104
00105 int len = buf_len + show_pos;
00106 if (sign < 0) len++;
00107 len += show_base_len;
00108
00109 int padding = len > w ? 0 : w - len;
00110 fmtflags pad_kind = flags & ::std::ios::adjustfield;
00111 char fill_char = os.fill();
00112
00113 if (padding > 0 &&
00114 ::std::ios::left != pad_kind &&
00115 ::std::ios::internal != pad_kind) {
00116 for (int i = padding - 1; i >= 0; --i) {
00117 if (! os.put(fill_char))
00118 goto fail;
00119 }
00120 }
00121 if (sign < 0 || show_pos) {
00122 if (! os.put(sign < 0 ? '-' : '+'))
00123 goto fail;
00124 }
00125 if (show_base_len) {
00126 if (! os.write(show_base, show_base_len))
00127 goto fail;
00128 }
00129 if ((fmtflags)::std::ios::internal == pad_kind && padding > 0) {
00130 for (int i = padding - 1; i >= 0; --i) {
00131 if (! os.put(fill_char))
00132 goto fail;
00133 }
00134 }
00135 if (! os.write(buf_ptr, buf_len))
00136 goto fail;
00137 if ((fmtflags)::std::ios::left == pad_kind && padding > 0) {
00138 for (int i = padding - 1; i >= 0; --i) {
00139 if (! os.put(fill_char))
00140 goto fail;
00141 }
00142 }
00143 os.osfx();
00144 return;
00145 fail:
00146
00147 os.osfx();
00148 }
00149
00150 ::std::ostream&
00151 operator << ( ::std::ostream& os, int64 n )
00152 {
00153 if (os.opfx()) {
00154 int sign = 1;
00155 uint64 abs_n = (uint64) n;
00156 if (n < 0 && (os.flags() & (::std::ios::oct|::std::ios::hex)) == 0) {
00157 abs_n = -1*((uint64) n);
00158 sign = -1;
00159 }
00160 sc_dt::write_uint64(os, abs_n, sign);
00161 }
00162 return os;
00163 }
00164
00165 ::std::ostream&
00166 operator << ( ::std::ostream& os, uint64 n )
00167 {
00168 if (os.opfx()) {
00169 sc_dt::write_uint64(os, n, 0);
00170 }
00171 return os;
00172 }
00173
00174 }
00175
00176
00177 #endif