libzypp 17.37.17
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
22namespace zypp
23{
25 namespace base
26 {
27
29 //
30 // CLASS NAME : Unit
31 //
46 {
47 public:
48 using ValueType = long long;
49
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
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 };
97
98
99
101 } // namespace base
104} // namespace zypp
106#endif // ZYPP_BASE_UNIT_H
Unit(ValueType factor_r, std::string symbol_r, unsigned prec_r)
ctor
Definition Unit.h:57
ValueType _factor
Definition Unit.h:93
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
unsigned _prec
Definition Unit.h:95
Unit()
Default ctor.
Definition Unit.h:51
std::string form(ValueType val_r, unsigned field_width_r, unsigned unit_width_r, unsigned prec_r) const
Definition Unit.h:78
long long ValueType
Definition Unit.h:48
ValueType factor() const
Definition Unit.h:63
unsigned prec() const
Definition Unit.h:69
std::string _symbol
Definition Unit.h:94
const std::string & symbol() const
Definition Unit.h:66
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition String.cc:39
Definition Arch.h:364
Easy-to use interface to the ZYPP dependency resolver.
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition Arch.h:247