22 #include <boost/io/ios_state.hpp> 32 char const SIPrefix[] = {
'y',
'z',
'a',
'f',
'p',
'n',
'u',
'm',
34 'k',
'M',
'G',
'T',
'P',
'E',
'Z',
'Y' };
35 unsigned const SIScales = 8;
41 boost::io::ios_base_all_saver ibas (os);
42 boost::io::ios_fill_saver ifs (os);
44 os.setf(v_.flags_, v_.mask_);
45 if (v_.havePrecision_)
46 os.precision(v_.precision_);
52 unsigned prec (os.precision());
55 unsigned w (os.width());
56 char fill (os.fill());
57 unsigned minw (prec+2+((os.flags() & std::ios_base::showbase) ? 1 : 4));
58 std::ios_base::fmtflags flags (os.flags());
59 std::ios_base::fmtflags align (flags & std::ios_base::adjustfield);
60 if (! std::isnan(v_.d_))
63 float ref (std::fabs(v_.v_));
66 if (! std::isnan(v_.d_)) d = std::fabs(v_.d_);
70 while (ref >= 1000.0f) {
76 while (ref > 0 && ref < 1) {
83 os << std::dec << std::setprecision(prec-3) << std::fixed;
85 if ((align == 0 || align == std::ios_base::right || align == std::ios_base::internal))
86 os << std::setw(prec+2+(w>minw ? w-minw : 0));
88 os << std::right << std::setfill(
' ') << std::setw(prec+2);
94 os << std::setfill(
'0') << std::noshowpos;
95 if (! std::isnan(v_.d_)) {
98 os << std::setw(prec+1);
102 if ((flags & std::ios_base::showbase) &&
unsigned(std::abs(scale/3)) <= SIScales) {
103 if (w > 0 || scale != 0)
104 os << SIPrefix[scale/3+SIScales];
106 else if ((flags & std::ios_base::showpoint) || scale != 0)
107 os << ((flags & std::ios_base::uppercase)?
'E':
'e')
108 << std::showpos << std::internal << std::setw(3) << scale;
111 if (w > minw && align == std::ios_base::left)
112 os << std::setfill(fill) << std::setw(w-minw) <<
"";
117 prefix_ std::string senf::format::detail::dumpintSigned(
long long v,
unsigned bits)
119 if (v<0)
return dumpintUnsigned(-v,bits,-1);
120 else return dumpintUnsigned(v,bits,+1);
123 prefix_ std::string senf::format::detail::dumpintUnsigned(
unsigned long long v,
unsigned bits,
126 int bytes ((bits+7)/8);
127 int digs (
int(2.4*bytes)+1);
128 std::stringstream ss;
129 ss << (sign ? (sign<0 ?
"-" :
" ") :
"")
130 <<
"0x" << std::setw(2*bytes) << std::setfill(
'0') << std::hex
132 <<
" (" << std::setw(digs+(sign ? 1 : 0)) << std::setfill(
' ') << std::dec;
134 ss << sign*static_cast<long long>(v);
138 for (
int i (bytes-1); i>=0; --i) {
139 char c ((v>>(8*i))&0xff);
140 ss << ((c>=32 && c<=126) ? c :
'.');
146 unsigned int senf::format::IndentHelper::static_level = 0;
std::ostream & operator<<(std::ostream &os, Packet const &packet)
PacketParserBase::size_type bytes(Parser const &p)