00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef TOOL_SI_HXX_
00023 # define TOOL_SI_HXX_
00024
00025 # include <cmath>
00026 # include <iomanip>
00027
00028 # include "si.hh"
00029
00030 namespace tool
00031 {
00032
00033 namespace internals
00034 {
00035
00036 template <size_t OneUnitInBits>
00037 SI_unit<OneUnitInBits>::SI_unit(uint64_t count):
00038 bits_ (count * OneUnitInBits)
00039 {
00040 }
00041
00042 template <size_t OneUnitInBits>
00043 template <size_t OneRHSUnitInBits>
00044 SI_unit<OneUnitInBits>::
00045 SI_unit(const SI_unit<OneRHSUnitInBits>& rhs): bits_ (rhs.bits())
00046 {
00047 }
00048
00049 template <size_t OneUnitInBits>
00050 uint64_t
00051 SI_unit<OneUnitInBits>::bits() const
00052 {
00053 return bits_;
00054 }
00055
00056 template <size_t OneUnitInBits>
00057 uint64_t
00058 SI_unit<OneUnitInBits>::bytes() const
00059 {
00060 return bits_ / 8;
00061 }
00062
00063 template <size_t OneUnitInBits>
00064 std::string
00065 SI_unit<OneUnitInBits>::abbrev()
00066 {
00067 return abbrev_;
00068 }
00069
00070 template <size_t OneUnitInBits>
00071 std::ostream&
00072 operator << (std::ostream& os, const SI_unit<OneUnitInBits>& unit)
00073 {
00074 const std::streamsize default_p = os.precision();
00075 const std::ios::fmtflags default_f = os.flags();
00076 const double v = unit.bits() / OneUnitInBits;
00077 const std::string u = SI_unit<OneUnitInBits>::abbrev();
00078
00079 return os << std::fixed << std::setprecision (0)
00080 << std::floor(v + 0.5) << ' ' << u
00081 << std::setprecision (default_p)
00082 << std::resetiosflags (~default_f)
00083 << std::setiosflags (default_f);
00084 }
00085
00086 }
00087
00088 }
00089
00090 #endif // ! TOOL_SI_HXX_