libzypp  11.13.5
Unit.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_BASE_UNIT_H
13 #define ZYPP_BASE_UNIT_H
14 
15 #include <iosfwd>
16 #include <string>
17 
19 namespace zypp
20 {
21 
22  namespace base
23  {
24 
26  //
27  // CLASS NAME : Unit
28  //
42  class Unit
43  {
44  public:
45  typedef long long ValueType;
46 
48  Unit()
49  : _factor( 1 )
50  , _prec( 0 )
51  {}
52 
54  Unit( ValueType factor_r, std::string symbol_r, unsigned prec_r )
55  : _factor( factor_r )
56  , _symbol( symbol_r )
57  , _prec( prec_r )
58  {}
59 
60  ValueType factor() const
61  { return _factor; }
62 
63  const std::string & symbol() const
64  { return _symbol; }
65 
66  unsigned prec() const
67  { return _prec; }
68 
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 ); }
74 
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 ); }
81 
82 
83  static std::string form( double val_r,
84  const std::string & symbol_r,
85  unsigned field_width_r,
86  unsigned unit_width_r,
87  unsigned prec_r );
88 
89  private:
91  std::string _symbol;
92  unsigned _prec;
93  };
95 
96 
98  } // namespace base
101 } // namespace zypp
103 #endif // ZYPP_BASE_UNIT_H