libzypp  17.25.2
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  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
zypp::base::Unit::_factor
ValueType _factor
Definition: Unit.h:90
zypp::base::Unit::form
std::string form(ValueType val_r, unsigned field_width_r, unsigned unit_width_r, unsigned prec_r) const
Definition: Unit.h:75
zypp::base::Unit::_symbol
std::string _symbol
Definition: Unit.h:91
zypp::base::Unit
Simple handling of Units.
Definition: Unit.h:43
zypp::base::Unit::symbol
const std::string & symbol() const
Definition: Unit.h:63
zypp::base::Unit::Unit
Unit()
Default ctor.
Definition: Unit.h:48
zypp::base::Unit::prec
unsigned prec() const
Definition: Unit.h:66
zypp::base::Unit::form
std::string form(ValueType val_r, unsigned field_width_r=0, unsigned unit_width_r=1) const
Build string representation of val_r.
Definition: Unit.h:70
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
zypp::base::Unit::ValueType
long long ValueType
Definition: Unit.h:45
zypp::base::Unit::factor
ValueType factor() const
Definition: Unit.h:60
zypp::base::Unit::Unit
Unit(ValueType factor_r, std::string symbol_r, unsigned prec_r)
ctor
Definition: Unit.h:54
zypp::base::Unit::_prec
unsigned _prec
Definition: Unit.h:92