1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/base/Unit.h
12 #ifndef ZYPP_BASE_UNIT_H
13 #define ZYPP_BASE_UNIT_H
18 ///////////////////////////////////////////////////////////////////
20 { /////////////////////////////////////////////////////////////////
21 ///////////////////////////////////////////////////////////////////
23 { /////////////////////////////////////////////////////////////////
25 ///////////////////////////////////////////////////////////////////
29 /** Simple handling of Units.
31 * Unit stores factor and symbol, and a precision value for printing.
32 * \ref form builds a string from a value according to the format
35 * static const Unit B( 1, "B", 0 );
36 * static const Unit K( 1024, "K", 1 );
37 * static const Unit M( 1048576, "M", 1 );
38 * static const Unit G( 1073741824, "G", 2 );
39 * static const Unit T( 1099511627776, "T", 3 );
45 typedef long long ValueType;
54 Unit( ValueType factor_r, std::string symbol_r, unsigned prec_r )
60 ValueType factor() const
63 const std::string & symbol() const
69 /** Build string representation of \a val_r. */
70 std::string form( ValueType val_r,
71 unsigned field_width_r = 0,
72 unsigned unit_width_r = 1 ) const
73 { return form( val_r, field_width_r, unit_width_r, _prec ); }
75 std::string form( ValueType val_r,
76 unsigned field_width_r,
77 unsigned unit_width_r,
78 unsigned prec_r ) const
79 { return form( double(val_r)/_factor, _symbol,
80 field_width_r, unit_width_r, prec_r ); }
83 static std::string form( double val_r,
84 const std::string & symbol_r,
85 unsigned field_width_r,
86 unsigned unit_width_r,
94 ///////////////////////////////////////////////////////////////////
97 /////////////////////////////////////////////////////////////////
99 ///////////////////////////////////////////////////////////////////
100 /////////////////////////////////////////////////////////////////
102 ///////////////////////////////////////////////////////////////////
103 #endif // ZYPP_BASE_UNIT_H