libzypp
10.5.0
|
00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00012 #ifndef ZYPP_BASE_UNIT_H 00013 #define ZYPP_BASE_UNIT_H 00014 00015 #include <iosfwd> 00016 #include <string> 00017 00019 namespace zypp 00020 { 00021 00022 namespace base 00023 { 00024 00026 // 00027 // CLASS NAME : Unit 00028 // 00042 class Unit 00043 { 00044 public: 00045 typedef long long ValueType; 00046 00048 Unit() 00049 : _factor( 1 ) 00050 , _prec( 0 ) 00051 {} 00052 00054 Unit( ValueType factor_r, std::string symbol_r, unsigned prec_r ) 00055 : _factor( factor_r ) 00056 , _symbol( symbol_r ) 00057 , _prec( prec_r ) 00058 {} 00059 00060 ValueType factor() const 00061 { return _factor; } 00062 00063 const std::string & symbol() const 00064 { return _symbol; } 00065 00066 unsigned prec() const 00067 { return _prec; } 00068 00070 std::string form( ValueType val_r, 00071 unsigned field_width_r = 0, 00072 unsigned unit_width_r = 1 ) const 00073 { return form( val_r, field_width_r, unit_width_r, _prec ); } 00074 00075 std::string form( ValueType val_r, 00076 unsigned field_width_r, 00077 unsigned unit_width_r, 00078 unsigned prec_r ) const 00079 { return form( double(val_r)/_factor, _symbol, 00080 field_width_r, unit_width_r, prec_r ); } 00081 00082 00083 static std::string form( double val_r, 00084 const std::string & symbol_r, 00085 unsigned field_width_r, 00086 unsigned unit_width_r, 00087 unsigned prec_r ); 00088 00089 private: 00090 ValueType _factor; 00091 std::string _symbol; 00092 unsigned _prec; 00093 }; 00095 00096 00098 } // namespace base 00101 } // namespace zypp 00103 #endif // ZYPP_BASE_UNIT_H