libzypp  17.35.8
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 
19 #include <zypp/Globals.h>
20 
22 namespace zypp
23 {
24  namespace base
26  {
27 
29  //
30  // CLASS NAME : Unit
31  //
45  class ZYPP_API Unit
46  {
47  public:
48  using ValueType = long long;
49 
51  Unit()
52  : _factor( 1 )
53  , _prec( 0 )
54  {}
55 
57  Unit( ValueType factor_r, std::string symbol_r, unsigned prec_r )
58  : _factor( factor_r )
59  , _symbol(std::move( symbol_r ))
60  , _prec( prec_r )
61  {}
62 
63  ValueType factor() const
64  { return _factor; }
65 
66  const std::string & symbol() const
67  { return _symbol; }
68 
69  unsigned prec() const
70  { return _prec; }
71 
73  std::string form( ValueType val_r,
74  unsigned field_width_r = 0,
75  unsigned unit_width_r = 1 ) const
76  { return form( val_r, field_width_r, unit_width_r, _prec ); }
77 
78  std::string form( ValueType val_r,
79  unsigned field_width_r,
80  unsigned unit_width_r,
81  unsigned prec_r ) const
82  { return form( double(val_r)/_factor, _symbol,
83  field_width_r, unit_width_r, prec_r ); }
84 
85 
86  static std::string form( double val_r,
87  const std::string & symbol_r,
88  unsigned field_width_r,
89  unsigned unit_width_r,
90  unsigned prec_r );
91 
92  private:
94  std::string _symbol;
95  unsigned _prec;
96  };
98 
99 
101  } // namespace base
104 } // namespace zypp
106 #endif // ZYPP_BASE_UNIT_H
Unit()
Default ctor.
Definition: Unit.h:51
ValueType factor() const
Definition: Unit.h:63
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:73
Definition: Arch.h:363
ValueType _factor
Definition: Unit.h:93
unsigned _prec
Definition: Unit.h:95
long long ValueType
Definition: Unit.h:48
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition: String.cc:37
unsigned prec() const
Definition: Unit.h:69
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition: ResTraits.h:93
Simple handling of Units.
Definition: Unit.h:45
const std::string & symbol() const
Definition: Unit.h:66
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:57
std::string _symbol
Definition: Unit.h:94
std::string form(ValueType val_r, unsigned field_width_r, unsigned unit_width_r, unsigned prec_r) const
Definition: Unit.h:78