libzypp 17.37.10

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{
25 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:
93 ValueType _factor;
94 std::string _symbol;
95 unsigned _prec;
96 };
97
98
99
101 } // namespace base
104} // namespace zypp
106#endif // ZYPP_BASE_UNIT_H
zypp::base::Unit::Unit
Unit(ValueType factor_r, std::string symbol_r, unsigned prec_r)
ctor
Definition Unit.h:57
zypp::base::Unit::_factor
ValueType _factor
Definition Unit.h:93
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:73
zypp::base::Unit::_prec
unsigned _prec
Definition Unit.h:95
zypp::base::Unit::Unit
Unit()
Default ctor.
Definition Unit.h:51
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:78
zypp::base::Unit::ValueType
long long ValueType
Definition Unit.h:48
zypp::base::Unit::factor
ValueType factor() const
Definition Unit.h:63
zypp::base::Unit::prec
unsigned prec() const
Definition Unit.h:69
zypp::base::Unit::_symbol
std::string _symbol
Definition Unit.h:94
zypp::base::Unit::symbol
const std::string & symbol() const
Definition Unit.h:66
form
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition String.cc:39
std
Definition Arch.h:364
zypp::base
Definition Random.cc:7
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition Application.cc:20
zypp::ZYPP_API
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition Arch.h:247
Globals.h