libzypp: zypp-core/base/Unit.h Source File

libzypp 17.38.9

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-core/Globals.h>
20
22namespace 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
Globals.h
Provides API related macros.
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 ansi.h:855
zypp::base
Definition Random.cc:7
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::ZYPP_API
const Arch Arch_empty ZYPP_API
relates: Arch This is an empty Arch represented by an empty string.
Definition Arch.h:173