4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief Format public header */
26 #ifndef HH_SENF_senf_Utils_Format_
27 #define HH_SENF_senf_Utils_Format_ 1
32 #include <boost/utility/enable_if.hpp>
33 #include <boost/type_traits/is_signed.hpp>
34 #include <boost/type_traits/is_unsigned.hpp>
36 //#include "Format.mpp"
37 ///////////////////////////////hh.p////////////////////////////////////////
42 /** \defgroup senf_utils_format Formating
47 /** \brief Format value in engineering representation
49 The engineering representation is an exponential representation. Exponents however are
50 always multiples of 3:
53 123.45e2 -> 12.345e+03
56 Additionally, an optional delta value may be displayed:
61 senf::format::eng supports several formating options:
63 If the width is set >0, the output will be padded internally. If the width is set to
64 more than the minimal required output width including internal padding, the output is
65 padded on the left or right depending on the streams \c ajustfield setting (changed
66 with \c std::left, \c std:;right or \c std::interal). If the \c adjustfield is set to \c
67 internal, padding is added between the sign and the number.
69 \par \c std::\c setprecision()
70 The default stream precision is 6. This will schow values with 6 significant digits. The
71 count includes the number of digits in front of the decimal point.
73 \par \c std::\c showbase
74 If the \c showbase flag is set, Instead of writing out the scale exponent in numeric
75 form, output the corresponding SI prefix.
77 \par \c std::\c showpos
78 If the \c showpos flag is set, positive values will have a '+' sign.
80 \par \c std::\c showpoint
81 If the \c showpoint flag is set, the exponent will be output even if it is 0. Otherwise,
82 if \c width is set, the exponent will be replaced with 4 blanks.
84 \par \c std::\c uppercase
85 If the \c uppercase flag is set, the exponent letter will be an uppercase 'E' instead of
86 'e'. SI prefixes are \e not uppercased, since some SI prefixes differ only in case.
88 \par \c std::\c setfill()
89 The fill character is honored for the outside padding but \e not for the internal
94 os << senf::format::eng(1.23);
96 os << std::setw(1) << senf::format::eng(1.23);
98 os << std::setw(25) << std::setprecision(5) << std::showpos << std::uppercase
99 << std::internal << senf::format::eng(12345,67);
100 -> "+ 12.35+-000.07E+03"
101 os << std::showbase << senf::format::eng(12345,67);
106 \param[in] d optional delta
108 \ingroup senf_utils_format
110 streamable_type eng(double v, double d=NAN);
116 eng(double v_, double d_ = std::numeric_limits<double>::quiet_NaN());
122 std::ostream & operator<<(std::ostream & os, eng const & v);
128 /** \brief Dump integer value with internal representation
130 senf::format::dumpint() will output a signed or unsigned numeric argument in the following
132 \li hexadecimal notation
134 \li byte values interpreted as ASCII characters (in network byte order)
136 All fields will be padded depending on the size of the type to a byte boundary (e.g. a 32bit
137 integer type will be padded to 8 hex-digits, 10 decimal digits and 4 ASCII characters)
139 \ingroup senf_utils_format
142 streamable_type dumpint(T const & v);
147 std::string dumpint(T const & v,
148 typename boost::enable_if<boost::is_signed<T> >::type * = 0);
151 std::string dumpint(T const & v,
152 typename boost::enable_if<boost::is_unsigned<T> >::type * = 0);
158 ///////////////////////////////hh.e////////////////////////////////////////
159 #include "Format.cci"
160 //#include "Format.ct"
161 #include "Format.cti"
168 // comment-column: 40
169 // c-file-style: "senf"
170 // indent-tabs-mode: nil
171 // ispell-local-dictionary: "american"
172 // compile-command: "scons -u test"