libzypp  17.32.4
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 #include <utility>
18 
20 namespace zypp
21 {
22  namespace base
24  {
25 
27  //
28  // CLASS NAME : Unit
29  //
43  class Unit
44  {
45  public:
46  using ValueType = long long;
47 
49  Unit()
50  : _factor( 1 )
51  , _prec( 0 )
52  {}
53 
55  Unit( ValueType factor_r, std::string symbol_r, unsigned prec_r )
56  : _factor( factor_r )
57  , _symbol(std::move( symbol_r ))
58  , _prec( prec_r )
59  {}
60 
61  ValueType factor() const
62  { return _factor; }
63 
64  const std::string & symbol() const
65  { return _symbol; }
66 
67  unsigned prec() const
68  { return _prec; }
69 
71  std::string form( ValueType val_r,
72  unsigned field_width_r = 0,
73  unsigned unit_width_r = 1 ) const
74  { return form( val_r, field_width_r, unit_width_r, _prec ); }
75 
76  std::string form( ValueType val_r,
77  unsigned field_width_r,
78  unsigned unit_width_r,
79  unsigned prec_r ) const
80  { return form( double(val_r)/_factor, _symbol,
81  field_width_r, unit_width_r, prec_r ); }
82 
83 
84  static std::string form( double val_r,
85  const std::string & symbol_r,
86  unsigned field_width_r,
87  unsigned unit_width_r,
88  unsigned prec_r );
89 
90  private:
92  std::string _symbol;
93  unsigned _prec;
94  };
96 
97 
99  } // namespace base
102 } // namespace zypp
104 #endif // ZYPP_BASE_UNIT_H
Unit()
Default ctor.
Definition: Unit.h:49
ValueType factor() const
Definition: Unit.h:61
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:71
Definition: Arch.h:363
ValueType _factor
Definition: Unit.h:91
unsigned _prec
Definition: Unit.h:93
long long ValueType
Definition: Unit.h:46
unsigned prec() const
Definition: Unit.h:67
Simple handling of Units.
Definition: Unit.h:43
const std::string & symbol() const
Definition: Unit.h:64
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19
Unit(ValueType factor_r, std::string symbol_r, unsigned prec_r)
ctor
Definition: Unit.h:55
std::string _symbol
Definition: Unit.h:92
std::string form(ValueType val_r, unsigned field_width_r, unsigned unit_width_r, unsigned prec_r) const
Definition: Unit.h:76